gary-rowe / hid4java

A cross-platform Java Native Access (JNA) wrapper for the libusb/hidapi library. Works out of the box on Windows/Mac/Linux.
MIT License
223 stars 70 forks source link

write()和sendFeatureReport()方法都报错-1 (Both write() and sendFeatureReport() methods report an error -1) #109

Closed a751116023 closed 3 years ago

a751116023 commented 3 years ago

厂家软件监听到的USB用的是这个函数,我用hid4java的write()和sendFeatureReport()方法都报错-1,监听到的数据包用的还是函数。 比如我的代码,设备已经被打开:

Google translate: The USB monitored by the manufacturer's software uses this function. I used hid4java's write() and sendFeatureReport() methods to report an error of -1. The monitored data packets are still functions. For example, in my code, the device has been opened:

        HidServices hidServices = HidManager.getHidServices();
        HidDevice hidDevice = hidServices.getHidDevice(0xFFFE, 0x0091, "0690460036");
        boolean open = hidDevice.open();

        byte[] buff2 = new byte[7];
        buff2[0] = (byte) 0xFA;
        buff2[1] = (byte) 0x06;
        buff2[2] = (byte) 0xFF;
        buff2[3] = (byte) 0x40;
        buff2[4] = (byte) 0x04;
        buff2[5] = (byte) 0x0A;
        buff2[6] = (byte) 0x8E;

        int i = hidDevice.write(buff2, buff2.length, (byte) 7);
        String lastErrorMessage1 = hidDevice.getLastErrorMessage();
        int i1 = hidDevice.sendFeatureReport(buff2, (byte) buff2.length);
        String lastErrorMessage2 = hidDevice.getLastErrorMessage();

image

gary-rowe commented 3 years ago

Thank you for bringing this to my attention. I need more details before I can comment.

Which version of hid4java are you using?

What are you expecting to see that you are not?

An error code of -1 indicates a failure so can you provide more details.

Google translate: 谢谢您引起我的注意。 我需要更多详细信息才能发表评论。

您使用的是哪个版本的hid4java?

您期望看到什么不是您?

错误代码-1表示失败,因此您可以提供更多详细信息。

a751116023 commented 3 years ago

我用的0.7.0版本的

Google translate: I use version 0.7.0

a751116023 commented 3 years ago

这个是监听厂家软件发送的usb数据包的截图:

Google translate: This is a screenshot of the usb data packet sent by the manufacturer's software

22-03-58-058.png

这个是hid4java-0.7.0发送的write()函数的数据包的截图:

Google translate: This is a screenshot of the data packet of the write() function sent by hid4java-0.7.0:

18-36-32-032.png

a751116023 commented 3 years ago

问题解决了,原因是一个读卡器在操作系统注册了2个HID device,hid4java默认拿的第一个设备操作,第二个是可以正常使用的。我改下代码重新打包下使用

Google translate: The problem is solved. The reason is that a card reader registers 2 HID devices in the operating system. Hid4java uses the first device to operate by default, and the second one can be used normally. I changed the code to repackage and use

gary-rowe commented 3 years ago

That is good news. I'm glad you were able to fix the problem. Good luck with your project.

Google translate: 这是个好消息。 很高兴您能够解决此问题。 祝您的项目好运。