Shutting down a queued event state machine with multiple parallel loops

I am trying to find the best way to shutdown a program that consists of a queued event state machine architecture with multiple parallel loops. Can anyone recommend the best way to accomplish this in my attached VI? (From browsing the forum, this seems to be a common question but I haven't found a solution that works for me.)
I welcome any other feedback on my code as well, if anyone is willing to offer it.
My Program Requirements:
If the user presses the "Shutdown" button, the program should prompt the user with "Are you sure you want to stop the program?" and then either return to the Idle state or proceed to stop the program. Additionally if there is an error, the program should prompt the user with "Clear error and continue, or Stop program?" Then either return to the Idle State or proceed to stop the program.
Details of architecture:
The program consists of 3 parallel loops: (1) an Event Handling loop that enqueues various States to a State Queue, (2) a State Machine which enters the latest state that is dequeued from the State Queue, and (3) an Error/Shutdown handling loop which processes any errors in the Error queue.
During normal Shutdown, in the Event Handling loop the "Program.Shutdown" event case executes, and the States "Shutdown" and "Idle" are added to the State Queue. In the State Machine, the "Shutdown" state is invoked. A special error code "5000" is added to the Error Queue. In the Error/Shutdown handling loop, the "5000" error triggers a prompt that asks the user if they want to stop the program. If the user chooses not to stop, a notifier StopNotif is sent to the "Shutdown" state and "Program.Shutdown" event case with the notification "Go". If the user chooses to stop, the notifier sends the notification "Stop". The Event handling loop and State Machine are terminated if they receive the notification "Stop".
In case of error, the program behaves similarly: if the user chooses to clear the error and continue, the program returns to the "Idle" state.
HOWEVER - if the user chooses to stop the program, the program stalls. The notifier that is sent to stop the Event Handling Loop and State Machine cannot be read because the Program.Shutdown event case and the Shutdown state (which contain the "Wait for Notifier" function) are not active.
I have been able to activate the Shutdown state by enqueuing it in the Error/Shutdown handling loop. But I don't know how to activate the "Program.Shutdown" event programmatically, and thereby access the "Wait for Notifier" function inside it.
I tried to place the "Wait for Notifier" function outside the event structure, but then the Event Handling loop never completes. Placing timeouts on the "Wait for Notifier" and on the Event structure makes the program work, but I want to avoid using timeouts because I don't want to turn my event-driven program into a polling-based program. I'd also like to avoid using variables or property nodes to stop the loops, because that requires creating a control/indicator for something that the user doesnt need to interact with.
Thank you!
Solved!
Go to Solution.
Attachments:
Queued event state machine parallel loops empty.vi ‏46 KB

Thanks for clarifying that, Ravens Fan.
I marked crossrulz as the solution for pointing out User Events to me.
I also adopted Ravens Fan's suggestion to keep the Shutdown procedure out of the Error Handling Loop. This has simplified the architecture by eliminating the need for Notifiers. Instead, I have used booleans in case structures to stop the Event Loop and State Machine, and Release Queue to stop the Error Handling Loop.
For reference, I'm attaching my corrected code.
Thank you to everyone who helped!
Attachments:
Queued event state machine parallel loops empty in progress.vi ‏44 KB

Similar Messages

  • An example of a state machine with transition array?

    I am looking at state machine design patterns and am interested particularly in a state machine with boolean trasition array which defines the next state to be executed using an array. Here, the index of the first “True” boolean in the boolean array corresponds to the index of the new state in the array of enums. Has anyone got an example of this design pattern as it would greatly help in my understanding of it. Refer to figure 3c in http://zone.ni.com/devzone/cda/tut/p/id/3024#toc2 for clarity on what i am asking for.
    Thanks in advance.

    That seems like a lot of extra work. Why not just use a queue, and queue up the enum you want to go to next? Look up examples on queued state machine. No need for an array and then a boolean to index that array. here is an example
    CLA, LabVIEW Versions 2010-2013

  • I can't start AE. Ae always shuts down. There is a Problem with the "AEDynamiclinkServer". I tried everything. But it doesn't work. How do I get AE back to work?

    I can't start AE. Ae always shuts down. There is a Problem with the "AEDynamiclinkServer". I tried everything. But it doesn't work. How do I get AE back to work?

    What "everything" have you tried?
    What exact version number (down to the last decimal) is your AE?
    What OS are you using?
    What are your other system specs?
    When did it work last? What happened between then and now?
    FAQ: What information should I provide?

  • Macbook froze while online. hard shutdown. when it restarted, an error message appeared saying finder shut down unexpectedly containing a message box with a long list of technical jibberish.  after clicking OK that it would send an error report to Apple,

    macbook froze while online. hard shutdown. when it restarted, an error message appeared saying finder shut down unexpectedly containing a message box with a long list of technical jibberish.  after clicking OK that it would send an error report to Apple, the same error message box appeared again and again every time OK was clicked.  Now the macbook will not turn on at all

    If you're able to boot, launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ If you’re running Mac OS X 10.7 or later, open LaunchPad. Click Utilities, then Console in the page that opens.
    Select the most recent panic log under System Diagnostic Reports. Post the contents — the text, please, not a screenshot. In the interest of privacy, I suggest you edit out the “Anonymous UUID,” a long string of letters, numbers, and dashes in the header and body of the report, if it’s present (it may not be.) Please don't post "shutdownStall" or "hang" reports.
    If you can't boot in the usual way, try a safe boot. The instructions provided by Apple are as follows:
    Be sure your Mac is shut down.
    Press the power button.
    Immediately after you hear the startup tone, hold the Shift key. The Shift key should be held as soon as possible after the startup tone, but not before the tone.
    Release the Shift key when you see the gray Apple icon and the progress indicator (looks like a spinning gear).
    During startup, you’ll see a progress bar, and then the login screen, which appears even if you normally log in automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin.
    Safe mode is slower than normal, and some things won’t work at all.
    Note: If FileVault is enabled under Mac OS X 10.7 or later, you can’t boot in safe mode.

  • Need help created state machine with timed digital output

    Hello everyone I'm new in LabView especially about how to make a state machine. I want to make simulation about state machine with digital output. In Front Panel there are volt_in as an input slider (0-10 V), two numeric control (upper limit and bottom limit), a waveform chart to plot those 3 value, and three boolean (P0.0, P0.1, P0.2) as an indicator. Boolean indicator will on if input from slider exceed the limit in certain situation. This simulation will work as follow:
    1. Define the upper & bottom limit (ex. 8 & 4V)
    2. Make an input from slider (0-10V)
    3. If input (2) exceed the upper limit but less than 10 second (ex. you have 9V input for 8 second, but after 8 second you change the slider back to normal between 4-8V) then the boolean indicator P0.0 & P0.2 will stay off
    4. If input (2) exceed the upper limit more than 10 second (ex. you have 9V input for 4 second, change to 8.5 V for 3 second, and then change to 10V for 3 second) then the boolean indicator P0.0 will turn on for 5 second, turn off, then follow by indicator P0.2 for 5 second, and turn off
    5. Wait 15 second, then repeat process from (2)
    Same process for input that exceed the bottom limit (P0.1 and P0.2 as indicator).
    Can you help me make the block diagram of this process? I will appreciate any of your help.
    Best Regards
    juventom 
    Attachments:
    State Machine Digital Output.vi ‏28 KB

    I would highly recommend you to open the template in LabVIEW to design state machines. You can the Standard State Machine template if you go to File -> New.. and Browse to VI -> From Template -> Frameworks -> Design Patterns.
    Also, here is a good explanation of one:
    https://decibel.ni.com/content/groups/northeast-oh-labview-users/blog/2009/09/08/state-machines
    Adnan Zafar
    Certified LabVIEW Architect
    Coleman Technologies

  • I did force shutdown on my MacBook Pro (2006 year, 15.4"), so, when I tried to boot, it shows apple logo (as usual) and shuts down. When I booting MacBook with Option key pressed it shows lock icon and field for password. Please help me.

    I did force shutdown on my MacBook Pro (2006 year, 15.4"), so, when I tried to boot, it shows apple logo (as usual) and shuts down. When I booting MacBook with Option key pressed it shows lock icon and field for password. Please help me.

    Wait for advice on repairing a damaged filesystem.  Forceshutdown stops processs in mid-stream and leaves some parts not-valid.
    Do not proceed until you get that avice.

  • 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 .

  • State machine with using event case

    Hallo everyone,
    i have a question about how to realize the "Timeout". In the flow diagram below we can see 2 different situation:
    1. in the 1st Situation i have used the state machine, it begins at state 1, which contains a event case. In there it will be at first determined, if the input value has changed within 10 second,  if it didn't, the state machine will go to state 2, if it 's  changed, will be furthermore determined, whether the input value equal to 3, if yes, the state mashine will jump to state 3, if no, jump back to state 1. (this VI i have done before, you can take a look at the Attachment).
    2. my question is in the 2nd situation. It begins also at state 1. In there the input value can also be changed (once or many times) or not. If the value has not been changed within 10 s, or even though it's been changed many times within 10s, but  it's never been equal to 3, the state machine will go to state 2; only when the input value within 10s equal to 3, it can jump to state 3.
    This problem i have no idea how to solve, does anybody have  idea or better methods?
    thanks a lot!!
    Solved!
    Go to Solution.
    Attachments:
    situation 1.vi ‏12 KB

    The statement in the OP is not covering all cases.
    mexaviesta wrote:
    2. my question is in the 2nd situation. It begins also at state 1. In there the input value can also be changed (once or many times) or not. If the value has not been changed within 10 s, or even though it's been changed many times within 10s, but  it's never been equal to 3, the state machine will go to state 2; only when the input value within 10s equal to 3, it can jump to state 3.
    This problem i have no idea how to solve, does anybody have  idea or better methods?
    thanks a lot!!
    Just check my implementation for Situation 2 and let us know, if it works for you.
    I am not allergic to Kudos, in fact I love Kudos.
     Make your LabVIEW experience more CONVENIENT.
    Attachments:
    Situation 2.llb ‏40 KB

  • My MacBook shuts down whenever I move the machine, and then refuses to turn back on. What is causing this?

    I've been in possession of a 2011 MacBook Pro with OS X Lion since October. Ever since the second or third month I received my MacBook, it has had this problem of shutting down whenever I even touch the monitor, and then occassionally refuses to turn back on. I used to be able to ignore it, as it was rare: now it has become a real problem. Does anyone have any advice? How could this have happened? Is it something I might have downloaded, or is it the battery itself? I think it would be the battery, as the machine refuses to cooperate unless being operated on a flat surface. Thanks in advance.

    Any word on this, I have a Macpro doing the same and have to reset the SMC everytime.

  • Photoshop CS3 shuts down after opening a PSD file with layers

    Hello, I have met a problem with Photoshop CS3 (Windows XP SP2, no network printer) - after opening a PSD file with layers (saved with CS2) Photoshop shuts down. No error message.
    Can some of you help me? (The only software that I have installed after Creative Suite CS3 is Corel X4. I have installed no upgrades of CS3.)

    > I have installed no upgrades of CS3
    You should!
    Even if it doesn't help here you should.

  • Mail Shuts Down when trying to Open Email with movie

    Just recently Mail is shutting down when I try to open an email with attached movie. When I mail again, the email is still there with the blue dot.
    I found one document suggesting a Java..Cocoa plug in may be the culprit but no luck.
    Any ideas?
    Any assistance very much appreciated.

    Am I the only one having troubles with Apple Mail?
    As I said, when I go to open an email that has a movie (.wmv) attached it shuts mail down. Must be a record if I am the only one encountering this problem.
    Any one? Any ideas?

  • Performance of state machine with enum vs string?

    I am laying out the groundwork for a very large state machine. It will have about 60 to 100 states. I kind of want to use an enum for selecting the states for convenience. But then if I use a string I can use Jim Carmody's case select tool so that wins out in convenience in one respect.
    One concern about using a string is performance. Since an enum is just an integer wouldn't the selections perform better? I need to squeeze out every ounce of performance and in fact this state machine will be set for subroutine priority. Another concern that I have about a typedef enum is that I have heard something about the possibility of them getting "out of sync" between VIs when you edit them. Is there some way to avoid that, such as making sure all VIs that use this typedef are in memory when editing it?
    =====================
    LabVIEW 2012

    Steve Chandler wrote:
    As for the number of states, I am pretty sure that it has to be one state machine. I'm afraid I cannot give a lot of details.
    I am having trouble figuring out the "has to" part.
    See this thread for designs I have posted previously.
    In this SM
    please look the section that is entered from "Change Request 8 " can take multiple paths but all ends at "Stop Monitoring? 15". I could have implemented that as a sub-SM and it would have reduced the number of state required for that part of the work from five to one.
    Any time I see "single entry, fan out, merge" I think sub-SM.
    This could also help with your shift register as well because (again seea bove) the bulk of the ose states deal with Logging so rather than use a SR, put what would have been in the SR (file path or ref) to be used there OR possibly an AE that can be used in each of those states.
    So I still don't understand why sub-SM aren't a possiblity.
    Trying to help,
    Ben 
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Why is iChat shutting down when trying to video-conference with Windows?

    My friend and I are trying to video-conference.
    I use an iBook G4, with an iSight.
    My friend uses a HP Pavilion ZV5000.
    For some reason, my iChat shuts down when it's connecting.
    It'll connect for one second and then, my iChat will close.
    I don't see what's wrong :(!
    Help me, please!
    iBook G4   Mac OS X (10.4.8)  

    Hi Bill,
    Yes I saw that kellyRAWR mentioned that they were using AIM.
    And Tony explained about the AIM 5.9 issue.
    I was merely offering another option that she may not know about, since the AIM->iChat is flaky at best.
    Respectfully,
    SimplyMac.

  • TS1702 Planet rock app shuts down after 20seconds, this worked perfectly with IOS5

    Hello, got this ipad3 for my 60th birthday, so not too good with it, I downloaded the Planet Rock app, and it seemed to work fine with IOS5, now with the updated IOS6 it shuts down after 20 seconds or so, also lost the YouTube app, I'm getting disheartened by this overly expensive gadget please help if you can,  many thanks.

    Hello, got this ipad3 for my 60th birthday, so not too good with it, I downloaded the Planet Rock app, and it seemed to work fine with IOS5, now with the updated IOS6 it shuts down after 20 seconds or so, also lost the YouTube app, I'm getting disheartened by this overly expensive gadget please help if you can,  many thanks.

  • Can I shut down my PWP and replace it with a self-built website?

    I'm interested in creating a page at home.comcast.net/~tyler.schultz that redirects users to another website. Is it possible to shut down the PWP, move it, or create a page that the URL goes to instead of the PWP? Or does the PWP support a redirection code in Javascript? Thanks.

    Tylerman wrote:
    I'm interested in creating a page at home.comcast.net/~tyler.schultz that redirects users to another website. Is it possible to shut down the PWP, move it, or create a page that the URL goes to instead of the PWP? Or does the PWP support a redirection code in Javascript? Thanks.Your redirect will work until they shut off PWP's and delete all the files. Hopefully you are notifying all who are redirected to your new page for the next few months to BOOKMARK the new address as the old one will soon go "poof" thanks to Comcast once again giving us LESS service for MORE money. May I ask what hosting service you went with and was it a free one or a pay service? Or did you just register a domain name and set up your own site?Thanks.

Maybe you are looking for