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
223 stars 70 forks source link

Regression in `hidApiLibrary.hid_open_path(path)` v 0.8 #148

Closed laborg closed 2 months ago

laborg commented 3 months ago

Describe the problem A USB hardware device which can be opened with version 0.7 can't be opened with 0.8.

To Reproduce

  1. Call open(String path) from HidApi.java https://github.com/gary-rowe/hid4java/blob/abb9c7f17adcb1e8a006d56cecf1b6dfdbf59875/src/main/java/org/hid4java/jna/HidApi.java#L147C1-L147C51
  2. It returns null for version 0.8

Expected behavior Do not return null.

Platform:

Additional information The underlying hidapi library version 0.14.0 works in for the same device in Julia (https://julialang.org/), where I maintain the wrapper (https://github.com/laborg/HidApi.jl), so I think this is not a problem with hidapi 0.14.0.

gary-rowe commented 3 months ago

Thanks for reporting this. That code hasn't changed beyond documentation since inception so I'm inclined to suspect the underlying compilation of the hidapi library.

Can you give some more detail on the following:

laborg commented 3 months ago
gary-rowe commented 3 months ago

If you have time, could you review issue #97 which provides a lot of information regarding Ubuntu and hidraw/libusb.

laborg commented 2 months ago

I didn't see anything related in #97, but I found out that in version 0.7 linux-x86-64\libhidapi-libusb.so and linux-x86-64\libhidapi.so are binary equal and are actually the libusb backend build. So the "regression" stems from the fact there was a build bug in 0.7 which resulted in only one linux backend for 64bit (not 32!): libusb.

Finding out why I can't open devices using the linux backend will need to be investigated further.

laborg commented 2 months ago

Success! With the correct udev rule it finally worked:

KERNEL=="hidraw*", ATTRS{idVendor}=="XXXX", ATTRS{idProduct}=="YYYY", TAG+="uaccess"

(where XXXX and YYYY are, of course, the corresponding vendor and product ids). This is from https://github.com/libsdl-org/SDL/blob/main/src/hidapi/udev/69-hid.rules. Other udev recommendations floating around (ATTRS{busnum}="X") didn't work for me.

gary-rowe commented 2 months ago

I'm glad you got to the bottom of this issue. Was the wiki Troubleshooting section any help? See https://github.com/gary-rowe/hid4java/wiki/Troubleshooting#how-usb-devices-are-mapped-in-linux