1

I've built the hid4java Maven project and successfully managed to put the library into a class library.

This is the code I'm using trying to open the device with which I am working :

public class JR3Controller implements HidServicesListener {
    private static JR3Controller Ctor = null;
    private JR3Reader Reader = null;
    private JR3Writer Writer = null;
    private HidDevice dev = null;
    private HidServices mgr = null;

    /**
     * R3 Controller Object.
     * @return 
     */
    public static boolean Initialize() throws HidException{
        if (JR3Controller.Ctor != null) return true;
        JR3Controller.Ctor = new JR3Controller();
        JR3Controller.Ctor.mgr.addHidServicesListener(JR3Controller.Ctor);
        return JR3Controller.Ctor.dev != null;
    }

    private JR3Controller(){
        this.mgr = HidManager.getHidServices();
        this.dev = this.mgr.getHidDevice(0x0003, 0x1001, null);
        if (this.dev != null){
            /*Stuff goes here : Doesn't matter because dev is never not null after the preceding line*/
        }

This is happening in Windows 10 (A search revealed that Windows 10 could be the issue : https://github.com/signal11/hidapi/issues/231), running a 32 bit JVM on Netbeans...

Am I doing something wrong here? Is there any way to resolve this? Is there an alternative to hid4java that I can use for a simple HID device?

Will
  • 3,413
  • 7
  • 50
  • 107

1 Answers1

1

The library you mentioned hid4java works well on Windows 10 32-bit and 64-bit.

HidServices services = HidManager.getHidServices();
List<HidDevice> devices = services.getAttachedHidDevices();
HidDevice device = null;
for(HidDevice d : devices) {
   if (d.isVidPidSerial(0x0003, 0x1001, null)) {
      device = d;
   }
}

if (device != null){
   System.out.println("We're not null!!")
}

If that still doesn't work, try listing all of them, perhaps you have the wrong Vendor ID.

for(HidDevice d : devices) {
   System.out.println("VendorId: " + d.getVendorId() + ", ProductId: " + d.getProductId()));
   System.out.println("    Manufacturer: " + d.getManufacturer() + ", Product: " + d.getProduct());
}
tresf
  • 7,103
  • 6
  • 40
  • 101