<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to use QStateMachine for Device Manipulation]]></title><description><![CDATA[<p dir="auto">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:</p>
<p dir="auto">gui-&gt;state_machine-&gt;command_creator(this basically constructs the command string according to the signal coming from state machine)-&gt;serial_port_communicator-&gt;physical device</p>
<p dir="auto">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.</p>
<p dir="auto">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.</p>
<p dir="auto">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?</p>
<p dir="auto">Anyhow as you can see I am somewhat confused, any help would be appreciated.</p>
]]></description><link>https://forum.qt.io/topic/139509/how-to-use-qstatemachine-for-device-manipulation</link><generator>RSS for Node</generator><lastBuildDate>Fri, 06 Nov 2026 08:41:11 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/139509.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 23 Sep 2022 01:33:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to use QStateMachine for Device Manipulation on Fri, 23 Sep 2022 05:25:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alexanderm">@<bdi>AlexanderM</bdi></a> said in <a href="/post/729857">How to use QStateMachine for Device Manipulation</a>:</p>
<blockquote>
<p dir="auto">Ideally I would want to have a statemachine with just two states: standby and waiting</p>
</blockquote>
<p dir="auto">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:</p>
<pre><code>enum class Actions
{
    Action1,
    Action2,
    ...
};
</code></pre>
]]></description><link>https://forum.qt.io/post/729868</link><guid isPermaLink="true">https://forum.qt.io/post/729868</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Fri, 23 Sep 2022 05:25:51 GMT</pubDate></item></channel></rss>