现在串口 DataReceived中的程序如下,第一行接收大半次数据,第二行接收小半次数据。请老师帮忙看看应该怎么修改,使接收的数据放在同一行上?
Dim s As String
Dim s1 As String
Dim cnt As Integer = 0
Dim sdt As Date = Date.Now
Do While Date.Now < sdt.AddSeconds(5) '等到5秒
cnt = Ports("COM1").BytesToRead
If cnt > 0 Then Exit Do '或者读取到数据
application.doevents
Loop
'Dim cnt As Integer = e.Port.BytesToRead
If cnt > 0 Then '缓冲区是否有数据
Dim Val(cnt - 1) As Byte
e.Port.Read(val,0,cnt)
Dim i As Integer
For i = 0 To cnt-1
' s1 = Val(i)
s1 = DecToHex(Val(i))
If s1.Length = 1 Then
s = s & 0 & DecToHex(Val(i))
Else
s = s & DecToHex(Val(i))
End If
Next
End If
'Output.Show(s)
'msgbox(s)
Dim r As Row = Tables("表A").AddNew()
r("第一列") = s
r("第二列") = Date.Now
r.Save()