Skip to content

Commit e686676

Browse files
committed
Always use communicator with SerialPort in its QThread
1 parent fd7e8c9 commit e686676

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

plugins/robots/utils/src/robotCommunication/robotCommunicator.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,18 @@ RobotCommunicator::~RobotCommunicator()
3737

3838
void RobotCommunicator::send(QObject *addressee, const QByteArray &buffer, const unsigned responseSize)
3939
{
40-
mRobotCommunicationThreadObject->send(addressee, buffer, responseSize);
40+
auto blockingConnectionType = mRobotCommunicationThreadObject->thread() == QThread::currentThread()
41+
? Qt::DirectConnection : Qt::BlockingQueuedConnection;
42+
QMetaObject::invokeMethod(mRobotCommunicationThreadObject.get(), [&](){mRobotCommunicationThreadObject->send(addressee, buffer, responseSize);},
43+
blockingConnectionType);
4144
}
4245

4346
void RobotCommunicator::send(const QByteArray &buffer, const unsigned responseSize, QByteArray &outputBuffer)
4447
{
45-
mRobotCommunicationThreadObject->send(buffer, responseSize, outputBuffer);
48+
auto blockingConnectionType = mRobotCommunicationThreadObject->thread() == QThread::currentThread()
49+
? Qt::DirectConnection : Qt::BlockingQueuedConnection;
50+
QMetaObject::invokeMethod(mRobotCommunicationThreadObject.get(), [&](){mRobotCommunicationThreadObject->send(buffer, responseSize, outputBuffer);},
51+
blockingConnectionType);
4652
}
4753

4854
void RobotCommunicator::connect()

0 commit comments

Comments
 (0)