B4J Question USB HID in B4J

DonManfred

Expert
Licensed User
Longtime User
Run the two Java examples, do they work for you?
i did a small testwrapper only implementing the enumerate

It does work. It lists the following devices on my PC.


I do not have any HID device where i could connect to...
 
Upvote 0

Toley

Active Member
Licensed User
Longtime User
Hi Erel and DonManfred,

I cannot run the examples since they are .java files and I don't know how to run those files. But if run this partial B4J wrapper there https://www.b4x.com/android/forum/threads/how-to-get-data-from-hid-device.101106/#post-639232 I am able to list the device connect to it but still not to send and receive data to and from the device.

edit: Maybe this library is a better choice, it seems pretty well written.
https://os.mbed.com/cookbook/USBHID-bindings-#example-in-java-on-windows

Thank you for your time.
 
Last edited:
Upvote 0

Toley

Active Member
Licensed User
Longtime User
Seems to connect normally here is the Log:
Waiting for debugger to connect...
Program started.
scanning
1133
-15061
1133
-15061
1133
-15061
11708
51
1133
-15061
1133
-15061
1133
-15061
11708
6436
item selected : purejavahidapi.windows.HidDeviceInfo@15b110b8
device found
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You should be able to read the data with that code. It correctly sets a listener:
B4X:
dev.setInputReportListener(new InputReportListener() {
    @Override
    public void onInputReport(HidDevice source, byte Id, byte[] data, int len) {
     System.out.printf("onInputReport: id %d len %d data ", Id, len);
      for (int i = 0; i < len; i++)
       System.out.printf("%02X ", data[i]);
       System.out.println();
    }
   });
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…