1

我尝试使用以下代码将带有 usb4java api 的消息发送到 ir 读写元素:

public static void sendData(DeviceHandle handle, int timeout) {
    
    ByteBuffer buffer = ByteBuffer.allocateDirect(12);
    buffer.put(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
    buffer.rewind();
    
    
    int transfered = LibUsb.controlTransfer(handle,
            (byte) (LibUsb.REQUEST_TYPE_CLASS | LibUsb.RECIPIENT_INTERFACE),
            (byte) 0x09, (short) 2, (short) 1, buffer, timeout);
    if (transfered < 0) {
        throw new LibUsbException("Control transfer failed", transfered);
    }
    System.out.println(transfered + " bytes sent");
    
}

但是每次我尝试它时,我都会在以下位置收到此错误int = controlTransfer(handle, (LibUsb.REQUEST_TYPE_CLASS | RECIPIENT_INTERFACE), 0x09, (short) 2, (short) 1, buffer, timeout);

Exception in thread "main" org.usb4java.LibUsbException: USB error 1: Control transfer failed: Input/Output Error
    at usb.reader.USBReader.sendData(USBReader.java:56)
    at usb.reader.USBReader.main(USBReader.java:42)
Java Result: 1

也许你们中的一个人知道如何解决这个问题?

我真的很期待你的回答。

编辑:我想我不得不说我的操作系统是 Windows 8.1 64 位上的 VM VirtualBox 中的 Linux 64 位。(USB 转发已激活;我已经访问了 USB 设备)

4

1 回答 1

-1
    int transfered = LibUsb.controlTransfer(
            handle,
            (byte) (LibUsb.REQUEST_TYPE_CLASS | LibUsb.RECIPIENT_INTERFACE),
            (byte) 0x09, //bmRequestType
            (short) 256, //wValue 
            (short) 0, //wIndex
            buffer, TIMEOUT);

值 wValue=256

于 2015-07-27T17:18:42.523 回答