我写了一个小型的C#应用程序,它从COM端口读取由Arduino板发送的一系列数字。C#SerialPort通信协议
问:
如果Arduino的发送单个值每500ms,但我的C#程序读取单个值每1秒不会在C#被甩在Arduino的背后?如果这是真的,从Arduino发送的数据是否存储在缓冲区中,还是只是被丢弃?
[编辑]
娄是我使用从COM
阅读代码
System.Windows.Forms.Timer tCOM;
...
tCOM.Interval = 1000;
tCOM.Tick += new System.EventHandler(this.timer1_Tick);
...
SerialPort port = new SerialPort();
port.PortName = defaultPortName;
port.BaudRate = 9600;
port.Open();
.....
private void timer1_Tick(object sender, EventArgs e)
{
log("Time to read from COM");
//read a string from serial port
string l;
if ((l = port.ReadLine()) != null)
{
......
}
}
亚历克斯,你如何从串行读取。发布您的代码。 – FeliceM
@FeliceM更新了我的代码 – Alex