Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Infinite update data over modbus protocol
QtWS25 Last Chance

Infinite update data over modbus protocol

Scheduled Pinned Locked Moved Unsolved General and Desktop
modbusqt5
3 Posts 2 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    UlrichRekkenin
    wrote on last edited by UlrichRekkenin
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      U 1 Reply Last reply
      1
      • SGaistS SGaist

        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.

        U Offline
        U Offline
        UlrichRekkenin
        wrote on last edited by
        #3

        @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...

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved