Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Claim interface error 87 #27

Open
Crustus opened this issue Oct 1, 2024 · 4 comments
Open

Claim interface error 87 #27

Crustus opened this issue Oct 1, 2024 · 4 comments

Comments

@Crustus
Copy link

Crustus commented Oct 1, 2024

Hello,

I am trying to use your library, on Windows 10 64bit, but I am getting error 87 when attempt to claim an interface

Exception in thread "main" net.codecrete.usb.windows.WindowsUsbException: claiming interface failed: Parameter not correct. (error code:87)
	at net.codecrete.usb.windows.WindowsUsbException.throwException(WindowsUsbException.java:54)
	at net.codecrete.usb.windows.WindowsUsbException.throwLastError(WindowsUsbException.java:80)
	at net.codecrete.usb.windows.WindowsUsbDevice.claimInteraceSynchronized(WindowsUsbDevice.java:178)
	at net.codecrete.usb.windows.WindowsUsbDevice.claimInterface(WindowsUsbDevice.java:126)

test code in Kotlin

private val VID: Int = 0x067b
    private val PID: Int = 0x23a3
    private val INTERFACE_NO: Int = 0
    private val ENDPOINT_OUT: Int = 2
    private val ENDPOINT_IN: Int = 3


System.setProperty("jextract.trace.downcalls", "true")

        val optionalDevice = Usb.findDevice(VID, PID)
        if (optionalDevice.isEmpty) {
            System.out.printf("No USB device with VID=0x%04x and PID=0x%04x found.%n", VID, PID)
            return
        }

        val device = optionalDevice.get()
        val inter = device.getInterface(INTERFACE_NO)
        println("inter num: ${inter.number}")

        device.open()
        device.claimInterface(INTERFACE_NO)

interface should exist as enumerated here:

 Device:
  VID: 0x067b
  PID: 0x23a3
  Manufacturer:  Prolific Technology Inc.
  Product name:  USB-Serial Controller
  Serial number: EKAFb136G03
  Device class:    0x00 ((Defined at Interface level))
  Device subclass: 0x00
  Device protocol: 0x00

  Interface 0
    Interface class:    0xff (Vendor Specific Class)
    Interface subclass: 0x00
    Interface protocol: 0x00

    Endpoint 1
        Direction: IN
        Transfer type: INTERRUPT
        Packet size: 10 bytes

    Endpoint 2
        Direction: OUT
        Transfer type: BULK
        Packet size: 64 bytes

    Endpoint 3
        Direction: IN
        Transfer type: BULK
        Packet size: 64 bytes

Device descriptor
0000  12 01 00 02 00 00 00 40 7b 06 a3 23 05 03 01 02
0010  03 01

Configuration descriptor
0000  09 02 27 00 01 01 00 a0 32 09 04 00 00 03 ff 00
0010  00 00 07 05 81 03 0a 00 01 07 05 02 02 40 00 00
0020  07 05 83 02 40 00 00
@Crustus
Copy link
Author

Crustus commented Oct 1, 2024

@manuelbl
Copy link
Owner

manuelbl commented Oct 1, 2024

Are you using version 1.0 of the library? Are you using Java 22 or 23?

@Crustus
Copy link
Author

Crustus commented Oct 1, 2024

yes, using version 1
implementation("net.codecrete.usb:java-does-usb:1.0.0")

and using Java 22

@manuelbl
Copy link
Owner

manuelbl commented Oct 1, 2024

Using a similar device (SIL CP2102), I can reproduce your case.

It's a rather confusing Windows error message. The actual problem is that device has already been claimed by a driver, most likely the Prolific driver that makes the device available as a COM port.

Such devices can be enumerated and queried. But it's not possible to claim an interface and communicate with its endpoints. On Windows, an interface can only be claimed if the device (or rather the interface or composite function) uses the WinUSB driver (also see README / Windows).

If you want to communicate with the device using this library, you have to replace the driver with WinUSB (using Zadig). It will then no longer be available as a COM port.

Unfortunately, this is a restriction of the rigid Windows driver model for USB devices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants