Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QModbusTcpServer (Qt 5.7) calling readData before writeData
QtWS25 Last Chance

QModbusTcpServer (Qt 5.7) calling readData before writeData

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
4 Posts 2 Posters 1.2k 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.
  • B Offline
    B Offline
    BartBart
    wrote on last edited by
    #1

    Hello,

    i am implementing a ModbusTcpServer. So i derived a class from QModbusTcpServer and implemented the functions writeData and readData to access my own backing store. Generally the communication works fine but reading Data starts a different process than writing Data. My problem is the following:

    Reading holding Reagisters from the server via Modbus calls the function readData. Writing the same holding Registers, calls readData first and then writeData, so i can't decide inside the readData function if this request is a read or a write out of the QModbusDataUnit-Object. Is there any other possibility to get the information or to avoid calling readData?

    Best Regards.

    Bart

    aha_1980A 1 Reply Last reply
    0
    • B BartBart

      Hello,

      i am implementing a ModbusTcpServer. So i derived a class from QModbusTcpServer and implemented the functions writeData and readData to access my own backing store. Generally the communication works fine but reading Data starts a different process than writing Data. My problem is the following:

      Reading holding Reagisters from the server via Modbus calls the function readData. Writing the same holding Registers, calls readData first and then writeData, so i can't decide inside the readData function if this request is a read or a write out of the QModbusDataUnit-Object. Is there any other possibility to get the information or to avoid calling readData?

      Best Regards.

      Bart

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi @BartBart,

      first thing: QtSerialBus was Technology Preview in Qt 5.7, so you should update to a newer Qt version to use the Modbus classes.

      To your problem: So you have a class derived from QModbusTcpServer, right? And then you re-implemented the QModbusResponse processRequest(const QModbusPdu &request) function, correct?

      So can you show us where your problem arises? It's not 100 % clear for me at the moment.

      Regards.

      Qt has to stay free or it will die.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        BartBart
        wrote on last edited by
        #3

        Hi and thanks for your reply!

        Yes my class is derived from QModbusTcpServer which is derived from QModbusServer. The class QModbusServer has the following virtual functions:

        virtual bool readData(QModbusDataUnit *newData) const
        virtual bool writeData(const QModbusDataUnit &newData)
        

        I have reimplemented these to store the data to an own backing store and to read data from it. When data is written to the ModbusServer it calls at first the readData function and then the writeData. My reimplemented readData function looks in pseudocode like this:

        bool ModbusServer::readData(QModbusDataUnit * newData) const
        {
           if(!updateData(newData))
           {
              return false;
           }
           emit dataWasRequested();
           return true;
        }
        

        I need to know in in this function if it was called because of an request or an write for further handling.

        Regards.

        aha_1980A 1 Reply Last reply
        0
        • B BartBart

          Hi and thanks for your reply!

          Yes my class is derived from QModbusTcpServer which is derived from QModbusServer. The class QModbusServer has the following virtual functions:

          virtual bool readData(QModbusDataUnit *newData) const
          virtual bool writeData(const QModbusDataUnit &newData)
          

          I have reimplemented these to store the data to an own backing store and to read data from it. When data is written to the ModbusServer it calls at first the readData function and then the writeData. My reimplemented readData function looks in pseudocode like this:

          bool ModbusServer::readData(QModbusDataUnit * newData) const
          {
             if(!updateData(newData))
             {
                return false;
             }
             emit dataWasRequested();
             return true;
          }
          

          I need to know in in this function if it was called because of an request or an write for further handling.

          Regards.

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi @BartBart:

          When data is written to the ModbusServer it calls at first the readData function and then the writeData.

          Without deeper understanding of the Modbus classes, this looks strange for me. Can you please provide a stacktrace in readData and writeData so I can see where the functions are called from? Thanks.

          Qt has to stay free or it will die.

          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