I never claimed to be that sharp... Python - log scanned barcode characters to file
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I never claimed to be that sharp... Python - log scanned barcode characters to file
55 of you may notice I originally tried to solve this with evdev ... this was just me being ignorant ...
I have a barcode scanner that, like most, injects the scanned string and a lf as text from a keyboard. Rather than scan data into an application, I'd like to simply log the time of the scan and barcode data scanned to a file.
I'm so new to this I feel like an idiot but assume I can loop and use the device to distinguish between the "real" keyboard and the scanner (scanner is on /dev/input/event7). My question is how to detect the scan, grab the characters to a file and, if possible, stop the scanned barcode characters from getting to X.
So far:
PHP Code:
import time, codecs scanner_location = '/dev/input/event7' # get the correct one from HAL
while True: scanner_device = open(scanner_location,"r") # log stuff to file here - below line for testing/debugging print repr(scanner_device.readline()) scanner_device.close() time.sleep(0.1)
This detects and captures what I need but not in a human readable form (a byte stream?) ... how to I convert the output (...'\xc8J\x88\xc1\x04\x00\x04\x00\x0...) to information I can use?
I know less than you but...you would expect a stream of digits. For this purpose it may be worth getting, eg, a pack of soap powder where they print the UPC or whatever they call it beneath the bar code so that you can compare the stream of electronic information with the printed UPC. Having 'the answer' in front of you will result in additional clues.
Quote:
'\xc8J\x88\xc1\x04\x00\x04\x00\x0..
I'd be guessing at ascii-hex 88, c1, 04, 00 ...but that raises a couple of interesting questions
-what about that single zero at the end...is that the representation of 00, or has a character fallen off at the end
-that c8J at the start, specifically the J. Maybe the J signifies a valid start sequence has been detected or something, because you wouldn't be expecting a j in a hex stream.
At some point, the manual for your reader has to be a help, and particularly when it comes to what the reader does with different encodings (maybe you get a code to tell you which encoding it is, maybe it is all 'transparent', I don't know and it probably depends on the reader)
My guess is that that's raw data (so indeed an encoding issue). How is the scanner connected? Parallel to the keyboard? Or USB? Or serial?
The scanner is connected via usb - I do have a "keyboard wedge" that will make it appear as ps2 kb input but would prefer not to use this as the PCs I plan to use it with do not have ps2 ports.
Quote:
-what about that single zero at the end...is that the representation of 00, or has a character fallen off at the end
-that c8J at the start, specifically the J. Maybe the J signifies a valid start sequence has been detected or something, because you wouldn't be expecting a j in a hex stream.
I may have been unclear - the actual output per scan is much longer ... I pasted a snippet hopping it would be enough to guess at its form.
perhaps I should have clarified ... at the same time that I read the cryptic string from /dev/input/event*, the characters show up on the window with focus. To me this implies that it is a pure encoding issue as there is no software installed on the client to interpret the input.
If I scan an ISBM barcode with the python loop running in a terminal terminal session (A) and the focus on another terminal session (B), I see
how would I start to determine the encoding? The manual and manufacturer of the scanner have been no help and keep asking why I do not just scan directly into a text box.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.