LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-19-2011, 02:37 PM   #1
Andy_CH
LQ Newbie
 
Registered: May 2011
Posts: 5

Rep: Reputation: Disabled
Barcode reader


I'm writing a program which gets data coming from a barcode reader. This reader acts as a keyboard.

We use almost Java, but I think with Java it's impossible to write a background process (without a GUI) which gets this input.

Has somebody an idea how to do that? e.g with C++ as a "bridge" to Java

Actually I have Kubuntu and Debian but if there is a better distribution to do that, I have the possibility to change

Best regards
Andy

Last edited by Andy_CH; 10-19-2011 at 02:40 PM.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 10-19-2011, 05:11 PM   #2
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
If the reader is supported by the Linux kernel (as a human input device, HID), it should show up as an input event device. For each event device, /dev/input/eventX, you can read the vendor ID from /sys/class/input/eventX/device/id/vendor and the product ID from /sys/class/input/eventX/device/id/product .

The details for reading the event streams (just as if it was a file) are in header file /usr/include/linux/input.h and described pretty well in an old two-part LinuxJournal article, here and here. The interface is extremely stable, and you do not need any special libraries to use it. It is the same across all (not too ancient) linux distributions. Just read the event device as if it was a binary file.

You do need superuser access rights (or modifications to the udev rule for that event device) to read the event stream, though. If you run your Java program with superuser rights (I wouldn't!), or if you modify the udev rules to allow the user your Java program runs as to read from the input device, you can do this in pure Java.

In your case, I would recommend writing a very small and compact daemon in C (I prefer C99), which would run as a system service (controlled by SysV init script, Upstart, runit, daemontools, or whatever your distribution uses). It will be responsible for locating the correct device (or devices!). It will do whatever initialization and translation that is necessary, although you probably need none.

The daemon will provide the inputs as messages, either via a named pipe, or -- my preferred for this -- a Unix domain datagram socket (DatagramSocket in Java, I believe). This way the daemon will provide only complete barcode messages, and the application side does not need to worry about the translation, details, or start/end stuff; it will always receive a complete (stream of) datagram(s), each being a full barcode.

The C daemon needed is almost trivial. (There are certain tricks, like how to read from multiple input devices using only a single thread efficiently, and how to queue and distribute the barcode messages to all connected clients. But nothing too serious.)
Personally, I'd take care to write it in a way which would allow you to use multiple scanners and multiple types of scanners at the same time. You might, for example, let the user configure a "name" for each scanner (based on either scanner-provided identifiers, or by USB connection path). Then, the client can ask the daemon for a list of currently-connected scanners, and filter (either in the client, or in the daemon) the scanning events it receives. It might not seem important right now, but having two or three scanners (one or more in fixed positions) may be a big improvement in ergonomics later on.

Note that the same scheme works for practically any HID-type device, not just barcode scanners. (I do believe fingerprint scanners, for example, could be similarly supported. As well as numeric keypads (for hand-typing the barcode number in problematic cases).)

I have done some input event programming myself (in C99), and a lot of daemon programming, but I don't have a barcode scanner, so I'm not exactly sure how they provide the information. (Just as a numeric string? With at least a final delimiter, e.g. a newline? Is there a starting delimiter?)

Hope this helps,
 
3 members found this post helpful.
Old 04-23-2013, 10:41 PM   #3
susannamoore53
LQ Newbie
 
Registered: Apr 2013
Posts: 3

Rep: Reputation: Disabled
Reply to barcode reader

To read a barcode correctly, the barcode has some requirements for scanning. In addition to data checksum, data type, quiet zone, the barcode image size is also need to be concerned.
From my experience, I tried barcode reading in C# project, and it is just one of many but I note it because it has a guide for barcode reading.
 
Old 05-29-2014, 10:28 PM   #4
hongdida
LQ Newbie
 
Registered: May 2014
Posts: 4

Rep: Reputation: Disabled
google with barcode reader keyboard

---------- Post added 05-29-14 at 10:29 PM ----------

and here I attach you a link for that

http://stackoverflow.com/questions/reading-usb-hid-barcode-scanner-input-barcode-reader
 
Old 05-29-2014, 10:30 PM   #5
hongdida
LQ Newbie
 
Registered: May 2014
Posts: 4

Rep: Reputation: Disabled
why it does not show up?
 
Old 05-29-2014, 10:31 PM   #6
hongdida
LQ Newbie
 
Registered: May 2014
Posts: 4

Rep: Reputation: Disabled
Quote:
Originally Posted by susannamoore53 View Post
To read a barcode correctly, the barcode has some requirements for scanning. In addition to data checksum, data type, quiet zone, the barcode image size is also need to be concerned.
From my experience, I tried barcode reading in C# project, and it is just one of many but I note it because it has a guide for barcode reading.
but how to integrate it?
 
Old 06-06-2014, 05:40 AM   #7
Andy_CH
LQ Newbie
 
Registered: May 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
The problem hasn't been really solved but the project ended Dezember 2011.
I mark the thread as closed to stop the mails containing: "You've posted a message in the last week which has gotten replies but has not been marked resolved."

... last week - ROTFL
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to redirect barcode reader to xterm window or ssh login linux_user_123 Linux - General 0 05-12-2010 12:43 PM
Serial Barcode Reader J-Man Linux - Hardware 2 11-22-2008 01:16 PM
Barcode reader software Elguapo Linux - Software 2 09-11-2005 12:54 AM
GnuCash Barcode Reader? JC404 Linux - Software 1 08-26-2003 08:43 PM
barcode 39 vressue Linux - Software 0 02-19-2003 07:19 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration