|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub Main()
Dim hComm As Long
Dim szTest As String
Dim rg As Range
Dim GET1 As String
Dim SEND1 As String
'打开串口1
hComm = OpenComm(3)
If hComm <> 0 Then
'设置串口通讯参数
SetCommParam hComm
'设置串口超时
SetCommTimeOut hComm, 2, 3
For Each rg In Range("C3:C6")
GET1 = BytesToString(ReadComm(hComm))
GET1 = "--"
SEND1 = rg.Offset(0, -1).Value
WriteComm hComm, StringToBytes(SEND1)
Sleep 50
'读串口
GET1 = BytesToString(ReadComm(hComm))
' Debug.Print GET1
rg.Offset(0, 1).Value = GET1
'If rg.Value = GET1 Then
'If InStr(GET1, rg.Value) = 0 Then
If rg.Value2 Like Left(GET1, Len(GET1) - 1) Then '*****************这里总是不成功*********************
rg.Offset(0, 2).Value = "OK"
Else
rg.Offset(0, 2).Value = "NG"
End If
Next
CloseComm hComm
End If
CloseComm hComm
End Sub
我改成这样对了。GET1多了个发送结束的字符在最后。 |
|