{... // 3. передача запроса в контроллер и получение ответа CThreadAdapter adapter(controller, timeout); unitVars = adapter.sendRequest(requestId,params);...}
C++ (Qt)class DeviceCommunicator : public QObject{ Q_OBJECT public: explicit DeviceCommunicator (QObject *parent) : QObject (parent) , serialPort_ {} { connect (serialPort_, &QSerialPort::readyRead, this, &DeviceCommunicator::readPort); } void sendCommand (int index, const QByteArray &command, int answerSize) { commandsQueue_.enqueue(std::make_tuple(index, command, answerSize)); if (commandsQueue_.size() == 1) { serialPort_.write(std::get<1> (commandsQueue_.first())); } } Q_SIGNALS: void commandSent (int index, const QByteArray &answer); private: void readPort () { answer_ += serialPort_.read(std::get<2> (commandsQueue_.first()) - answer_.size()); if (answer_.size() == std::get<2> (commandsQueue_.first())) { emit commandSent (std::get<0> (commandsQueue_), answer); commandsQueue_.dequeue(); answer_.clear(); if (!commandsQueue_.isEmpty()) { serialPort_.write(std::get<1> (commandsQueue_.first())); } } } private: QSerialPort serialPort_; QQueue<std::tuple<int, QByteArray, int>> commandsQueue_; QByteArray answer_;}