我遇到了一个问题: 我在我的 Windows 8 笔记本电脑上使用 usb4java。我在我的 USB 端口上插入了一个红外线 Remote 。现在我想访问这个 Controller 。我得到了以下示例代码(没有编程异常并且没有处理 NullPointers,因为我只想看看我的代码是否有效):
public class IRController_Test {
/**
* @param args the command line arguments
* @throws javax.usb.UsbException
*/
public static void main(String[] args) throws UsbException {
UsbServices usbServ = UsbHostManager.getUsbServices();
UsbHub hub = usbServ.getRootUsbHub();
List<UsbDevice> list = hub.getAttachedUsbDevices();
UsbDevice device = null;
for(UsbDevice dev : list){
if(dev.getUsbDeviceDescriptor().idVendor() == (short)0x0755 &&
dev.getUsbDeviceDescriptor().idProduct() == (short)0x2026){
device = dev;
System.out.println("Found the port!!");
}else{
System.out.println("Not the port!");
}
}
UsbConfiguration config = device.getActiveUsbConfiguration();
List<UsbInterface> listInf = config.getUsbInterfaces();
UsbInterface inter = listInf.get(0);
inter.claim();
所以,它找到了端口,但是当我调用“inter.claim()”时,我得到了这个异常:
Exception in thread "main" javax.usb.UsbPlatformException: USB error 12: Can't open device Bus 002 Device 003: ID 0755:2026: Operation not supported or unimplemented on this platform
at org.usb4java.javax.ExceptionUtils.createPlatformException(ExceptionUtils.java:39)
at org.usb4java.javax.AbstractDevice.open(AbstractDevice.java:226)
at org.usb4java.javax.AbstractDevice.claimInterface(AbstractDevice.java:406)
at org.usb4java.javax.Interface.claim(Interface.java:102)
at org.usb4java.javax.Interface.claim(Interface.java:93)
at IRController_Test.main(IRController_Test.java:48)
Java 结果:1 构建成功(总时间:0 秒)
我通过 Zadig 安装了 WinUSB (v6.1.7600.16385) 驱动程序,但仍然出现此错误。有人可以帮助我吗? 感谢您的帮助:)
最佳答案
我已经用我的一些设备测试了你的代码。它正在运行。我会说这是一个驱动程序问题。使用 ZADIG,您应该检查菜单项“列出所有设备”,然后您必须从下拉列表中选择正确的设备。然后只需按下“更换驱动程序”按钮即可。
但请注意:如果这样做,您只能通过 Java 应用程序与您的设备进行通信。没有其他应用程序可以再访问该设备。但是,如果出现问题,您可以从 Windows 设备管理器中重新安装旧的。
关于java - UsbInterface 声明失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23386118/