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