上位机与单片机通信的问题 用vb写的程序连发4个字节再连收4个字节并且循环老是出错 而用串口助手就没问题 第一次接受没问题 第二次就不行 VB的程序如下: Private Sub mscomm1_OnComm() If MSComm1.CommEvent = comEvReceive Then good = MSComm1.Input If good = "a" Then i = 0 If good = "d" Then i = 3 ee(i) = good i = i + 1 If i > 3 Then i = 0 End If If ee(3) = "d" And ee(0) = "a" Then Text1.Text = ee(0) Text2.Text = ee(1) Text3.Text = ee(2) Text4.Text = ee(3) i = 0 End If End Sub Private Sub Timer1_Timer()
hh(0) = "m" hh(1) = "n" hh(2) = "w"
kk = hh(q) MSComm1.Output = "a" MSComm1.Output = kk MSComm1.Output = "c" MSComm1.Output = "d" For o = 0 To 100000 Next q = q + 1 If qq > 3 Then qq = 0
End Sub
|