Wish Wrapper for HID-Api Lib (connecting USB HID devices)

The existing B4J lib does not help further: I want to access different devices (e.g. pedometers, body scales, step counters, pulse meters), where communication is based on proprietary protocols. Usually, it is a peer-to-peer communication via HID reports.

Possibly the pure java lib may be interesting. But isn't there also need for a wrapper to use it with B4J ?
 
I already found it, but it seems quite difficult (at least fo me...)

Would be great, if somebody could help with translating the short samples coming with the lib:

Code: Copy
import java.util.List;

import purejavahidapi.*;

public class Example1 {

    public static void main(String[] args) {
        try {
            List<HidDeviceInfo> devList = PureJavaHidApi.enumerateDevices();
            for (HidDeviceInfo info : devList) {
                System.out.printf("VID = 0x%04X PID = 0x%04X Manufacturer = %s Product = %s Path = %s\n", //
                        info.getVendorId(), //
                        info.getProductId(), //
                        info.getManufacturerString(), //
                        info.getProductString(), //
                        info.getPath());

            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}

and

Code: Copy
import java.util.List;

import purejavahidapi.*;

public class Example2 {

    public static void main(String[] args) {
        try {
            List<HidDeviceInfo> devList = PureJavaHidApi.enumerateDevices();
            HidDeviceInfo devInfo = null;
            for (HidDeviceInfo info : devList) {
                if (info.getVendorId() == (short) 0x0810 && info.getProductId() == (short) 0x0005) {
                    devInfo = info;
                    break;
                }
            }
            if (devInfo == null)
                System.err.println("device not found");
            else {
                HidDevice dev = PureJavaHidApi.openDevice(devInfo.getPath());
                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();
                    }
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}

TIA..
Oliver
 
i'm trying to implement the HID but stucked at the first step
Got the PureJavaHidApi.jar and added to the additional Libs (see file attached)
then when i try following:
Code: Copy
   Dim jo As JavaObject
   Dim bi As JavaObject
   jo.InitializeStatic("com.squareup.picasso.Picasso")
    bi.InitializeStatic("purejavahidapi.PureJavaHidApi")
the example of Erel works, but got a java.lang.ClassNotFoundException: purejavahidapi$PureJavaHidApi error for the PurejavaHidApi

But when i insert bi.InitializeStatic("purejavahidapi.HidDevice") it works.
But we need the functions OpenDevice and EnumerateDevices for getting the HID of USB

may be someone has a idea why i cannot access the functions?
 

Attachments

Last edited:
Back
Top