By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,404 Members | 2,145 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,404 IT Pros & Developers. It's quick & easy.

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

100+
P: 547
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.
Expand|Select|Wrap|Line Numbers
  1. SendKeyStrokes (DATA.replace (/[^0-9]/g, ""));
  2. SendKeyStrokes (",");
  3. SendKeyStrokes ("{ENTER}");
I need to receive the data directly from scanner in a form called "frmRTMainChip" 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?
Expand|Select|Wrap|Line Numbers
  1. Dim intPortID As Integer ' Ex. 1, 2, 3, 4 for COM1 - COM4
  2.     Dim lngStatus As Long
  3.     Dim strError  As String
  4.     Dim strData   As String
  5.     ' Initialize Communications
  6.     lngStatus = CommOpen(intPortID, "COM" & CStr(intPortID), _
  7.         "baud=9600 parity=N data=8 stop=1")
  8.         If lngStatus <> 0 Then
  9.     ' Handle error.
  10.         lngStatus = CommGetError(strError)
  11.     MsgBox "COM Error: " & strError
  12.     End If
  13.         ' Set modem control lines.
  14.     lngStatus = CommSetLine(intPortID, LINE_RTS, True)
  15.     lngStatus = CommSetLine(intPortID, LINE_DTR, True)
  16.  
  17.     ' Write data to serial port.
  18.     lngSize = Len(strData)
  19.     lngStatus = CommWrite(intPortID, strData)
  20.     If lngStatus <> lngSize Then
  21.     ' Handle error.
  22.     End If
  23.     ' Read maximum of 64 bytes from serial port.
  24.     lngStatus = CommRead(intPortID, strData, 64)
  25.     If lngStatus > 0 Then
  26.         ' Process data.
  27.     ElseIf lngStatus < 0 Then
  28.         ' Handle error.
  29.     End If
  30.     ' Reset modem control lines.
  31.     lngStatus = CommSetLine(intPortID, LINE_RTS, False)
  32.     lngStatus = CommSetLine(intPortID, LINE_DTR, False)
  33.     ' Close communications.
  34.     Call CommClose(intPortID)
Jan 14 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.