Dim max As Integer =40
Dim start As Integer =0
Dim a As Integer
Dim b As Integer
Dim st As String =""
For i As Integer = 1 To max/2
a = start
b = start + 2
start= start+3
If start>max Then
a =start-3
b = max
Exit For
End If
st = cstr(DecToHex(a)).PadLeft(8,"0") & cstr(DecToHex(b)).PadLeft(8,"0")
Dim st1 As String =DecToHex(dr("地址")) & "65090D" & st
Functions.Execute("sendstr",st1,dr("串口号")) '发送代码
Dim cnt As Integer = Ports(dr("串口号")).BytesToRead '接受设备反馈回来的代码
Dim str As String=""
If cnt > 0 Then '缓冲区是否有数据
Dim rval(cnt - 1) As Byte
Ports(dr("串口号")).Read(rval,0,cnt)
str =BitConverter.ToString(rval).Replace("-", "")
Dim dr1 As DataRow =DataTables("日志信息").AddNew
dr1("记录信息")="【接收数据】" & str
dr1("记录时间")= Date.Now
dr1.Save
End If
Next
问题是:当循环进行的时候速度太快,设备都来不及反应。怎么才能让循环慢慢进行,比如说 发送和接受全部数据后再下一轮发送,请老师帮忙解决一下 谢谢
[此贴子已经被作者于2021/8/7 18:10:42编辑过]