要在
objective-c中设置USB请求类型,请使用:
#define USBmakebmRequestType
例如:
IOUSBDevRequest request;
request.bmRequestType = USBmakebmRequestType(kUSBOut, kUSBVendor, kUSBDevice);
我如何在swift中使用它? swift中没有功能USBmakebmRequestType
最佳答案 我自己实现了:
func USBmakebmRequestType(direction:Int, type:Int, recipient:Int) -> UInt8 {
return UInt8((direction & kUSBRqDirnMask) << kUSBRqDirnShift)|UInt8((type & kUSBRqTypeMask) << kUSBRqTypeShift)|UInt8(recipient & kUSBRqRecipientMask)
}
用法:
USBmakebmRequestType(direction: kUSBIn, type: kUSBDevice, recipient: kUSBStandard)