vb.netbarcode-scannervirtual-serial-port

Send data to Honeywell Xenon 1902 barcode reader via virtual com port


I am trying to send a query to the Honeywell Xenon 1902 barcode scanner. The scanner is connected via virtual com port. Setting up the communication works fine:

With SerialPort1

        If Not .IsOpen Then
            Try
                .PortName = "Com9"
                .BaudRate = 115200
                .DataBits = 8
                .Parity = Parity.None
                .StopBits = StopBits.One
                .Handshake = Handshake.None
                .DtrEnable = False
                .RtsEnable = False

                .Open()

            Catch ex As Exception
                MessageBox.Show(ex.Message & vbNewLine & ex.StackTrace, "Fehler beim Öffnen des COM Ports", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try

        End If

    End With

When I press manually the button for scanning I receive the data of reading from the scanner:

Private Sub SerialPort1_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived

    Try

        Dim sp As SerialPort = CType(sender, SerialPort)
        PufferString = sp.ReadExisting

        MsgBox(PufferString)

    Catch ex As Exception
        MessageBox.Show(ex.Message & vbNewLine & ex.StackTrace, "Fehler beim Empfangen", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try

End Sub

Now I would like to send the query command "cbr?." from the Honeywell Documentation to the scanner and receive the answer. If I do this on the Honeywell WebInterface it all works fine:

Screenshot from the Honeywell Web Interface Terminal So my problem is that I am unable to send commands to the scanner neither via Tera Term or any other terminal nor via my code:

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Dim BefehlsString As String = "cbr?."
    Dim enc As System.Text.Encoding = New System.Text.ASCIIEncoding()

    Try
        Dim ByteArray() As Byte                             ' Oder String in ...
        ByteArray = enc.GetBytes(BefehlsString & vbCr)             ' ... Einzelbytes umwandeln
        SerialPort1.BaseStream.Write(ByteArray, 0, ByteArray.Length)   ' Einzelbytes senden

    Catch ex As Exception
        MessageBox.Show(ex.Message & vbNewLine & ex.StackTrace, "Fehler beim Senden", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try

End Sub

Solution

  • Due to kunif tip I read the Honeywell Documentation again and I solved my problem:

    The command need the prefix "SYN M CR" (ASCII 22,77,13) --> "SYNMCRcbr?." has to be send to the scanner via serial connection.

    This is the code I send to the scanner:

     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
        Try
    
            Dim BefehlsString As String = Chr(&H16) & "M" & Chr(&HD) & "cbr?."  
    
            serialport.WriteLine(BefehlsString)
    
        Catch ex As Exception
            MessageBox.Show(ex.Message & vbNewLine & ex.StackTrace, "Fehler beim Senden", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    
    End Sub
    

    Then I get an answer as defined in the documentation.