Android Question USB HID Terminal written in Java

ahmed-1a

Member
Licensed User
Longtime User
Hi everybody,

I found an app which is USB HID Terminal, after contacting with its developer, fortunately it is an open source app written in Java, it works fine with any HID device, I usually make HID devices using MikroC and communicate with them by Visual Basic.net or C#.

I've been trying hard to get USB library in basic4android doing the same, but I couldn't.

I don't know if there is a possibility to convert the code to B4A and get the app work.
 

Giulio Pipitone

New Member
Licensed User
Longtime User
Hi guys,
I'm surprised to find this topic: I'm right now into trying to send commands exactly to the same 18F4550 you were working on some months ago!
Could you please update me with your best result (attaching the project perhaps?).
My intention is actually to just toggle a led status by sending 0x1000000 to the device.
THank you for your time

Giulio
 
Upvote 0

ahmed-1a

Member
Licensed User
Longtime User
Hi guys,
I'm surprised to find this topic: I'm right now into trying to send commands exactly to the same 18F4550 you were working on some months ago!
Could you please update me with your best result (attaching the project perhaps?).
My intention is actually to just toggle a led status by sending 0x1000000 to the device.
THank you for your time

Giulio

Hia

You could try the code on the first page of this thread, I actually stopped working on it, I got some excellent results with FTDI chip which can work as a Host USB.
 
Upvote 0

Giulio Pipitone

New Member
Licensed User
Longtime User
Hi, thank you for your help.
I tried your example but messed up a little with VID and PID...now it works...meaning that I give permission and I see, every TImer Tick "-1" logged....so it looks fine.

Now....what I am trying to do is NOT reading but WRITING to the device.
Exactly I would like to send a single byte (0x80) to the device.
Using your example as starting point I change the Timer1_Tick into:

Sub Timer1_Tick
If ( HIDstreams.IsInitialized = True ) Then
Log( HIDstreams.BulkTransfer(inEndpoint,RxPlcBuffer,64,300))
Dim stringa As String : stringa = "0x80"
TxPlcBuffer = conv.HexToBytes(stringa)
HIDstreams.BulkTransfer(outEndpoint,TxPlcBuffer,64,300)
End If
End Sub

The problem is that I get a "buffer start or length out of bounds"...probably because the buffer dimension is set to 64 and I'm only sending 1.
THe fact is that I tried to reduce 64 (both in buffer and in Dim declaration) to 1 but in that case program stucks without giving me any information even in debug.
Maybe you can fix my code to correctly send that byte?
Thank you
 
Last edited:
Upvote 0

ahmed-1a

Member
Licensed User
Longtime User
Hi Giulio,

I want you to try "USB HID terminal" app on play store, check that you can send without any problem. If it doesn't work, the problem is your hardware.

the number of bytes should be the same in your hardware program and B4A app.

I don't really see any problem in your app, try to send a simple character after pressing a button, the problem might be because the timer. I can't try it really because I don't have any hardware to work on.

B4X:
TxPlcBuffer(0)= 79
HIDstreams.BulkTransfer(outEndpoint,TxPlcBuffer,64,300)
 
Upvote 0

Giulio Pipitone

New Member
Licensed User
Longtime User
Hi,
I confirm it works with "USB HID terminal"..and with my app now too :)
I moved it in a procedure with dedicated button click but wasn't still working, it worked when I tried:

B4X:
TxPlcBuffer(0)= 10000000
HIDstreams.BulkTransfer(outEndpoint,TxPlcBuffer,64,300)

..so I forgot the conversion from hex to byte and decided to use byte directly :)
Maybe the conversionbyte function has something wrong, not sure...but it's ok this way too for me :)

Yesterday I was looking FTDI chips as you suggested and they look interesting, easier for sure to embed, program...and with nice libraries already developed for android. I think they have their market but PICS are still more popular and with more possibilities to find infos googling, I'll keep an eye on FTDI in future but I'll continue trusting PICs in present.

Thank you very much for your help in this issue,
Regards

Giulio
 
Upvote 0

ahmed-1a

Member
Licensed User
Longtime User
Great news Giulio

I suggest trying PIC24 or 32, they support USB Host, the only thing I can think of why to use USB host is to provide power to the android device. At the end it depends on what your hardware should do.

Microchip provides libraries for communicating with android via host usb.
 
Upvote 0
Top