我正在尝试读取Arduino正在发送的串行数据,但即使我更改了Arduino输出,它也会不断地给我一遍又一遍收到的字符串。为什么它只给我第一个值而不是更新?
Module Module1
Sub Main()
Dim com4 As IO.Ports.SerialPort = Nothing
com4 = My.Computer.Ports.OpenSerialPort("COM4")
Dim incoming As String
Do
incoming = com4.ReadLine()
Console.WriteLine(incoming)
Threading.Thread.Sleep(250)
Loop
End Sub
End Module
答案 0 :(得分:0)
可能是,根据你的arduino草图,它会将相同的数据发送一段时间,填满接收缓冲区,这是在Do循环中读取一段时间的内容。
尝试使用活动
dim withevents com4 as serialport.......
sub datareceivedhandler (sender as object, e as eventargs) handles com4.datareceived
dim incoming as string = com4.readline
console.writeline(incoming)
end sub