Pages: [1]   Go Down
Author Topic: Serial communication: Which character am I missing?  (Read 758 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 164
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi!

Im interfacing with a windows forms application over USB, which works pretty well. But one strange point: On the arduino, I run "Serial.println("connect"). I read this string on the computer and make "If message = "connect" Then..." which is always a false. If I make "If message.Substring(0,7) = "connect" Then..." I always get a true. The Substring function just takes the 7 first letters beginning from the first. So for me, this means, the Arduino sends one character more. If I let the Arduino print the ASCII numbers for what hes sending to the serial monitor, there also only appear 7 characters, and the last one is the "t" from the "connect".

What character am I missing, what should the software check for?

Thanks!
Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

println vs. print
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 164
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for your answer.

Yes, this is what I was thinking too, but I don't know how I should check for this character (since the Arduino doesn't send an ASCII code for this, according to the serial monitor. Only print() is not possible, since the SerialPort Class doesn't accept it as "finished".
Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://arduino.cc/en/Serial/Println
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 553
Posts: 46300
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The println() method adds '\n' and '\r' to the output. On the receiving end, you should be looking for these characters, and NOT storing them in the array to be compared.
Logged

Pages: [1]   Go Up
Jump to: