Tips to remember when using Queued State machine

I have been able to work through to convert my State Machine architecture to a QSM thereby eliminating using Local variables/property nodes to send values/data to my State machine but instead sending them through queues.
I would like some tips/advice on making use of them perfectly. Especially, "Not to do" stuff with queues and How to efficiently release a queue etc. What is the convention when using queues? Thanks!
V
I may not be perfect, but I'm all I got!
Solved!
Go to Solution.

VeeJay wrote:
Hmmm!! I jumped the gun... I would have to say, Neither... I guess it isn't really QSM or Queued message handler. My State machine is the generic one. But, data for the SM is obtained from a queue and feedback is sent back from the State machine through a queue. Does that clarify ?
BTW, good to know more variations.. Thanks!
That is a QSM.
I will defer to those that use them regularly.
I would only use such a a construct if the queue was limited to a single entry and prevented inserting multiple states at the front or back of the queue.
As long as the queue is limited to a single entry then a State Transition Diagram could be used to described all of the states.
The multiple entry version can be thought of as a method to implement a "goto" statement in LV. Very useful for those that come from a background working with stacks and pushing and popping off work and those that use them often love them.
But for me let me refer to a letter from Dijkstra quote from here
"GOTO Staements Concidered Harmful" goto statement introduces chaos
Ben
Ben Rayner
I am currently active on.. MainStream Preppers
Rayner's Ridge is under construction

Similar Messages

  • Need help with basic user events in Queued state machine example

    I have written a little queued state machine example to try to teach myself about creating and using user events.  The objective of the machine is to periodically choose a number (I'm doing it now with a control instead of a random number generator for troubleshooting), and compare that number with the number I have set in a control.  When they match, I want to cause an event to fire so I can do something about having found a match.  The examples in the LV Help file references show the events within the event structure, but I want to reach out of a state and cause an event ....
    Can someone point me in the right direction here?
    Thanks
    Hummer1
    Solved!
    Go to Solution.
    Attachments:
    User Event Generator Example01 snip.png ‏102 KB

    Yep....That was it...I had tried to do that but got fouled up with the variant definition...so defined the user event using a boolian and did the same in the case structure where I wanted to create the event and it worked great...
    Thanks.
    Here is the final version...not bulletproof, but does have a queued state machine using a user event to cause an event to fire.
    Hope you find it useful.
    Hummer1
    Attachments:
    User Event Generator Example01.vi ‏45 KB
    Operating States Enum Example01.ctl ‏5 KB

  • Exit of queued state machine

    Hello,
    i have probleme existing an queued state machine vi :
    I can't see how to do to make my vi stop before the wainting time here example is 3s (splitted in 25ms) .
    I
    thinkthere is a probleme flush queued or course competition  something like that
    but i a little new to this kind of codind that i'm a little bit lost.
    here zip file of a minimized programme to isolate part that make me crazy
    For the moment to make it run in a trash mode i put the 25ms wait out of case structure , it works but it means that every case take 25ms
    and is not  good job , because i have something like 20 cases in reality  
    Thank you for help
     Best regards
    Tinnitus
    CLAD / Labview 2011, Win Xp
    Mission d'une semaine- à plusieurs mois laissez moi un MP...
    RP et Midi-pyrénées .Km+++ si possibilité de télétravail
    Kudos always accepted / Les petits clicks jaunes sont toujours appréciés
    Don't forget to valid a good answer / pensez à valider une réponse correcte
    Attachments:
    Ma distribution du code source.zip ‏97 KB

    Well..
    I was not able to get events you have registered with event structures. And also couldnot understand properly because of french texts.
    Anyway, you are facing this problem due to the STTM Q MGR_new.vi in the consumer loop. You are queing more elements in each iteration. This causes your loop to hault untill this vi finishes execution although you have dequed exit case in the end.
    So is it really necessary to have this vi outside the case structure? cant you use this vi to que elements in the producer loop? (loop above?) 
    . Or you can queue required elements inside the case structure of consumer loop.(Place this vi in whichever cases necessary)
    As shown in the figure,  move that vi either inside the case, or you can just que those when the user action takes place in the producer loop.
      I hope i am clear in what i am trying to say. Your lower loop will never stop untill the STTM Q MGR_new.vi stops its execution, so it is necessary to meve as mentioned in the figures
    Attachments:
    Deque.PNG ‏64 KB

  • Simple State Machine Vs Queued State Machine

    Using LV2009 + WIN7+Pentium 4 @ 2.5Ghz with 3 GB RAM.
    I have a machine control code inside a 10mS main loop that has 7 ( yes seven ) Queued State Machines (  QSM) and I find the  Finished Late boolen keeeps poppping often. Not a very good sign if you ask me.
    And the code itself does not have too much of computation or FP activity. But it has four Graphs with one plot on each of them. These are updated once every 10ms. Can slowing this update ( say once every 250ms ? ) help ? 
    A simple query : In terms of performance overhead, does a QSM  demand more than a  Simple State Machine ( SSM ) ? Can I avoid the Finished Late warning by switching over to SSM at least in three of the cases out of the seven ?
    Thanks 
    Raghunathan
    LV2012 to Automate Hydraulic Test rigs.

    I think your question demonstrates my point.  Unfortunately, I don't have a good example to point you to and don't have the time to write one.  I will try to explain better.  Let's take a simple example - a landscape watering controller (sprinkler controller).  This controller will have several states (e.g. initializing, waiting, watering, closing). Each of these states will accept several commands, but not all commands are accepted in all states.  For example, if the system is watering, a command to start watering could be ignored.
    In most programs, at least some states should be interruptible.  For example, if it starts to rain, the watering system should stop watering immediately instead of watering for a set length of time.  However, if the system is in the initialization state, this will probably not be interruptible (but also short).
    As you said, the classic LabVIEW way to implement such a thing is to have a case statement to represent the state, and a case statement (usually queue driven) in each state frame to handle the commands.  You thus have a loop with a double case structure.  This can get somewhat unwieldy for large programs.  Note that which case structure represents what will be determined by the relative number of each item. For example, if you have fifty commands and three states, the state should go into the command case.
    So how do LabVIEW classes help?  They can eliminate one or both levels of these case structures through the use of dynamic dispatch.  This is done as follows.  A parent class is created that is a generic command.  It has commands for each state.  For each actual command, a class is derived from the parent class.  There are VIs in the specific command class for each state.  A command is generated by creating the correct object for the current state, then calling the parent class command.  Dynamic dispatch will execute the code for the correct command.  The command execution loop is then reduced to a single command VI which dynamically dispatches based on the actual command and the current state.
    In practice, things as usually not quite this simple, and you may want different cases for either different commands or different states so that you can change the connector pane of the dynamically dispatched VI as needed.  Look up the LabVIEW examples on dynamic dispatch to see this in action.
    I am afraid I have still not made myself clear.  Keep asking questions and I will try to keep answering.
    This account is no longer active. Contact ShadesOfGray for current posts and information.

  • Double Click Property Node not functioning with Queued State Machine

    I am writing an application which relies on input from the operator to start different steps in a process of steps.  I am using a queued state machine, however I cannot get the Double-Click property of my listbox to function with in this Queued state machine.  I have tried Creating a refrence to the Listbox and creating a property node from that refrence.  I have tried a property node of the control.  The double click functon works only if the queueing is not occuring.  It has something to do with the queue but I am at a loss as to what is causing it.  Any help would be GREATLY appreciated.  I have attached a simplified version of the state machine with the double click function.  Thanks for any help on this.  It is written in LV7.1
    Attachments:
    Test Q.llb ‏55 KB

    Hi
    Its  Simple....
    Your Properrty node is not getting read..... dont understand how..
    see the attachment...
    now laugh at your small mistake... (even i have the habbit of making such small mistakes ;-) )
    Message Edited by Tushar Jambhekar on 01-11-2006 11:38 AM
    Tushar Jambhekar
    [email protected]
    Jambhekar Automation Solutions
    LabVIEW Consultancy, LabVIEW Training
    Rent a LabVIEW Developer, My Blog
    Attachments:
    Test Q.llb ‏55 KB
    Picture.JPG ‏44 KB

  • LabVIEW Queued State Machine as Parellel Process Enabler

    Hi
    LabVIEWs Queued State Machine Architecture is a detailed article on its application for parallel process programming geared to take advantage of LabVIEWs hyperthreading capabilities and multi-core processor PCs of today.
    I am writing future book chapters as blog articles so your critique/comments are appreciated.
    Anthony L.

    I have really enjoyed the articles on ExpressionFlow.  I also like this one, but I think it could use just a little work.  I think that the content is good.  However, about 1/4 of the way down, you have:
    A general layout of QSM-PC architecture comprises of the four objects annotated by the encircled numerals 1 to 4 shown in Figure 1.
    These objects are namely: (1) Queue reference object; (2) User events
    object (optional for head-less embedded applications that require no
    user interaction); (3) Main state machine object; (4) One or more
    parallel processes subVI objects.
    You then go on to have
    Item (1) The Queue Reference
    Item (2) Consumer Object State Machine
    Item (4) Parallel Process SubVIs
    You need to reconcile the two.  I think that a separate (probably earlier??) chapter/article on event structures including dynamic (user) events could be referenced as item 2.
    Thanks for the articles and I hope that this helps!
    Bob Young
    Bob Young - Test Engineer - Lapsed Certified LabVIEW Developer
    DISTek Integration, Inc. - NI Alliance Member
    mailto:[email protected]

  • Queued State Machine, not a state machine?

    I've been reading up a bit on design patterns that seem popular among LabVIEW users, and I have a question with regards to the design pattern described in the following article:
    http://expressionflow.com/2007/10/01/labview-queued-state-machine-architecture/
    I don't see how this is a state machine at all. To me it just looks like a producer/consumer pattern for queuing up actions (what is described in the article as states) to be executed in the consumer loop. I don't see where a state machine comes into play, determining state transitions based on current state and inputs, like shown in the following:
    http://zone.ni.com/devzone/cda/tut/p/id/3024
    Am I completely off?

    Yeah exactly.
    I was thinking a nice way to implement something QSM-like would be to produce instances of a message handler object that maintains its own state and a message queue. You could produce a new object for network I/O that inherits from the general message handler, one for managing the UI, data aquisition etc. They would communicate in a network by passing messages back and forth to their respective queues and each would be a true implementation of a state machine.
    Has to be right up LabVIEW's visual alley
    Edit:
    Now that I come to think of it, this would be almost exactly what could be done compactly with LabVIEW event handlers and user-generated events.

  • How to avoid data repetation when using select statements with innerjoin

    how to avoid data repetation when using select statements with innerjoin.
    thanks in advance,
    satheesh

    you can use a query like this...
      SELECT DISTINCT
             frg~prc_group1                  "Product Group 1
             frg~prc_group2                  "Product Group 2
             frg~prc_group3                  "Product Group 3
             frg~prc_group4                  "Product Group 4
             frg~prc_group5                  "Product Group 5
             prc~product_id                  "Product ID
             txt~short_text                  "Product Description
    UP TO 10 ROWS
    INTO TABLE l_i_data
    FROM
    Joining CRMM_PR_SALESG and
    COMM_PR_FRG_ROD
    crmm_pr_salesg AS frg
    INNER JOIN comm_pr_frg_rod AS prd
    ON frgfrg_guid = prdfragment_guid
    Joining COMM_PRODUCT and
    COMM_PR_FRG_ROD
    INNER JOIN comm_product AS prc
    ON prdproduct_guid = prcproduct_guid
    Joining COMM_PRSHTEXT and
    COMM_PR_FRG_ROD
    INNER JOIN comm_prshtext AS txt
    ON prdproduct_guid = txtproduct_guid
    WHERE frg~prc_group1 IN r_zprc_group1
       AND frg~prc_group2 IN r_zprc_group2
       AND frg~prc_group3 IN r_zprc_group3
       AND frg~prc_group4 IN r_zprc_group4
       AND frg~prc_group5 IN r_zprc_group5.
    reward it it helps
    Edited by: Apan Kumar Motilal on Jun 24, 2008 1:57 PM

  • Queued State Machine skipping states?

    Hi,
    I started out writing my application using a simple state machine but I realized it was necessary to make the application more interactive and prevent the UI from freezing when interupted. For example, I want the user to be able to abort the test by clicking the stop button or a reset button that sends the state machine sequential flow to the reset state.
    I implemented the my QSM by looking at the example in the link below.
    https://decibel.ni.com/content/docs/DOC-14169
    However, the problem now is that the state machine no longer runs sequentially as in my initial simple state machine. Sometimes a state is repeated and at other times a state is skipped. By skipped, I meant it didn't follow the order I tried to implement in my code. I flush the queue before any new user input so I don't know what's causing this behavior in my application.  Has anyone experienced this type of problem before? If so how can it be fixed.
    Thanks

    Hi
    I'm still trying to find a solution to this problem. I was able apply a temporay remedy in an earlier application but in my current application, I'd have to find a permant fix to it.  This problem is described in comment number 4 of the community example code link below. I tried to apply the recommended solution but it didn't work. Perhaps, I was doing it the wrong way. How will the example code be modified to fix the problem described in the comment? I will appreciate any suggestions.  Thanks
    https://decibel.ni.com/content/docs/DOC-14169 
    Comment4
    This pattern has a potential risk of get cycled or get into unwanted states. Let me explain it. When you click on button, an event occurs and typically an element is enqueued to the queue. But in the lower loop another element is enqueued (in this case Report or Process). So when you for example want to go to idle state by clicking on the Stop button, you go to idle state but then you go to report or process state because the element was enqueued behind the idle element as explained above. The solution is to check if the queue is empty before enqueuing the element in the lower loop:
    If the queue is empty, it is safe to enqueue element in lower loop:
    If it is not empty (this occurs when an element is enqueued in the upper loop due to event occurence), the element will not be enqueued:

  • Compiler error when useing switch statements in an inner class

    I have defined several constants in a class and want to use this constans also in an inner class.
    All the constants are defined as private static final int.
    All works fine except when useing the switch statement in the inner class. I get the compiler error ""constant expression required". If I change the definition from private static final to protected static final it works, but why?
    What's the difference?
    Look at an example:
    public class Switchtest
       private static final int AA = 0;     
       protected static final int BB = 1;     
       private static int i = 0;
       public Switchtest()
          i = 0; // <- OK
          switch(i)
             case AA: break; //<- OK, funny no problem
             case BB: break; //<- OK
             default: break;
      private class InnerClass
          public InnerClass()
             i = 0; // <- OK: is accessible
             if (AA == i) // <- OK: AA is seen by the inner class; i  is also accessible
                i = AA + 1;
             switch(i)
                case AA: break; // <- STRANGE?! Fail: Constant expression required
                case BB: break; // <- OK
                default: break;
    }Thank's a lot for an explanation.

    Just a though:
    Maybe some subclass of Switchtest could decalare its own variable AA that is not final, but it can not declare its own BB because it is visible from the superclass. Therefore the compiler can not know for sure that AA is final.

  • Statement closed when using callable statements with oracle xe

    hi all, i've got this problem with oracle express edition 10g. I am using also oc4j v10.1.2.0.2. When working with a normal oracle database it was working fine (i think the code was the same, it's some time since i last tried, but you can see the code is very simple).
    So i just create a callable statement like this:
    CallableStatement cs = con.prepareCall(sentencia.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.HOLD_CURSORS_OVER_COMMIT);
    and then when trying to access the statement to register an out parameter like this
    cs.registerOutParameter(1, parámetros[0].getTipo());
    it gives this error:
    java.sql.SQLException: Statement was closed
    It's puzzling me because, as i said before, i think the same code was working ok with a normal oracle database.
    Any idea what can it be?
    cheers

    Ah okay, sorry I've re-read your post.
    I believe you need to create a clob object that encapsulates your xml file.
    I've never done this but I would image it involves creating a class that implements the clob interface and passing an instantiation of this class to the callablestatement.
    Let me know how you get on.

  • How to get a "blank" answer when using "if" statements in a table

    I'm using a table for an invoice where an item is ordered, but more may be shipped than ordered. I have the formcalc expression figured out where I can get a 0 in the "backordered" column if the amount shipped is more than the item ordered, but I can't get rid of the 0 in the rest of the backordered column when there isn't any information in the "ordered" and "shipped" columns. Trying to get that column to be blank if there is no shipping or ordering information.
    So far this is working for the math part. Not sure how to write a "blank" into the calculation
    Sum(ordered-shipped)
    if (Sum(ordered-shipped)>0)
    then backordered=Sum(ordered-shipped)
    elseif (Sum(ordered-shipped)<0)
    then backordered=0
    endif
    Any advice will be greatly appreciated. Thanks!

    I'm still getting a 0 in all the backordered columns when I'd like them to be empty. The form has more rows than I will be using, so when there is no information in the shipped and ordered row, I'd like the backordered row to be empty/blank. I've tried writing this at the end of my formula
    elseif ordered=null and shipped=null
    then backordered=null(but I really want it to be blank)
    or elseif Table1.Row1.ordered=null and Table1.Row1.shipped=null
    then Table1.Row1.backordered=null
    And yes, backordered is a numeric field.
    Any more advice? Thanks!

  • Got error when use case statement in oracle stored procedure

    Hi,
    I have a query like:
    select merchant_id,
    case
    when product_type='K' then 'Production'
    when product_carrier='UC' THEN 'Shipping'
    end the_type
    from product_tbl
    where merchant_id=10114
    It works fine. But as soon as I put it into a stored procedure, I got error like:
    Encountered the symbol "CASE" when expecting one of the following:
    ( - + mod null <an identifier>
    Please help!

    Oracle 8i doesn't support CASE into PL/SQL, so as Kamal said, create a view with the CASE, and use this view into your PL/SQL.
    Nicolas.
    And an example here :
    Re: Execute Immediate doesnot work in 8i (8.1.7) and Ref Cursor not exec qu
    Sorry Kamal.
    Message was edited by:
    N. Gasparotto

  • Group folders when using Lion server machine as a client

    Hi,
    I want to use the server we use in a small lab as a client as well. Most of the collaborative work is done in a group folder, which works perfectly on all clients.
    However, when I log into the OD on that sever on the server itself (as a OD user) the logon procedure correctly finds that it should mount the group folder.
    However it also sees that the shared folder is a local folder, so it suggests (complains) that I should use the file locally instead.
    This is all wery well, but I have applications where the config items require a path to be specified. This path now differs between computers (server computer v.s. pure clients) which creats a problem for me.
    So, how do I make the server (loop) mount itself as if it was a pure client (and not complain about it)?
    Please help me.
    Fredrik

    Have you try this command ?
    $ sqlplus scott/tiger@scomachine
    -agun-
    null

  • How can I establish an enum typedef for use with state machines and action engines?

    Hey all--
    I have an action engine with several instances.  Any time that I add a method to the engine, I have to modify all of the calling code to update the constant that determines the method being called.  There must be a smarter way to address this problem but my LV experience is insufficient to identify it.  Can any of you wiz-bangs tell me if it is possible to make a type def (I can do this) and use it with each instance of the action engine call so that changing any instance also updates the typedef?
    Thanks.

    Take your enumerator.  If it is not a control (ie constant), change it to a control.
    Under File Menu, select New > Custom Control.
    Move (or copy) your Enum Control to the Custom Control.  Change the Control to Strict Type Def (the selection to the right of the wrench).  Save it.
    (EDIT: ** OOps, the picture shows the wrong one.. sorry**)
    Copy that new Strict Type Def control to your code.
    See images below.
    OR.. If you're using LV8.x, and using a project, I would recomment that you do it from within your project explorer.  Simply insert a new "Control".  The rest of the steps are similar, except that you can insert it from your project. 
    R
    Message Edited by JoeLabView on 07-08-2008 06:47 PM
    Attachments:
    TypeDef.PNG ‏33 KB

Maybe you are looking for