How to use QStateMachine for Device Manipulation
-
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.
-
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.
@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, ... };