manuelbl / JavaDoesUSB

USB library for Java
MIT License
140 stars 11 forks source link

Claim interface error 87 #27

Open Crustus opened 2 hours ago

Crustus commented 2 hours ago

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 commented 2 hours ago

maybe this could be relevant? https://stackoverflow.com/questions/9184439/writefile-returning-error-code-87

manuelbl commented 2 hours ago

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

Crustus commented 2 hours ago

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

and using Java 22