Use event to jump to a case in a state machine

How would I use an event to force a jump to a certain case in a state machine? For example, in the attached VI, I have a state machine that will simply blink a green LED indicator on and off for five seconds. I have a case in which the LED turns red for five seconds and a button which I would like to use to jump to this case. In other words, if the state machine is currently halfway (2.5 seconds) through my "Green_Light_ON" case when the button is pressed, I would like the state machine to immediately jump out of the "Green_Light_ON" case and into the "Red_Light_ON" case. This is not my ACTUAL VI, but it's a simplified example that will work for finding my solution. Thank you very much in advance for your help! 
Attachments:
DemoStateMachine.zip ‏18 KB

Sounds like the classic "Producer-Consumer (Events)" design pattern.  File>>New...>>VI from template.  There is a good shipping example as well as the comments on the template vi
Jeff

Similar Messages

  • 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

  • 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

  • Can i use events for anything i want?

    hi
    i've got a doubt about events. i am using events to send information between objects, so that the objects don't need to know who they are sending the information to.
    so i created my own events, listener and listenermulticaster
    but i have the feeling that events are intended to be used by the GUI objects, swing and awt.
    my question is if it is a good programming practice to use events to communicate other kind of objects. or maybe using events is not desirable at all??
    if events must not be used for this kind of works, what are the other ways to do it??
    thanx in advance,
    Lagarto

    well, thank you for your time
    now im considering using interfaces. if i understand it, the idea would be this:
    object A has information to send, so it has an atribute of tipe MyInterface, which has the methods to send the data.
    object B wants to get the data, so it create a new MyInterface and do something like:
    A.setMyInterface(new MyInterface() {....});
    i think this would work if there is only object B which wants the data (actually, this is the case i was thinking of from the beginning)
    but what can i do if there are more objects wich must get the data?
    Must the object A keep a Vector or something of more than one interfaces??
    thanks again...
    Lagarto

  • Why and how to use events in abap objects

    Dear all,
      Please explain me why and how to use events in abap objects with real time example
    regards
    pankaj giri

    Hi Pankaj,
    I will try to explain why to use events... How to use is a different topic.. which others have already answered...
    This is same from your prev. post...
    Events :
    Technically speaking :
    " Events are notifications an object receives from, or transmits to, other objects or applications. Events allow objects to perform actions whenever a specific occurrence takes place. Microsoft Windows is an event-driven operating system, events can come from other objects, applications, or user input such as mouse clicks or key presses. "
    Lets say you have an ALV - An editable one ...
    Lats say - Once you press some button  you want some kind of validation to be done.
    How to do this ?
    Raise an Event - Which is handled by a method and write the validation code.
    Now you might argue, that I can do it in this way : Capture the function code - and call the validate method.
    Yes, in this case it can be done.. But lets say .. you change a field in the ALV and you want the validation to be done as soon as he is done with typing.
    Where is the function code here ? No function code... But there is an event here - The data changed event.
    So you can raise a data changed event that can be handled and will do the validation.
    It is not user friendly that you ask the user to press a button (to get the function code) for validation each time he enters a data.
    The events can be raised by a system, or by a program also. So in this case the data changed event is raised by a system that you can handle.
    Also, Lets say on a particular action you want some code to trigger. (You can take the same example of validation code). In this case the code to trigger is in a separate class. The object of which is not available here at this moment. (This case happens very frequently).
    Advantage with events : Event handlers can be in a separate class also.
    e.g : In the middle of some business logic .. you encounter a error. You want to send this information to the UI (to user - in form of a pop up) and then continue with some processing.
    In many cases - A direct method call to trigger the pop up is not done. Because (in ideal cases) the engine must not interact with UI directly - Because the UI could be some other application - like a windows UI but the error comes from some SAP program.
    So - A event is raised from the engine that is handled in the UI and a pop up is triggered.
    Here -- I would have different classes (lets say for different Operating Systems). And all these classes must register to the event ERROR raised in application.
    And these different classes for different Operation systems will have different code to raise a pop-up.
    Now you can imagine : If you coded a pop-up for Windows (in your application logic) .. it will not work for Mac or Linux. But of you raise a event.. that is handled separately by a different UI classes for Win, Linux or Mac  they will catch this event and process accordingly.
    May be I complicated this explanation .... but I couldn't think of a simpler and concrete example.
    Cheers.
    Varun.

  • How to update Payload in existing BO using Event SubProcess( Non Interrupt)

    Hi ,
    I am using oracle BPM 11.6 Version.
    Let me explain the Problem :
    1. CoreProcess contains Three Human Task.Following Roles
    1) Approver One .
    2) Approver Two.
    3) Approver Three.
    2. Request Created through external Application ( As-Synchronous Process )
    3. PAN Card number as Correlation Key and Maintain Status element also.
    Status like -- Created, cancelled ,opened, Re-opened.
    4. External system have to update status on CoreProcess , using Event Subprocess ( as non interrupting Event to update Current Payload ).
    Problem I am facing :
    When I try to update Status , Not updated in my coreProcess payload.when ever coreProcess instance wait in any human task workspace.
    Using Event subProcess ( Non interrupt Event to achive this ) but my coreProcess pay load information not changed.I tried with Update Task to achive but no option to achive this.
    Can any one please help me . Thanks in advance.
    Regards
    krishna Moorthi p

    A non-interrupting even subprocess will no work on a copy of the data, it works on the same copy of the data as the rest of the process. Your problem is coming from the fact that human tasks are handled by the TaskService which is external to the BPMN engine. When the human task is created a copy of the payload is sent to the TaskService. This data is kept there until the task is completed at which time the updated payload is sent back to BPM.
    In your case you are updating the process data objects but that does not update the task payload as well. Unfortunately the Update Task activity does not seem to support updating the payload. I think the 2 options you would have are:
    1. Use the TaskService directly as a web service to update the payload
    2. Try updating the payload and then withdrawing the task. You can then possibly model a loop back to your human task in the process.

  • Can I use Event structures in a subVI?

    Hi,
    I have a subVI (ProvaEv1.vi) that use an event structure inside. But when I use it in a VI (ProvaVI.vi) the event structure in the subVI doesn't catch the events.
    I tried to insert the event structure in a while loop but it doesn't work too.
    Could you help me?
    Thanks Ius
    Attachments:
    ProvaVI.vi ‏11 KB
    ProvaEv1.vi ‏15 KB

    "iusn" <[email protected]> wrote in message news:[email protected]...
    Thanks to all for your answers!
    Wiebe! I tried to do as you suggested but I am not able to link the Event Reference Number inside te SubVI with the Event Register Number of the Register for Event in Main VI. There is e class conflict. Another question: how the SubVI can know the structure of the Register event outside?My aim was to create a modular structure but it seems very difficult, wath do you think about these problems?
    The broken wire is related to your question. The event structure inside the sub vi knows about the events you register in the main, because the reference wire/control has a "strong" type. It contains information about the registered events. That is also why the wire is broken. You have to register all events, then create an indicator/control of the output. Use that control in the subvi. You have to do this every time the events change (you might use a type def if you use the control a lot).
    Usually, the events that you would want to put inside subvi's are those related to user interface objects. I've had this a lot. You make a nice interface, but it's not reuseable, because the events are mixed with all the other events. Only solotion is to manually add the needed event cases in your program, and copy the code.
    Even if you can put the events in a sub vi, I'd expect hanging vi's when more subvi's are registered for the same event. It's hard to tell without trying. So it's not a real solution either.
    Like Chrisger suggested, the event callback might help a little, but they are tricky, and actually ment for this (they are intended for activex callbacks).
    Perhaps you should look at XControls (if you use 8.2). It would be more work to replace your code to XControls, but once you're done, you have reusable code.. Haven't worked with them jet, but they are invented for this problem...
    Regards,
    Wiebe.
    I have already create my application using event structure just in Main VI but it seems very complicate to read and keep update, I would have wanted to give modularity to my application.
    Thanks Ius
    SubVIEventMain.vi:
    http://forums.ni.com/attachments/ni/170/203225/1/SubVIEventMain.vi
    SubVIEvent.vi:
    http://forums.ni.com/attachments/ni/170/203225/2/SubVIEvent.vi

  • Trigger process chain using event

    Hi all,
    I’d like to know if someone ever faced this kind of situation.
    I have a process in R/3 and it must run every day, and when it’s finished I have to start a process chain in BW.
    I thought to do this using events. So, I created a Job that executes this process and added a step( an ABAP program ) that generates an event in a target system, BW.
    The program is this one:
    PARAMETERS:
        p_eventi   TYPE btceventid,
        p_eventp   TYPE btcevtparm,
        p_server   TYPE btcserver.
    Obligatory parameter: EventID.
    EventID should be an existing event already defined in transaction
    SM64 or using CREATE method of class CL_BATCH_EVENT:
    p_eventi   = 'SAP_TEST'.
    Optional parameters: event parameter and target server.
    p_eventp = 'Event parameter'.
    p_server    = ''.
      CALL METHOD cl_batch_event=>raise
        EXPORTING
          i_eventparm                    = p_eventp
          i_server                       = p_server
          i_eventid                      = p_eventi
        EXCEPTIONS
          excpt_raise_failed             = 1
          excpt_server_accepts_no_events = 2
          excpt_raise_forbidden          = 3
          excpt_unknown_event            = 4
          excpt_no_authority             = 5
          OTHERS                         = 6.
      CASE sy-subrc.
        WHEN 0.
          EXIT.
        WHEN 1 OR 2 OR 3.
    Raise failed.
        WHEN 4.
    Event does not exist.
        WHEN OTHERS.
    Raised failed due to unknown reason.
      ENDCASE.
    The execution of the job appears to be OK, but I checked the log at SM62 and couldn’t find any entrie, and the process chain didn’t start too.
    I created the event at BW and R/3 side,  informed the variant with event / server in R/3, etc.
    I’m missing some step??
    Best Regards,
    Tomas

    This is what this note does.  From R/3, it will trigger an event in BW.
    You can also read this post:
    Triggering a Process Chain From R/3 pgm
    Hope this helps.

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

  • How to do state machine using events .

    Hi all.
    i like to create a state machine using events methos .
    i have 4 functions 1,2,3,4. (event based functios) (seperate sub vis)
    1.i will trigger the 1 function.
    then end of the first function should trigger the next function.
    like state machine .
    how to create this method in labview .. i tried value signaling its still not working . what i want.
    Solved!
    Go to Solution.

    JGar wrote:
    Wouldn't it make sense to have the entire state machine within one event case?  When you trigger the event case the state machine then executes like a normal state machine.
    DO NOT DO THAT!!!!!!  Long parts of code do NOT belong inside of an event case.
    The Event Structure should be in its own state and the state machine should to to that state every once in awhile to check for user events.
    Alternatively, you could put just the state case structure inside of the Timeout event case.  Something like this: http://www.notatamelion.com/2015/03/02/building-a-proper-labview-state-machine-design-pattern-pt-2/
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How to control the tab control using event structure?

    Hi,
    I am using tab control and event structure in the program.
    When i run the application event is not happening for the active page.
    When user switches from active page to the other page then event is taking place for all pages
    So, how to get the event trigger for the active page when the application is started
    For more clarification i am attaching the code "Test Control Tab using Event Structure.vi"
    Attachments:
    Test Control Tab using Event Structure.vi ‏52 KB

    You have a basic misunderstanding of dataflow. Maybe you should start with some tutorials or study some of the examples that ship with LabVIEW.
    The event structure belongs inside the while loop, and not vice versa. RIght now, the event structure only runs exactly once and never again.
    If the stop is pressed first, the VI will stop. Game over.
    If the tab control is changed (from any state to any other state!), the inner loop will spin forever as fast as the CPU allows, either executing one or the other case. It just reads the tab terminal to decide which case to execute. Changing tab never triggers any events. The VI is trapped inside the event until stop is pressed to stop the VI.
    you were closer to a reasonable program in the other thread:
    http://forums.ni.com/ni/board/message?board.id=170&view=by_date_ascending&message.id=287905
    Have you tried execution highlighting? Maybe things would become more clear of you do.
    LabVIEW Champion . Do more with less code and in less time .

  • How do I use event.target.name in AS2?

    Thanks to kglad I was able to see how event.target.name in AS3 could make a button load a movieclip with the same namesake.
    I'm doing the same thing now in AS2 but don't know what to write instead of event.target.name.
    And so at the moment each button pushes info into an array and then a function uses that to decide which movieclip to attach to a holder after it has faded out once, and then fades in again...
    // ***** IMAGE GALLERY START ***** //
    // Add image to holder
    imgholder.attachMovie("img0", "image0_0", 1)
    // Array
    var nextLoad = ["img0"];
    // Btn listeners
    img5.onRelease = function() { trace (nextLoad); nextLoad.pop(); nextLoad.push("img5"); btnClick() } // Written on 1 line
    img4.onRelease = function() { trace (nextLoad); nextLoad.pop(); nextLoad.push("img4"); btnClick() }
    img3.onRelease = function() { trace (nextLoad); nextLoad.pop(); nextLoad.push("img3"); btnClick() }
    img2.onRelease = function() { trace (nextLoad); nextLoad.pop(); nextLoad.push("img2"); btnClick() }
    img1.onRelease = function() {
    nextLoad.pop();
    nextLoad.push("img1");
    btnClick()
    img0.onRelease = function() {
    nextLoad.pop();
    nextLoad.push("img0");
    btnClick()
    // The btn function
    function btnClick() {
    trace ("click");
    var myImgTween:Object = new Tween(imgholder, "_alpha", Strong.easeOut, 100, 0, 1, true);
    myImgTween.onMotionFinished = function() {
    fadeOutImg();
    // The btn function part II
    function fadeOutImg() {
    trace ("fadeOutImg");
    imgholder.attachMovie(nextLoad, "image1_1", 1);
    var myImgTween:Object = new Tween(imgholder, "_alpha", Strong.easeOut, 0, 100, 1, true);
    I know I should be able to push the button name into the array, but am having to use a string... I'm sure my code is cumbersome!! But it works. I've tried pushing the button name but it end up including the full stage reference.
    Is there a cleaner way of doing this using event.target.name?
    Thanks for looking!

    There is no event.target in AS2. However since AS2 has no way of remembering the scope object where the target object resides, you can use this to your advantage to retrieve the name of the target by using the "this" command in the function whenever you use the above format "mc.onPress = myfunc". FYI, the popular workaround Delegate, made it possible that when you called "this" in the function, you could retrieve the scope object where the target instance resides. So without its use, "this" will return the name of the target object. Anyway this is the code you can use:
    imgholder.attachMovie("img0","image0_0",1);
    var nextLoad = ["img0"];
    img5.onRelease = onImgRelease;
    img4.onRelease = onImgRelease;
    img3.onRelease = onImgRelease;
    img2.onRelease = onImgRelease;
    img1.onRelease = onImgRelease;
    img0.onRelease = onImgRelease;
    function onImgRelease():Void {
       nextLoad.pop();
       nextLoad.push(this._name);
       btnClick();
    // The btn function
    function btnClick() {
       trace("click");
       var myImgTween:Object = new Tween(imgholder, "_alpha", Strong.easeOut, 100, 0, 1, true);
       myImgTween.onMotionFinished = function() {
          fadeOutImg();
    // The btn function part II
    function fadeOutImg() {
       trace("fadeOutImg");
       imgholder.attachMovie(nextLoad,"image1_1",1);
       var myImgTween:Object = new Tween(imgholder, "_alpha", Strong.easeOut, 0, 100, 1, true);

  • How can I view my photos in "Events" like in iPhoto? How can I create events?  I have 55,000 photos and 1700 events so the only way I can possibly manage my photos is using events that are one slide in size.

    I have 55,000 images organized into about 1700 events. The only reasonable way to view my library is using events in iPhoto where each event has one image That still leaves 1700 images to sort through but that is a lot easier than 55,000 images.  In the side bar is a folder with "iPhoto Events" but those views still show all of the slides.  How can I create events and view my photos as events as in iPhoto?  Events are critical for large libraries and has been my primary way to sort images.
    Thanks!

    I had a problem a couple of months ago when iPhotos suddenly rearranged the order of my Events (Why won't iPhoto let me arrange my photos?) .  I was told "Use albums not events - events are not a good way to organize - albums and folder are designed for organisation and are very flexible".
    Haha!  I should have paid attention and read between the lines!  My iPhotos were highly organised groupings - not according to date but the way I wanted them - and it was so easy to do!  I see now that if I had them all in albums, as per the Apple Apologist suggestion, I wouldn't have this unholy mess I have been left with just to make iPhone & iCloud users happy.  I am now going through Photos and making Albums (of what used to be in my Events)  ... maybe I'll get this finished before they do another non user friendly update!

  • Add fields to maintenance view and update then using events

    Hi experts:
      I've created a table with 4 fields, one of them is userid. Also, there is a maintenance view to add new entries.
      I want to display user name when typing userid using events (1 or 21). I know how to do it if username is one of the fields of the table, but there is a requirement to not store username in the table, just userid.
    My question is: is possible to add a field into the maintenance view and update it using events but not store the value in DB?.
    Thanks in advance for your help.
    Regards,
    Carlos.

    In the save event just clear the entries of the field(user name) in the internal table.

  • HOW TO CREATE  and  USE EVENTS IN WORKFLOWS .

    HOW TO CREATE  and  USE EVENTS IN WORKFLOWS with the help of classes.
    What i am doing is..
    open se24
    event tab->event name->parameters
    method tab->method name->event handler->copy parameters
    interface tab->if_workflow->enter
    tell me what else to do step by step
    Another important thing is that HOW to use these class events to trigger the workflows.
    REPLY ASAP
    THXS IN ADVANCE

    Hi,
    Pl. see this blog...
    Raising ABAP OO events for workflow
    Regards,
    JOy.

Maybe you are looking for

  • How to grab the acct# from my url

    I have inserted a Spry Menu on my Coldfusion reports page that contains all of my custom reports at our Intranet. This reports cfm page was then added to our Company website. Here is what a typical url looks like when accessing the Spry menu: http://

  • ITunes claims I need an excessive amount of memory to sync a little bit of music

    I have an iPhone 5c and is up to date with iOS 7.1.2. I've had the problem previously and after 2 hours of intensive "help" from an iTunes customer support member they came up with a short term solution of manually adding the new songs. However, I'm

  • Cannot Order Front/Back a Question Rollover Caption

    Following from another post, http://forums.adobe.com/thread/609673, I cannot z-order the Rollover Caption when it's on a Question slide. I right-click the text caption and the Order -> Bring to Front / Send to Back options are grey / disabled. Is thi

  • Selection screen - where is my parameter?

    Hi all! I've got a curious situation! I added a new parameter in my abap program. SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-004. PARAMETERS p_wkzrl  TYPE boolean AS CHECKBOX DEFAULT 'X'. SELECTION-SCREEN END OF BLOCK b1a. In our test s

  • Dynamic columns in query depending on hierarchy nodes

    Hello all I want to design a query with dynamic number of columns depending on hierarchy node. A hierarchy node is selected while running the query and user has authorization to see all subsequent nodes below the selected node. e.g. consider grp hier