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. QtModbus doesn't reconnect programmatically
Forum Updated to NodeBB v4.3 + New Features

QtModbus doesn't reconnect programmatically

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 5 Posters 1.7k Views 3 Watching
  • 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.
  • AndySA Offline
    AndySA Offline
    AndyS
    Moderators
    wrote on last edited by
    #4

    Hi @Mark81,

    You did it right thanks!

    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    Pablo J. RoginaP 1 Reply Last reply
    1
    • AndySA AndyS

      Hi @Mark81,

      You did it right thanks!

      Pablo J. RoginaP Offline
      Pablo J. RoginaP Offline
      Pablo J. Rogina
      wrote on last edited by
      #5

      @AndyS if your issue is solved, please don't forget to mark your post as such! Thanks.

      Upvote the answer(s) that helped you solve the issue
      Use "Topic Tools" button to mark your post as Solved
      Add screenshots via postimage.org
      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

      AndySA 1 Reply Last reply
      0
      • Pablo J. RoginaP Pablo J. Rogina

        @AndyS if your issue is solved, please don't forget to mark your post as such! Thanks.

        AndySA Offline
        AndySA Offline
        AndyS
        Moderators
        wrote on last edited by
        #6

        @Pablo-J.-Rogina It's not my issue :)

        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #7

          Neither is mine :)

          Anyway, closing this as there is nothing we can do here anymore.

          Qt has to stay free or it will die.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mark81
            wrote on last edited by
            #8

            Sorry guys, but the issue is not solved at all! We've just discovered a documentation bug - but that wasn't the main issue.

            The big problem, still there, is the second part of the question. Why does reconnection work only if triggered by a user click and it doesn't executing the same code using a QTimer?

            aha_1980A 1 Reply Last reply
            0
            • M Mark81

              Sorry guys, but the issue is not solved at all! We've just discovered a documentation bug - but that wasn't the main issue.

              The big problem, still there, is the second part of the question. Why does reconnection work only if triggered by a user click and it doesn't executing the same code using a QTimer?

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

              @Mark81 don't connect the timer to the action, connect it to the corresponding slot instead.

              Qt has to stay free or it will die.

              M 1 Reply Last reply
              2
              • beeckscheB Offline
                beeckscheB Offline
                beecksche
                wrote on last edited by beecksche
                #10

                The QtModubus module has an asynchronous API. So by calling connectDevice() or disconnectDevice() your client is not connected/disconnected to the device immediately, but rather in ConnectingState/ClosingState. You have to receive the signal stateChanged() to ensure the connection state of your client. Only when the state of the client is ConnectedState your client is connected.

                Also when you want to reconnect, I would ensure that you the state of the client is UnconnectedState.

                Or just do a QHostInfo::lookupHost . Once the lookup was successfull you can connect again.

                M 1 Reply Last reply
                2
                • aha_1980A aha_1980

                  @Mark81 don't connect the timer to the action, connect it to the corresponding slot instead.

                  M Offline
                  M Offline
                  Mark81
                  wrote on last edited by
                  #11

                  @aha_1980 said in QtModbus doesn't reconnect programmatically:

                  @Mark81 don't connect the timer to the action, connect it to the corresponding slot instead.

                  Tried: nothing change.

                  aha_1980A 1 Reply Last reply
                  0
                  • beeckscheB beecksche

                    The QtModubus module has an asynchronous API. So by calling connectDevice() or disconnectDevice() your client is not connected/disconnected to the device immediately, but rather in ConnectingState/ClosingState. You have to receive the signal stateChanged() to ensure the connection state of your client. Only when the state of the client is ConnectedState your client is connected.

                    Also when you want to reconnect, I would ensure that you the state of the client is UnconnectedState.

                    Or just do a QHostInfo::lookupHost . Once the lookup was successfull you can connect again.

                    M Offline
                    M Offline
                    Mark81
                    wrote on last edited by
                    #12

                    @beecksche said in QtModbus doesn't reconnect programmatically:

                    The QtModubus module has an asynchronous API. So by calling connectDevice() or disconnectDevice() your client is not connected/disconnected to the device immediately, but rather in ConnectingState/ClosingState. You have to receive the signal stateChanged() to ensure the connection state of your client. Only when the state of the client is ConnectedState your client is connected.

                    Also when you want to reconnect, I would ensure that you the state of the client is UnconnectedState.

                    I'm aware of this, but I have some thoughts about:

                    • I cannot wait such a long time: the built-in timeout is too long for my needs. Hence when I want to disconnect and reconnect I must use my own timeout timer

                    • I understand it might not be the best approach, but after calling disconnectDevice() I actually delete the object. It's not enough to force a disconnection?

                    • Anyway, I don't understand why it works clicking the action on the UI, even one right the other, and it doesn't by code, even waiting few seconds

                    1 Reply Last reply
                    0
                    • M Mark81

                      @aha_1980 said in QtModbus doesn't reconnect programmatically:

                      @Mark81 don't connect the timer to the action, connect it to the corresponding slot instead.

                      Tried: nothing change.

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

                      @Mark81

                      Then either debug it yourself, or provide more code.

                      Are you sure ui->actionDisconnect->trigger(); does what you expect?

                      It should work the same way with a timer as it would work with a button.

                      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