hid4java icon indicating copy to clipboard operation
hid4java copied to clipboard

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

Open laborg opened this issue 1 year ago • 3 comments

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:

  • OS: Ubuntu 22.04 x64 [e.g. darwin-aarch64, win32-x86-64]
  • hid4java Version 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.

laborg avatar Apr 15 '24 06:04 laborg

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 (libusb or hidraw (default))
  • verification that the udev settings are correct
  • exact platform (e.g. linux-aarch64)

gary-rowe avatar Apr 15 '24 09:04 gary-rowe

  • 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

laborg avatar Apr 15 '24 12:04 laborg

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

gary-rowe avatar Apr 15 '24 14:04 gary-rowe

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 avatar May 03 '24 06:05 laborg

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.

laborg avatar May 03 '24 06:05 laborg

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

gary-rowe avatar May 03 '24 07:05 gary-rowe