Making sequence structures a state machine

Hey I would like some help I need to work on changing my code and get rid of the flat sequence structure and replace with a state machine I have attached my code at an earlier state but would like some input on changing it over to a state machine in the sequence at the bottom of the code this program is used to cycle a valve and the sequences need to be done in order .any input would be great.
Attachments:
valve Cycles with temp.vi ‏132 KB

Right click on the Flat Sequence and pick Replace with Stacked Sequence  (never would have thought I'd say that.)
Right click on the Stacked Sequence and Replace with Case Structure.
Now a lot of wires will wind up broken.  So you'll need to hunt them down and fix them.  Those wires will probably need to go to shift registers so there values are maintained for the next loop iteration.  Keep a copy of your original VI so you have something to refer back to.
Create a Typedef Enum and define what your states will be.
Start wiring the Enum into a shift register at the left of the loop, then into the selector of the Case Structure.  Rename all the cases to what their respective state should be.
Wire enum constants in each case to direct what the next case should be.  It will run out of the case structure to the right hand shift register.
Keep working and cleaning still everything is fixed.
Try running your VI to see if it behaves like it originally did.
Now you are safe to start making modifications to make it behave like you really want it to.

Similar Messages

  • Using multiple events structure inside state machine to control the Tab

    Hi y'all,
    Anne here.I have a Tab indicator in my front panel and I want to be able to control the flow of my program based on what controls I clicked inside the tab. I am using a state machine architecture and inside every state, I use an event structure to check for user interaction  to determine the next state and what tab page is going to be displayed next. This means that I am actually using multiple event structures in my application and I use them in just one while loop, but just that they are not running in parallel since I am only using "one event structure per state" which means that only one event structure is running at one time. My questions is, programming technique wise, am I doing it correctly? So far, I am not facing any problem (I am still in the early stage of the project) but I want to check with you all first on your opinion regarding this architecture. Will there be any issue on using multiple event structures in a vi? Since I will be using a tab, and the controls available in the tab will be the controls that will control my event structure for that state, by right, there should be no issue. Am I correct to assume this? Is there any limit on the use of event structures? I have attached here a simple sample of the architecture that I am talking about for your reference. I have attached a 2010 version and a 8.6 version. Let me know what you think or any opinions that you may have.
    Hoping to hear from you soon! Thanks so much in advance!
    Cheers!
    Anne
    Attachments:
    State Machine-Event Structure Sample_2010.vi ‏19 KB
    State Machine-Event Structure Sample_8.5.vi ‏25 KB

    Hi jak888,
    I decided to use tabs cause I don't want to have subvi pop ups every time i need to perform the process in the state and show an update in the front panel. This is actually going to be more of an ATE where you will have to choose first whether the one using is the operator or the engineer. If the operator is logged in, she will proceed to choose what test to run (this state will have its own event structure). This part, I don't want a pop up, so what happens is that from Login page, if the user logs in as operator, the tab will automatically switch to the Test Selection page. After selecting the test, it will proceed to Start Test state and the tab will show the Result Summary page. If the user logs in as engineer, then a totally different tab will be automatically shown next and so on. By doing this, I will be able to show an update on the front panel objects without having the subvis pop up. I will also just need to use the call reference functions to call my subvis, making my Main VI more generic. The tab Page header will be hidden so the operator will actually not see that there is a tab and that there are a lot of controls and indicators cause they are hidden in the tabs and that page will only be shown based on what they selected from the main tab. 
    I appreciate your thoughts! thanks so much!

  • Help with cycling sequence structure, I may need a state machine?

    Hi All,
    So I have this VI that needs to control two solenoid valves by opening and closing them through the digital outputs.
    I want the program to have a function like this
    Phase 1: Valve 1 open, Valve 2 closed (Amount of time for this defined by user)
    Phase 2: Both valves closed (for .1 seconds)
    Phase 3: Valve 1 closed, Valve 2 open (Again, this amount of time is defined by user)
    and I want it to cycle through phase 1-3 100,000 times. However, every 10,000 cycles of phase 1-3 I want it to change the condition on Phase 2 so that both valves are closed for an hour instead of .1 seconds, then after this hour loop I want it to return back to the original cycling conditions (.1 sec instead of 1 hour) until it does another 10,000 cycles.
    I was thinking that a sequence loop would be fine because I would wire it up with timing and a counter, and every time it goes to the last sequence it would increase the counter so that when its at the phase 2 timing I can use a case structure (if counter > 10,000 hold 1 hour, if counter <10,000 hold .1 sec) and then in the last sequence reset the counter to 1 if it is >10,000.
    I thought a sequence structure would be good for this but I'm fairly new to labview and if theres a better way to do this I'm open to suggestions .
    Attached is my code so far, except that I have not finished wiring the ports for valve B
    Attachments:
    Adhesive Pressure Cycling.vi ‏100 KB

    First, you should avoid the use of a sequence structure. Don't even consider it to be an option. At least not at this stage of your learning. Learn how to use data flow. Also, avoid the use of local/global variables. They tend to lead to race conditions which in turn result in some difficult bugs to find and fix. Think of the wires as your variables.
    As for the time delay in your state machine, your actual state should delay for a short time like 100 ms. Use the current time of day to determine when you have reached your desired timeout. If you use a single delay of an hour your program will be unresponsive for that hour. Users tend to get very annoyed if they try to stop the program and they have to wait a long time for it to actually stop.
    Here is a basic example that shows the concept in a state machine.
    When naming states for your state machine give them a meanigful name. Use a typedefed ENUM for your state variable. For simplicity sake the example attached does not use a typedef. But naming things like State 1, State 2 and so on makes the code difficult to read and understand. Your Open/Close valves states can be written in such a way that they are generic and take the valve data as input. At a minimum I would create a subVI to do this so you only have one piece of code to manage. You could have explcit states though such as Open Valve A and Open Valve B that call your generic Open Vavle subVI with the appropriate input data.
    One last comment, the express VIs tend to be very inefficient. They are OK for learning how things are done but I would implement their functionality directly. For example, the express VIs tend to open, initialize, do something, close the instrument. You really don't have to do all of that every time. Open and Initialize once in the begining (hint, this could be a state), put the stuff that does the work in appropriate states/subVIs (other states) and then close at the end of your application (the exit state for example).
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot
    Attachments:
    Simple Delay in State Machine.vi ‏15 KB

  • Problems closing several loops in a state machine with an event structure

    I am having some problems closing three loops running in parallel in a state machine.  I have one loop for an event structure to monitor user controls to change the state.  The other loop is the state machine which will control an actuator, and the third loop is for data aquisition/analysis.  I want to be able to hit the stop button and go to a "shutdown" state where I can home the actuator then close the loops and finally go to the last "shutdown" subdiagriam in the flat sequence structure.  Currently when hitting the stop button it goes into the shutdown state and will end the state machine loop but it appears the other loops are not closing until I hit the stop button again.  Could this be due to using a local variable for the boolean to control the loop conditions? I attached a screenshot of the block diagram.  Any advice would be great!
    Attachments:
    example.png ‏108 KB

    You have a classic race condition due to overuse of local variables. If the stop event fires in the upper loop, the local variable connected to the loop termination condition has already been read (it is false!). This means that the upper loop will iterate once more and again wait at the event structure for the next event. At this time, the local variable connected to the loop termination is TRUE, but the loop cannot complete until the event fires again, for example if you press the stop button once more.
    The correct way is to connect the terminal of the stop button across the right event frame directly to the loop termination terminal. Now it will get the TRUE value correctly once the stop event fires for the first time.
    LabVIEW does not execute left to right, execution order is determined by the wiring.
    I also agree with the above message that you should rethink and re-architect your code using established coding guidelines. 
    LabVIEW Champion . Do more with less code and in less time .

  • How to use a event structure with a state machine

    First, I would like to inform you that I only work on LabView part time, and have much to learn.  Anything I do learn, I usually forget until I need it again, because I only work on it part time.
    Using your StopWhileLoopMOD[1].vi, I am trying to put a state machine inside the event structure.  
    Related link: http://forums.ni.com/t5/LabVIEW/How-to-stop-while-loop-in-Event-case/td-p/465564/page/2
    Here is my application:  on the front panel, the user can select any combination of 7 different tests.  I have created cases to perform each step of each test in the correct order, but if the user presses stop, the tests won't stop because some of the cases have a while loop inside the event structure (like you mentioned is a bad idea).  The user should be able to stop the test, reselect tests to perform, and re-start the tests. 
    When the start button is pressed for the event structure, I need all the cases to run in the proper order, unless stop is pressed.
    In the past I have indexed an array and used that to run the state machine, but it won't stop immediately.  
    I have sub VIs that are built in while loops because the outputs of the product needs time to stabilize.  The state machine stops and waits up to a certain number of iterations.  If it passes the test, the while loop stops and the next state starts.  If it takes too long, it exits and reports an error.  Maybe I need to just use the state machine and not an event structure?
    Is there a good example of an event structure?
    metzler CLAD
    Solved!
    Go to Solution.

    I'm not sure exactly what you are asking, but it sounds like you want to script a bunch of tests and if the user says stop, to immediately stop the current test and abandon the others?  I'm going to assume that you know how to clear the array so that it will abandon the others, so I'm guessing that you are having trouble abandoning the current test?  If this is indeed the case, then the problem is that you are not able to propagate the message from the main VI FP which is the GUI to the sub vi which is the test, where the test may or may not have a GUI (FP visible) of it's own.  Threading was the first thing to come to mind, but this may not be necessary using events.
    You can do this by passing a refnum of the stop button to the subVI, where you can then add that wait to the event case structure.
    I've attached 2 VIs, mainvi.vi which is just a loop displays the count*2 (number of seconds passed since running) that will call subvi.vi and then check to see if the stop button is pressed.  mainvi.vi is by no means a state engine, it is just a simple loop for demonstration purposes.  subvi.vi just waits 2 seconds and leaves, it is a better structured state engine with an init state to start a poll case to wait for events and an exit state to clean up.  You can modify this any way you wish to get it to do what you want.  You will note that even if subvi.vi is being executed, it will terminate immediately when the stop button is pressed.
    Hope this helps.
    A
    Attachments:
    mainvi.vi ‏17 KB
    subvi.vi ‏33 KB

  • Event structure in a State machine

    Hello all,
    I've got a state machine with a sort of Stand-by state from where a user can select the next state using buttons. I tried using an Event structure with value change to select the next case but when the state machine is in a specific case and the button of an other state is pressed the whole thing blocks. I've attached an example, the LEDs just indicate what state you are in.
    Thx for your time,
    Bert
    edit: Indeed, I miss-clicked
    Solved!
    Go to Solution.
    Attachments:
    Question.lvproj ‏2 KB
    Question.vi ‏21 KB

    All your inner while loop should not be there, they just gum up the gears. It is a bad idea to trap the code inside inner loops, because during that time, events cannot be handled, whil they are still queued up. For example if you are in state 1 and press state 3 100 times, then exit state 1, state 3 will be entered 100 times in a row, witout a possibility of escaping.
    Thus the use of an event structure is also ill advised here.
    Here's is a quick draft showing the same code without inner loops and without the event structure just to give you an idea what I meant. See if it gets you some ideas. It is still not perfect ...
    (Sorry, I had to disconnect the type definitions, because you did not include it)
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Question 1mod2.vi ‏19 KB

  • Producer consumer vs state machine

    Hi there,
    I have been on and around for quite a while to understand how can I re-design an application, which was originally built using a mix of sequence structure, while loops and event structures. And now I am making a newer version of the same application, for research purposes, while learning the LabVIEW techniques. Earlier I used LabVIEW versions 5 and 6 to make simple programs for fuzzy logic and neural networks. And that's not a good reference.
    Ok, after learning that Producer Consumer (PC) and Standard State Machines (SSM or SM) are two new approaches for a better (scalable, flexible and efficient) coding as suggest by veterans, in one thread where I asked about another issue, I have started digging into this topic and now I am on a point where I have to implement it finally (spent pretty much time in the learning phase).
    I have several questions.
    To start the discussion, I would give a brief description of my application.
    It's a networked application, where the network communication happens using DataSocket (one reason to use LabVIEW as the environment).
    We are talking about the client application, which communicates with other applications on remote computer, via Internet.
    User interface involves a tab control, with several pages-
    On startup, the controls/indicators (now onwards referred as controls only), are initialized, datasocket connection is checked (rather internet is checked, and a connection established with the remote datasocket server) (page 1)
    If connected to the datasocket server, the user selects Login/Registration (page 2)
    Login and/or Registration happen on page 3/4
    Then the user sees a table of remote users to connect to (page 5)
    Upon selection of a remote user, and after clicking on "connect", the user will see a video indicator, with a lot of other controls. (page 6)
    On this page with video indicator and controls, the user has a lot of activities, in which many messages are sent and received to/from the remote machine.
    the user may disconnect and go back to page 5, and log out and go back to page 2 and so on.
    I hope this is clear.
    I have thought about two different ways to do this application. Using PS or by SSM.
    In the attachments, I have given a diagram (with errors, of course, because of unlinked controls), for each of the approach, plus the original application's diagram.
    I hope this is sufficient for anybody to understand my case and give suggestions.
    I am looking for suggestions about which is a better model for my type of case. I have been to discussions like this one and saw that there are many issues regarding dequeue in PC model. So I am curious to know if SSM is a better and latest model or it's more primitive? Which looks better for my application's performance?
    Thanks ahead!
    Vaibhav
    Attachments:
    OldDesign.vi ‏41 KB
    PCDesign.vi ‏42 KB
    SSMDesign.vi ‏46 KB

    Vaibhav wrote:
    @ Harold
    Thanks. Any suggestion how can I start and stop that loop in parallel with other loops? Like, if some event occurs, the loop should start execution, and keep on moving, while other events are being traced and executed.
    In those examples where you had a while loop inside a case structure, that bit of code will only execute one time.  It will immediately read the boolean at the start of the program, if the value was true before the porgram started, then the while loop will run.  Once that while loop stops, the case structure will end.  It will never execute again unless you completely stop and restart your program.  If the boolean is false before the program starts, the false case will execute immediately.  Nothing happens since it is empty and it is done, never to run again (unless you stop and restart your VI)  You should turn the structure around.  Put the case structure in the while loop.  Make sure you put a small wait statement in the loop so that it doesn't run full speed eating up CPU cycles just polling the status of the boolean.
    @ Ravens
    Thanks for the detailed comment.
    One thing I would clarify. The user will not be able to switch between the pages using the tab control. The program will direct appropriate page to the user. I kept the tabs visible just for your idea of the pages. Sorry, I didn't mention that.
    Do you think it's still a bad design?
    If the tabs will be hidden or disabled, you will probably be okay.  I wouldn't call it a bad design.  I wouldn't do it that way.  But as long as you understand the possibility of problems and prevent that.  Especially some time down the road when you modify the program in some other way that could lead to a problem because you forgot about the dependencies of the event structures on the state of the state machine. 
    Yes, I agree about only one event structure to handle all the events. But since the user will not be able to click somewhere else, other than those possible controls, I thought to keep it like this.
    I thought the events are captured only if we are in that case. I think I am wrong, right? Events are captured at any time, even if the case has never executed before, or will never execute.  Ok, The events will be captured, but will not be executed until in that case.
    And that's the reason why I have two separate event structures, in two separate phases of the program.
    Because, prior to page 6, the events will occur sequencially. The user will click somewhere, then some message will be transmitted over DataSocket, then some message may come , then again some user action and so on. But, when the user starts using page 6, there will be parallel process of user controls events and actions, and incoming messages and corresponding actions. For this, in the page 6, I need a different kind of execution. So I separated the two event structures.
    At first I thought to have SSM, and then I thought to PC, just because I can have two separate parallel processes - one for user events, and another for messages (because that way I can take maximum advantage of message tracking). But looking at other complexities, I find SSM more appropriate. Can you please tell me how can I have my message loop and events loop parallel to each other and just one event structure?
    You can have a dequeue function in your state machine loop and have it be a consumer loop.  Use a timeout on the Dequeue.  If there is a timeout, have the statemachine execute normally after that perhaps just passing the enum wire straight into the case structure of the state machine.  If it doesn't timeout meaning you got a message, then look at the message that is dequeued and act on it.  Perhaps it means ignoring the enum coming in from the shift register and changing the enum to something else to feed into the case structure of the state machine.  Attached is an example
    Attachments:
    PCDesign[1]_BD.png ‏6 KB

  • How do you create array of enums for transitions in a state machine?

    Hello,
    I am trying to build a state machine, but, I am struggling with understanding the methods for determining which state to transition to next.  In other words, I have several states, but, I don't want to go in any particular sequence.  If I have states numbered 1 through 10, I want to be able to go 1-4-2-5-6-2-6-1-10 etc. in no particular order. I want the transition to the next state  (and actions) to be determined by the streaming data, which can be random and require access to any of my 10 states at any time and in any sequence.
    I saw this picture on the "Application Design Patterns: State Machines" white paper, but, it leaves out some important details.  How does one create the structure in BLUE shown in 3C?  When I try to create this array of enums, all of them are the same. I am not able to make a list of different enum values.  In other words, when I type in "2", then, all the values in the array display as "2."
    There is a nice, simple video example of a state machine for dispensing soda for $0.15, however, this state machine moves in a single sequence, from 5 cents, to 10 cents to dispense; it does NOT illustrate how to select a state "out of order."  I need to understand how a state machine can move from "5 cents" state to dispense directly, with the addition of 10 cents to the "5 cents" state.
    Can anyone suggest a really good tutorial on how to make the selector work in a state machine?  I have been reading some of the available material on ni.com, but, I can't find a good detailed explanation of how to do it.  I remain confused. 
    Or, can you just explain how they created the BLUE array in the attached picture?  Maybe I can figure it out from there.
    Thanks,
    Dave
    Solved!
    Go to Solution.
    Attachments:
    next state.jpg ‏75 KB

    Hi Kathryn,
    Yes, this is EXACTLY what I want to accomplish...
    So it would basically run:
    State 1
    Read input
    Determine next state (say 3)
    State 3
    Read input
    Determine next state
    State
    Read input
    Determine next state
    And so on...
    But, I am quite new to programming Labview state machines, and can't figure out how to even start when the sequence of states is random instead of fixed!!! I can do 1,2,3,4, like the vending machine VI example, but,  not 1,3,2,2,2,5,2,1 etc. based on external input.  Is there some simple example case I can study?  I can't believe I am inventing this for the first time.
    "select the state to run" 
    But, HOW do I do this???????   This is exactly the question I am asking...how is this done?  Please see the attached 3-state system....how do I hook this up????  I am totally lost here...can you help me understand how to wire this thing??  In this simpe RED/GREEN/BLUE case, my input is just the number a user would input on the front panel....  Apparently, there are two files necessary... a vi and .ctl???  What  is .ctl?
    Thanks,
    Dave
    Attachments:
    forum nov 12 red green blue.vi ‏7 KB
    forum nov 12 red green blue.ctl ‏5 KB

  • Producer Consumer with a state machine within the consumer

        Hi All,
    I have been trying to develop a data acquisition system with the producer consumer architecture.  To the left of the two main loops I initialize the serial port and any constants and variables im using.  I also have an obtain queue VI needed for enqueue and dequeue. Then in the producer loop i have a state machine.  The first state is where I wait for a button press on the front panel to write a GO signal on the serial line which will tell the device connected to the serial port to begin sampling data.  After this button press I go into the next state which is called my read state.
    In the read state I use a property node to read all of the available bytes at the serial port and then enqueue this collected data into a queue.  The state machine then is directed to continously go to the read state again and collect more data.
    Now this is where my dilemma is......  The consumer loop has the dequeue VI inside it and after this VI i have a state machine (while loop and case structure) which contains the following states
    1.  Build Array - build an array from the dequeue element and if there is any left over data from the parsing states it will build an array with the left over data and the dequeued data
    2.  Determine packet type - this state looks for the packet type byte(not necessarily the first byte in the message) and also check the next byte (packet length) to ensure that I am at the begininng of this chunk of data.  This state may be a little slow because there can be three different packet types and based on this byte and the packet length it may have to search the array several time to find the valid starting point.  This state also determine the next state to go to based on the packet type.
    3 packet type 1 parsing - parse data and store the remaining data it leftOver array.  Go to exit state.
    4 packet type 2 parsing - "" ""
    5 packet type 3 parsing - "" ""
    6 exit - leave this state machine and fall back to the consumer while loop.
    After it exit I think it should fall back to the consumer while loop and dequeue more data and enter the state machine again to build a new array with the dequeued data and leftover data.  It seems to work when I trace the execution using the Highlight execution feature, however when I run this all at full speed, it seems to go into the consumers 1st and 2nd states back and forth and not completely go through the state machine.
    I tried adding in a delay in the producer loop to give the consumer loop time, but I didnt notice any difference.  Is it possible that my dequeue element is retreiving more data while im still in the state machine, causing the execution to leave the state machine before it finished all states?
    Is there a better approach to take to solve this problem. Basically I need to read data at a 1,000,000 baudrate and parse it as quickly as possible so that I can break it up into 3 different packet types, write the data to a file, and graph the actual data (header info removed) in realtime.  I need to also ensure that I am not losing any of the collected data.  Data loss cannnot occur.

    A couple of things more to go along with Ben's pointers:
    You convert your data from a string, to a U8 array, to a Hex string array in the producer loop, then convert back to a integer to determine what to do with it.  In the process, you create two or three copies of your data, slowing yourself down quite a bit.  The code would be quite a bit more efficient if you left the data as a U8 array.  You can change the format of the controls and indicators to show hex values instead of integer by right clicking on them and selecting Format and Precision...
    Your search code is fairly inefficient.  I made a whack at making it a bit better.  See attachment below.
    If you continue to run into race conditions, you can debug them using a calls to the Windows debug write sprinkled liberally about your code.  Check out the post here for more information.
    Don't let your lack of format LabVIEW training stop you.  The biggest thing to get is the data flow paradigm (aka data is wires, not registers).  Once you get past that and learn how to pass data around using shift registers, queues, events, etc, you are most of the way to mastering LabVIEW.  The rest is just learning the plethora of functionality LabVIEW gives you (yes, I have reimplemented LabVIEW native code more than once in the process of learning).
    Let us know if you need more help.
    This account is no longer active. Contact ShadesOfGray for current posts and information.
    Attachments:
    serialUtil_V3_DFG.zip ‏137 KB

  • How to run a particular case continuously in event based state machine architecture.

    I am making a program using event based state machine architecture, it is running as expected whenever i am generating an event, case structure corresponding to that event executes.
    we are taking some measurements from oscilloscope e.g. i am having one boolean button for rise time whenever i am pressing that that button it displays the value of rise time, it displays only once( since i have generated an event on that boolean button so it executes only once and displays value for one time and then comeback to timeout state) but in our program what we want, we want it to update value continously once that button is pressed.
    Now for a time being i have placed while loop on the case corresponding to rise time but this is not the right approach.
    since i am using state machine architecture( event based ), i am not getting how to run particular case continuously ,or if there is any other better architecture that i can use to implement the same application.
    Attached below is the program.
    Attachments:
    OScilloscope .zip ‏108 KB

    Say, in the attached program, when the user selects Autoset, it inserts corresponding state (Autoset) and now if you want this state to run again and again, probbbly you can again insert Autoset state while executing Autoset state... ohhh its confusing... check the picture below (A picture is worth a thousand words):
    1. Based on user selection, insert Autoset state.
    2. Re-insert Autoset state again and again while executing Autoset state.
    3. Now to come out of this loop, based on appropriate event generation, insert any other state AT FRONT (equivalent to Enqueue Element At Opposite End).
    I am not allergic to Kudos, in fact I love Kudos.
     Make your LabVIEW experience more CONVENIENT.

  • Can you move back to a previous frame in a sequence structure?

    I have a VI that contains a sequence structure with seven frames. I would like to add a button on the front panel to allow the user to move back to the previous frame. Is this possible?
    Thanks

    I don't think that's possible. Try replacing the sequence structure with a
    state machine.
    A state machine is a case statement embedded in a while loop. Each case
    outputs at least an integer to indicate the next case to be executed and a
    boolean to indicate if the while loop should continue. The integer is wired
    to a shift register. The input side of the shift register is wired inside
    the while loop to the conditional terminal of the case statement. Outside
    of the while loop, the input side of the shift register would be wired to a
    constant indicating the first case to be executed.
    To mimic a sequence structure, each case would take the incoming integer and
    increment it by one. To move back to the previous frame, the integer would
    be decremented instead.
    "Jeff - PP
    L" wrote in message
    news:[email protected]..
    > I have a VI that contains a sequence structure with seven frames. I
    > would like to add a button on the front panel to allow the user to
    > move back to the previous frame. Is this possible?
    >
    > Thanks

  • Proper use of stacked sequence structure

    Hello
    I have been reading this forum up and down, trying to figure out what the proper use of a stacked sequence struckture is.
    The reason i ask was that almost evryone in this forum thinks it is miss used / and or hides code. And that there is berrer ways of doing it.
    I ask this question, wondering what is the PROPER use of SSS?
    attached is the code so you can see what i am doing. As you will see, the code in the SSS are all the same for each frame, only channel number and numeric indicator is different, making upscaling more efficiant.
    Faster readings is not an issue since i will be slowing it down later on, so we get a visual value evry 5-10 seconds or so.
    keep in mind i am a novice at LabView, and all input is much appreciated.
    Attachments:
    r read 1ch.vi ‏52 KB

    TorbH wrote:
    I tried using array as you showed, but i fail to get it to work properly, well it works as it should but i want it to be able to stop with a button, when i did that only channels 202 - 206 stopped. 201 kept going.
    The reason for me to have this opportunity is that later i will connect channels 207-212. and they also will need to be started/stopped seperatly.
    Put the stop button inside of the loop.  The button is read with the terminal.  The terminal is read outside of the loop, so it will have the same value for every iteration of your loop.  By moving the terminal inside of the loop, your terminal will be read every iteration and you can therefore abort the loop.
    TorbH wrote:
    Also, frome here on out, how would i go ahead and use the data? Can i in a "state machine" use several for loops to perform the same tasks as i had in my previous version?
    A state machine is actually just a single loop.  You can use a state macine with other loops, you just need to be careful of how you pass the data around.
    State Machine
    Producer/Consumer
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How to implement state machine architecture

    Earlier in this forum, i had taken help in improving the subparts of my main vi, now i had developed a main vi,it is working correctly without any error, but i had used sequence architecture in that and as everyone says we should use state machine instead of sequence architecture, i am posting my vi please help how to implement state machine architecture in this, and actually in my vi, i am having 5 tabs( presently i have developed only 2 tabs) 1. patient info, 2.naadi acquisition, 3.nostril temp., 4.vision acquisition, 5.other info. presently with tab control i am using case structure so that only only particular page runs at particular time, i want to know how can i improve this code to work more efficiently.
    Attachments:
    intelligent diagnostic bench.lvproj ‏68 KB

    i am sorry, i thought that vi's are by default attched with project files,i am attaching the main vi and all other associated subvi's also. 
    Attachments:
    Final Diagnostic Project.vi ‏375 KB
    createfolder(SubVI).vi ‏65 KB
    checkstring(SubVI).vi ‏11 KB

  • Flexible state machine "configuration" (script interpreter?)

    Hi all,
    I am currently re-thinking the implementation of a larger labview project which controls
    an instrument via RT on a CRIO system.
    Since the instrument is constantly improved and new features added to make it more and more
    automated I come to the limits of the current design.
    A quick description:
    The instrument should be capable of taking different kinds of measurements either at
    constant conditions or at conditions that continuously change.
    Before an measurement, the instruments needs to be conditioned, which is a rather complicated
    sequence of valves opened/closed, pumps started/stopped, temperature settings and so on.
    I currently use commands stored in a text file and read into an array of command clusters (enum'ed command + string for parameters)
    to be processed during conditioning.
    Then the user can run another sequence to make a certain kind of measurement.
    This works nicely but is not flexible enough. The conditioning and measurement sequences should be easily 
    editable without making changes to LV code.
    This is one reason I did not yet code this as a state machine, but it is a logical next step to do so.
    States would be idle, conditioning, measurement, re-conditioning ....
    But how do I do this in a most flexible way?
    In the sequences, I sometimes need to check for instrument parameters, and it would be elegant to
    call sub-sequences. I already implemented a looping feature to repeat some commands
    between two positions in the command array several times. But without the possibility to jump
    out of the loop.
    In short, if I continue this way I am about to write an interpreter for a simple scripting language .....
    I know that possibly VeriStand has a lot of this functionality but I am bit hesitant to make
    a big change like this and I am not sure if I can re-use the existing LV code to access and control
    hardware using VeriStand.
    Is there a good/elegant solution to what I intend to do with just LV and without re-inventing the wheel (script interpreter)?
    Olaf

    The most flexible way to implement this would be to use a command pattern and LabVIEW classes.  Using this approach, you core state machine would probably never change and you dynamically add or remove steps as needed.  Take some time to learn how this works by writing a couple of simple examples, then dive in.  It will be easier than you may think.
    This account is no longer active. Contact ShadesOfGray for current posts and information.

  • Sequence structure and Latch action

    Dear Sir or Madam,
    I have a sequence with commands in each frame. Is there a way to have a
    LATCH ACTION, between frames??.
    Thanks in advance for your any help.
    Sincerely,
    Luis Diaz
    [email protected]

    I would recomend that you get rid of the sequence structures and use a state
    machine. A State machine will give you a much more powerful and flexible
    program. Browse the example programs available at the Resource Library of
    NI's Developer Zone zone.ni.com). There is even an example called Pause/Resume
    & State Machine.
    "Kevin B. Kent" wrote:
    >Luis Diaz wrote>> Dear Sir or Madam,>>>> I have a sequence with commands
    in each frame. Is there a way to have a>> LATCH ACTION, between frames??.>>>>
    Thanks in advance for your any help.>>>> Sincerely,>>>> Luis Diaz>> [email protected]>>Not
    quite sure what you mean here.>You can pause between each frame, there are
    2 ways to do this.>Add a frame AFTER the frame to pau
    se>1) put in a timer
    (Wait MS) you can hardcode this wait or have>a value that the user can enter.>2)
    put in a while loop and have a button to proceed, or use some sort of>logic.>>All
    this will do is send the commands and then wait for the timer to expire>or
    the loop to end.>>A more elegant approach is to use a state machine. This
    is a combination of>a case structure inside of a while loop. You have much
    more control over the>>sequence of events and it is much easier to read and
    debug.>>Again all this will do is wait between cases (if setup that way)>>Using
    the state machine you can have a case return to itself which>is esentially
    a LATCH.>>There are samples of the state machine at various locations.>>Let
    me know if you need more help> Kevin Kent>

Maybe you are looking for