[Solved] Qextserialport send ascii problem
-
wrote on 19 Sept 2013, 15:18 last edited by
Hello,
I made an Qt application that send and received data from a board throught a serial port, but i have some problem with the sending.@QByteArray data4;
data4[0] = 124;
port->write(data4, data4.length());@The board receive the ASCII characters of the number "|" instead of the decimal value 124.
If I convert the value in HEX like this@data4 = data4.toHex;@
the sent value is right, 7C.
How can I send decimal value?Thank you
-
wrote on 19 Sept 2013, 16:03 last edited by
You have to think in byte.
124 (decimal) means 7c (hexadecimal) means | (see ascii table, in this case is a printable value).
Always only one byte. -
wrote on 19 Sept 2013, 16:35 last edited by
You need to decide what to send. As already pointed out you are basically sending the byte representation of 124 which is binary and only one byte.
If you would like to send it as three characters '1', '2' and '4' you have to convert the binary representation to ASCII characters first.
E.g.
@
QString str = QString::number ( 124 );
@ -
wrote on 19 Sept 2013, 19:07 last edited by
I would like to send an integer through the port as the board's firmware is programmed to receive an integer and not a character or hexadecimal,
@ QByteArray data4;
data4[0] = 124;
port->write(data4, data4.length());
@but in this way the board receives only an ASCII character "|"
Even if I perform a conversion of this type
@ QString str = QString::number ( 124 );@
the board continues to see ASCII characters and does not work
Thank you
-
Lifetime Qt Championwrote on 19 Sept 2013, 19:57 last edited by SGaist 6 Mar 2015, 22:17
Hi,
You might be misunderstanding something:
124 == 7C == |
These are three representations of the same value. Could you post the portion of the firmware that handles that ?
-
wrote on 20 Sept 2013, 14:13 last edited by
Thank you very much, I solved thanks to your advice