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. make communication using modbus
QtWS25 Last Chance

make communication using modbus

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 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.
  • R Offline
    R Offline
    rezaMSLM
    wrote on last edited by
    #1

    hi;
    i want to write a simple program to make communication between PC and some slave devices using modbus via serial port. but since i'm a newbie i dont know how to start it!.
    I think that first I have to create an object and then give it the required parameters and the open the port and send commands and receive the answers.(is that right?)
    for first step I think i have to create an object of QModbusDevice but I receive error:

    #include <QCoreApplication>
    #include <QModbusRtuSerialMaster>
    #include <QModbusClient>
    #include <QModbusDevice>
    #include <QModbusServer>
    #include <QModbusDataUnit>
    #include <QModbusReply>
    
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
        QModbusDevice my_ModBus_Object;
        return a.exec();
    }
    

    please help and guide me

    J.HilkJ 1 Reply Last reply
    0
    • R rezaMSLM

      hi;
      i want to write a simple program to make communication between PC and some slave devices using modbus via serial port. but since i'm a newbie i dont know how to start it!.
      I think that first I have to create an object and then give it the required parameters and the open the port and send commands and receive the answers.(is that right?)
      for first step I think i have to create an object of QModbusDevice but I receive error:

      #include <QCoreApplication>
      #include <QModbusRtuSerialMaster>
      #include <QModbusClient>
      #include <QModbusDevice>
      #include <QModbusServer>
      #include <QModbusDataUnit>
      #include <QModbusReply>
      
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
          QModbusDevice my_ModBus_Object;
          return a.exec();
      }
      

      please help and guide me

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @rezaMSLM
      have you seen jet the Modbus Example that comes with qt?

      https://doc.qt.io/qt-5/qtserialbus-modbus-master-example.html

      and to your error, without seeing the actual error, my guess is, you did not add QT += serialport serialbus in your *.pro file


      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.

      1 Reply Last reply
      3
      • R Offline
        R Offline
        rezaMSLM
        wrote on last edited by
        #3

        my .pro file:

        QT -= gui
        QT += serialbus core serialport
        
        CONFIG += c++11 console
        CONFIG -= app_bundle
        
        # The following define makes your compiler emit warnings if you use
        # any feature of Qt which as been marked deprecated (the exact warnings
        # depend on your compiler). Please consult the documentation of the
        # deprecated API in order to know how to port your code away from it.
        DEFINES += QT_DEPRECATED_WARNINGS
        
        # You can also make your code fail to compile if you use deprecated APIs.
        # In order to do so, uncomment the following line.
        # You can also select to disable deprecated APIs only up to a certain version of Qt.
        #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
        
        SOURCES += \
                main.cpp
        

        that example is too hard for me
        I'm a newbie and I got confused when opened that example
        I want to write my own and very simple program for start but i need help to do that

        here is the error:

        D:\Projects\Qt_ProjectFolder\ModbusTest\main.cpp:13: error: cannot declare variable 'my_ModBus_Object' to be of abstract type 'QModbusDevice'
             QModbusDevice my_ModBus_Object;
                           ^
        
        aha_1980A 1 Reply Last reply
        0
        • R rezaMSLM

          my .pro file:

          QT -= gui
          QT += serialbus core serialport
          
          CONFIG += c++11 console
          CONFIG -= app_bundle
          
          # The following define makes your compiler emit warnings if you use
          # any feature of Qt which as been marked deprecated (the exact warnings
          # depend on your compiler). Please consult the documentation of the
          # deprecated API in order to know how to port your code away from it.
          DEFINES += QT_DEPRECATED_WARNINGS
          
          # You can also make your code fail to compile if you use deprecated APIs.
          # In order to do so, uncomment the following line.
          # You can also select to disable deprecated APIs only up to a certain version of Qt.
          #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
          
          SOURCES += \
                  main.cpp
          

          that example is too hard for me
          I'm a newbie and I got confused when opened that example
          I want to write my own and very simple program for start but i need help to do that

          here is the error:

          D:\Projects\Qt_ProjectFolder\ModbusTest\main.cpp:13: error: cannot declare variable 'my_ModBus_Object' to be of abstract type 'QModbusDevice'
               QModbusDevice my_ModBus_Object;
                             ^
          
          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi @rezaMSLM,

          can you show your main.cpp file regarding the error?

          that example is too hard for me
          I want to write my own and very simple program for start but i need help to do that

          Sorry to tell you, but for an advanced topic as Modbus you'll need some Qt basics first.

          You'll at least need a Qt event loop running to let the communication run.

          I'd suggest you to get a feeling for the mainwindow.cpp of that example. The function names directly correspond to user interface actions, so the main structure should be easy to get. Then try to understand e.g. what happens on a connection.

          Regards

          Qt has to stay free or it will die.

          1 Reply Last reply
          2
          • R Offline
            R Offline
            rezaMSLM
            wrote on last edited by
            #5

            my project is a console application and has no mainwindow.cpp file.
            for first step i just want to build an object, this shouldn't be very complex. but i receive error

            aha_1980A 1 Reply Last reply
            0
            • R rezaMSLM

              my project is a console application and has no mainwindow.cpp file.
              for first step i just want to build an object, this shouldn't be very complex. but i receive error

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

              @rezaMSLM

              how should we help you if you don't provide the needed infos?

              so please show your main.cpp.

              Qt has to stay free or it will die.

              R 1 Reply Last reply
              0
              • aha_1980A aha_1980

                @rezaMSLM

                how should we help you if you don't provide the needed infos?

                so please show your main.cpp.

                R Offline
                R Offline
                rezaMSLM
                wrote on last edited by
                #7

                @aha_1980
                I have posted it in my first post

                1 Reply Last reply
                0
                • mranger90M Offline
                  mranger90M Offline
                  mranger90
                  wrote on last edited by
                  #8

                  That is because QModbusDevice is an abstract base class.
                  You can not instantiate an instance of such.
                  You should try to instantiate either a QModbusServer or QModbusClient.

                  1 Reply Last reply
                  4

                  • Login

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