简体   繁体   English

VB.Net Visual Studio 2017

[英]VB.Net Visual Studio 2017

Team.. I have read a number of posts and still in need of guidance please.团队.. 我已经阅读了一些帖子,仍然需要指导。 I have a Weighing Program VB.2017 that I have written from Scratch instead of porting the VB6 version but stumbling on a Hand Scanner issue.我有一个称重程序 VB.2017,我是从零开始编写的,而不是移植 VB6 版本,而是在手持扫描仪问题上绊倒了。 (OnComm not supported in VB.Net) (VB.Net 不支持 OnComm)

This Code will read the input (Printed Barcode using a serial handheld barcode scanner - Motorola Symbol) but I'm trying to get a SUB executed when the Barcode Scanner button is pressed.此代码将读取输入(使用串行手持条码扫描器打印的条码 - 摩托罗拉符号),但我试图在按下条码扫描器按钮时执行 SUB。 It simply reads off a Barcode and will populate a text box.它只是读取条形码并填充文本框。

Working code that does capture the barcode (after defining the scanner properties and opens the com port. But Can not work out how to execute a Sub when the button is pressed on the scanner.确实捕获条形码的工作代码(在定义扫描仪属性并打开 com 端口之后。但是当按下扫描仪上的按钮时无法计算出如何执行 Sub。

            MyCOMPortScanner.Open()

        _continue = True

        Do
            Dim Incoming As String = MyCOMPortScanner.ReadLine()
            If Incoming Is Nothing Then
                Exit Do
            Else
                returnStr = Incoming
            End If
        Loop

    Catch ex As IOException
        Showmessage(ex.Message & " ComOpen IO")

    Catch ex As Exception
        Showmessage(ex.Message & " ComOpen EX")

Code not working unless I have the cursor in a textbox and only keyboard input not scanner.除非我在文本框中有光标并且只有键盘输入而不是扫描仪,否则代码不起作用。 I have KeyPreview set to true.我将 KeyPreview 设置为 true。

I've tried both KeyPress & also KeyDown.我已经尝试过 KeyPress 和 KeyDown。

Private Sub Weighing_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

    Private Sub Weighing_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress

Again the above 2 work but only for the keyboard and not recognising the trigger press of the barcode scanner.同样,上述 2 项工作但仅适用于键盘,并且无法识别条码扫描器的触发按下。

Sorry Team.. Still at a loss as I simply don't understand.. I tried so many different ways around defining the event like the keydown which works.对不起团队.. 仍然不知所措,因为我根本不明白.. 我尝试了很多不同的方法来定义事件,例如有效的 keydown。 but still at a loss sorry.但还是不知所措抱歉。

    Private Sub Weighing_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

End Sub
'Public Event KeyDown As KeyEventHandler
'Public Event GetSerialData As KeyEventHandler
'Public Event GetSerialData As GetSerialDataEventHandler
Public Event GetSerialData(sender As Object, e As GetSerialDataEventHandler)

Private Sub GetSerialData(ByVal sender As System.Object, ByVal e As IO.Ports.SerialDataReceivedEventArgs) Handles MyBase.GetSerial

End Sub

'Private Sub GetSerial(ByVal sender As System.Object, ByVal e As System.Windows.Forms.GetSerialEventArgs) Handles Me.GetSerial
'End Sub

Public Sub GetSerial()

End Sub

Please help as Im going nuts reading so many posts and not getting anywhere.请帮忙,因为我读了这么多帖子却一无所获。 My code is over 1k lines and this is the only outstanding issue我的代码超过 1k 行,这是唯一未解决的问题

I think that catching the textbox changed event suffice to your needs.我认为捕获文本框更改事件足以满足您的需求。

Private Sub TextBox_TextChanged(sender As Object, e As EventArgs) Handles TextBox.TextChanged
   Try
      ' Do something
   Catch
      ' Catch something
   End Try
End Sub 

OMG.. Sorry for wasting everyone's time and Alessandro prompts. OMG..抱歉浪费大家的时间和亚历山德罗提示。 When I defined the port and did my initial read which worked I was simply using a different PortName (MyCOMPortScanner) instead of SerialPort1.当我定义端口并进行初始读取时,我只是使用不同的 PortName (MyCOMPortScanner) 而不是 SerialPort1。 Now when I press the trigger on the scanner it now enters the code.现在,当我按下扫描仪上的触发器时,它现在会输入代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM