简体   繁体   中英

Arduino Serial Port, data don't arrive

I have a problem with my Arduino (Yun) Basically I would like the board communicate its data with a C# program Loading this on Arduino:

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

And this is the C# code:

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

Every time I start the program will come something unpredictable Sometimes there is nothing written, sometimes this: 5 6 7 10 _ But why? Sometimes data is lost, sometimes do not "arrive" anything Trying with an emulator of serial monitor (puTTY) data arrives Then why? Where am I wrong?

Change the line: Console.WriteLine(a);

to Console.WriteLine(data);

it should help!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM