سؤال

I got a Problem: I'm using usb4java on my windows 8 laptop. I got an Infrared Remote Controller plugged in, in my usb port. Now I want to access this Controller.I got the following example code(There are no Exceptions programmed and NullPointers are not handled, because I just want see if my code works):

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();

}

So, it finds the port but when i call "inter.claim()", I get this Exception:

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 Result: 1 BUILD SUCCESSFUL (total time: 0 seconds)

I installed via Zadig a WinUSB (v6.1.7600.16385) driver,but there is still this error.Is there someone who can help me? Thanks for every help :)

هل كانت مفيدة؟

المحلول

I've tested your code with some of my devices. It is running. I would say it is a driver issue. With ZADIG you should check the menu item "list all devices" then you have to choose the right device from the dropdown-list. Then just push the "replace driver" button.

But be careful: if you do so, you can only communicate with your device out of the Java app. No other apps can access the device anymore. But you could just reinstall the old one from windows device manager, if that should be a problem.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top