Function ShowCharCode(strData As String) As String
Dim i As Integer
For i = 1 To Len(strData)
ShowCharCode = ShowCharCode & " " & Asc(Mid$(strData, i, 1))
Next i
ShowCharCode = Trim$(ShowCharCode)
End Function
Private Sub cmdSync_Click()
Dim str As String
Dim strData As String
Dim StrSync As String
Dim strOutput As String
Dim i, j As Integer
StrSync = Chr$(&HAA) & Chr$(&HD) & Chr$(&H0) & Chr$(&H0) & Chr$(&H0) & Chr$(&H0)
Label1.Caption = StrSync
MSComm1.Output = StrSync
Do
DoEvents
Loop Until MSComm1.InBufferCount >= 2
str = MSComm1.Input
For i = 1 To Len(str)
strData = strData & " " & Asc(Mid$(str, i, 1))
Next i
strData = Trim$(strData)
txtBox.Text = strData
End Sub
I don't have much knowledge about serial port communications myself, but you
could have a look at these links:
Article:
http://www.bitwisemag.com/copy/vb/vb1.html
Example COM Detect
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=57069&lngWId=1
Example Send & Receive to com port
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=31818&lngWId=1