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.

VID = 0x046A PID = 0xB090 Manufacturer = Cherry Product = USB keyboard Path = \\?\hid#vid_046a&pid_b090&mi_01&col01#7&deb9ec1&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
VID = 0x0B05 PID = 0x17BE Manufacturer = ASUS Computer Inc. Product = ASUS GAMING MOUSE GX950 Path = \\?\hid#vid_0b05&pid_17be&mi_01&col02#7&3ada128&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
VID = 0x046A PID = 0xB090 Manufacturer = Cherry Product = USB keyboard Path = \\?\hid#vid_046a&pid_b090&mi_01&col02#7&deb9ec1&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
VID = 0x046A PID = 0xB090 Manufacturer = Cherry Product = USB keyboard Path = \\?\hid#vid_046a&pid_b090&mi_01&col03#7&deb9ec1&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
VID = 0x047F PID = 0xC056 Manufacturer = Plantronics Product = Plantronics Blackwire 3220 Series Path = \\?\hid#vid_047f&pid_c056&mi_03&col01#8&619a733&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
VID = 0x047F PID = 0xC056 Manufacturer = Plantronics Product = Plantronics Blackwire 3220 Series Path = \\?\hid#vid_047f&pid_c056&mi_03&col02#8&619a733&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
VID = 0x047F PID = 0xC056 Manufacturer = Plantronics Product = Plantronics Blackwire 3220 Series Path = \\?\hid#vid_047f&pid_c056&mi_03&col03#8&619a733&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}

Event in b4j
HID_DeviceList({purejavahidapi.windows.HidDeviceInfo@50fc41bf=purejavahidapi.windows.HidDeviceInfo@50fc41bf, purejavahidapi.windows.HidDeviceInfo@208bb1a=purejavahidapi.windows.HidDeviceInfo@208bb1a, purejavahidapi.windows.HidDeviceInfo@44bf6bac=purejavahidapi.windows.HidDeviceInfo@44bf6bac, purejavahidapi.windows.HidDeviceInfo@59e618e3=purejavahidapi.windows.HidDeviceInfo@59e618e3, purejavahidapi.windows.HidDeviceInfo@31f2d251=purejavahidapi.windows.HidDeviceInfo@31f2d251, purejavahidapi.windows.HidDeviceInfo@76657f1e=purejavahidapi.windows.HidDeviceInfo@76657f1e, purejavahidapi.windows.HidDeviceInfo@49b88875=purejavahidapi.windows.HidDeviceInfo@49b88875})
purejavahidapi.windows.HidDeviceInfo@50fc41bf ' one HidDeviceInfo inside the map...

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
Top