【发布时间】:2013-06-29 09:50:57
【问题描述】:
我确实编写了一个小型 C# 应用程序,它从 COM 端口读取 Arduino 板发送的一系列数字。
问题:
如果 Arduino 每 500 毫秒发送一个值,但我的 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 更新了我的代码