state machine (labview programming) - wikipedia, the free encyclopedia

Upload: jokerbuddy01

Post on 28-Feb-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/25/2019 State Machine (LabVIEW Programming) - Wikipedia, The Free Encyclopedia

    1/7

    01/07/2016 State machine (LabVIEW programming) - Wikipedia, the free encyclopedia

    https://en.wikipedia.org/wiki/State_machine_(LabVIEW_programming)

    State machine (LabVIEW programming)From Wikipedia, the free encyclopedia

    A state machine is a type of programming technique that is used in a majority of different programming language

    The state machine is especially important and flexible tool that is used in LabVIEW programming because the

    coding is very easy to maintain, document and reuse. [1]

    Contents

    1 Introduction to state machines2 State Machines in LabVIEW

    2.1 Common Devices of a State Machine2.2 Simple soda machine example

    3 Benefits4 References

    Introduction to state machines

    State machines revolve around 3 concepts: the state, the event, and the action. The state is the position or status

    that the program is at when it is working through the problem. For example a state could be waiting for the user to

    do something, or running a calculation. States work to help break up the big picture and help to make everything

    run smoother. Developing these wisely will help to make the state machine run more efficiently. Events are

    occurrences that have specific meaning to the program itself. The example that we will be building is a soda

    machine that dispenses soda after the user has inserted the correct amount of money. An event for this program

    could be the money being inserted, or theperson hitting the start button. The action is how the program will react

    to the particular event that has occurred. [2]

    State Machines in LabVIEW

    In LabVIEW, state machines are even more powerful. A state machine can help the program respond intelligently

    to different types of data that the user could put in. [3]To help explain this feature we will use a simple soda

    machine program to help illustrate the technique.

    Common Devices of a State Machine

    In LabVIEW state machines can be started by simply creating a while loop with a case structure located within thloop. The while loop can have a special constant wired to it called an enumerated constant. An enumerated

    constant is a constant word or phrase is changed to a simple integer from 0 to n - 1, where n is the number of case

    the user would like to have. Doing this makes programming a lot easier for the user to understand because instead

    of looking at number codes they are looking at a few words describing what is going on. A state machine also

    relies heavily on shift registers. A shift register is used to pass information around in a while loop, for example a

    shift register will start with information that will be worked on in the loop, after the work is finished then new

    value can be saved on the shift register to be used at the start of the loop next time.[4]Next all the programmer ha

    to do is add tasks to each case individually. After the initial enumerated constant is created it is often worth while

    to make it into a type definition (commonly referred to as type def.). Making the enumerated constant into a type

    https://en.wikipedia.org/wiki/LabVIEWhttps://en.wikipedia.org/wiki/LabVIEWhttps://en.wikipedia.org/wiki/LabVIEWhttps://en.wikipedia.org/wiki/LabVIEWhttps://en.wikipedia.org/wiki/LabVIEW
  • 7/25/2019 State Machine (LabVIEW Programming) - Wikipedia, The Free Encyclopedia

    2/7

    01/07/2016 State machine (LabVIEW programming) - Wikipedia, the free encyclopedia

    https://en.wikipedia.org/wiki/State_machine_(LabVIEW_programming)

    This is a picture of a simple for loop located in a while loop using Enumerated constants and shift registers

    def. allows

    the user to

    continue to

    copy the

    original and

    re-use it in

    the program,

    like a normal

    controlexcept with

    a type def. if

    you change

    one of them

    you end up

    changing all

    of them.

    Type def.

    allows the

    program to

    be muchmore robust

    and making

    it much

    simpler to

    change if

    something

    new needs to

    be added.

    Simple soda machine example

    In the soda machine example we are using shift registers to pass around the total amount of money in the machine

    and the enumerated constants that control which case we are in. When we look at our start case picture shown

    below we can see the shift registers on the left and right side and the enumerated constants in the middle. we can

    also see at the bottom of the picture there is a Tab that is used to display each individual section is being written to

    as an indicator. By doing this we remove the possibility of the user getting off of the loop and locking them into th

    case they are supposed to be in. When we are in the start stage of the program we want to make sure that the user

    right there with the program.

    https://en.wikipedia.org/wiki/File:LabVIEW_State_Machine_example_(End_Case).png
  • 7/25/2019 State Machine (LabVIEW Programming) - Wikipedia, The Free Encyclopedia

    3/7

    01/07/2016 State machine (LabVIEW programming) - Wikipedia, the free encyclopedia

    https://en.wikipedia.org/wiki/State_machine_(LabVIEW_programming)

    This is the start case from the Soda machine example

    This case

    holds the

    user on the

    start menu

    on the block

    diagram,shown

    below,until

    the user hits

    the start

    button. Once

    the start

    button is

    pressed the program is then sent to the next case

    (called the Insert change case).

    Once in the Insert change case the user will once again be held here to continue adding money to the total they

    have had so far through the use of shift registers and buttons that money every time you hit them. This is the main

    case where most of the work is being done and where the soda machine is as real as possible, with out adding

    actual coins, every other case has most of the work running in the background. Once the user has finished adding

    money they press the Finished inserting money button to move on to the Dispense case.

    https://en.wikipedia.org/wiki/File:LabVIEW_State_Machine_example_(Start_Block_Diagram).pnghttps://en.wikipedia.org/wiki/File:LabVIEW_State_Machine_example_(Start_Case).png
  • 7/25/2019 State Machine (LabVIEW Programming) - Wikipedia, The Free Encyclopedia

    4/7

    01/07/2016 State machine (LabVIEW programming) - Wikipedia, the free encyclopedia

    https://en.wikipedia.org/wiki/State_machine_(LabVIEW_programming)

    The Insert

    money case

    also

    changeswhich tab is

    being

    displayed to

    the Insert

    Change tab

    on the block diagram. Here the user can insert

    money and also see how much money was through

    the Total Money Inserted display.

    The dispense case starts by first checking to make sure that the user has inserted enough money to buy a soda.

    There is a case second case structure in this case to handle the two options of either enough money, or not enough

    money. If there is enough money in the system a message box will pop up saying thank you for purchasing the

    soda and then subtracts the amount of money it takes to purchase a soda from the total amount of money in the

    system. If there is not enough money in the system the program outputs a new message saying that there is not

    enough money and sends out all of the money that was previously inserted before moving on to the end case.

    https://en.wikipedia.org/wiki/File:LabVIEW_State_Machine_example_(Insert_Change_Block_Diagram).pnghttps://en.wikipedia.org/wiki/File:LabVIEW_State_Machine_example_(Insert_Money_Case).png
  • 7/25/2019 State Machine (LabVIEW Programming) - Wikipedia, The Free Encyclopedia

    5/7

    01/07/2016 State machine (LabVIEW programming) - Wikipedia, the free encyclopedia

    https://en.wikipedia.org/wiki/State_machine_(LabVIEW_programming)

    The block

    diagram for

    the dispense

    case and the

    end case is

    the same

    picture. There is really nothing that the user really

    has to do besides pop up messages that the program

    will output.

    https://en.wikipedia.org/wiki/File:LabVIEW_State_Machine_example_(Dispense_Change_Block_Diagram).pnghttps://en.wikipedia.org/wiki/File:LabVIEW_State_Machine_example_(Dispense_Case).png
  • 7/25/2019 State Machine (LabVIEW Programming) - Wikipedia, The Free Encyclopedia

    6/7

    01/07/2016 State machine (LabVIEW programming) - Wikipedia, the free encyclopedia

    https://en.wikipedia.org/wiki/State_machine_(LabVIEW_programming)

    The end case

    is a very

    simple case

    that works to

    simply delay

    the program

    to allow the

    user enoughtime to

    check that

    they have

    received

    their change

    and picked

    up their

    soda. After

    5000

    milliseconds

    (or 5seconds) the

    wait timer is

    used up and

    the program

    continues

    back to the

    start page to wait for another user to come by to begin the process over again.

    Benefits

    The state machine is often used because it is easy to quickly start up and add or remove parts of the program. Stat

    machines work in a fashion as to also help keep the developer organized as they work.[5]

    References

    1. Bitter, Rick.LabVIEW Advanced Programming Techniques.Boca Raton: CRC Press LLC, 2001

    http://www.physics.utah.edu/~jui/3620/supp/LV_Adv_Prog/2049ch03.pdf

    2. Bitter, Rick

    3. Bitter, Rick

    4. LabVIEW Help Page from LabVIEW 2011

    5. "Tutorial: State Machines," 2014, http://www.ni.com/white-paper/7595/en/

    Retrieved from "https://en.wikipedia.org/w/index.php?title=State_machine_(LabVIEW_programming)&oldid=720829946"

    Categories: Virtual machines

    This page was last modified on 18 May 2016, at 05:53.Text is available under the Creative Commons Attribution-ShareAlike License additional terms may applyBy using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia is a registered trademark

    https://wikimediafoundation.org/wiki/Privacy_policyhttps://wikimediafoundation.org/wiki/Terms_of_Usehttps://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_Licensehttps://en.wikipedia.org/wiki/Category:Virtual_machineshttps://en.wikipedia.org/wiki/Help:Categoryhttps://en.wikipedia.org/w/index.php?title=State_machine_(LabVIEW_programming)&oldid=720829946http://www.ni.com/white-paper/7595/en/http://www.physics.utah.edu/~jui/3620/supp/LV_Adv_Prog/2049ch03.pdfhttps://en.wikipedia.org/wiki/File:LabVIEW_State_Machine_example_(End_Case).png
  • 7/25/2019 State Machine (LabVIEW Programming) - Wikipedia, The Free Encyclopedia

    7/7

    01/07/2016 State machine (LabVIEW programming) - Wikipedia, the free encyclopedia

    https://en.wikipedia.org/wiki/State_machine_(LabVIEW_programming)

    of the Wikimedia Foundation, Inc., a non-profit organization.

    https://www.wikimediafoundation.org/