Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accesing the serial port

Status
Not open for further replies.

RSH

Technical User
Jun 15, 2000
55
US
So far I have not found how to access the serial port to both send and recieve data.&nbsp;&nbsp;This is quite simple in basic<br>but VB plays by different rules.&nbsp;&nbsp;Can someone give me some sample code for at least sending data from the serial port.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;73 RSH
 
Have a look at the MSComm control, here's some example code from the VB6 Help<br><FONT FACE=monospace><b><br>Private Sub Form_Load ()&nbsp;&nbsp;&nbsp;' Buffer to hold input string<br>Dim Instring As String&nbsp;&nbsp;&nbsp;' Use COM1.<br>&nbsp;&nbsp;&nbsp;&nbsp;MSComm1.CommPort = 1<br>&nbsp;&nbsp;&nbsp;&nbsp;' 9600 baud, no parity, 8 data, and 1 stop bit.<br>&nbsp;&nbsp;&nbsp;&nbsp;MSComm1.Settings = &quot;9600,N,8,1&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;' Tell the control to read entire buffer when Input&nbsp;&nbsp;&nbsp;' is used.<br>&nbsp;&nbsp;&nbsp;&nbsp;MSComm1.InputLen = 0&nbsp;&nbsp;&nbsp;' Open the port.<br>&nbsp;&nbsp;&nbsp;&nbsp;MSComm1.PortOpen = True<br>' Send the attention command to the modem.<br>&nbsp;&nbsp;&nbsp;&nbsp;MSComm1.Output = &quot;ATV1Q0&quot; & Chr$(13)<br>&nbsp;&nbsp;&nbsp;&nbsp;' Ensure that <br>&nbsp;&nbsp;&nbsp;&nbsp;' the modem responds with &quot;OK&quot;.<br>&nbsp;&nbsp;&nbsp;&nbsp;' Wait for data to come back to the serial port.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Do<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoEvents<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Buffer$ = Buffer$ & MSComm1.Input<br>&nbsp;&nbsp;&nbsp;&nbsp;Loop Until InStr(Buffer$, &quot;OK&quot; & vbCRLF)<br>&nbsp;&nbsp;&nbsp;&nbsp;' Read the &quot;OK&quot; response data in the serial port.<br>&nbsp;&nbsp;&nbsp;&nbsp;' Close the serial port.<br>&nbsp;&nbsp;&nbsp;&nbsp;MSComm1.PortOpen = False<br>End Sub<br></font></b><br><br> <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top