Android Question Read the data stream of the barcode scanner

dfrgr7dcdf%4

New Member
I have a barcode scanner connected by USB to my Andoid Pc.
It functions like a keyboard but that is slow since an edittext of my application need to has the focus and then recive every charcter.
Is it possible read the stream of data from the USB and work directly with that?
It is ok also if you suggest me external libraries
 

drgottjr

Expert
Licensed User
Longtime User
if your scanner only works in HID mode (as a keyboard), then no. this is usually the default. turn off HID mode (if that option is available). one of my scanners then emulates usb com port mode.
 
Upvote 1

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
I have a barcode scanner connected by USB to my Andoid Pc.
It functions like a keyboard but that is slow since an edittext of my application need to has the focus and then recive every charcter.
Is it possible read the stream of data from the USB and work directly with that?
It is ok also if you suggest me external libraries
Your scanner needs to support SPP mode, here's a link to get you started searching as there are several posts here discussing it.
 
Upvote 0

dfrgr7dcdf%4

New Member
if your scanner only works in HID mode (as a keyboard), then no. this is usually the default. turn off HID mode (if that option is available). one of my scanners then emulates usb com port mode.
I checked the manual and you were right, it was in HID mode but the barcode supported the serial mode as well. I switched it to serial mode.
Now what is the B4A code to read from serial mode?
 
Upvote 0

dfrgr7dcdf%4

New Member
You need to check your scanner documentation and see whether it provides an API for this.
I switched the barcode in serial mode.
Do the producer of the barcode also need to provide an api for my B4A application to read the data?
I found that B4A has a library called UsbSerial. Isn't it enought to read the data?
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
in my opinion, hid mode is not all that slow. the alternative - reading from the device directly - is faster, but it could be much more inconvenient than
having an hid scannner populate a label or edittext. if the scanner does not support "interrupt mode", then every time you press the trigger to scan a
barcode, you will then have to tap a button in the app to read the result from the scanner. the device is designed to act like a keyboard.

i think there are examples here relating to different hardware scanners. i really wouldn't know what to search for. that's why i implemented my own
utility. and because of the inconvenience i describe above, i don't use it "in production". it's just much easier to let the scanner do what it does naturally.

in any case, you first need to query the attached devices and find out which one is the scanner and what it's capable of doing (eg, does it support "interrupt mode").
then you need code to address that. i can probably convert my code to a library to let you see what the scanner advertises, but you may find something else before i get to it.

if your scanner has a bluetooth mode and supports spp, i'm pretty sure you'll be able to find an example. communication with bluetooth devices is
much more common than with otg (you can only have 1 device at a time, and external drives and keyboards come with drivers that basically save you the
time needed to figure out how to communicate with them natively).
 
Upvote 0

QSerg

Member
I have a barcode scanner connected by USB to my Andoid Pc.
It functions like a keyboard but that is slow since an edittext of my application need to has the focus and then recive every charcter.
Is it possible read the stream of data from the USB and work directly with that?
It is ok also if you suggest me external libraries
Read scanner documentation and search for transfer rate. Inside app upon receiving data event (it WILL be triggered each character) search for terminal character that you set in scanner. Usually it is CR/LF, but sometimes it is worth to use something else like "~" ot "|". I developing bar-scanning applications for decades and never have problem with performance.
 
Upvote 0
Top