Sending data via USB with parameters.
I would like to send data to my USB device, but all the examples only show whereby the request consists only with 1 byte data. My communication document state that I need to send request with parameters consists of 1 word data. How can I do that?
enum EsconRequest: UInt8 {
case GETSTATUS = 0x01
case ENABLE = 0x05
}
func systemEnable () throws {
guard let deviceInterface = self.deviceInfo.deviceInterfacePtrPtr?.pointee?.pointee else {
throw EsconDeviceError.DeviceInterfaceNotFound
}
var kr:Int32 = 0
let length:Int = 2
var requestPtr:[UInt16] = [UInt16](repeating: 0, count: length)
// creating request
var request = IOUSBDevRequest(bmRequestType: 161,
bRequest: EsconRequest.ENABLE.rawValue,
wValue: 0,
wIndex: 0,
wLength: UInt16(length),
pData: &requestPtr,
wLenDone: 255)
kr = deviceInterface.DeviceRequest(self.deviceInfo.deviceInterfacePtrPtr, &request)
if (kr != kIOReturnSuccess) {
throw EsconDeviceError.RequestError(desc: "Enable Device request Error: \(kr)")
}
}
I assume that My request consists of 1 Byte and my parameter consists of 1 word data, but in sequence that would be 3 bytes of data. How can I construct this request?