我尝试用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也许你们中有人知道怎么解决这个问题?
我真的很期待你的回答。
编辑:我想我必须说我的操作系统是Windows8.1 64位上VM VirtualBox中的Linux64位。(USB转发被激活;我已经访问了USB设备)
发布于 2015-07-27 17:18:42
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
https://stackoverflow.com/questions/31519922
复制相似问题