LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

State machine no longer in design patterns

Solved!
Go to solution

I have been using Labview to program user GUIs for 15 years now as a sideline to my work. I started with Labview 7 (or 6, can't remember) and saw new features being added over the years to every new release. It used to be a secret (or it seemed that way) back then that in order to avoid spagetty-code, a state machine design was a good practice. Along came then a new Labview version (again forgot which) having design patters as templates, and sure enough the state machine pattern was one of them. But then in the later releases state machines are no longer included in the templates' collection. I've always wondered why. Is NI advicing us to used other patterns instead? I still use state machines extensibly, but started looking into the others as well (specially events). I still find code written as a state machine to be the most efficient and lean, easy to mainain, document, and understand. I've had some nasty effects using events. Any one agrees?

Message 1 of 11
(4,780 Views)
Solution
Accepted by Billynares

I disagree. There is no such thing as you use state machine OR Events. All in my codes I use both of them. State machine is a programmatic concept, Events is a programming tool (sorry for the naming, English is not my first language).

So it does not make sense to compare Events <--> State machines, they are not in the same category. And if you had "nasty effects" with Events, it only means you did not learn a proper use of them yet. I suggest you to have a look some more advanced desgn patterns, like a Queued State Machine (with Events), where you have a GUI loop with an Event structure and another loop where your state machine exist, and states can self-Enqueue themself, accept commands from the EVent loop, etc...

 

Besides, I think every professional LV application using Events and specially together the Dynamic User Events we have very powerful tools to program good LabVIEW applications.

I suggest you to take the Core 2-3, etc. online training, they will show you many ideas...

 

Edit: I just opened my LabVIEW 2016 window, and clicked on "create project", and the State Machine is there, plus the more advanced templates:

 

statemach.png

Message 2 of 11
(4,764 Views)

2010-2015 it'll look like this:

New thingy.PNG

 

My favorite/go-to pattern is the Event driven Producer/consumer.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 11
(4,734 Views)

It's still there in LabVIEW 2016, but is no longer located under File, New ..., From Templates.  It is now under the New Projects button on the Welcome Screen when you start LabVIEW.  In addition to the Simple State Machine (see picture in Blokk's earlier post), there are several "more complex" Templates and Sample Projects (such as the Queued Message Handler, a State Machine + Producer/Consumer, in a way).

 

There's also the JKI State Machine in the LabVIEW Tools Network that you can find by firing up VIPM which has been bundled with LabVIEW for at least the last 4-5 years.

 

State Machines are still Alive and Kicking in LabVIEW.

 

Bob Schor

Message 4 of 11
(4,701 Views)

I can not say I have found much use for any of the included design templates. Most of them are so tightly coupled to NI DAQ devices and so inflexible that is takes more work to figure out how they are supposed to work, get rid of the stuff I don't need, and then make then do what I need them to do. (like the old "continus measurment data logger" template) 

 

Specially with a state machine, it is far faster to start with a blank VI, drop a while loop,  drop in a case inside, drop an enum, make it a typedef and go. 

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 5 of 11
(4,667 Views)

Hmm, I have often started with a Producer/Consumer (Events) template, then started to modify the error handling, setting up a state machine in the consumer, puting the required dynamic user events for the parallel VIs, and so on... It was faster maybe with a minute than from scratch 🙂

0 Kudos
Message 6 of 11
(4,661 Views)

I would agree with Blokk that comparing user events and a state machine isn't very fair as user events are really just a form of inter-process communication while a state machine is just a single process. A lot of people that call me are still just using a single state machine or simple producer consumer pattern but I'm sure you've seen that at some point your application is complex enough that just using those patterns doesn't really cut it.

 

User events are something that I don't see too often beyond a stop condition for a QMH. It seems like they have a pretty unique ability to be re-registered while your application is running and I'd love to see an application where that's abused.

Matt J | National Instruments | CLA
0 Kudos
Message 7 of 11
(4,650 Views)

@RTSLVU wrote:

I can not say I have found much use for any of the included design templates. Most of them are so tightly coupled to NI DAQ devices and so inflexible that is takes more work to figure out how they are supposed to work, get rid of the stuff I don't need, and then make then do what I need them to do. (like the old "continus measurment data logger" template) 

 

Specially with a state machine, it is far faster to start with a blank VI, drop a while loop,  drop in a case inside, drop an enum, make it a typedef and go. 

 


I agree.  Not that they are bad, but I spend somuch time figuring what to save and what to gut that I may as well start from scratch.


Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 8 of 11
(4,647 Views)

Thanks to all replies. My Labview version (2015) does not have the standard state machine template, for some reason. I have two separate installations and it is missing in both. Go figure.

 

Bill Linares

0 Kudos
Message 9 of 11
(4,595 Views)

It is not found under File->New..., you need to click on the Create Project. 

Or start using some of the other templates, like the Producer/Consumer Design Pattern (Events).

 

0 Kudos
Message 10 of 11
(4,571 Views)