QSerialPort problem for sending data

  • Hello,

    I have a problem for sending data through serial port, my code is working well except if I add a sleep() after sending the data. bytesWritten() return 1 but the byte is not sent (I check with my scope).
    Here is my code :

        connect(m_port, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWritten(qint64)));
            char startByte = 0x7f;
            sleep(1);         /* code is working if I comment this line */

    What I am doing wrong ?
    Thanks for your help.

  • Lifetime Qt Champion


    You have a infinite loop that is blocking Qt's event loop thus Qt can't process anything.

    If you want to use your serial port in an infinite loop, you have to move that code in it's own thread.

  • Hi,
    Thank you for your answer.
    That code is already in a thread.
    Maybe it's hardware problem with my board because I just realized that this code is working with 9600baud and not with 115200 ...

  • Lifetime Qt Champion

    Are you configuring the serial port correctly ?
    Does your device have any limitation ?

Log in to reply

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