Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to send data other than string through serial



  • Hi everyone,
    I am programming in Qt and I would like to send data other than string through the serial port. For example: using the YAT software, it is necessary to use the command \d(number) to send decimal number or \h(number) to send a hexadecimal number. How would be it in Qt? Is there a way of doing it?
    Tks in advance,



  • @rvrv

    Hi and welcome to devent

    Why should this not possible?
    You basically give a pointer to writeData() and tell it the number of bytes to send. Either you pack your binary number into a binary stream and send off this, or you can send also directly.

    int i = 15;
    serial->writeData (&i, sizeof (int) );
    

    Probably you have to cast the pointer.



  • @koahnig

    Thanks for your help!

    I have implemented the mentioned code, but it still not working. The following message is given:
    " error: no matching function for call to 'QSerialPort::write(int*, unsigned int)'
    serial->write(&i, sizeof(8));"



  • @rvrv

    int i = 15;
    serial->writeData ( (char *) &i, sizeof (int) );
    

    That is what I meant with "Probably you have to cast the pointer."
    You might want tohave also a look on to QDataStream . There you can store several values in teh buffer and send all at once.


Log in to reply