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

杀马特。学长 韩版系。学妹 提交于 2020-01-04 07:25:22

问题


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?


回答1:


Distinguishing Barcode Scanners from the Keyboard in WinForms

Check out this thread. There's everything you need there.

If you'll be using this particular scanner, you can setup it to send a specific signal at the end of the input. To setup your scanner gun you need to read the documentation for your device, probably provided on the website of the manifacturer.

Another solution if you will be using the same scanner gun.

If your clients are going to use a lot of different scanners, it would be slight difficult to set everyone of them and track their input. In such case, you have to do it with counting the time between the keypresses (Windows cannot distinguish between barcode scanner and normal keyboard). But you still have to know the suffix of the input the scanner sends.




回答2:


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.




回答3:


Motorola Driver and SDK for Scanners

Sounds to me that Motorola actually have a SDK for this kind of thing with a driver specific LS2208.

Lot of documentation:

Motorola LS2208 Documentation

Seriously, google moar!




回答4:


The symbol or Motorola LS2208 is a pretty standard barcode scanner. LS2208 on RJLTechnologies.com

However the issue with what you are doing is not the scanner it may be the way you are approaching the entire application from the foundation which relates to the barcode being used.If there are multiple layers of information that need to be gathered from a single code maybe it would be better to utilize a 2d barcode maybe a data matrix or something to that effect.

additionally parsing would be simplified and you can use the symbol/motorola adf pre existing library to program the scanner outside of the application either through programming barcodes or you can use the scan utility 123SCAN2 from Motorola Solutions. This means that your application is a bit more flexible is not tied down to a particular scanner and gives greater flexibility to use what ever hardware is needed instead of a codependence on a particular brand or scanner.

regards,




回答5:


You want a solution that will be used to do some sort of actions after the barcode is scanned. You want to do something just after scanning a barcode by your barcode reader, right? Then this will help you more. Write the keyPress event for the textbox which is used to scan the barcode. Now if you write any code there it will be executed every time you presses any key from keyboard or every time when barcode scanner reads a character. If you want to execute some code after the barcode has been scanned, you need to add on condition in that keyPress event. Barcode scanners has the return character (\n) associated with every barcode scan. So you need to add this condition in keyPress event. Below is the code for your reference.

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == (char)Keys.Return)
        {
            MessageBox.Show( textBox1.Text + " scanned...");
            //write your code here
        }

    }
}


来源:https://stackoverflow.com/questions/13343458/how-do-i-correctly-capture-data-from-a-symbol-ls2208-barcode-scanner-with-c-shar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!