IddoB
Posts: 56
Joined: Wed Aug 23, 2017 4:39 pm

Reading Data From USB

Thu Mar 08, 2018 10:57 am

Hello guys!

I am working on my school project using the RPI and I am facing a small problem. I have bought a simple USB barcode reader and I am having trouble reading from it.
When I connect it to my PC on Windows it works completely fine. But when I go into the RPI I am not getting any input from it. (Its supposed to work like a regular keyboard I think)

When I run lsusb this is the Barcode scanner: Bus 001 Device 018: ID 6778:0112

I have looked online for solutions and I came across this, not sure if it can help me or not: http://pyserial.readthedocs.io/en/latest/index.html

Thank you!

User avatar
topguy
Posts: 6523
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Reading Data From USB

Thu Mar 08, 2018 1:08 pm

Its supposed to work like a regular keyboard I think
Your first job is to verify that this is also the truth on Linux.

- Boot your Pi without the scanner plugged in..
- Open a terminal.
- Plug in your scanner and wait a couple of seconds.
- run the command "dmesg".

The last lines of output from "dmesg" then contain the kernel information related to your scanner. If you post those lines here we can usually see if it is in a working state or not.

If you think things are working ok you can install and run a program called "evtest" and if you run it without any parameters I belive it will let you choose from a list of "input" devices to test. Your scanner should be in that list, and if you select it and scan something, then evtest should print out every keystroke event.

IddoB
Posts: 56
Joined: Wed Aug 23, 2017 4:39 pm

Re: Reading Data From USB

Fri Mar 09, 2018 10:18 am

topguy wrote:
Thu Mar 08, 2018 1:08 pm
Its supposed to work like a regular keyboard I think
Your first job is to verify that this is also the truth on Linux.

- Boot your Pi without the scanner plugged in..
- Open a terminal.
- Plug in your scanner and wait a couple of seconds.
- run the command "dmesg".

The last lines of output from "dmesg" then contain the kernel information related to your scanner. If you post those lines here we can usually see if it is in a working state or not.

If you think things are working ok you can install and run a program called "evtest" and if you run it without any parameters I belive it will let you choose from a list of "input" devices to test. Your scanner should be in that list, and if you select it and scan something, then evtest should print out every keystroke event.
Thank you for your respond! I have downloaded Evdev for Python and managed to capture all the barcodes that I scan. My question is, is there a easier way to get that data? Becuase in evdev I get so much more information that I dont need (I need the value only)

User avatar
topguy
Posts: 6523
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Reading Data From USB

Fri Mar 09, 2018 12:06 pm

My question is, is there a easier way to get that data?
I believe any easier way would be more dependent on what environment your program is running in. A method working in the Linux console might not work if a GUI environmnent with X and vice versa. I feel that using evdev is the only safe way if you have a HID scanner.

If you buy a scanner that is "serial" based you will get a serialport to read from, and that is simpler for software development than HID devices.

IddoB
Posts: 56
Joined: Wed Aug 23, 2017 4:39 pm

Re: Reading Data From USB

Fri Mar 09, 2018 1:31 pm

topguy wrote:
Fri Mar 09, 2018 12:06 pm
My question is, is there a easier way to get that data?
I believe any easier way would be more dependent on what environment your program is running in. A method working in the Linux console might not work if a GUI environmnent with X and vice versa. I feel that using evdev is the only safe way if you have a HID scanner.

If you buy a scanner that is "serial" based you will get a serialport to read from, and that is simpler for software development than HID devices.
Im pretty sure it is serial based. How could I read from it?

User avatar
topguy
Posts: 6523
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Reading Data From USB

Sat Mar 10, 2018 10:11 pm

As long as the scanner is detected as a keyboard and not a serialport in Linux it doesnt matter what you think, but you should look at the documentation to see if there is a way to switch from HID mode to UART/Serial mode.

Since you have not said which make and model this is nor posted the output from dmesg, its not much more I can do to help.

IddoB
Posts: 56
Joined: Wed Aug 23, 2017 4:39 pm

Re: Reading Data From USB

Mon Mar 12, 2018 6:10 am

topguy wrote:
Sat Mar 10, 2018 10:11 pm
As long as the scanner is detected as a keyboard and not a serialport in Linux it doesnt matter what you think, but you should look at the documentation to see if there is a way to switch from HID mode to UART/Serial mode.

Since you have not said which make and model this is nor posted the output from dmesg, its not much more I can do to help.
I can configure the scanner to these modes:
RS-232
USB HID
RS484

User avatar
topguy
Posts: 6523
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Reading Data From USB

Mon Mar 12, 2018 12:11 pm

Switch it to RS232 then and go back to my first answer in this thread.
( I'm now assuming that there isn't a seperate cable for the RS232 mode, but still working over USB. )

User avatar
scruss
Posts: 3256
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Reading Data From USB

Mon Mar 12, 2018 12:57 pm

USB HID will (or at least should) make it appear as a keyboard. Anything you scan goes in as if you typed in the barcode. It's probably the easiest to support
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

IddoB
Posts: 56
Joined: Wed Aug 23, 2017 4:39 pm

Re: Reading Data From USB

Mon Mar 12, 2018 2:35 pm

topguy wrote:
Mon Mar 12, 2018 12:11 pm
Switch it to RS232 then and go back to my first answer in this thread.
( I'm now assuming that there isn't a seperate cable for the RS232 mode, but still working over USB. )
Ill try that. Thank you

IddoB
Posts: 56
Joined: Wed Aug 23, 2017 4:39 pm

Re: Reading Data From USB

Mon Mar 12, 2018 2:37 pm

scruss wrote:
Mon Mar 12, 2018 12:57 pm
USB HID will (or at least should) make it appear as a keyboard. Anything you scan goes in as if you typed in the barcode. It's probably the easiest to support
That is the case in Windows, but for some reason, it doesn't detect it in Raspbian.
Maybe I need to configure the system or download drivers? What are your thoughts?

User avatar
scruss
Posts: 3256
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Reading Data From USB

Mon Mar 12, 2018 4:43 pm

It may need a udev rule for the system to accept it as a keyboard. Try searching for the usb vendor and ID codes along with "udev" and see if someone else has got it working. I couldn't work out your device from the one line you gave: we need the dmesg output too.

That vendor (0x6778) isn't recognized by any USB-IF list I can find
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

IddoB
Posts: 56
Joined: Wed Aug 23, 2017 4:39 pm

Re: Reading Data From USB

Tue Mar 13, 2018 12:09 pm

scruss wrote:
Mon Mar 12, 2018 4:43 pm
It may need a udev rule for the system to accept it as a keyboard. Try searching for the usb vendor and ID codes along with "udev" and see if someone else has got it working. I couldn't work out your device from the one line you gave: we need the dmesg output too.

That vendor (0x6778) isn't recognized by any USB-IF list I can find
I'll try to get more information and post it as soon as possible. Thank you anyway!

IddoB
Posts: 56
Joined: Wed Aug 23, 2017 4:39 pm

Re: Reading Data From USB

Wed Mar 14, 2018 6:31 am

scruss wrote:
Mon Mar 12, 2018 4:43 pm
It may need a udev rule for the system to accept it as a keyboard. Try searching for the usb vendor and ID codes along with "udev" and see if someone else has got it working. I couldn't work out your device from the one line you gave: we need the dmesg output too.

That vendor (0x6778) isn't recognized by any USB-IF list I can find
Here is the info info from dmesg:

Code: Select all

[  923.047302] usb 1-1.2: Product: HID Keyboard Device
[  923.047310] usb 1-1.2: Manufacturer: HID Keyboard Device
[  923.047318] usb 1-1.2: SerialNumber: Keyboard Device
[  923.057155] usb 1-1.2: output irq status -32 received
[  923.057461] input: HID Keyboard Device HID Keyboard Device as /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/0003:6778:0112.0001/input/input0
[  923.121327] hid-generic 0003:6778:0112.0001: input,hidraw0: USB HID v1.10 Keyboard [HID Keyboard Device HID Keyboard Device] on usb-3f980000.usb-1.2/input0
[ 1207.891184] usb 1-1.2: USB disconnect, device number 4
[ 1210.130668] usb 1-1.2: new full-speed USB device number 5 using dwc_otg
[ 1210.266784] usb 1-1.2: New USB device found, idVendor=6778, idProduct=0112
[ 1210.266798] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1210.266806] usb 1-1.2: Product: HID Keyboard Device
[ 1210.266814] usb 1-1.2: Manufacturer: HID Keyboard Device
[ 1210.266821] usb 1-1.2: SerialNumber: Keyboard Device
[ 1210.277404] usb 1-1.2: output irq status -32 received
[ 1210.277546] input: HID Keyboard Device HID Keyboard Device as /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/0003:6778:0112.0002/input/input1
[ 1210.341496] hid-generic 0003:6778:0112.0002: input,hidraw0: USB HID v1.10 Keyboard [HID Keyboard Device HID Keyboard Device] on usb-3f980000.usb-1.2/input0

User avatar
topguy
Posts: 6523
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Reading Data From USB

Wed Mar 14, 2018 1:28 pm

I feel this thread is going in circles, we already established in post number 3 that IddoB can read the keystrokes from the HID device using the evdev module in Python. I still will claim this method is the best solution because it will ignore input from other keyboards connected to the same device and also keystrokes being sent over SSH or Remote Desktop.

The dmesg output confirms that the device still is recognized as a HID-Keyboard and not a serialport.

IddoB
Posts: 56
Joined: Wed Aug 23, 2017 4:39 pm

Re: Reading Data From USB

Wed Mar 14, 2018 2:00 pm

topguy wrote:
Wed Mar 14, 2018 1:28 pm
I feel this thread is going in circles, we already established in post number 3 that IddoB can read the keystrokes from the HID device using the evdev module in Python. I still will claim this method is the best solution because it will ignore input from other keyboards connected to the same device and also keystrokes being sent over SSH or Remote Desktop.

The dmesg output confirms that the device still is recognized as a HID-Keyboard and not a serialport.
The thing is that with this method I am getting a huge output of system information that is not needed (Timestamps, type, and more).

User avatar
topguy
Posts: 6523
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Reading Data From USB

Wed Mar 14, 2018 3:04 pm

You don't have to do anything with that extra data, just use the keystrokes as you need.
I can configure the scanner to these modes:
RS-232
USB HID
RS484
You haven't said how you were supposed to configure the scanner. And since Linux still thinks its a keyboard we cant conclude you have done it successfully either.

We have no make and model, no data sheet, no link to documentation or where you bought it from that could have helped us help you.

Return to “Python”