How can i read bar code from my bar code reader

强颜欢笑 提交于 2019-12-24 06:29:36

问题


i just got a bar code reader : Barcode Reader

how can i read the data from this gadget with C# ?


回答1:


Typically, barcode readers work as a standard keyboard.

When you scan a barcode, the appropriate information will be "typed" just as if it were a keyboard entry. You just need to author your software to handle the entry information as normal key data.




回答2:


A barcode scanner can operate in two modes

  • as Reed says like a keyboard
  • or as a serial device.

To get it into the latter you will need to 'program' the device (most likely using a special barcode in the manual) and connect to it using SerialPort. For example:

void setup()
{
    scannerSerialPort = new SerialPort("com1", 9600, Parity.None, 8, StopBits.One);
    if (!scannerSerialPort.IsOpen)
    {
        scannerSerialPort.Open();
        scannerSerialPort.DataReceived += new SerialDataReceivedEventHandler(scannerSerialPort_DataReceived);
    }
}

void scannerSerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
    {
        scan += scannerSerialPort.ReadExisting();
        if (scan.EndsWith("\r\n")) {
            scan = scan.Substring(0, scan.Length - 2);
            //act on new value
            UpdateDisplay(scan);
            scan = "";
        }
    }



回答3:


As Reed stated, most barcode readers can be configured for "keyboard emulation". However, if you need more control, look into whether the vendor supplies an OPOS driver. Then you can utilize the OPOS common controls from here:

http://monroecs.com/posfordotnet/opos_dotnet.htm



来源:https://stackoverflow.com/questions/8621033/how-can-i-read-bar-code-from-my-bar-code-reader

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