Visual Basic Code for Serial Communication

H

Thread Starter

HASBALLAH

I have serial communication protocol transmit data. I want make vb.6 code. Each package has 21 bytes and starts with Chr(2) and ends up with
Chr(13). Serial data baud rate is adjustable between 300, 600, 1200, 2400, 4800, 9600, 19200, 38400. Data length is 8 bits, and there is no parity. Data will be sent only after standstill condition is reached. Order of bytes in each package is as follows:<pre>
SB A B SP WIEGHT1 SP WIEGHT2 CH CK ST</pre>
 
R
Put a comm control on a form

Call this sub to open the form<pre>
Public Sub OpenCommExample()
With frmMenu
.Comm.Settings = "9600,N,8,1"
.Comm.CommPort = 4
.Comm.RThreshold = 1
.Comm.HandShaking = comNone
.Comm.PortOpen = True
End With

Send Data to form

Public Sub CommSend(ByVal sData As String)
frmMenu.Comm.Output = sData
End Sub


Make Data String

Public Function MakeDataString(ByVal sDataIn As String) As String
Dim sX As String
sX = Chr$(2)
sX = sX & sDataIn
sX = sX & vbCr
MakeDataString = sX

End Function<.pre>
 
Top