简体   繁体   中英

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. (OnComm not supported in VB.Net)

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. 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.

            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.

I've tried both KeyPress & also 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.

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. 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

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. When I defined the port and did my initial read which worked I was simply using a different PortName (MyCOMPortScanner) instead of SerialPort1. Now when I press the trigger on the scanner it now enters the code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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