Reference Design Content

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW State Diagram Toolkit

SDE Icon v2.png

The LabVIEW State Diagram Toolkit assists in large scale application development by providing a framework in which you can build state machines in LabVIEW. Using the state diagram editor, you can create a state diagram that reflects a complex decision-making algorithm, while LabVIEW simultaneously generates the block diagram code necessary to implement the state machine.

 

In addition to visualizing the flow of a complex decision-making algorithm, the state diagram is a functional form of application planning. To create an effective state diagram, you must know the various states of the application and how the states relate to one another. By visualizing the various execution states of an application, you improve the overall design of the application. The State Diagram Editor provides a user interface that you can use to design state diagrams.

 

What is a State Machine?

 

"A state machine is a programming architecture that can be used to implement any algorithm that can be explicitly described by a state diagram or flowchart. It introduces a way to create a program such that it responds to user events (such as key strokes and mouse events) or in-state calculation (such as comparing system variables). This architecture provides a distinct advantage over using a sequential architecture that uses data dependency to force execution in exactly the same way every time. Almost all programs that have more than a rudimentary user interface employ the state machine architecture—they wait for an event (user interaction or calculation result), and then take appropriate actions based on this input." - Using a State Machine (Event Driven) Architecture

 

State machines are frequently used in the design and architecture of individual LabVIEW VIs and enable the orderly transition between different execution states in a VI. The purpose of the LabVIEW State Diagram Toolkit is to easily manage and modify the underlying state diagram and to have nay changes in the state diagram automatically reflect in the implementation of the state machine in your VI.

 

Application Design Patterns: State Machines

Tutorial: State Machines

 

Using the LabVIEW State Diagram Toolkit

 

Installing the toolkit adds a new palette item (Addons >> State Diagram Editor) in your LabVIEW function palette.

 

To create a state machine VI using the state diagram editor, start on a blank VI diagram, select the State Diagram from the function palette, and place it on the diagram in the same way you place a new loop or structure. The VI will create a new state machine on the diagram and open the corresponding state diagram editor.

 

SDT Screenshot1.png

 

You can now define your state diagram in the editor by adding and removing states and defining transitions between states. Right-click on the state diagram to create new states and transitions. You can move transition end point between states, and change the names of states and transitions. As you make changes on your state diagram they will be immediately reflected in the corresponding state machine VI.

 

You can close the state diagram editor and the state diagram will be stored and saved with the VI. To reopen the editor, right-click on the While Loop frame in your state machine VI and select Edit State Diagram.

 

In your state machine VI, you need to define when individual transitions become active which is done by terminating the inner While loop from the appropriate inner Case structure. Additional logic can be placed in each state and transition.

 

The State Diagram Editor includes two examples, which are located in the labview\examples\statediagram folder.

 

SDT Screenshot2.png

 

The manual is available in the labview\manuals directory and attached below.

 

Installation

 

The LabVIEW State Diagram Toolkit can be installed from VI Package Manager.

 

Requirements

  • LabVIEW Full or Professional Development System, version 2014 or later
    • Supported in Windows, Mac OS and Linux
  • State machine VIs created using this toolkit can be deployed to LabVIEW Real-Time and LabVIEW FPGA targets

 

Support

 

Questions about the LabVIEW State Diagram Toolkit should be posted in the general LabVIEW support forum.

 

Feedback and suggestions for the toolkit can be posted in the comments below.

 

Known Issues

 

  • You can copy and paste the state machine block diagram in LabVIEW, but it will not copy the associated state diagram with the code.
  • Undo does not work in the State Diagram Editor window. Making changes in the state diagram editor, removes the Undo history in the VI block diagram.
  • Highlight execution on the state diagram editor brings up the probe window with a probe on the state wire in the block diagram. Running the VI in highlight execution mode will highlight the active state on the state diagram.
  • If you TypeDef the enum that is created by the state diagram editor, it may crash the environment if you subsequently make changes to the state diagram.
authored by
Christian L, CLA
Applications Engineering Senior Manager - Automotive and Transportation
NI - Austin, TX


  
Comments
Ben
Knight of NI Knight of NI
Knight of NI
on

An example of how to use "Single_Step" mode would be helpful. Since the SDE was not free add-on the last time I did a cRIO project, I did not investigate but...

 

It seems the "single-step" mode would be handy for complex FPGA functionality.

 

Can you advise?

 

Thank you,

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Christian_L
Active Participant
Active Participant
on

Thank you, Ben. I will add it to my list of things to do, though it may be a while. Do you have any good suggestions for an FPGA- and state machine-based algorithm? I would consider rewriting some of the communication protocols I have written for FPGA in the past such as SPI or SPDIF (digital audio).

authored by
Christian L, CLA
Applications Engineering Senior Manager - Automotive and Transportation
NI - Austin, TX


  
wildcatherder
Active Participant
Active Participant
on

I have tried to use this toolkit on a couple of occasions.  The first time, the example in the tutorial did not work and I was unable to unlock the state machine code to fix it.  I reported this to NI.  I came back a year later, went through the tutorial and it did work.  I spent 12 hours developing a 24-state state machine, only to discover that the generated code would not run because of an obvious wire type error.  I could not unlock the code to fix the error.  I reported this problem and was presented with an assurance of zero support because of "not invented here".  I was able to make an unlocked version using "Save as", however this introduced new errors "Int to enum refused to compile".  So I am currently slogging through the code, manually adding bits at a time from the generated code and fixing it along the way.  Make no mistake, a State Diagram to State Machine tool is a great idea but I find it buggy in the extreme and you must not expect help from NI or a referral to anyone who can help you.

Contributors