c# - Arduino串口,数据未到达

标签 c# c++ c arduino

我的 Arduino (Yun) 有问题 基本上我希望主板与 C# 程序通信其数据 将其加载到 Arduino 上:

int Loop=0;
void setup() {
    Serial.begin(9600);
}
void loop() {
    Serial.println(" Data loop = " + String(Loop));
    Loop++;
    delay(500);
}

这是 C# 代码:

SerialPort ArduinoSerial = new SerialPort("COM7", 9600);
ArduinoSerial.Open();
while (true)
{
    string data= ArduinoSerial.ReadLine();
    Console.WriteLine(a);
}

每次启动程序都会发生一些不可预测的事情 有时什么也没有写,有时是这样: 5 6 7 10 _ 但为什么?有时数据会丢失,有时不会“到达”任何内容 尝试使用串行监视器(puTTY)模拟器数据到达 那么为什么?我哪里错了?

最佳答案

更改行: Console.WriteLine(a);

至 Console.WriteLine(数据);

应该有帮助!

关于c# - Arduino串口,数据未到达,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33321331/

相关文章:

c# - 为什么压缩文件夹并没有压缩其大小?

c# - 使用命令列表解析自定义文件

c++ - 文学编码与。 std::pair,解决方案?

C++未初始化的内存?

c - 不同的字符串如何具有相同的地址

检查命令是否由用户直接运行

c# - 获取应用程序ID

c# - 不获取返回值和获取并丢弃返回值在性能上有区别吗?

C++ 如何将 std::mutex 和 std::lock_guard 与仿函数一起使用?

c - 24 小时范围交叉逻辑