How to handle re-entrant functions? #123
Replies: 1 comment 17 replies
-
Hi Paul, just to make sure I understand the problem correctly, what you are seeing is
This is a problem inherent to any asynchronous code, even if you were not using coroutines, then you would most likely be In those scenarios I usually end up using a command queue - instead of directly invoking If you are on Qt6 (sorry, I can't remember if you said you were using Qt5 or Qt6), you could just use |
Beta Was this translation helpful? Give feedback.
-
Following up from the discussion in #103, I'm experiencing an interesting problem while using a "heartbeat" with a
QSerialPort
. I'm note 100% sure if I'm using this term correctly, but it seems thesendData()
function below is re-entrant. Based on the discussions in #103, we have the heartbeat coroutine polling the device but periodically we also need to send auxiliary commands to our device. However, when we do this, we interrupt the heartbeat before it finishes reading the response or we get the default command response instead of the true response when sending data directly usingsendData()
.Previously it was stated
But I'm not sure this is actually the case unless I'm doing something wrong. Could how we're reading from the SerialPort be causing this issue?
Our basic setup is the following:
We want to ensure that when we send the default command via the
heartbeat()
that we always get the default response and when we send auxiliary commands directly viasendData()
we get the reponse for that command only. Any help is much appreciated.Beta Was this translation helpful? Give feedback.
All reactions