PDA

View Full Version : send hex or ascii or int value through serial port



omegaKnot
27th May 2011, 09:50
I have been able to write serial port. I need to get integer value from line edit, then send the value through serial port.


unsigned char c = ui->lineEdit->text().toInt();


How can i send all 255 ascii values through serial port?

high_flyer
27th May 2011, 09:53
How can i send all 255 ascii values through serial port?
you said also:

I have been able to write serial port.

So I don't understand the question.
If you can write to the serial port, where is the problem?

omegaKnot
27th May 2011, 10:11
i can send values like 1,2,5, A,},R. They all are single character. Now i need to send decimal 65 or hex 41. Im thinking of sending it as its ASCII 'A'. How do i do it?

high_flyer
27th May 2011, 10:18
i can send values like 1,2,5, A,},R. They all are single character.
Exactly.
That is ALL you can do.
How these bytes are interpreted, is the job of the receiving end.
You are not sending the bytes "as ASCII" you interpret them as ASCII when you receive the bytes.
The same stream can be interpreted by the receiving end as ASCII binary or hex or what ever else.

omegaKnot
27th May 2011, 10:27
Then how am i gonna send value 41. Actually this value gets calculated in sender side. Should i send 'A' then?

high_flyer
27th May 2011, 10:38
Then how am i gonna send value 41
Simply by sending a byte with the decimal value of 41.
On the receiving side this can be displayed as an 'A', or used to calculate the meaning of life by adding 1 to it and displaying the decimal outcome.