I'm writing Java code with usb4java for communication with a measurement instrument connected through USB using control transfers (Windows). The data is transferred using a ByteBuffer populated with hexadecimal values expected by the device.
Here's the relevant fragment of code:
byte[] query = new byte[]{ 0x1d, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
ByteBuffer buffer = ByteBuffer.allocateDirect(8);
buffer.put(query);
buffer.rewind();
int transferred = LibUsb.controlTransfer(handle, (byte)0x21, (byte)0x1, (short)0, (short)0, buffer, 1000);
The code works fine, but whenever any value in the buffer is over 0x7F (127), an incorrect number is passed and the device doesn't respond properly.
I'm clearly hitting the limit of the signed byte type used in Java. But is there a way to get around it and get the correct value to the device?
These have been really tough few days and just as the problem appeared to be solved, I hit the wall with the byte size limit. Thanks in advance for any suggestions!