Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to use QStateMachine for Device Manipulation
Qt 6.12 LTS is out! See what's new in the release blog

How to use QStateMachine for Device Manipulation

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
2 Posts 2 Posters 549 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.
  • A Offline
    A Offline
    AlexanderM
    wrote on last edited by
    #1

    Hello, I am new to Qt and working on the project which requires communicating with the device using gui. The device receives/responds to commands using serial port according to a known protocol. Some commands take longer time to return from physical device, thus I use a statemachine to 'synchronize' with a physical device and wait for it without blocking the main thread. I show the command flow below:

    gui->state_machine->command_creator(this basically constructs the command string according to the signal coming from state machine)->serial_port_communicator->physical device

    The problem which I have here is the connections between gui and the state machine and then to command_creator: I have many buttons for controlling the device and thus far each is connected to it's own statemachine state, entering to which triggers specific command_creator commands. Obviously this is a very inefficient way to program such commandflow, and hence I am here. I am pretty sure that such scenarios are super typical in embedded programming so I want to ask how are these usually done.

    Ideally I would want to have a statemachine with just two states: standby and waiting. Then gui buttons just trigger transitions. The problem is passing the information on which button was clicked down to the command_creator.

    Could I somehow assign the string to the buttons and just pass that string through the state_machine? Thus the command_creator isn't even required?

    Anyhow as you can see I am somewhat confused, any help would be appreciated.

    jsulmJ 1 Reply Last reply
    0
    • A AlexanderM

      Hello, I am new to Qt and working on the project which requires communicating with the device using gui. The device receives/responds to commands using serial port according to a known protocol. Some commands take longer time to return from physical device, thus I use a statemachine to 'synchronize' with a physical device and wait for it without blocking the main thread. I show the command flow below:

      gui->state_machine->command_creator(this basically constructs the command string according to the signal coming from state machine)->serial_port_communicator->physical device

      The problem which I have here is the connections between gui and the state machine and then to command_creator: I have many buttons for controlling the device and thus far each is connected to it's own statemachine state, entering to which triggers specific command_creator commands. Obviously this is a very inefficient way to program such commandflow, and hence I am here. I am pretty sure that such scenarios are super typical in embedded programming so I want to ask how are these usually done.

      Ideally I would want to have a statemachine with just two states: standby and waiting. Then gui buttons just trigger transitions. The problem is passing the information on which button was clicked down to the command_creator.

      Could I somehow assign the string to the buttons and just pass that string through the state_machine? Thus the command_creator isn't even required?

      Anyhow as you can see I am somewhat confused, any help would be appreciated.

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

      @AlexanderM said in How to use QStateMachine for Device Manipulation:

      Ideally I would want to have a statemachine with just two states: standby and waiting

      For that you do not need a state machine. Just remember what state is currently active ( a boolean member variable would be enough). To remember/know what the last triggered action was you could use an enum and a member variable of that enum type. Each button would trigger an action of specific enum entry:

      enum class Actions
      {
          Action1,
          Action2,
          ...
      };
      

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

      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
      • Unsolved