B4J Question how to send data to usb hid?

bagazhou

Member
Licensed User
Longtime User
Hi

i have a usb hid lcd , i want to send data to hid , but how can i do this on b4j?
 

bagazhou

Member
Licensed User
Longtime User
I think I'll find a solution

this is purejavahidapi.jar , i call this jar from b4J
link:https://github.com/nyholku/purejavahidapi

please add this
#AdditionalJar: purejavahidapi
#AdditionalJar: jna-4.0.0

B4X:
'initial HidDeviceInfo
Dim hdi As JavaObject
hdi.InitializeStatic("purejavahidapi.HidDeviceInfo")
 
  
'initial PureJavaHidApi
Dim jo As JavaObject
jo.InitializeStatic("purejavahidapi.PureJavaHidApi")
 
'list all usb hid 
Dim lst As List
lst = jo.RunMethodJO("enumerateDevices", Null)
 
For i=0 To lst.Size-1
Log("lst:" & lst.Get(i))
ListView1.Items.Add("lst:"  & lst.Get(i))
Next
 
 
'open usb hid
Dim obj As JavaObject
obj.InitializeStatic("purejavahidapi.HidDeviceInfo")
obj = lst.Get(i-1) 
 
Dim getPath As String
getPath = obj.RunMethod("getPath",Null)
 
 
Log("----------------------- HidDeviceInfo -----------------------")
Log("obj:" & obj)
Log("hdi" & hdi)
Log("getProductId:" & obj.RunMethod("getProductId",Null))
Log("getProductString:" & obj.RunMethod("getProductString",Null))
Log("getReleaseNumber:" & obj.RunMethod("getReleaseNumber",Null))
Log("getSerialNumberString:" & obj.RunMethod("getSerialNumberString",Null))
Log("getUsagePage:" & obj.RunMethod("getUsagePage",Null))
Log("getVendorId:" & obj.RunMethod("getVendorId",Null))
Log("getManufacturerString:" & obj.RunMethod("getManufacturerString",Null))
 
Dim hd As JavaObject
hd.InitializeStatic("purejavahidapi.HidDevice")
hd = jo.RunMethod("openDevice",  Array As String(getPath))
 
Log("----------------------- HidDevice -----------------------")
Log("hd:" & hd)
Log("getHidDeviceInfo:" & hd.RunMethod("getHidDeviceInfo",Null))
Log("getPath:" & getPath)
 
 
' send data to hid
Dim data(64) As Byte
Dim s As String
Dim bc As ByteConverter
s="0001020304050607080910111213141516171819202122232425262728293031323334353637383940414243444546474849 5051525354555657585960616263"
data = bc.HexToBytes(s)
Log("----------------------- Send Data -----------------------")
Log("s:" & s)
Log("data.Length:" & data.Length)
 
Dim ival As Int
ival = hd.RunMethod("setFeatureReport", Array As Object( data, 64 ))
Log("ival:" & ival)
 
Upvote 0

bjfhs

Active Member
Licensed User
I want to get data from HID device
B4X:
Dim getPath As String
    getPath = obj.RunMethod("getPath",Null)
    Log(getPath)
    Dim hd As JavaObject
    hd.InitializeStatic("purejavahidapi.HidDevice")
    hd = jo.RunMethod("openDevice",  Array As String(getPath))
LOG:\\?\hid#vid_6816&pid_1001#7&5dc41fe&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
But I get error "java.lang.RuntimeException: Method: openDevice not matched."
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I want to get data from HID device
NEVER post to existing threads. Always create a NEW thread for any Question your have.
 
Upvote 0
Top