Serial synchronous communication
-
Hi,
I used an example Blocking Master Example to my serial request-response communication . I send request in thread and I get response by emit signal to slot in my main thread.My example reqest is below:
void SerialParser::req_SimpleTest()
and response is in a slot:
void SerialParser::showResponse(const QByteArray &response, const QByteArray &request, const quint8 typeRequest)This request recive all devices addresses on serial bus.
I would like to realize function that can be return recived data. Analogously to the above function the new function should be like:
QByteArray SerialParser::SimpleTest()
This function should send request , wait for read, parse data and return result...
How realize this functionality for example in while loop?
Thanks for any tips. -
This function should send request , wait for read, parse data and return result...
that's not how event programming works. you don't "wait" for anything in a function. you'll stall the event loop.
-
The Blocking Master and Blocking Slave examples (from Qt 5) show how to achieve an entire conversation using blocking IO calls in a worker thread to maintain a responsive GUI.
If you execute an endless or long-running while() loop in the main thread you will break your GUI responsiveness (as @Kent-Dorfman implies) and negate the effort put into the examples to avoid this.
You will have to explain which part of this example pair you do not understand and/or better describe the conversation you are trying to have over the serial line.