Usb4java与Device通信时出错

时间:2018-02-14 21:47:07

标签: java usb device libusb

需要你的帮助。

我目前正在使用libusb Library中的usb4java开发可与ingenico iWL220设备通信的Java应用程序。我安装了驱动程序,它可以从设备管理器中读取就好了。我主要遵循

的代码 低API的

http://www.mets-blog.com/java-usb-communication-usb4java/

高级API的

http://www.mets-blog.com/java-usb-communication-usb4java-high-api/

我尝试的第一个是低API,我的主类如下:

public class DeviceHandles {
private static final Short VendorID = 0x079b;
private static final Short ProductID = 0x0028;    
public static void main(String[] args){
UsbLowPos upos = new UsbLowPos();
upos.claimDevice(VendorID,ProductID);
   }
}

这一个返回错误:

Device Found 
Exception in thread "main" org.usb4java.LibUsbException: USB error 12: Unable to open USB device: Operation not supported or unimplemented on this platform     at Usb.UsbLowPos.getDeviceHandle(UsbLowPos.java:121)    at Usb.UsbLowPos.findDevice(UsbLowPos.java:103)     at Usb.UsbLowPos.claimDevice(UsbLowPos.java:27)     at Usb.DeviceHandles.main(DeviceHandles.java:24)

之后,我尝试了高级API,我的主类是这样的:

public class DeviceHandles {
private static final Short VendorID = 0x079b;
private static final Short ProductID = 0x0028;
public static void main(String[] args){
UsbHighPos upos = new UsbHighPos();
UsbDevice usbDevice = upos.findDevice(VendorID,ProductID);
upos.readMessage(upos.getDeviceInterface(usbDevice, 0), 0);  
   }
}

这也会返回错误:

javax.usb.UsbException: Properties file javax.usb.properties not found.     at javax.usb.UsbHostManager.setupProperties(Unknown Source)     at javax.usb.UsbHostManager.getProperties(Unknown Source)   at javax.usb.UsbHostManager.createUsbServices(Unknown Source)   at javax.usb.UsbHostManager.getUsbServices(Unknown Source)  at Usb.UsbHighPos.getUsbRootHoob(UsbHighPos.java:29)    at Usb.UsbHighPos.findDevice(UsbHighPos.java:43)    at Usb.DeviceHandles.main(DeviceHandles.java:27) Exception in thread "main" java.lang.NullPointerException  at Usb.UsbHighPos.findDevice(UsbHighPos.java:49)    at Usb.UsbHighPos.findDevice(UsbHighPos.java:43)    at Usb.DeviceHandles.main(DeviceHandles.java:27)

我在这里遗漏了什么吗?图书馆是否无法与设备通信?或者问题出在设备上?请帮助,谢谢您的时间。

1 个答案:

答案 0 :(得分:0)

解决了,我改用Java串行连接,它工作正常!