LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What is the disadvantage of state machine?

Hi,all,
Anybody can briefly introduce what the disadvantage of state machine? Is it make the LV program large and hard to read?
Thanks.
Message 1 of 16
(12,531 Views)

Is it make the LV program large and hard to read?

Compare to what exactly?

A well written state machine makes the diagram easier to read, because it modularizes the code into logical states. Code maintenance is also easy, because new states can be added without having to mess much with the existing states.

What do you propose as a better alternative? 🙂
Message 2 of 16
(12,515 Views)
I don't know if there is a disadvantage. It makes large programs easier to read, modify, and maintain. If you were to write a state machine program only for handling user events, then the event structure is more efficient than constantly polling controls. I will even use a state machine when one isn't stricly called for. This might be where all states are sequentiaol (i.e. state 2 is always after state 1, state 3, is always after state 4, etc.). Something like this could use a flat sequence structure or just dataflow but with a lot of states, I can fit all of the program on one screen. I would rather click through the different case statements than scroll back and forth the window.
0 Kudos
Message 3 of 16
(12,516 Views)
There are several programming architecture templates that are available in the "New..." dialog. They are under VI from Template -> Frameworks -> Design Patterns. There are six different design patterns. I would say that the State Machine would be a bad choice only when one of the others is better.

That being said, state machines are not so good at parallelism, so if you had a need for that you might want to look at something else. Also, if you cannot see a good way to break your code into actual states, you should consider something else (and once you have don't it with something else, you will probably be able to see the states 🙂 ). Extremely simple, straight-forward algorithms usually don't need to be state machines unless there is a good probablility that it will grow in complexity as the software matures.

Hope that this helps,
Bob
Message 4 of 16
(12,492 Views)

If two state changes occur at the same time, only the first state change will be handled and the second will be lost

0 Kudos
Message 5 of 16
(10,818 Views)
Please don't make absurd comments to an old thread.
Message 6 of 16
(10,807 Views)

@Dennis:

There is a question in the CLAD exams on those state machines and it goes along the line of that "What happens in a state machine when two states changes occur at the same time"…

 

So commenting that post as "absurd" should be forwarded to NI!

(I agree on the age of that thread…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 16
(10,776 Views)
I don't know what sort of state machine can have two state changes at the same time but if they write to a queue, nothing is lost. Without providing some details, I the poster was absurd to make such a comment but NI will also lose points for such a question on the exam.
Message 8 of 16
(10,759 Views)

Isn't a state machine with a queue a QMH? Smiley Wink

0 Kudos
Message 9 of 16
(10,754 Views)

@REAL! wrote:

Isn't a state machine with a queue a QMH? Smiley Wink


Not quite.  There is a slight difference between a Queued State Machine and a Queued Message Handler.  They look alike, but the QSM handles its own queue to go through states while the QMH just accepts commands from other threads through the queue.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 16
(10,722 Views)