Serial read from rs232

Hi guys
I sending comand to device rs232 and grab the data
When im using serial.print to see the data i getting numbers
When i use serial.write i geting the correct text i need
Any one knows why? If i need serial write to see the txt is it means my data recive from the device is in int? Assci?
If i want to pars the data how can i do that if i dont know in what data type the the serial read is using?
Thanks!

MosheAsh:
If i need serial write to see the txt is it means my data recive from the device is in int?

Sounds like you are receiving the decimal (or hex) values of the ASCII characters. Take a look at the ASCII Chart to see if they line up.

I will check it

You are presumably printing each character separately.
This code snippet:

  uint8_t c = 66;
  Serial.println(c);
  Serial.write(c);
  Serial.println();

prints
66
B
because print/println treats 'c' as an integer whereas write treats it as a character.

Pete

el_supremo:
because print/println treats 'c' as an integer whereas write treats it as a character.

I think it is more accurate to say that Serial.print() converts the number into the two characters '6' and '6' so a human can read them and Serial.write() just sends the number without any conversion.

...R

Serial.print() treats it as an integer, converts it into human readable format, and prints that out.
Serial.write() just places the value into the Serial buffer as is.

Change the snippet from #6 a little and it should give you the expected output:

  char c = 66;
  Serial.println(c);
  Serial.write(c);
  Serial.println();

should print:
B
B

Change the snippet from #6 a little

#3 ?

Pete

el_supremo:
#3 ?

Pete

You could of course have reposted the snippet from #3 and make my post perfect :slight_smile:

Har har! :slight_smile:

Pete