Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
How to read a value from a barcode reader device using c#?
Posted
Updated 6-Jan-10 4:50am
v2
Comments
EscKey2004 27-May-11 16:52pm    
I found this article interesting

Reading Barcodes From Any Image[^]

For most barcode readers, it's just like pressing the keyboard. Hence, create a textbox, position the cursor inside the textbox and scan with the barcode reader. It should send keys and one newline character.
 
Share this answer
 
Another solution would be adding a MessageFilter in the contructor of your form to intercept all keyboard messages. This way you dont have to enter a textfield and the scanner can be used independently.

Application.AddMessageFilter(new BarcodeMessageFilter());

In BarcodeMessageFilter you need to implement bool PreFilterMessage(ref Message m) of IMessageFilter to catch all char messages (m.Msg == 0x0102).

If you set your scanner to have a special start byte (could be a non printable char), you can use this byte to find out if the following bytes/chars were sent from a barcode scanner. The end can be detected by the stop byte that is set in the scanner.

You should also use a timeout for reading bytes from the scanner (e.g. 50ms), so that you know when the transmission was somehow aborted. Without a timeout the message filter would catch all following char messages, if the stop byte gets somehow lost.

Now you can read all following bytes into a buffer and trigger an event that gives you the complete string without using a textfield.
 
Share this answer
 
I concur with Answer #2. . .that's how things work with the readers in my work area. ..when the device successfully recognizes a barcode it sends the characters to the PC via an inline-with-the-keyboard cable, thereby mimicking a person typing the contents of the barcode.

What you also have at play is the barcode typically needing the contents wrapped in a control character (asterisk for instance) that instructs the device to send the enter key too. . .. .but this is not required.
 
Share this answer
 
If you post the model of barcode reader, it would be easier to give you specific help. That being said, most barcode readers that I've seen mimic keyboard input, so you can do something as simple as set focus to a textbox on a winform and instruct the user to scan the barcode. The barcode will then appear in the textbox.

[2c from Brady] What I do is set up the bar-code scanner to use a control character prefix and a tab suffix. I then have a 'global' keypress listener on the main window, so whenever a code is scanned, the app gives the textbox focus first, and the tab suffix loses the focus again an triggers calculations etc.
 
Share this answer
 
v2
Check the barcode device manufacturer's manual (if they gave you one). That should provide some of the information you need.
 
Share this answer
 
v2
Reading a barcode does not require any code I think. I have been using it in my application, and when the Barcode device is connected, it produces produces the text automatically on the TextBox you focus and will put a Return after the data.

You have to work on the Data based on the Return key. :thumbsup:
 
Share this answer
 
Check this Article.

I think it will help you.
http://www.codeproject.com/KB/recipes/bcreader2of5.aspx
 
Share this answer
 
usually reading barcode reader is not required any code for most of the barcode readers. It works as a input media like keyboard. You just need to point the cursor where you want to enter the data.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900