dwedar
Posts: 6
Joined: Mon Dec 28, 2015 3:22 pm

reading from barcode scanner to a text file

Mon Jan 18, 2016 10:22 pm

i have a problem that i want to read the input that read by barcode and save it to a text file.
any one know how can i do that plz help me
raspberry pi B+ with latest version of wheezy
barcode scanner datalogc qw 2100
thanxxx in advance

SonOfAMotherlessGoat
Posts: 690
Joined: Tue Jun 16, 2015 6:01 am

Re: reading from barcode scanner to a text file

Mon Jan 18, 2016 10:24 pm

If that scanner can operate in 'wedge`mode then you could just accesses it like a keyboard.
Account Inactive

dwedar
Posts: 6
Joined: Mon Dec 28, 2015 3:22 pm

Re: reading from barcode scanner to a text file

Mon Jan 18, 2016 10:49 pm

sorry @SonOfAMotherlessGoat
how can made barcode in "wedge mode" !?
when i plug the barcode into the pi and
read any barcode it doesn`t read anything and doesn`t appear any thing
i wan any help please
and thanxx for your answer :D :D

dwedar
Posts: 6
Joined: Mon Dec 28, 2015 3:22 pm

Re: reading from barcode scanner to a text file

Mon Jan 18, 2016 10:50 pm

SonOfAMotherlessGoat wrote:If that scanner can operate in 'wedge`mode then you could just accesses it like a keyboard.
how can made barcode in "wedge mode" !?
when i plug the barcode into the pi and
read any barcode it doesn`t read anything and doesn`t appear any thing
i wan any help please
and thanxx for your answer :D :D

SonOfAMotherlessGoat
Posts: 690
Joined: Tue Jun 16, 2015 6:01 am

Re: reading from barcode scanner to a text file

Mon Jan 18, 2016 11:19 pm

What does the output from the following command show for your scanner when you plug it in?

Code: Select all

lsusb
Also, when you scan a code, are you in a text editor window that you can type into? Wedge mode is basically a keyboard emulation, so it's just like you pressing the keys and thus you need to be in a text editor of some kind that you can type into with your regular keyboard first, then try scanning a code.
Account Inactive

dwedar
Posts: 6
Joined: Mon Dec 28, 2015 3:22 pm

Re: reading from barcode scanner to a text file

Tue Jan 19, 2016 12:03 am

SonOfAMotherlessGoat wrote:What does the output from the following command show for your scanner when you plug it in?

Code: Select all

lsusb
Also, when you scan a code, are you in a text editor window that you can type into? Wedge mode is basically a keyboard emulation, so it's just like you pressing the keys and thus you need to be in a text editor of some kind that you can type into with your regular keyboard first, then try scanning a code.
i try it and open a leaf bad document and scan a code it was useless
thank u for your effort :)
Attachments
raspberr.PNG
this the out put
raspberr.PNG (8.93 KiB) Viewed 5295 times

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

Re: reading from barcode scanner to a text file

Wed Jan 20, 2016 12:52 pm

Some quick googling on "05f9 4202" indicates that this is a serial-port emulating scanner and not a HID-emulating scanner.

To find the name of the device that is created you can plug the unit in after you are finished booting, and then type the "dmesg" command and look at the last lines of the output. Most likely there should be a reference to a "ttyACM0" or "ttyUSB0" device.

shoman0
Posts: 1
Joined: Sat Feb 27, 2016 6:02 am

Re: reading from barcode scanner to a text file

Sat Feb 27, 2016 6:26 am

i solved problem with few steps simply:

1) make sure your repo is updated

2) your barcode scanner is selected as USB KEYBOARD as shown in img:"1.PNG" [DATALOGIC QW2100 KEYBOARD SELECTION][1][1]: http://i.stack.imgur.com/bxkG2.png

3) in Ubuntu barcode scanner capture data and view it in any window can capture input " terminal or text file " or any other thing

4) in raspberry pi problem is that barcode scanner captured or read value is made into "/dev/hidraw0" for example.."that file is created auto when your barcode is connected to your raspi

HERE IS SOME SIMPLE PYTHON CODE TO CAPTURE DATA FROM THAT FILE ONLY WHEN BARCODE IS CONNECTED TO RASPI ........

CODE
start from here
import sys

done = False

while not done:

hid = { 4: 'a', 5: 'b', 6: 'c', 7: 'd', 8: 'e', 9: 'f', 10: 'g', 11: 'h', 12: 'i', 13: 'j', 14: 'k', 15: 'l', 16: 'm', 17: 'n', 18: 'o', 19: 'p', 20: 'q', 21: 'r', 22: 's', 23: 't', 24: 'u', 25: 'v', 26: 'w', 27: 'x', 28: 'y', 29: 'z', 30: '1', 31: '2', 32: '3', 33: '4', 34: '5', 35: '6', 36: '7', 37: '8', 38: '9', 39: '0', 44: ' ', 45: '-', 46: '=', 47: '[', 48: ']', 49: '\', 51: ';' , 52: '\'', 53: '~', 54: ',', 55: '.', 56: '/' }

hid2 = { 4: 'A', 5: 'B', 6: 'C', 7: 'D', 8: 'E', 9: 'F', 10: 'G', 11: 'H', 12: 'I', 13: 'J', 14: 'K', 15: 'L', 16: 'M', 17: 'N', 18: 'O', 19: 'P', 20: 'Q', 21: 'R', 22: 'S', 23: 'T', 24: 'U', 25: 'V', 26: 'W', 27: 'X', 28: 'Y', 29: 'Z', 30: '!', 31: '@', 32: '#', 33: '$', 34: '%', 35: '^', 36: '&', 37: '*', 38: '(', 39: ')', 44: ' ', 45: '_', 46: '+', 47: '{', 48: '}', 49: '|', 51: ':' , 52: '"', 53: '~', 54: '<', 55: '>', 56: '?' }

fp = open('/dev/hidraw0', 'rb')

ss = ""

shift = False

done = False

while not done:

## Get the character from the HID
buffer = fp.read(8)
for c in buffer:
if ord(c) > 0:

## 40 is carriage return which signifies
## we are done looking for characters
if int(ord(c)) == 40:
done = True
break;

## If we are shifted then we have to
## use the hid2 characters.
if shift:

## If it is a '2' then it is the shift key
if int(ord(c)) == 2 :
shift = True

## if not a 2 then lookup the mapping
else:
ss += hid2[ int(ord(c)) ]
shift = False

## If we are not shifted then use
## the hid characters

else:

## If it is a '2' then it is the shift key
if int(ord(c)) == 2 :
shift = True

## if not a 2 then lookup the mapping
else:
ss += hid[ int(ord(c)) ]
print ss

DONE
........................... I ADDED FIRST WHILE LOOP TO MAKE SCRIPT WORK CONTINUOUS TILL U KILL IT WITH "CTRL+C"

ANOTHER THING: IMAGE IS FOR DATALOGIC BARCODE CODE SCANNER QW2100 LITE..SO CHECK YOUR BARCODE MANUEL CAREFULLY TOO..THANKS! :D :D :D

Return to “General discussion”