Go Down

Topic: Serial reading from c# problem (Read 1 time) previous topic - next topic


Jan 11, 2011, 04:25 pm Last Edit: Jan 11, 2011, 04:26 pm by ae553 Reason: 1
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();

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?


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.


Jan 11, 2011, 05:05 pm Last Edit: Jan 11, 2011, 05:06 pm by pwillard Reason: 1
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.


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.

Go Up