【发布时间】:2016-09-09 00:13:15
【问题描述】:
我正在使用 Arduino 将文本数据发送到 COM15(通过微型 USB)。在我的桌面上,我试图从我的 C# 应用程序中读取数据。但是,当我运行它时,控制台什么也没有显示,并且程序停留在“string s = myPort.ReadLine()”这一行。
以下是我的 C# 程序:
static void Main(string[] args)
{
var myPort = new SerialPort("COM15", 115200);
myPort.Open();
while (true)
{
var s = myPort.ReadLine(); // execution stucks here waiting forever!
Console.WriteLine(s);
}
}
以下是Arduino代码(向COM15发送数据):
int counter = 1;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(" Data Loop = " + String(counter));
counter++;
delay(500);
}
arduino 串行监视器确实显示在 COM15 接收到的数据。我还尝试了其他读取 COM 端口的软件,并验证了该端口上的数据可用。
【问题讨论】:
标签: c# arduino serial-port