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. Reading data from device via QModbusRtuSerialMaster

Reading data from device via QModbusRtuSerialMaster

Scheduled Pinned Locked Moved Solved General and Desktop
modbusserialportcom-portqmodbusdevicec++ qt
3 Posts 2 Posters 979 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
    BeaverShallBurn
    wrote on 1 Sept 2021, 04:17 last edited by BeaverShallBurn 9 Jan 2021, 04:39
    #1

    Cheers to everyone!

    I've received a quite simple task: develop an app that can read/write data from a MCU-based device utilizing Modbus and COM-port interface. Having absolutely zero experience in Qt development i rushed to doc.qt.io to gather some info and found QModbusRtuSerialMaster class. After having a sigh of relief i began writing my class, inheriting the one listed above.

    Then i ran into a problem. Guys from MCU department provided me with some sort of communication table, which has a register to read/write data (e.g. 3001, or 1007:2 for bit data type) and the data type. For example: reading register 2001 will get us serial number of the device (uint16).

    QtCreator has an included example of Modbus master app, which is capable of connecting to my device with no problems. But when it comes to reading/writing data, there is no way to use my register codes.

    An hour of googling brought me to similar app written in C#, which converts register codes to 16bit before sending them into "read" function.

    Any suggestions on further investigation will be highly appreciated.

    Also begging your pardon for my english.

    UPD: found this topic and trying to implement same way of reading.

    -Knock knock
    -Who's there?
    -Compi
    -Compi who?
    -Compilation error

    J 1 Reply Last reply 1 Sept 2021, 05:40
    0
    • J J.Hilk
      1 Sept 2021, 05:40

      hi @BeaverShallBurn and welcome

      I'm sorry but I really fail to see the problem,
      The QModbusRtuSerialMaster class allows you to request/read registers and you get a list(vector) of uint16_t back, what's there to convert?

      can you show what code you actually have so far, and where exactly the problem is with it?

      B Offline
      B Offline
      BeaverShallBurn
      wrote on 1 Sept 2021, 06:42 last edited by BeaverShallBurn 9 Jan 2021, 07:03
      #3

      Hi, @J-Hilk!

      Looks like i found desired method in QModbusDataUnit class docs. Don't know how i missed it being mentioned in List of All Members for QModbusRtuSerialMaster. I guess digging into Qt docs about Modbus was a proper way to solve this :)

      QModbusDataUnit::QModbusDataUnit(QModbusDataUnit::RegisterType type, int address, const QVector<quint16> &data)
      

      In my case this will be:

      QModbusDataUnit input(QModbusDataUnit::InputRegisters, 3001, data);
      

      Thanks for joining my journey!

      -Knock knock
      -Who's there?
      -Compi
      -Compi who?
      -Compilation error

      1 Reply Last reply
      2
      • B BeaverShallBurn
        1 Sept 2021, 04:17

        Cheers to everyone!

        I've received a quite simple task: develop an app that can read/write data from a MCU-based device utilizing Modbus and COM-port interface. Having absolutely zero experience in Qt development i rushed to doc.qt.io to gather some info and found QModbusRtuSerialMaster class. After having a sigh of relief i began writing my class, inheriting the one listed above.

        Then i ran into a problem. Guys from MCU department provided me with some sort of communication table, which has a register to read/write data (e.g. 3001, or 1007:2 for bit data type) and the data type. For example: reading register 2001 will get us serial number of the device (uint16).

        QtCreator has an included example of Modbus master app, which is capable of connecting to my device with no problems. But when it comes to reading/writing data, there is no way to use my register codes.

        An hour of googling brought me to similar app written in C#, which converts register codes to 16bit before sending them into "read" function.

        Any suggestions on further investigation will be highly appreciated.

        Also begging your pardon for my english.

        UPD: found this topic and trying to implement same way of reading.

        J Offline
        J Offline
        J.Hilk
        Moderators
        wrote on 1 Sept 2021, 05:40 last edited by
        #2

        hi @BeaverShallBurn and welcome

        I'm sorry but I really fail to see the problem,
        The QModbusRtuSerialMaster class allows you to request/read registers and you get a list(vector) of uint16_t back, what's there to convert?

        can you show what code you actually have so far, and where exactly the problem is with it?


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        B 1 Reply Last reply 1 Sept 2021, 06:42
        0
        • J J.Hilk
          1 Sept 2021, 05:40

          hi @BeaverShallBurn and welcome

          I'm sorry but I really fail to see the problem,
          The QModbusRtuSerialMaster class allows you to request/read registers and you get a list(vector) of uint16_t back, what's there to convert?

          can you show what code you actually have so far, and where exactly the problem is with it?

          B Offline
          B Offline
          BeaverShallBurn
          wrote on 1 Sept 2021, 06:42 last edited by BeaverShallBurn 9 Jan 2021, 07:03
          #3

          Hi, @J-Hilk!

          Looks like i found desired method in QModbusDataUnit class docs. Don't know how i missed it being mentioned in List of All Members for QModbusRtuSerialMaster. I guess digging into Qt docs about Modbus was a proper way to solve this :)

          QModbusDataUnit::QModbusDataUnit(QModbusDataUnit::RegisterType type, int address, const QVector<quint16> &data)
          

          In my case this will be:

          QModbusDataUnit input(QModbusDataUnit::InputRegisters, 3001, data);
          

          Thanks for joining my journey!

          -Knock knock
          -Who's there?
          -Compi
          -Compi who?
          -Compilation error

          1 Reply Last reply
          2

          1/3

          1 Sept 2021, 04:17

          • Login

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