条形码读取C#中的额外数字值 [英] Barcode reading extra digit values in C#

查看:113
本文介绍了条形码读取C#中的额外数字值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用c#读取条形码扫描器并在变量中收到读数值时,它在扫描时读取扫描项目为3300002266 / r

但在读取记事本或文本框时它阅读正确30026

为什么这个额外的数字读取以及如何使其读取正确为30026

我的代码如下

我的扫描仪阅读器数据如下所示

when read barcode scanner by c# and recieve value of reading in variable
msg it reading scanned item as 3300002266/r on debug
but when reading in notepad or textbox it reading correct 30026
why this extra digits read and how to make it read correct as 30026
my code as below
my scanner reader data as below

Barcode read 2d for Items 

Barcode Device DataLogic Lite QW2100

MODEL QY2100

CLASS QY2120-BK

S/N G17079019





我的尝试:





What I have tried:

private void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {
            TimeSpan elapsed = (DateTime.Now - _lastKeystroke);
            if (elapsed.TotalMilliseconds > 100)
                _barcode.Clear();

            // record keystroke & timestamp
            _barcode.Add(e.KeyChar);
            _lastKeystroke = DateTime.Now;
            //		e.KeyChar	52 '4'	char

            // process barcode
            if (e.KeyChar == 13 && _barcode.Count > 0)
            {


                string msg = new String(_barcode.ToArray());
                //  MessageBox.Show(msg);
                label1.Text = msg;
                _barcode.Clear();
            }
        }

推荐答案

好吧,我可以告诉你,你的TimeSpan想法确定它是否是条形码扫描仪或人类在键盘上的想法是完全废话。 Windows是一个共享系统,您的代码可能无法在代码查找的时间范围内控制CPU,即使扫描程序仍在键入它,也基本上会终止您的条形码。



大多数条形码扫描仪都可以让你配置它们在条形码前加上字符代码并附加字符代码,基本上给你一个标签,让我们知道下一次击键来自条形码扫描器,直到发送条形码末尾的标签。



对于双字符,你没有将事件args的Handled属性设置为True告诉控件不是处理按键事件。基本上,你的letting事件键事件发生两次,一次在你自己的代码中,一次由具有焦点的控件发生。
Well, I can tell you that your TimeSpan idea to determine if it's the barcode scanner or a human at the keyboard idea is complete crap. Windows is a shared system and your code may not be given control of the CPU in the time frame that your code is looking for, essentially killing your barcode even though the scanner is still "typing" it.

Most barcode scanners will let you configure them to prepend and append character codes to the barcode, essentially giving you a tag to look for to know that the next keystrokes are coming from the barcode scanner, up until the tag at the end of the barcode is sent.

As for the double characters, your not setting the Handled property of the event args to True to tell the control to NOT handle the keypress event. Essentially, your letting event key event happen twice, once in your own code and once by the control that has the focus.


这篇关于条形码读取C#中的额外数字值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆