我遇到了一个问题:我在 Windows 8 笔记本电脑上使用 usb4java。我在我的 USB 端口中插入了一个红外遥控器。现在我想访问这个控制器。我得到了以下示例代码(没有编程异常并且没有处理 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) 驱动程序,但仍然出现此错误。有人可以帮助我吗?感谢您的每一个帮助:)