hid4java
hid4java copied to clipboard
Regression in `hidApiLibrary.hid_open_path(path)` v 0.8
Describe the problem A USB hardware device which can be opened with version 0.7 can't be opened with 0.8.
To Reproduce
- Call
open(String path)fromHidApi.javahttps://github.com/gary-rowe/hid4java/blob/abb9c7f17adcb1e8a006d56cecf1b6dfdbf59875/src/main/java/org/hid4java/jna/HidApi.java#L147C1-L147C51 - It returns null for version 0.8
Expected behavior Do not return null.
Platform:
- OS: Ubuntu 22.04 x64 [e.g. darwin-aarch64, win32-x86-64]
hid4javaVersion 0.8.0
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.
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:
- which library is being used (
libusborhidraw(default)) - verification that the
udevsettings are correct - exact platform (e.g.
linux-aarch64)
- Hidraw (This might be the difference, because in Julia I'm using the build that used libusb backend)
- udev settings should be fine, as it works in Julia on the same computer
linux-x86-64
If you have time, could you review issue #97 which provides a lot of information regarding Ubuntu and hidraw/libusb.
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.
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.
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