I am working on an application that requires communication with serial port. I am using the blocking mater example provided by QT.
The problem is, I need to be able to Close and Open the port as I have another program that needs to sometimes to connect to the same serial port.
In that example, the thread will always keep the serial port open. I tried added a bool as a member variable and a pair of public functions to make it stop and start..but it does not work...
I think the problem is when I call a public function of "MasterThread" from my GUI thread the variable is not getting updated.
The "MasterTrhead" class has a bool "m_quit"...but it does not have an example how to use it...
Here is the changes I made:
I added this two function into the body of the class:
void MasterThread::stopCommunication()
{
mFreeThePort = true;
}
void MasterThread::resumeCommunication()
{
mFreeThePort = false;
}
Then in the overrided "run()" function I have:
while (!m_quit) {
if(mFreeThePort) {
serial.close();
QThread::msleep(5);
continue;
}
So I have only added that mFreeThePort boolean and two functions to set it true or false...
But it never closes the serial port...I guess because of the while loop.
You can find the source code of the original example here for the HEADER and here for the BODY