[Solved] Qextserialport send ascii problem
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.
data4 = 124;
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?
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.
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.
QString str = QString::number ( 124 );
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 = 124;
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
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 ?
Thank you very much, I solved thanks to your advice
Could you share the solution you found. I am facing the same problem and I couldn't solve it so far.