tags:

views:

7446

answers:

4

How to read data from Bar Code Scanner in .net windows application?

Can some one give the sequence of steps to be followed? I am very new to that.

+4  A: 

Most modern bar code scanners act just like keyboards.

I've previously written code in C# for scanning tickets - no special tricks necessary, just make sure the input focus is in a suitable text box and scan the code!

Alnitak
In addition to that: sometimes you have to make settings in the bar code scanner (see manual how to do it) so that it reads the code correctly. For example, if we don't set the language of our scanners to German (default: english), some special (non-english) characters are messed up after reading.
haarrrgh
Alnitak, can you provide code snippet?
Dhana
You can even use it in web applications. Just set focus to a text box and scan the bar code. The code will be written to the text box as if the user entered the code manually.
Rune Grimstad
no code needed, it's just the same as if they'd type the barcode number in on the keyboard
Alnitak
Be careful though because the bar code scanner might submit additional information well (CR, LF, TAB, ENTER etc) before or after the data is submitted. If you buy a decent bar code scanner these things can be specified by scanning special set-up bar codes from a manual (as is the case for Metrologic Voyager scanners for instance).
Marc
+13  A: 

Look at the scanner jack.

If it looks like this:

, then it's a keyboard wedge scanner. It acts like a keyboard: just types your barcode into an edit field.

If it looks like this:

, it's a serial port scanner.

You need to create an instance of System.IO.Ports.SerialPort and use it to communicate with the scanner.

If it looks like this:

, it's a USB scanner. From programmer's point of view, it can be either a keyboard wedge or a serial port scanner. You need to look at the manual, find out which is it and use one of the approaches above.

P.S. It will be easier if you post your scanner's model here, really.

Quassnoi
This isn't necessarily true - I have a USB keyboard wedge scanner at work...
Jon
Haha, for the two cases he presents it is true. trying to find where Quassnoi is incorrect here.
Ray Booysen
I've heard of usb kb wedge scanners, but Posiflex USB scanners that are most popular here use serial emulation.
Quassnoi
loved your answer
Rohit
+1  A: 

I now use the Wasp USB WCS3905 barcode scanners attached to several of my winform (and 1 console) applications although have not noticed differences with other brands of USB scanner.

The way I always test when a new one comes along is to fire up notepad and scan a load of codes off everything that comes to hand; books, DVD, asset tags, but most importantly the stock I need to track. This will allow you visualise how the data is captured.

In my experience they all act like a user typing each character succesively on a keyboard followed by an "Enter" keypress.

For each character (NOTE: not complete bar-code) scanned in a textbox control then at least following events fire:
KeyDown
KeyPress
TextChanged
KeyUp

The Enter keystroke at the end of a scan can be used to push a form's AcceptButton

It should probably be noted that I've only used these on UK-English & US-English configured windows systems.

G-

G-
A: 

If you're using a keyboard wedge, normally the device or wedge software allow one to prefix and/or suffix the keyboard stream with additional characters.

One can use key preview per form to "listen" for the prefix & suffix characters - and when intercepting something that resembles a barcode, the barcode text can be sent to the correct edit box or used to pop up a dialog box.

If you're setting up your own coding systems, depending on the barcode type, you can also embed special characters in to your barcode to identify what's being scanned e.g. a scan starting with SB^ would represent the scan of a stock bin.

When using the keyboard wedge, one is generally unable to determine which type of barcode one is scanning - sometimes the format can be handy to determine the content.