Infinite update data over modbus protocol
-
Good day,
I`m trying to implement my ModbusWorker class:
class ModbusWorker : public QObject { Q_OBJECT public: explicit ModbusWorker(const QString &filename, QModbusClient* modbus = nullptr, QObject* parent = nullptr); private slots: void read(); void readReady(); private: QTimer* _timer; Tags* _tags; //... }
where Tags is a class wich parses xml-file with modbus tags.
In the constructor QTimer connect with read():_timer = new QTimer(); connect(_timer, &QTimer::timeout, this, &ModbusWorker::read);
And
void ModbusWorker::read(){ QMapIterator<QString, Tag*> iterator(_tags->container(QModbusDataUnit::DiscreteInputs)); while(iterator.hasNext()) { iterator.next(); // construct QModbusDataUnit = data if (auto* reply = _modbusDevice->sendReadRequest(data, _server)) { if (!reply->isFinished()) { connect(reply, &QModbusReply::finished, this, &ModbusWorker::readReady); } else { delete reply; } } } } void ModbusWorker::readReady(){ //.. auto reply = qobject_cast<QModbusReply*>(sender()); switch (reply->error()) { case QModbusDevice::NoError: // ... qInfo() << "type:" << unit.registerType() << "values =" << values; // another cases... default: qDebug() << "read response error:" << reply->error() << reply->errorString(); } }
Here is ther following response:
"read response error: QModbusDevice::Error(TimeoutError) 'Request timeout.'"My question is how to manage infinitly process of updating data (read and write so on).
PS.
Tags in the xml-file may be unordered, so it`s impossible to use_modbusDevice->sendReadRequest(QmodbusDataUnit(QModbusDataUnit::DiscreteInputs, startAddress, maxValues), _server);
I think this will not solve my problem, because there will be the sets[type][numberOfSet] of data for
each QModbusDataUnit::RegisterType type.Upd.
The few first requests are done well with correct data, but shortly I get the error above. -
Hi and welcome to devnet,
I haven't used that module yet but are you sure you are not spamming your devices or triggering network congestion ?
From what you describe it sounds rather like you should trigger a read and once all your devices have been read restart the process rather than having a timer that doesn't take into account network and device(s) latencies.
-
@SGaist said in Infinite update data over modbus protocol:
I haven't used that module yet but are you sure you are not spamming your devices or triggering network congestion ?
Hi, I'm thinking that I do...