1)通信口初始化
Private Sub Initialize()
MSComm1.CommPort =1
MSComm1.Settings = “9600,E,7,1”
MSComm1.InBufferSize = 1024
MSComml.OutBuffersize = 1024
MSComm1.InputLen = 0
MSComml.InputMode = comInputText
MSComm1.Handshaking = comNone
MSComm1.PortOpen = True
End Sub
2)请求通信与确认
Private Function MakeHandshaking()As Boolean
Dim InPackage As String
MSComml.OutBufferCount = 0
MSComml.InBufferCount = 0
MSComml.OutPut = Chr(&H5)
Do
DoEvents
Loop Until MSComml.InBufferCount = 1
InPackage = MSComml.Input
If InPackage = Chr(&H6) Then
MakeHandShaking = True
Else
MakeHandshaking = False
End If
End Function
3)发送命令报文
Private Sub SendFrame ()
Dim Outstring As String
MSComml.OutBufferCount = 0
MSComml.InBufferCount = 0
Outstrin = Chr(&H2)+″on″+″10F604″+Chr(&H3)+″74″
MSComml.Output = Outstring
End Sub
4)读取应答报文
Private Sub ReceiveFrame()
Dim Instring As String
Do
DoEvents
Loop Until MSComml.InBufferCount = 12
InString = MSComml.Inpult
End Sub
楼主最近还看过