gary-rowe / hid4java

A cross-platform Java Native Access (JNA) wrapper for the libusb/hidapi library. Works out of the box on Windows/Mac/Linux.
MIT License
229 stars 71 forks source link

Writes of 1 byte size doesn't work fine #51

Closed alejandrosierra closed 7 years ago

alejandrosierra commented 7 years ago

Writing one byte size always writes 0. This seems to be because of the following conditional that checks for above one byte. File org.hid4java.jna.HidApi.java

Function write: public static int write(HidDeviceStructure device, byte[] data, int len, byte reportId)

Section: } else { // Put report ID into position 0 and fill out buffer
report = new WideStringBuffer(len + 1); report.buffer[0] = reportId; if (len > 1) { System.arraycopy(data, 0, report.buffer, 1, len); } I did the following: } else { // Put report ID into position 0 and fill out buffer
report = new WideStringBuffer(len + 1); report.buffer[0] = reportId; if (len > 0) { System.arraycopy(data, 0, report.buffer, 1, len); }

gary-rowe commented 7 years ago

Fixed in #41 .