How do I correctly capture data from a Symbol LS2208 barcode scanner with C#

Karl picture Karl · Nov 12, 2012 · Viewed 14.7k times · Source

I have been asked to develop a C# Winforms application that reads barcodes and processes data based on products with the relevant barcode.

The barcode scanner we're using is a Symbol LS2208 usb scanner and when it came there was no instructions or cd in the box. We plugged it in, it beeped at us and were were able to scan barcode values into notepad as a test.

In my application, how do I ensure that the scanner populates data into the relevant textbox (I've been setting focus after every other action such as button clicks etc) and how do I know when the entire barcode has been scanned? Currently I have a form timer that ticks every 50ms and checks the length of the textbox value. If it stops getting bigger, I assume the entire barcode has been written.

It just feels a bit "clunky" and wondered if there was another way to do this?

Answer

PhonicUK picture PhonicUK · Nov 12, 2012

Most barcode scanners send a couple of control characters before and after the actual barcode data, usually something like ^B and ^C.

Take a look at what keys its actually sending by listening to the keypress event and watch for what control characters it sends. Then you can be sure when the barcode data begins and ends.