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

Similar Messages

  • 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

  • How to use a event structure in a subVI

    I am trying to use an event structure inside a subVI.  The subVI has an array builder that builds arrays, and the event structure is used so that when the program is running, it allows you to change the elements of the array.  It works, but when I implement it inside a subVI, it does not work properly.  This is going into a subVI, because it will be a part of a much larger progrram, so it needs to be modular.

    If you're using an event structure, it's not a subVI.  if you're worried about modularity, you shouldn't be using the event structure.
    You seem to have a fundamental misunderstanding of modularity.  An event structure should be placed within a while loop.  If you have a while loop within a subVI, you've handed over control of your program to the subVI.  You're not modular at this point.  Your top level GUI has no control.  You'd have to create some asinine system of variables to pass data down to that loop to stop the loop and return to your main VI.  That's not a good design decision.
    Instead of looking for a way to do something broken, you should spend effort trying to understand what you actually want to accomplish.  You should also spend some time learning how event structures work.
    This application is small right now and it's already on the path to unreadable.  That's a terrible thing to do to yourself.  Break these habits now.  se variables only when absolutely necessary.  Use subVIs to accomplish individual tasks, not run the entire application.  With event structures, use a stop button value change event to not be held hostage by the timeout.  If your variable has "2" in it, you're doing something wrong.  There has to be something different between the setpoints, put that in the name.  If you want to make subVIs, create an icon.
    But first and foremost, invest time in understanding dataflow

  • How to use an Event Structure responding to an image control that belongs to a parent VI.

    Hi
    I am loading a subpanel vi by pressing a button located in the user interface of the main vi which also contains an image display. Subpanel vi opens up on the side and doesn't hide the image display of the main vi. Subpanel vi contains an event structure that needs to respond to user clicking on the image display of main vi.
    Since the bug that occured while creating an image reference control isn't fixed, I am passing the main vi pane reference onto the subpanel vi. From that point I've tried to edit event structure and have it respond to the image control/pane that belongs to main vi but I don't know how.
    Any help would be appreciated.
    Thanks

    Post a screenshot of your subVI code where you register the events.
    André
    Regards,
    André
    Using whatever version of LV the customer requires. (LV5.1-LV2012) (www.carya.nl)

  • How to use For-Each Structure with Multiple node XML structure

    Hi,
      How to use for-each (BPEL 2.0) construct for Multinode XML structure.
    Here is the easy case: I have list of suppliers specified by supplier
    <supplierList>
    <supplier>1</supplier>
    <supplier>2</supplier>
    <supplier>3</supplier>
    </supplierList>
    Now there is a web service http://hostname/getsupplierdetails/wsdl which accepts one supplier at a time.
    like
    <supplier>1</supplier>
    reponse object is
    <message> notfound/found </message>
    But how can I use for each of XML node to call this service and collect the result like
    <supplierList1>
         <Suppinfo>
            <supplier>1</supplier>
            <message> not found</message>
    </suppinfo>
        <suppinfo>
            <supplier>1</supplier>
            <message> not found</message>
    </suppinfo>
    </supplierlist1>
    Thanks

    For looping you use foreach loop and , loop for the number of occurences and when constructing response, adding a new element you have to use bpelx:append.  Good sample at Enterprise Integration: Oracle SOA Suite 11g: Populating a list or an array in BPEL without using XSLT.

  • Event Structure with Event source: This VI and Event: Mouse Up

    I downloaded an old example from 2008 on this forum and would like to duplicate it.  It uses an event structure with an event case of just Mouse Up.  Under Event Specifiers:  the Event Source is <This VI>  and Event: Mouse Up.  This works like I want in LV 2009.
    In LV 2009 if I choose for Event Source  <This VI>   under Events Mouse Up is not an option!    I tried Event Source: Pane,  and  then Event  Mouse Up is an option, but this does not trigger the event if you drag the mouse off the pane before you lift the mouse button.
    I can copy the Event Structure over to my VI  and rewire every case but that does not seem to be a good solution cuz I want this in several VIs.
    I have attached the original VI with the Event Specifier I want.  How do I get this Event Specifier in LV 2009?
    Attachments:
    Slider event control.vi ‏19 KB

    phillman wrote:
    I downloaded an old example from 2008 on this forum and would like to duplicate it.  It uses an event structure with an event case of just Mouse Up.  Under Event Specifiers:  the Event Source is <This VI>  and Event: Mouse Up.  This works like I want in LV 2009.
    In LV 2009 if I choose for Event Source  <This VI>   under Events Mouse Up is not an option!    I tried Event Source: Pane,  and  then Event  Mouse Up is an option, but this does not trigger the event if you drag the mouse off the pane before you lift the mouse button.
    So what you can do is monitor the 'Mouse Leave' event for th pane, and then start polling the mouse state.
    Technically it is correct that there is no Mouse Up event detected since the Mouse Up is not happening on th epane.
    Ton
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!

  • Is it better to have one Event Structure with more (10 or 15) cases or several with fewer?

    I have several buttons and events on the GUI of my app to monitor. Would it be better to use one Event Structure with several cases (10 or 15) or have a couple and split the cases evenly? None of the cases have much processing to handle, so there is not a time lag issue. I am just worried about overloading the structure. One of the tech support guys mentioned that the event structures are not that hard to get confused.
    Has anyone had any problems with Event Structures?

    I use event structures very often in my code. I use them just to handle the interface and to run small code. I have had event structures that handled over 50 user interface events and never had a problem. In my personal opinion If there was any code to run I would let the event structure handle the the user interface event that fired a que in another while loop that handled the code.You can find examples on this, if not I will send you one. It is just good programming practice for beginners because it will alow you to build more robust VI's in the future.
    Hope this helps
    Joe
    Joe.
    "NOTHING IS EVER EASY"

  • How to use the eventing and databag with a WAS 6.20 ?

    How to use the eventing and databag with a WAS 6.20 ?
    Is what there is a good guide for these services?
    Thank's

    In the raise event you can pass the value
    like below.
    <SCRIPT>
    function raiseEvt(value1){
    if(window.document.domain == window.location.hostname){
    if ( document.domain.indexOf(".") > 0 ) document.domain = document.domain.substr(document.domain.indexOf(".")+1);
       EPCMPROXY.raiseEvent( "urn:com.sap:BWEvents","BWiViewevent", value1, null );
      // alert('tree domain'+document.domain);
    </SCRIPT>
    and in the
    subscribe event you can get the values like below.
    <script language="javascript">
    if(window.document.domain == window.location.hostname){
    document.domain = document.domain.substring(document.domain.indexOf('.')+1);
        EPCMPROXY.subscribeEvent("urn:com.sap:BWEvents","BWiViewevent", window, "myreceiveEvent");
    function myreceiveEvent( eventObj ) {
          document.forms[0].gp_hidden.value = eventObj.dataObject;
    </script>
    Also look at the following link for a complete documentation.
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/Enterprise%20Portal%20Client.pdf
    Regards
    Raja

  • Can I use Ctlref in a event structure with a mouse up event?

    I have a large number of controls on a front pannel. I'm using a event structure that triggers the motion of a given motor when the corresponding control is pressed. However, I would like to avoid creating N mostly identical events, so I was planning on using a mouse down event on the front pannel, then retrieve the control reference using the Ctlref node (with gives "Reference to the control on which the event occurred" according to labview manual) and scan a array of references to find out which motor is supposed to move. However, it seems that this node does not appear (contrary to what the manual says).
    I have found other ways to do what I need (I was thinking of using an array containing the coordinates of my controls and the coords node of the event structure), but I wanted to know why I can not find that node (which appears for "value change" event for instance). I'm using Labview 2013.
    Solved!
    Go to Solution.

    Bad luck for you. Mouse down on panel does not have the control refnum as it is not operating on a control. Mouse down on a control does have it and since you can configure mouse down events on several controls in the same event case, it provides also a control refnum so that you can still operate on the control in question.
    This is probably also the issue Jeff might have seen. When configuring multiple events for the same frame LabVIEW will only show the event terminal that are present in all of those events. Terminals that don't exist in at least one specific event of the multiple events for that frame are not selectable anymore.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Using an event structure to reset a boolean control with ring menu value change

    I am trying to get two boolean buttons to reset when the value of a ring menu changes.  For this I am using an event structure set to execute with a ring value change.  However I have other code that needs to be executing while the event structure waits for the value change.  I place my event structure inside the while loop the buttons reset as expected but my other code does not run (except at the moment of value change). If I place it outside the loop the rest of the code functions as expected but the buttons do not reset.  Any help you can offer is much appreciated.
    Solved!
    Go to Solution.
    Attachments:
    event structure reset.vi ‏11 KB

    try this
    Attachments:
    event structure reset_edit.vi ‏14 KB

  • Acquiring continuous data using an event structure

    I am new to labview, having recently taken the Core I and II courses.
    I am programming a test rig to acquire the linear position of a hydraulic cylinder and plot it over time.  In programming this code, I elected to use an event structure so that when a front panel button is pressed, a certain part of the test is run. 
    In one particular part of the test, called the Snub Test, I need to measure the position of the cylinder over time and plot it to a graph.  The data acquisition needs to be continuous, however the event structure only allows the loop to run once. 
    I have attached a portion of my code for reference.
    Can someone please advise how I can get this data acquisition to run continuously until the user (or a reference trigger) stops the test?
    Thanks
    Attachments:
    Front Panel.vi ‏115 KB

    A few comments to your VI in general:
    You changed the stop button to "switch until released", most likely because you fabricated a race condition and did this as a quick fix. The reason is (1) your placement of the stop terminal outside the event structure and (2) the use of a local variable wired to the stop condition. The button terminal of a latch action boolean belong inside it's associated event case! This way it gets read (and reset to false) when the event occurs. In your case, the local variable and the button get read before the event occurs and the loop needs to spin once more at the event that occurs when you release it (true->false). At this point, the local is still true from the earlier event and the loop stops. Correct would be: latch action, stop terminal inside stop case and wired to the stop condition from inside the event. Other cases use the default output (false) and don't stop the loop.
    Your "equal false" code fragment is just an invert, right? So why complicate things?
    Why do you need a wait if there is an event structure?
    LabVIEW Champion . Do more with less code and in less time .

  • Can I have multiple event structures with the same event cases?

    Hello, 
    I'm doing an application that reproduces the front panel of the HP6675A power supply. To achieve this, I have done a state machine with different states
    (initialize, measures, voltage, current, ocp, ov, store, recall, etc). In each state, should have an event structure that catches the events of the buttons, like for example: if the current state is the Voltage mode and the user press the current button the next state will be the Current mode. For this in each state of the state machine should be the same event structure with the same events.
    My problem is that the Vi doesn't work properly when I have multiple event structures with the same event cases. There are some possibily to do this, and how? Or is impossible to have multiple events? I have been reading some posts, but I don't find solutions. 
    Any help is appreciated.
    Thank you very much.
    Solved!
    Go to Solution.

    natasftw wrote:
    Or as others mentioned, make two parallel loops.  In one loop, have your state machine.  In the other, have just the Event Handler.  Pass the events from the handler to the state machine by way of queues.
    A proper state machine will not need the second loop.  The "Wait For Event" or "Idle" state (whatever you want to call it) is all you really need in order to catch the user button presses.  The setup is almost there.  Maybe add a shift register to keep track of which state to go to in the case of a timeout on the Event Structure.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Who has figured out how to use a print server with LR 2.1?

    Who has figured out how to use a print server with LR 2.1?
    Mac OS 10.4.11, G5 2.3 dual, 8 GB RAM. PS CS 3 Dual monitors
    Print server is Mac G4 dual 533 (audio)
    Epson Pro 9600 and Epson R2400 Both are connect by USB. Could be connected with FW 400.
    I can use a print server with PS However color management does not come through when using a print server and LR. Image prints, but color horrendous.
    All custom .icc profiles are on both the G5 and the print server, G4 dual 533 (audio)

    Hi,
    Based on my research, if we want to filter events based on user name, we need to edit the XML query.
    Please refer to this blog below:
    Advanced XML filtering in the Windows Event Viewer
    http://blogs.technet.com/b/askds/archive/2011/09/26/advanced-xml-filtering-in-the-windows-event-viewer.aspx
    Best Regards,
    Amy

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

  • How to use Protected event CLICK_ROW_COL  of  cl_gui_alv_grid.

    I've  worked with Double_click,Hotspot_click events of Cl_gui_alv grid class quite comfortable as they are Public.
    But i'm unable to work with click_row_col..
    Could u tell me how to use protected event click_row_col..

    Hi Ilayarajaramana 
    Did you try to build up a subclass of cl_gui_alv_grid and access the protected events via the subclass?
    You could e.g. throw an own public event every time the click_row_col event is risen.
    I know this isn't the best way, but it should work.
    Kind Regards,
    Sebastian

Maybe you are looking for