usb4java发送消息时出错:USB错误1:控制传输失败:输入/输出错误

时间:2015-07-20 15:04:21

标签: usb infrared usb4java write-error

我尝试使用以下代码将带有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设备)

1 个答案:

答案 0 :(得分:-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