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

Problem with QSerialport



  • I have build a application with Qt and use QSerialport for communication with an arduino device. When I write a command to the Arduino I get a response back and try to read the data with a Signal-SLOT (readyread()) and in this slot I execute a serial->readall() call. Sometimes I get the whole message of 32 bytes but sometimes I get a part of the message and in the next message I have the other part of the message. That's ok, but.... I get the message again and sometimes 3 times.
    example message complete in one call:
    "Writefunction not implemented yet\r\n"
    example message complete in two calls:
    *"Writefunction not implement"
    "ed yet\r\nWritefunction not implemented yet\r\n" *

    Can someone help me what is happening here? When I look with a terminal program I see the message only once.


  • Lifetime Qt Champion

    @marpan70

    Sometimes I get the whole message of 32 bytes but sometimes I get a part of the message and in the next message I have the other part of the message.

    Well, thats how serial ports work. You need to define a protocol to come around this. Most often, line endings are used to indicate the end of a message.

    That's ok, but.... I get the message again and sometimes 3 times.
    example message complete in one call:
    "Writefunction not implemented yet\r\n"
    example message complete in two calls:
    *"Writefunction not implement"
    "ed yet\r\nWritefunction not implemented yet\r\n"

    That would be an error in your code, which you didnt show us so far.

    Regards


Log in to reply