UsbSerialForAndroid icon indicating copy to clipboard operation
UsbSerialForAndroid copied to clipboard

The bulkTransfer supports offsets

Open IhorNehrutsa opened this issue 3 years ago • 0 comments

https://github.com/anotherlab/UsbSerialForAndroid/blob/b448a2cd61238dcc0268e53582ef6ec7db5908f9/UsbSerialForAndroid/driver/CdcAcmSerialDriver.cs#L365 https://github.com/anotherlab/UsbSerialForAndroid/blob/b448a2cd61238dcc0268e53582ef6ec7db5908f9/UsbSerialForAndroid/driver/Ch34xSerialDriver.cs#L183 https://github.com/anotherlab/UsbSerialForAndroid/blob/b448a2cd61238dcc0268e53582ef6ec7db5908f9/UsbSerialForAndroid/driver/FtdiSerialDriver.cs#L242 https://github.com/anotherlab/UsbSerialForAndroid/blob/b448a2cd61238dcc0268e53582ef6ec7db5908f9/UsbSerialForAndroid/driver/ProlificSerialDriver.cs#L483 https://github.com/anotherlab/UsbSerialForAndroid/blob/b448a2cd61238dcc0268e53582ef6ec7db5908f9/UsbSerialForAndroid/driver/STM32SerialDriver.cs#L196 There are 5 places in the code with the assertion that "bulkTransfer does not support offsets, make a copy."

But bulkTransfer has overloaded method whith offset parameter, see https://developer.android.com/reference/android/hardware/usb/UsbDeviceConnection#bulkTransfer(android.hardware.usb.UsbEndpoint,%20byte[],%20int,%20int,%20int)

public int bulkTransfer (UsbEndpoint endpoint, byte[] buffer, int offset, int length, int timeout)

It allows to reduce code(and make it faster) like in Cp21xxSerialDriver.cs https://github.com/IhorNehrutsa/UsbSerialForAndroid/blob/c805220355feb0de034f8ffa9ea9cb9ea47b24a0/UsbSerialForAndroid/driver/Cp21xxSerialDriver.cs#L210-L236

IhorNehrutsa avatar Sep 29 '22 05:09 IhorNehrutsa