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 - state connecting
Forum Updated to NodeBB v4.3 + New Features

Modbus TCP Client - state connecting

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 942 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.
  • D Offline
    D Offline
    Damian7546
    wrote on last edited by
    #1

    Hi,

    I have a little problem....
    to check connection with my Modbus Client I use this slot:

    void MyMbClient::onModbusStateChanged(int state)
    {
    
        if (state == QModbusDevice::UnconnectedState){
            qDebug() <<"Modbus TCP Client Disconnected";
            tim_reconnect.start(10000);
            emit modbusTCPClientConnectedState(true);
        }
        else if (state == QModbusDevice::ConnectedState){
           qDebug() <<"Modbus TCP Client Connected";
           tim_reading_inputRegisters.start(1000);
           emit modbusTCPClientConnectedState(false);
        }
        else if (state == QModbusDevice::ConnectingState){
            qDebug() << "Modbus TCP Client Connecting";
            emit modbusTCPClientConnectedState(true);
        }else
        {
            qDebug() <<"Modbus TCP Client Disconnected";
            tim_reconnect.start(10000);
            emit modbusTCPClientConnectedState(true);
        }
    }
    
    

    When I close app with modbus Server the state changing in above slot on Disconnected. But when I plug off form power the PC with server Modbus application the state not change, why ?

    jsulmJ 1 Reply Last reply
    0
    • D Damian7546

      Hi,

      I have a little problem....
      to check connection with my Modbus Client I use this slot:

      void MyMbClient::onModbusStateChanged(int state)
      {
      
          if (state == QModbusDevice::UnconnectedState){
              qDebug() <<"Modbus TCP Client Disconnected";
              tim_reconnect.start(10000);
              emit modbusTCPClientConnectedState(true);
          }
          else if (state == QModbusDevice::ConnectedState){
             qDebug() <<"Modbus TCP Client Connected";
             tim_reading_inputRegisters.start(1000);
             emit modbusTCPClientConnectedState(false);
          }
          else if (state == QModbusDevice::ConnectingState){
              qDebug() << "Modbus TCP Client Connecting";
              emit modbusTCPClientConnectedState(true);
          }else
          {
              qDebug() <<"Modbus TCP Client Disconnected";
              tim_reconnect.start(10000);
              emit modbusTCPClientConnectedState(true);
          }
      }
      
      

      When I close app with modbus Server the state changing in above slot on Disconnected. But when I plug off form power the PC with server Modbus application the state not change, why ?

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

      @Damian7546 said in Modbus TCP Client - state connecting:

      But when I plug off form power the PC with server Modbus application the state not change, why ?

      Probably because the client has no way to notify the server in this case.

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

      D 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Damian7546 said in Modbus TCP Client - state connecting:

        But when I plug off form power the PC with server Modbus application the state not change, why ?

        Probably because the client has no way to notify the server in this case.

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

        @jsulm So how resolve case when the pc will be plug off power , and my client it knew that connection was lost ?

        J.HilkJ 1 Reply Last reply
        0
        • D Damian7546

          @jsulm So how resolve case when the pc will be plug off power , and my client it knew that connection was lost ?

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

          @Damian7546 try exchanging data, if the answer times out -> connection lost


          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.

          D 1 Reply Last reply
          1
          • J.HilkJ J.Hilk

            @Damian7546 try exchanging data, if the answer times out -> connection lost

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

            @J-Hilk do you mean that i should change value in server for example in Input Register, cyclically 0,1,0..etc and in the Modbus TCP Client check if this vale is changing ?

            J.HilkJ 1 Reply Last reply
            0
            • D Damian7546

              @J-Hilk do you mean that i should change value in server for example in Input Register, cyclically 0,1,0..etc and in the Modbus TCP Client check if this vale is changing ?

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

              @Damian7546 no need to change a value, make a cyclic read request


              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
              0
              • R Offline
                R Offline
                ryder_z
                wrote on last edited by
                #7

                Hello, have you solved your problem? I also encountered this problem on Linux, but the Unconnected status can be detected when I disconnect the server in Windows

                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