使用usb4java向USB设备发送消息-输入/输出错误

使用usb4java向USB设备发送消息-输入/输出错误,java,usb,libusb-1.0,usb4java,libusb-win32,Java,Usb,Libusb 1.0,Usb4java,Libusb Win32,我正在尝试使用以下代码向我的USB设备(Silicon Labs USB-UART桥接器)发送消息: public void sendMessage(UsbInterface iface, String message, int i){ UsbPipe pipe = null; try { iface.claim(new UsbInterfacePolicy() { @Override publi

我正在尝试使用以下代码向我的USB设备(Silicon Labs USB-UART桥接器)发送消息:

public void sendMessage(UsbInterface iface, String message,
        int i){

    UsbPipe pipe = null;

    try {
        iface.claim(new UsbInterfacePolicy() {
            @Override
            public boolean forceClaim(UsbInterface usbInterface) {
                return true;
            }
        });

        UsbEndpoint endpoint = (UsbEndpoint) iface.getUsbEndpoint((byte) i);
        pipe = endpoint.getUsbPipe();
        pipe.open();

        int sent = pipe.syncSubmit(message.getBytes());

        System.out.println(sent + " bytes sent");
        pipe.close();

    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        try {
            iface.release();
        } catch (UsbClaimException e) {
            e.printStackTrace();
        } catch (UsbNotActiveException e) {
            e.printStackTrace();
        } catch (UsbDisconnectedException e) {
            e.printStackTrace();
        } catch (UsbException e) {
            e.printStackTrace();
        }
    }
}//sendMessage
当我执行它时:

public static void main(final String[] args) throws UsbException {

    Usb4JavaHigh usb4java = new Usb4JavaHigh();
    UsbDevice usbDevice = usb4java.findDevice((short) (0x10C4), (short) (0xEA60));

    usb4java.sendMessage(usb4java.getDeviceInterface(usbDevice, 0), "01FF05FB13", 0x81);
    usb4java.readMessage(usb4java.getDeviceInterface(usbDevice, 0), 0x01);
}
我得到这个错误:

javax.usb.UsbPlatformException: USB error 1: Transfer error on bulk endpoint: Input/Output Error
at org.usb4java.javax.ExceptionUtils.createPlatformException(ExceptionUtils.java:39)
at org.usb4java.javax.IrpQueue.transferBulk(IrpQueue.java:239)
at org.usb4java.javax.IrpQueue.transfer(IrpQueue.java:197)
at org.usb4java.javax.IrpQueue.read(IrpQueue.java:126)
at org.usb4java.javax.IrpQueue.processIrp(IrpQueue.java:76)
at org.usb4java.javax.AbstractIrpQueue.process(AbstractIrpQueue.java:104)
at org.usb4java.javax.AbstractIrpQueue$1.run(AbstractIrpQueue.java:73)
at java.lang.Thread.run(Unknown Source)
然而,我的readMessage没有收到错误消息,有人知道为什么会这样,或者有人得到了提示吗

提前谢谢


编辑:当我将端点更改为0x01时,代码会生效,但该端点是EP 1 out,0x81是EP 1 IN,所以我应该在那里发送消息还是不发送消息

编辑2:readMessage的代码:

public void readMessage(UsbInterface iface, 
        int j){

    UsbPipe pipe = null;

    try {
        iface.claim(new UsbInterfacePolicy() {
            @Override
            public boolean forceClaim(UsbInterface usbInterface) {
                return true;
            }
        });

        UsbEndpoint endpoint = (UsbEndpoint) iface.getUsbEndpoint((byte) j); // there can be more 1,2,3..
        pipe = endpoint.getUsbPipe();
        pipe.open();

        /*pipe.addUsbPipeListener(new UsbPipeListener()
        {            
            @Override
            public void errorEventOccurred(UsbPipeErrorEvent event)
            {
                UsbException error = event.getUsbException();
                error.printStackTrace();
            }

            @Override
            public void dataEventOccurred(UsbPipeDataEvent event)
            {
                byte[] data = event.getData();

                System.out.println(data + " bytes received");
                for(int i =0 ; i<data.length; i++){System.out.print(data[i]+" ");}
            }
        });*/

        byte[] data = new byte[8];
        int received = pipe.syncSubmit(data);
        System.out.println(received + " bytes received");
        for(int i =0 ; i<data.length; i++){System.out.print(data[i]+" ");}//*/

        pipe.close();

    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        try {
            iface.release();
        } catch (UsbClaimException e) {
            e.printStackTrace();
        } catch (UsbNotActiveException e) {
            e.printStackTrace();
        } catch (UsbDisconnectedException e) {
            e.printStackTrace();
        } catch (UsbException e) {
            e.printStackTrace();
        }
    }

}
public void readMessage(UsbInterface iface,
int(j){
UsbPipe管道=空;
试一试{
iface.索赔(新的UsbInterfacePolicy(){
@凌驾
公共布尔forceClaim(UsbInterface UsbInterface){
返回true;
}
});
UsbEndpoint endpoint=(UsbEndpoint)iface.getUsbEndpoint((字节)j);//可以有更多的1,2,3。。
pipe=endpoint.getUsbPipe();
管道打开();
/*addUsbPipeListener(新的UsbPipeListener()
{            
@凌驾
发生公共无效ErrorEvent(UsbPipeErrorEvent事件)
{
UsbException error=event.getUsbException();
错误。printStackTrace();
}
@凌驾
发生公共无效DataEvent(UsbPipeDataEvent事件)
{
byte[]data=event.getData();
System.out.println(数据+“接收字节”);

对于(int i=0;iYes),Fidor是正确的0x01用于写入,0x81用于读取。 输入和输出是从主机控制器的角度进行的


您可以从IN端点读取和写入OUT端点。唯一的例外是方向独立的控制传输。

抱歉,以下是我得到的描述符:

Endpoint Descriptor:
  bLength                  7
  bDescriptorType          5
  bEndpointAddress      0x01  EP 1 OUT
  bmAttributes             2
    Transfer Type             Bulk
    Synch Type                None
    Usage Type                Data
  wMaxPacketSize          64
  bInterval                0

Endpoint Descriptor:
  bLength                  7
  bDescriptorType          5
  bEndpointAddress      0x81  EP 1 IN
  bmAttributes             2
    Transfer Type             Bulk
    Synch Type                None
    Usage Type                Data
  wMaxPacketSize          64
  bInterval                0

“当我将端点更改为0x01时,代码会生效,但那一个是EP1 out”-我怀疑术语混淆。我猜是“out”从客户端的角度来看。这是您的输出,即管道的输入…当我尝试从0x81读取时,我得到了与readMessage完全相同的errormessage。sendMessage似乎可以工作。完全相同的意思也是USB错误1?您查看过这些端点的端点描述符吗?是的,如上所述的相同错误,我使用设备转储获取了端点描述符,这些是描述符:我看不到任何描述符。您单击了添加注释吗?因此端点是正确的。传输一定有问题。您可以用readMessage源代码编辑问题吗?