1

我已经构建了 hid4java Maven 项目并成功地将库放入类库中。

这是我试图打开我正在使用的设备的代码:

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*/
        }

这发生在 Windows 10 中(搜索显示 Windows 10 可能是问题:https ://github.com/signal11/hidapi/issues/231 ),在 Netbeans 上运行 32 位 JVM...

我在这里做错了吗?有没有办法解决这个问题?是否有可用于简单 HID 设备的 hid4java 替代方案?

4

1 回答 1

1

您提到的库hid4java在 Windows 10 32 位和 64 位上运行良好。

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!!")
}

如果这仍然不起作用,请尝试列出所有这些,也许您的供应商 ID 错误。

for(HidDevice d : devices) {
   System.out.println("VendorId: " + d.getVendorId() + ", ProductId: " + d.getProductId()));
   System.out.println("    Manufacturer: " + d.getManufacturer() + ", Product: " + d.getProduct());
}
于 2016-06-15T01:36:04.320 回答