【问题标题】:usb4java Error while sending message: USB error 1: Control transfer failed: Input/Output Errorusb4java 发送消息时出错:USB 错误 1:控制传输失败:输入/输出错误
【发布时间】:2015-07-20 15:04:21
【问题描述】:

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

【问题讨论】:

    标签: usb infrared usb4java write-error


    【解决方案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

    【讨论】:

    • 您好,欢迎来到Stack Overflow。不鼓励仅使用代码回答这些部分,因此请在回答的同时解释一下您的代码。
    • 我想如果用户将 wValue 传递为 256,答案可能很明显......但他们没有......并且没有解释为什么这可能会导致问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-25
    • 2019-07-18
    • 2016-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-23
    相关资源
    最近更新 更多