阅读使用USB棒code扫描仪酒吧code。与忽略键盘输入数据,同时沿扫描仪产品ID和供应商ID是未知 [英] Reading a barcode using a USB barcode scanner along with ignoring keyboard data input while scanner product id and vendor id are not known
问题描述
有没有一种方法而忽略了键盘和不知道的USB扫描仪的PID或VID从USB棒code读取器读取?我知道有USB扫描仪输入和键盘输入之间的区别的一种方式,通过使用USB扫描仪的VID和或PID;这是使用code从<一个完成href=\"http://nicholas.piasecki.name/blog/2009/02/distinguishing-bar$c$c-scanners-from-the-keyboard-in-winforms/\">http://nicholas.piasecki.name/blog/2009/02/distinguishing-bar$c$c-scanners-from-the-keyboard-in-winforms/
但有另一种解决方案,而把扫描仪的VID或PID在一个配置文件(或源$ C $ C)键盘和USB扫描仪区分?对于不希望把各种的VID或PID的配置文件中的原因是,正在开发的应用程序将被部署在众多便携式计算机和具有任意类型附加到他们的扫描仪。
另外,我不想配置扫描仪的一个开始和结束,或将输出序列,因为扫描仪正在使用其他软件在同一台机器上很好,我不希望有改变对其他软件code。我不想在酒吧code Reader程序是在串行模式无论是出于同样的原因提到previously。
有键盘和USB棒code读卡器之间的区分办法
您可以依靠这些事实:
- 的code。通过酒吧code读者minmum 4个字符扫描
- 将酒吧code读卡器扫描code。与RETURNENTER结束
- 它需要不到50 mseconds扫描孔栏code
这是使用VS2005 VB一个简单的表单包含:
- TextBox1中
- TextBox2中
- textbox3
- Button1的
- 定时器1的时间间隔设置为50MS
公共类Form1的昏暗酒吧codeSTR的String =
昏暗IsBar codeTaken由于布尔= FALSE
昏暗str作为字符串=
昏暗的STR3的String =
私人小组Form1_KeyDown(BYVAL发件人为对象,BYVAL E上System.Windows.Forms.KeyEventArgs)处理Me.KeyDown 如果Timer1.Enabled = false,那么
海峡= TextBox1.Text
STR3 = TextBox3.Text
万一结束小组私人小组Form1_Key preSS(BYVAL发件人为对象,BYVAL E上System.Windows.Forms.Key pressEventArgs)处理Me.Key preSS
如果Timer1.Enabled = false,那么
Timer1.Enabled = TRUE
万一
酒吧codeSTR =酒吧codeSTR&安培; e.KeyChar
如果升序(e.KeyChar)= 13和len(酒吧codeSTR)&GT; = 4那么
IsBar codeTaken = TRUE
TextBox2.Text =酒吧codeSTR
万一结束小组
私人小组Form1_KeyUp(BYVAL发件人为对象,BYVAL E上System.Windows.Forms.KeyEventArgs)处理Me.KeyUp
如果IsBar codeTaken = true,那么
TextBox1.Text =海峡
TextBox1.Select(莱恩(TextBox1.Text),0)
海峡= TextBox3.Text = STR3
TextBox3.Select(莱恩(TextBox3.Text),0)
STR3 =
万一结束小组
私人小组Timer1_Tick(BYVAL发件人为System.Object的,BYVAL E上System.EventArgs)把手Timer1.Tick
酒吧codeSTR =
IsBar codeTaken =假
Timer1.Enabled =假
结束小组
私人小组的button1_Click(BYVAL发件人为System.Object的,BYVAL E上System.EventArgs)把手Button1.Click
TextBox2.Text =结束小组末级
Is there a way to read from a USB barcode reader while ignoring the keyboard and not knowing the PID or VID of the USB scanner? I know that there is a way of differentiating between USB scanner input and keyboard input by using the VID and or PID of the USB scanner; this was done using code from http://nicholas.piasecki.name/blog/2009/02/distinguishing-barcode-scanners-from-the-keyboard-in-winforms/ But is there another solution to differentiate between keyboard and USB scanner without putting the scanner's VID or PID in a configuration file (or source code)? The reason for not wanting to put various VIDs or PIDs in a configuration file is that, the application being developed will be deployed on numerous laptops and have arbitrary types of scanners attached to them.
Also, I don't want to configure the scanner's with a starting and or ending sequence that would be outputted, since the scanner is being used by other software on the same machine as well and I don't want to have to change the code on the other software. I don't want to program the barcode reader to be in serial mode either for the same reason mentioned previously.
There is a way to differentiate between keyboard and USB barcode reader
You can depend on these facts:
- the code scanned by barcode reader in minmum 4 characters
- the code scanned by barcode reader ends with RETURN "ENTER"
- it take less than 50 mseconds to scan the hole barcode
This is a simple form using VS2005 VB contains:
- textbox1
- textbox2
- textbox3
- Button1
- Timer1 "the time interval set to 50"ms"
Public Class Form1
Dim BarcodeStr As String = ""
Dim IsBarcodeTaken As Boolean = False
Dim Str As String = ""
Dim str3 As String = ""
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If Timer1.Enabled = False Then
Str = TextBox1.Text
str3 = TextBox3.Text
End If
End Sub
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
If Timer1.Enabled = False Then
Timer1.Enabled = True
End If
BarcodeStr = BarcodeStr & e.KeyChar
If Asc(e.KeyChar) = 13 And Len(BarcodeStr) >= 4 Then
IsBarcodeTaken = True
TextBox2.Text = BarcodeStr
End If
End Sub
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
If IsBarcodeTaken = True Then
TextBox1.Text = Str
TextBox1.Select(Len(TextBox1.Text), 0)
Str = ""
TextBox3.Text = str3
TextBox3.Select(Len(TextBox3.Text), 0)
str3 = ""
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
BarcodeStr = ""
IsBarcodeTaken = False
Timer1.Enabled = False
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox2.Text = ""
End Sub
End Class
这篇关于阅读使用USB棒code扫描仪酒吧code。与忽略键盘输入数据,同时沿扫描仪产品ID和供应商ID是未知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!