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. Modbus TCP Client write holding registers
Forum Updated to NodeBB v4.3 + New Features

Modbus TCP Client write holding registers

Scheduled Pinned Locked Moved Solved General and Desktop
29 Posts 2 Posters 5.0k 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.
  • jsulmJ jsulm

    @Damian7546 said in Modbus TCP Client write holding registers:

    So how define wr_redy in *.h file ?

    Don't define it as lambda, but a normal method.

    D Offline
    D Offline
    Damian7546
    wrote on last edited by Damian7546
    #14

    @jsulm How do I do that?
    When I declare my function in *.h file :
    void wr_redy();

    And I will create definition this function outside my run() function , I do not have acces to variables defined in run()...

    jsulmJ 1 Reply Last reply
    0
    • D Damian7546

      @jsulm How do I do that?
      When I declare my function in *.h file :
      void wr_redy();

      And I will create definition this function outside my run() function , I do not have acces to variables defined in run()...

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #15

      @Damian7546 If you want to connect a lambda to a signal then do it properly:

      connect(this, ClientMachine1::holdRegArrayChanged, this, wr_redy);
      

      wr_redy is NOT a member of your class, so simply do not prefix it with your class name.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Damian7546 If you want to connect a lambda to a signal then do it properly:

        connect(this, ClientMachine1::holdRegArrayChanged, this, wr_redy);
        

        wr_redy is NOT a member of your class, so simply do not prefix it with your class name.

        D Offline
        D Offline
        Damian7546
        wrote on last edited by
        #16

        @jsulm said in Modbus TCP Client write holding registers:

        @Damian7546 If you want to connect a lambda to a signal then do it properly:

        connect(this, ClientMachine1::holdRegArrayChanged, this, wr_redy);
        

        wr_redy is NOT a member of your class, so simply do not prefix it with your class name.

        Right

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Damian7546
          wrote on last edited by
          #17

          @jsulm Unfortunetly my write function still doesn't work:/

          auto wr_redy = [&](){
                      for(int i=0; i < m_holdRegArray.count(); i++){
                          qDebug() << "count: " << i;
                          wr.setValue(i, m_holdRegArray[i]);
                      }
              };
          

          The application was crash when it wr.setValue(i, m_holdRegArray[i]); is called...

          jsulmJ 1 Reply Last reply
          0
          • D Damian7546

            @jsulm Unfortunetly my write function still doesn't work:/

            auto wr_redy = [&](){
                        for(int i=0; i < m_holdRegArray.count(); i++){
                            qDebug() << "count: " << i;
                            wr.setValue(i, m_holdRegArray[i]);
                        }
                };
            

            The application was crash when it wr.setValue(i, m_holdRegArray[i]); is called...

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #18

            @Damian7546 said in Modbus TCP Client write holding registers:

            The application was crash when

            So, did you use debugger to see why it crashes?
            What is wr?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • D Offline
              D Offline
              Damian7546
              wrote on last edited by
              #19

              @jsulm When I have status: "ModbusTCPClient is disconnected" my app crash when I try write registers..

              jsulmJ 1 Reply Last reply
              0
              • D Damian7546

                @jsulm When I have status: "ModbusTCPClient is disconnected" my app crash when I try write registers..

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #20

                @Damian7546 Then don't write registers if there is no connection...

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                D 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @Damian7546 Then don't write registers if there is no connection...

                  D Offline
                  D Offline
                  Damian7546
                  wrote on last edited by
                  #21

                  @jsulm I was wrong, sometimes app was crash when I try write value. I get message like below :

                  QSocketNotifier: Socket notifiers cannot be enabled or disabled from another thread
                  QObject: Cannot create children for a parent that is in a different thread.
                  (Parent is QModbusTcpClient(0x504f8fc), parent's thread is ClientTicketMach(0x1215a30), current thread is QThread(0x11c0b28)
                  QObject::startTimer: Timers cannot be started from another thread
                  Error Modbus TCP CLient read:  QModbusDevice::TimeoutError
                  QObject::killTimer: Timers cannot be stopped from another thread
                  
                  jsulmJ 1 Reply Last reply
                  0
                  • D Damian7546

                    @jsulm I was wrong, sometimes app was crash when I try write value. I get message like below :

                    QSocketNotifier: Socket notifiers cannot be enabled or disabled from another thread
                    QObject: Cannot create children for a parent that is in a different thread.
                    (Parent is QModbusTcpClient(0x504f8fc), parent's thread is ClientTicketMach(0x1215a30), current thread is QThread(0x11c0b28)
                    QObject::startTimer: Timers cannot be started from another thread
                    Error Modbus TCP CLient read:  QModbusDevice::TimeoutError
                    QObject::killTimer: Timers cannot be stopped from another thread
                    
                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #22

                    @Damian7546 As all these errors tell you: do the threading properly!

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    D 1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      Damian7546
                      wrote on last edited by Damian7546
                      #23
                      This post is deleted!
                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        Damian7546
                        wrote on last edited by
                        #24
                        This post is deleted!
                        1 Reply Last reply
                        0
                        • jsulmJ jsulm

                          @Damian7546 As all these errors tell you: do the threading properly!

                          D Offline
                          D Offline
                          Damian7546
                          wrote on last edited by
                          #25

                          @jsulm said in Modbus TCP Client write holding registers:

                          @Damian7546 As all these errors tell you: do the threading properly!

                          Can you explain me ?

                          jsulmJ 1 Reply Last reply
                          0
                          • D Damian7546

                            @jsulm said in Modbus TCP Client write holding registers:

                            @Damian7546 As all these errors tell you: do the threading properly!

                            Can you explain me ?

                            jsulmJ Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on last edited by
                            #26

                            @Damian7546 Look:

                            QObject: Cannot create children for a parent that is in a different thread.
                            (Parent is QModbusTcpClient(0x504f8fc), parent's thread is ClientTicketMach(0x1215a30), current thread is QThread(0x11c0b28)
                            

                            It seems like your QModbusTcpClient is used in different threads. Please analyse your code to see how you're using it.

                            I already mentioned in this thread that threads should only be used if really necessary.

                            https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            0
                            • D Offline
                              D Offline
                              Damian7546
                              wrote on last edited by Damian7546
                              #27
                              This post is deleted!
                              1 Reply Last reply
                              0
                              • D Offline
                                D Offline
                                Damian7546
                                wrote on last edited by Damian7546
                                #28

                                @jsulm This connect declared in run() function:
                                connect(this, &ClientTicketMach::holdRegArrayChanged,wr_redy);
                                run wr_redy in other threadss..:/

                                Do you have any idea how run wr_redy in my thread by change values in holdRegArray?

                                1 Reply Last reply
                                0
                                • D Offline
                                  D Offline
                                  Damian7546
                                  wrote on last edited by
                                  #29

                                  @jsulm Now I use Modbus TCP Client without threads and everything works.

                                  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