[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 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.


  • Moderators

    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


  • Lifetime Qt Champion

    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 ?



  • Thank you very much, I solved thanks to your advice



  • @Memphis

    Could you share the solution you found. I am facing the same problem and I couldn't solve it so far.
    Thanks,


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.