[Solved] Qextserialport send ascii problem
-
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
-
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 );
@ -
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
-
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 ?