How to check the serial port for data and if available copy to txtbox in form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neelsfer
    Contributor
    • Oct 2010
    • 547

    How to check the serial port for data and if available copy to txtbox in form

    Has anybody perhaps have code to check the serialport of the PC(rs232) for data received from a a rfid scanner, and if its available, then populate it to a textbox on a form.

    i currently use 3rd party logger software but it is not very stable. The hex characters received through a serial port are converted into numbers and then transmits these numbers to the app as keystrokes. i.e 0004, or 0005, etc. followed by a comma and "ENTER".
    i use the following code in my 3rd party application but it sometimes give me garbage numbers in between.
    Code:
    SendKeyStrokes (DATA.replace (/[^0-9]/g, ""));
    SendKeyStrokes (",");
    SendKeyStrokes ("{ENTER}");
    I need to receive the data directly from scanner in a form called "frmRTMainC hip" in my application.
    The textbox on the main form is called "StrInput"

    Is there anybody out there that receive data directly from scanners and it is added to textbox? It must also not be more than 5 characters, split by a "," and only numeric format.Can one perhaps block duplicates mumbers also?
    Pls assist

    i found this code on the internet if it may assist?
    Code:
    Dim intPortID As Integer ' Ex. 1, 2, 3, 4 for COM1 - COM4
        Dim lngStatus As Long
        Dim strError  As String
        Dim strData   As String
        ' Initialize Communications
        lngStatus = CommOpen(intPortID, "COM" & CStr(intPortID), _
            "baud=9600 parity=N data=8 stop=1")
            If lngStatus <> 0 Then
    	' Handle error.
            lngStatus = CommGetError(strError)
    	MsgBox "COM Error: " & strError
        End If
            ' Set modem control lines.
        lngStatus = CommSetLine(intPortID, LINE_RTS, True)
        lngStatus = CommSetLine(intPortID, LINE_DTR, True)
    
        ' Write data to serial port.
        lngSize = Len(strData)
        lngStatus = CommWrite(intPortID, strData)
        If lngStatus <> lngSize Then
    	' Handle error.
        End If
        ' Read maximum of 64 bytes from serial port.
        lngStatus = CommRead(intPortID, strData, 64)
        If lngStatus > 0 Then
            ' Process data.
        ElseIf lngStatus < 0 Then
            ' Handle error.
        End If
        ' Reset modem control lines.
        lngStatus = CommSetLine(intPortID, LINE_RTS, False)
        lngStatus = CommSetLine(intPortID, LINE_DTR, False)
        ' Close communications.
        Call CommClose(intPortID)
Working...