Pages: [1]   Go Down
Author Topic: Serial reading from c# problem  (Read 952 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi all, i would like to ask,

i'm currently sending a value for example 1000 from my c# to the arduino.

i am reading from serial 3 btw. this is how i read from the arduino:

int value;

if (serial3.available >2){
value = serial3.read();
serial.print(value);
}


but when i open my serial monitor, the value is not 1000,  it is within 0 to 255. what can i do if i want to receive my exact value of 1000?
tiv!
« Last Edit: January 11, 2011, 10:26:10 am by ae553 » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 616
Posts: 49433
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First thing we would need to know is how you are sending the value from the C# application.

If it is being sent as a string, you need to read all the characters, store them in a char array, NULL terminate the array, and use atoi() to convert the array to an integer.
Logged

Cumming, GA
Offline Offline
Edison Member
*
Karma: 20
Posts: 1656
Ultimate DIY: Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

SERIAL DATA is sent as ASCII characters, not as VALUES.

You could send ASCII "1000", but that is in reality most likely sent as the following "decimal" ASCII values:  "49,48,48,48,13,10"  with 13 and 10 being there or not as line endings. So you need to create an "interpreter" that recreates the ASCII data back into a value.

The question comes up a lot so a search will find some solutions.


« Last Edit: January 11, 2011, 11:06:28 am by pwillard » Logged

Florida
Offline Offline
Sr. Member
****
Karma: 4
Posts: 431
hookedup!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Just a note, it is bad practice to double post the same question in two forums at roughly the same time as this question was.
Logged

Pages: [1]   Go Up
Jump to: