Get data from a barcode reader in Linux

Started by
2 comments, last by adriano_usp 16 years, 10 months ago
Hi, I'm looking for a good way to get data from a barcode reader to a C++ application in Linux. The barcode reader sends an integer value to where the keyboard focus is, that could be a text file or a textbox. The application should periodically get the code, so I thought to read a text file where the barcode reader would print in. But the text file would lost the focus when handling other windows. So: 1) How could I do, using C or C++, to set the focus to a text file? 2) Do you know a better way to get data from the barcode reader? Thanks in advance
Advertisement
There is no standard for barcode reader hardware. There is no barcode reader API or standard driver library to access. You need to make a more computer expert rather then user level analysis of the barcode reader.

For example you say that it sends an integer value to where the keyboard has focus. By integer value do you actually mean it sends a string a characters that to an unwashed user would be an "integer"? And is it doing this in Linux, all by itself? Has you looked behind the computer, to see if this barcode reader happens to be plugged straight into the PS/2 port along with the keyboard using a Y-splitter cable of some kind? If that's the case, the barcode reader is just sending exactly the same input as a PS/2 keyboard typing out the barcode (a good number of inexpensive barcode readers do this). Meaning you read the input just like you read input from the keyboard - much as you describe other applications being able to easily do without any special drivers or software.
I recently wrote a project that read data from a barcode reader. The reader was attached to the PS2 port, via some divider to allow the keyboard to use the same port. So the computer only thought that there was one keyboard attached.

The reader sent data in ascii. Let's say that it read a barcode that was 35. Then it sent the ascii-value for 3, then the ascii-value for 5 and finally the ascii-value for return. So to the computer it looked like someone had simply pressed 3, 5 and return on the keyboard.

If your reader works in the same way you could just use cin to read the values. I used SDL instead, since the project I did was a graphical program.
Thanks friends.

Yes, my barcode reader has an Y-splitter cable plugged to the PS/2 port. But I'm also considering to use USB barcode readers.

Well, since these reader behave like keyboards, independently of the connector type, I will read data from the keyboard, like you suggest [smile].

But my application could not have the focus. In true, it will run in background and a simple input call like getch(), scanf(), std::cin... will not work in this case.

Using DirectInput, I can capture keyboard data independently on where the focus is. But how could I do this in Linux?

Another doubt:
- I intend to use two USB barcode readers plugged to the same computer. Is there an way to identify from which reader the data is coming?

Thanks again.

This topic is closed to new replies.

Advertisement