1,451
社区成员
发帖
与我相关
我的任务
分享
Dim iBuf() As Byte
Dim lnx As String
Dim i As Long
ReDim iBuf(bytesTotal - 1)
' log每个收到的字节
i = 0
lnx = "-->BYTE:" + Right("0000000" + Hex(i), 8) + "-"
For i = 0 To bytesTotal - 1
lnx = lnx + " " + Right("0" + Hex(iBuf(i)), 2)
If i Mod 16 = 15 Then
debug.print lnx
lnx = "-->BYTE:" + Right("0000000" + Hex(i + 1), 8) + "-"
End If
Next
i = bytesTotal - 1
If i Mod 16 <> 15 Then
debug.print lnx
End If
Option Explicit
Private Sub Form_Load()
MSComm1.CommPort = 1 'comport
MSComm1.Settings = "9600,n,8,1" '设置串口1的参数
MSComm1.InputMode = comInputModeBinary '接收二进制数据
MSComm1.InBufferSize = 2048
MSComm1.RThreshold = 1 ' MSComm1.Input = 0
MSComm1.InputLen = 0
MSComm1.OutBufferCount = 0
MSComm1.InBufferCount = 0
MSComm1.PortOpen = True
End Sub
Private Sub MSComm1_OnComm()
Dim J As Long
Dim I As Integer
Dim strBuff As Variant
Dim BytReceived() As Byte
Select Case MSComm1.CommEvent
Case 2
strBuff = MSComm1.Input
BytReceived() = strBuff
For I = 0 To UBound(BytReceived)
Print BytReceived(I)
Next
'jieshou
'数据处理代码
End Select
End Sub