从 .net (C#) windows 应用程序中的条形码扫描仪读取数据!

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/519771/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 06:33:02  来源:igfitidea点击:

Read data from Bar Code Scanner in .net (C#) windows application!

c#barcode

提问by Dhana

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

如何从 .net windows 应用程序中的条码扫描仪读取数据?

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

有人可以给出要遵循的步骤顺序吗?我对此很陌生。

采纳答案by Quassnoi

Look at the scanner Hyman.

查看扫描仪插孔。

If it looks like this:

如果它看起来像这样:

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

,那么它就是一个keyboard wedge扫描仪。它就像一个键盘:只需在编辑字段中输入您的条形码。

If it looks like this:

如果它看起来像这样:

, it's a serial portscanner.

,这是一台serial port扫描仪。

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

您需要创建一个实例System.IO.Ports.SerialPort并使用它与扫描仪进行通信。

If it looks like this:

如果它看起来像这样:


(source: datapro.net)


(来源:datapro.net

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

,这是一台USB扫描仪。从程序员的角度来看,它可以是keyboard wedge一个serial port扫描仪,也可以是一个扫描仪。您需要查看手册,找出它是什么并使用上述方法之一。

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

PS 如果你在这里发布你的扫描仪型号会更容易,真的。

回答by Alnitak

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!

我以前用 C# 编写了用于扫描门票的代码 - 不需要特殊技巧,只需确保输入焦点位于合适的文本框中并扫描代码即可!

回答by G-.

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.

我现在使用连接到我的几个 winform(和 1 个控制台)应用程序的 Wasp USB WCS3905 条码扫描仪,尽管没有注意到与其他品牌的 USB 扫描仪的差异。

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.

当一个新的出现时,我总是测试的方法是启动记事本并从手头的所有东西中扫描大量代码;书籍、DVD、资产标签,但最重要的是我需要跟踪的库存。这将允许您可视化如何捕获数据。

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

根据我的经验,它们都像用户在键盘上连续键入每个字符,然后按“Enter”键一样。

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

对于在文本框控件中扫描的每个字符(注意:不完整的条形码),至少会触发以下事件:
KeyDown
KeyPress
TextChanged
KeyUp

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

扫描结束时的 Enter 键可用于按下表单的 AcceptButton

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

应该注意的是,我只在英国-英语和美国-英语配置的 Windows 系统上使用过这些。

G-

G-

回答by G-.

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.

如果您正在设置自己的编码系统,根据条码类型,您还可以将特殊字符嵌入到您的条码中以识别正在扫描的内容,例如以 SB^ 开头的扫描将代表对库存箱的扫描。

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.

使用键盘楔时,通常无法确定正在扫描哪种类型的条码 - 有时格式可以方便地确定内容。