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

Create a function using QSerialPort



  • Hello everyone,

    I need your help with creating a function using the QSerialPort class.

    The overall functioning of the function is there but I have trouble turning all that into code.

    The purpose of this function will be:

    -to send an address (type "\ FE \ 01 \ XX \ XX \ XX") via serial link every second until the reception buffer is full

    -If the buffer is full and reading it, we get the same address as the one sent then we empty the buffer

    -when the buffer is empty the loop still executes but this time the address will be ("\ FE \ 02 \ XX \ XX \ XX") and the loop starts again

    When reading the documentation Qt I came across "bool QSerialPort :: canReadLine ()" which returns true or false if the buffer is filled, so I can use this to trigger my function.

    The problem is that I have a lot of trouble implementing the code from the ideas I have on paper, I do not know if my choices are the right ones. If anyone can help me draw the structure that my function will take

    Thank you



  • @Elocau

    Hi and welcome to devnet forum

    There are a couple of examples available for QSerialPort. Those examples may be compiled for initial tests and build typically a good start for own applications.



  • @koahnig
    Are you talking about the examples available in Qt Creator or examples available elsewhere? I will see the examples on Qt Creator, I forgot. Thank you



  • @Elocau

    Either in creator or directly the examples you may install with Qt libs. They should be the same.



  • @Elocau
    If I understand correctly you are trying to talk with device/devices using some kind of ping-pong messaging? The PC (master) sends frame FE 01... waits for the reception from the device (Slave) and the cycle is repeated but with the new frame FE 02...? Am I correct?



  • @Elocau said in Create a function using QSerialPort:

    "\ FE \ 01 \ XX \ XX \ XX"

    Your example suggests that you are sending binary data so in this case using bool QSerialPort :: canReadLine () will probably not work as expected as it will seek for end line ASCII character.

    You need to define if you want to use binary of ASCII protocol and then handle data accordingly


Log in to reply