简体   繁体   English

使用java(usb4java)从libusb中的usb设备读取数据

[英]Read data from usb device in libusb with java(usb4java)

I'm reading data from usb device in java with libusb api. 我正在使用libusb api从java中的usb设备读取数据。 I'm able to write data to the device but I can not read data from device. 我能够将数据写入设备但我无法从设备读取数据。 I can read first data group (size : 1 byte) but when I want to read second data group (size : 2 byte) I'm getting the time out error (USB error 7: Control Transfer Failed: Operation timed out). 我可以读取第一个数据组(大小:1个字节),但是当我想读取第二个数据组(大小:2个字节)时,我收到超时错误(USB错误7:控制传输失败:操作超时)。

My code is like that ; 我的代码就是这样;

    buffer = ByteBuffer.allocateDirect(1);
    //03
    LibUsb.controlTransfer(handle,(byte) (LibUsb.REQUEST_TYPE_VENDOR | LibUsb.ENDPOINT_IN), (byte) 0xdb, (short) 0, (short) 0, buffer, 0);

    //00 04
    buffer.rewind();
    buffer = ByteBuffer.allocateDirect(2);

    transferred = LibUsb.controlTransfer(handle,(byte) (LibUsb.REQUEST_TYPE_VENDOR | LibUsb.ENDPOINT_IN), (byte) 0xf0, (short) 0x1c30, (short) 0, buffer, 0);

    if(transferred < 0){

        throw new LibUsbException("Control Transfer Failed", transferred);
    }

I have achieved this data transfer in C language, but I must do that in java. 我用C语言实现了这种数据传输,但我必须在java中实现。 Please help me. 请帮我。

Edit : I'm changing timeout but there is no change in my application. 编辑:我正在更改超时但我的应用程序没有变化。

Edit : I can read 1 byte data. 编辑:我可以读取1字节数据。 When I want to read 2 byte data I'm getting error. 当我想读取2字节数据时,我收到错误。

USB printer devices create more than one end-point, most likely you are addressing the endpoint which could be a read only. USB打印机设备创建多个端点,很可能您正在寻址可能是只读的端点。 Use USB diagnostics freeware to understand what are the end-points when you connect your device to the host. 使用USB诊断免费软件了解将设备连接到主机时的终点。 One of the end-point will be read-write and this is meant for reading from the device. 其中一个端点是读写,这是为了从设备读取。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM