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

Open and read a serial Com Port connected to a scanner

100+
P: 547
I would like to open a serial com port (RS232) when a form (frmRtMain) open, collect the data when the scanner is activated and read data, and then add it to a textbox (text10) in a form. The port should stay open while the form (frmRtMain) is open.
This is what i have tried so far
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. '(com 8)
  7.     lngStatus = CommOpen(intPortID, "8" & CStr(intPortID), _
  8.         "baud=57600 parity=N data=8 stop=1")
  9.         If lngStatus <> 0 Then
  10.     ' Handle error.
  11.         lngStatus = CommGetError(strError)
  12.     MsgBox "COM Error: " & strError
  13.     End If
  14.  
  15.     ' Set modem control lines.
  16.     lngStatus = CommSetLine(intPortID, LINE_RTS, True)
  17.     lngStatus = CommSetLine(intPortID, LINE_DTR, True)
  18.  
  19.     ' Read maximum of 64 bytes from serial port.
  20.     lngStatus = CommRead(intPortID, strData, 64)
  21.     If lngStatus > 0 Then
  22.         ' Process data.
  23.     ElseIf lngStatus < 0 Then
  24.     Me.Text10 = strData
  25.         ' Handle error.
  26.     End If
  27.  
  28.     ' Reset modem control lines.
  29.     lngStatus = CommSetLine(intPortID, LINE_RTS, False)
  30.     lngStatus = CommSetLine(intPortID, LINE_DTR, False)
  31.  
  32.  
I will need a module for the "commopen" and "commget" and "commread" calls to get it to work
I have seen this done with an TCP/IP address/network setup also where the scanner links to a wireless router. Would that be a better option? How is that done?
Any suggestions will be welcomed pls i am rather desperate.
May 22 '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.