Advantages of Using Queued Message Handler vs. Standard State Machine

What are the advantages of using a Queued Message Handler?  Also, why are they more powerful than using Standard State Machines?

They are really just sort of an extension of a state machine.  The general idea is that you have one loop doing a specific job.  You then use a queue to tell it how/when to do this job.  For instance, I might have a log file loop.  I will send it commands to open a file, write some data, write some more data, and finally close the file.  Each of those commands are coming from the queue.  The beauty with this setup is that anybody that can get a reference to that queue can send the command to that loop.
So the QMH is "better" than a state machine mostly because of the decoupling of functions.  In a given application, I will have a loop for log file writing, GUI updates, reading of a DAQ, instrumenet communications, server communications, etc.  Trying to do all of that in a single loop state machine is a major pain in the rear end.  Seperating them out makes life so much easier.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines

Similar Messages

  • Where to store data (queued message handler)

    i'm developing an image processing application. As a template i'm using the 'queued message handler'. In my app I need to store some images, arrays, and so on in RAM. Now the question is  if i should store that data in the message loop's shift register (in a cluster) or somewhere else.
    At the moment i have hidden front panel indicators where i store all my data. This isn't good practise, is it?
    thanks alot

    nollMarvin wrote:
    i'm developing an image processing application. As a template i'm using the 'queued message handler'. In my app I need to store some images, arrays, and so on in RAM. Now the question is  if i should store that data in the message loop's shift register (in a cluster) or somewhere else.
    At the moment i have hidden front panel indicators where i store all my data. This isn't good practise, is it?
    thanks alot
    No that is not good practice.
    A Shift register is a much better place to store data in memory it does that without creating copies the OS must interperate for display.  (Yeah the displaying of data to a user is a different concept than having data in memory) Ben's famous Action Engine Nugget is always a good read.
    And a basic concept to LabVIEW that attending a training session (or asking questions on these forums) will help you master

  • I need tips about queued message handler

    Hello, I have to use, for the first time a queued message handler. I'd like to know what is the best way to share data between cases in a loop and from a loop to another, I think with local variables  isn't  the best way...
    However all the tips on the queued message handler are welcome!!!

    smilegv wrote:
    I'd like to know what is the best way to share data between cases in a loop
    Shift registers.  Doesn't matter if QMH, State Machine, Producer-Consumer, etc.
    smilegv wrote:
    I'd like to know what is the best way to share data ...from a loop to another
    Well, now that completely depends on what you are passing around.  Streaming data?  Use a Queue or User Event.  Last known value (ie Tag)?  Global Variables, Action Engine.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Queued Message Handler Project Template

    Currently prepping for CLD exam.
    I was told we could use LV 2012 Professional Version.  Is it OK during exam to use Project template for Queued Message Handler to generate VIs and block diagram code?  Or must a QMH be generated from scratch?  
    I assume there will be a main VI which we must modify, but the thought was to reuse the generated template code into this VI.
    Thank you,

    You can use templates, examples etc that ships with LabVIEW. I am sure I read this somewhere, will post a link if I find it.
    Here is one tip offered by one of the experts:​IEW/m-p/2267688#M540
    Beginner? Try LabVIEW Basics
    Sharing bits of code? Try Snippets or LAVA Code Capture Tool
    Have you tried Quick Drop?, Visit QD Community.

  • How best to decouple the UI in the LV 2012 Queued Message Handler Template?

    If you create a new "Queued Message Handler" from the new LV 2012 Template, you'll see a blue box in the "Update Display" case which says the following:
    Code Recommended - If you wish to decouple the Message Handling Loop from your user interface, consider creating User Events (like the "Stop" event in this VI) to message the Event Handling Loop whenever the user interface needs updating.
    I'd like to give this suggestion a shot but I'm struggling to find the best way to do this and still keep the code modular.  The template creates a "User Event - Stop.lvlib" with Create/Destroy/Fire SubVI's.  I would like to create a similar "User Event - Update UI.lvlib" library with similar Create/Destroy/Fire SubVI's to keep this new user event separate and modular.  The problem I'm hitting is that there can only be one Dynamic Event Terminal in the Event Structure so how do I modularlize creating user events into separate SubVIs and still maintain this one Dynamic Event Terminal?
    As a follow on question, would it be best to have one user event library per indicator that needs updating or just one single UI update user event and then pass a cluster as the message which contains the name of the control to update (to be used with a case structure) and then the data to go along with it?
    Go to Solution.
    CLD.png ‏10 KB

    Instead of having the Register Events in the "Create Methods" you could do that part outside your "create" SubVIs and then simply bundle them. Then you create your individual User Event handling. See snippet where i created a "Create User Event - Update" vi in front of the Stop.
    “A child of five could understand this. Send someone to fetch a child of five.”
    ― Groucho Marx

  • How to access SOAP header without using SOAP message handler

    I have a requirement to retrieve SOAP header information within each web services operation. So I can't use SOAP message handler. Is there any way to do that? BTW, I am not using workshop.

    Howeve how can I put data into soap header in UDF? DynamicConfiguration won't work for soap header, right?
    Which data do you want ot put into the Header section.
    ASMA or Dynamic Configuration is used to read/ put the details from/ into the header elements.....
    From the help section:
    This information is not located in the payload of the message, but in additional message header fields.

  • Saving string array in Standard State Machine.

    I use a Standard State Machine to control a laser unit with multiple lasers. When I give the unit a command, it gives me much information back. When LabVIEW is reading this information, it is putting it in a string array.
    But the program shows only the information in the array when I enable 'Highlight Execution'.  What do I have to do to solve this problem?
    Thanks for all commands,
    StandardStateMachine ‏26 KB
    statemachine.ctl ‏5 KB

    Does your device use a termination charcter at the end of each transmission?  You are already set up to use 0xA as a termination character (default on the Configure Serial Port).  If so, do not do the big mess with the checking of bytes at port and what not.  Just use a VISA Read with a very large number for the bytes to read.  The read will complete when that termination character is reached.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Build applicatio​n based on queue message handler template

    I programmed an application, using QMH template in LV and made a build out of it. The build has the "" and it is always included. But, after build is complete, the application starts by clicking on my apllication.exe and immediately terminate itself !!!! any idea about why? (I have one global function ("exit" which set to false at initialize state of the application" and shared variables, but both seem not the items to be blamed !!

    I recently (about two years ago) started using the QMH fairly heavily, "re-inventing" my usage of it several times (that means taking a LabVIEW Real-Time project of several hundred VIs and almost "starting over").  I've attached a Demo Snippet to illustrate some Lessons Learned.
         First, an admission -- see all of those Queue wires?  I've gotten rid of most of them by using a Queue Action Engine that handles all of the Queue actions except Dequeue.  In place of the Obtain Queue, Enqueue, and Release Queue calls, I have a Message Queue VI that takes an Enum (Obtain, Enqueue, or Release) and (optional) inputs (such as the Element to Enqueue).  The only Queue wire in my diagram is the one from the call to Enqueue Initialize to the (necessary) Dequeue Element (but I don't need the Queue wire coming out of Dequeue Element as I use my VI instead of Release Queue).  Not only don't I need a Queue wire going into the parallel Event Handling loop, but I don't need a wire going into a sub-VI that needs to "send a Message", which makes spawning asynchronous parallel loops easy.
         You'll notice my Messages are Strings, not an Enum.  I'm a little conflicted here -- I like the "error-checking" feature of Enums, but especially when designing, it is so much easier to say "Hey, I need another State here to do this" and simply name it and add it.
         The Event Handling Loop, for the most part, should do nothing except generate a message, passing the Event New Value (if needed) as the Data part of the message.  In particular, the Exit message is just another Message -- it doesn't need to be "filtered out" for special handling.
         To stop all of the loops, I use a Local Shared Variable (you could use a Global or FGV/VIG as well) -- the TimeOut case in the Event Handling Loop wires this variable to the loop Stop, and as you can see, the Exit message sets it;
         You may notice the 500 msec timeout on the Dequeue -- this allows you to catch cases where no messages come in.  Here I "do nothing".  But you'll notice that this makes my Stop code work.  The User pushes Stop, generates an Event, calls the Stop Message, sets the Stop Shared Variable to True, but that (probably) does not stop the lower loop, as the earlier False value was probably read and "connected" to the Stop indicator when the loop was entered.  200 msec later, the Event Timeout fires, sees the Stop Shared Variable = True, and stops the Event loop.  After another 300 msec, the Dequeue times out, enters the True Case and does nothing, but now the Shared Variable is True and the lower loop stops.
         You are correct that if you want to do repetitive things with this model, you need to repeatedly call the State you want to run.  It depends how much of your code you want to put into a single QMH -- it might be just as simple to have yet another parallel loop do the same thing every 100 msec, and use the State Machine to handle the User Interface (I've done it both ways, depending on circumstances).
         Have fun!

  • 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:
    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
    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, which is just a loop displays the count*2 (number of seconds passed since running) that will call and then check to see if the stop button is pressed. is by no means a state engine, it is just a simple loop for demonstration purposes. 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 is being executed, it will terminate immediately when the stop button is pressed.
    Hope this helps.
    Attachments: ‏17 KB ‏33 KB

  • Any penalty to using one big cluster in a state machine?

    I've been working on a lot of small/medium sized state machines lately, and I've gotten into a habit of putting most of my data (single values, arrays, strings, even LVOOP objects) in one cluster that I pass from state to state with a shift register.  I just unbundle the data I need in each state, work on it, and bundle it back in for the next state.  Part of me says that this is a bad idea - that I should separate the big cluster into a set of smaller clusters that group the data by logical categories.  Another part of me says that if I do it that way, I'm just creating needless clutter on my diagram.
    So my question is simply this - is there any significant performance penalty for using a single cluster rather than multiple clusters in this fashion?  I never run the whole cluster into subVIs, and I never split the main cluster wire, so it doesn't seem like there should be... but I've been wrong before!

    As Norbert mentioned, the answer to your Q is dependant on your data structure. Provided you can do all of your data manipulation "in-place" there should not be any issues. The more complex structures can still be handled "in-place" but you may have to use the in-place operations to achieve this effect. Depending how comfortable you are with those operators, they can complicate the appearence of our code.
    If you can'y do everything "in-plcae" and you have a Super-Cluster, then its time for me to Quote Rolf again when he wrote "Once all of you physical memory is filled up with a single cluster, your application is probably going to suck."
    So lest say you have cleared all of the above hurdles and still want to use a single SR that has all data for all states. I ask you to carefull examine where the app may go in the future and what type of animal it could turn into. if there is even a small chance that app may turn into something that non-computer users will use (requires robust app to prtect itself from dumb users) the single cluster approach is going to get in your way when the app gets big.
    1) If you have to add another field to the cluster, every function that uses that cluster should be re-tested. WE have an app in-house that was developed by our customer and we support. There is an 800+ step proceedure required to re-verify the app!
    2) AS more functionality is added you will add more states to your state machine. Personally, I cringe when I see the support developer have to choose from a list of 300 states when working with the Stae machine.
    3) You will have a hard time re-using code aside from cutting-n-pasting
    4) When you unbundle manipulate and replace, you are in danger of creating duplicate data which will impact performance.
    I never went through the formal IS training but my wife did and she has given me the short version to learn how to normalize a DB. There is actually a science to the process that results in only related items being grouped together and if you take to the full exdtreme of "fully Normalized DB", there absolutely no duplicates of data. For LV apps a Fully Normalized DB adds some overhead so I don't go that far.
    THe following will ignore using an Object Oriented approach and stick with old-school ideas.
    So after I analyze my data structures and group related items together and review who touches what when, THEN I try to wrap-up the data in Action Engines. More often than not, the action will replace some or most of the work done in some states. From your Q it sounds like your "read-mod-replace" constructs can be moved into AEs with little effort.
    Now for OOP
    I'm still learning OO system design but I have found myself "turning my apps inside out" with LVOOP. By this I mean rather than think that the data AND the function are inside the AE, the data is outside and acted on by what is inside the LVOOP methods. I have been amazed at the degree to which LVOOP can operate in-place, but I digress. There is some arguement/design pattern that says that if you have a function like a test that uses other classes, then you can create a class for the test and slam all of the required object into you need.
    Done rambling for now. As usual, if there is anyone out there that want to correct me any of the above, please do so!
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Using "don't care" in digital state machine?

    I am trying to use the digital state machine component and received some advice from tech support about how to properly make a state.txt file.  However, the simulation of the state machine freezes when a "don't care" condition is encountered for any of the inputs.  Here is what my state.txt looks like: 
    I'm assuming that an "x" represents a "don't care".
    Any advice, comments, etc.  Would be greatly appreciated.
    state-x.txt ‏1 KB

    The digital state machine is a XSPICE model and the 'don't care' condition is not supported by the XSPICE model engine.
    Tien P.
    National Instruments

  • How to treat error handling in the consumer loop in the queue message handler structure?

    I'd like to know how to stop the producer loop(event loop) in the QMH structure when the error happened in the consumer loop.
    I've construct a demo code by myself as the attached image, but it's a pity that I have to create a recdundant indicator "End" to trigger the value change event to stop the program. This is not a good way to do it. Could someone give me some better idea how to deal with it? Very appreciated to you sharing ideas.

    Concerning your doubts about the "traditional" implementation of this pattern, I hear you. As I have written many times before, its main benefit is that it is easy to explain in a training class. It unfortunately has a lot of drawbacks.
    Tim's suggestion about User Events, is a good one. But to use it to the best advantage, you will need to get away from having everything on one block diagram. If you think about it there is no real need for the two loops to be on the same block diagram and a lot of really good reasons for them not to be. For example, if they are in separate VIs, they can both be event driven and any communication problems between loops evaporates.
    Its also more modular, easier to maintain, more reusable, etc...
    Check the link in my signature.
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Use single message with multiple spry "states"

    forgotten past decided to use spry widgets to do the validation. One of the things that can get old pretty quick is to have to create a different message for each thing that can go wrong, even if you need to display the same message. For example, if a user needs to enter 9 digits, the message for entering too few, too many, and letters can pretty much be handled by "The value should be exactly 9 digits."
    Is there a way to use just one div/span and have it show for all of these conditions? I need to be able to code this manually, because for whatever reason the widgets don't show up properly in the DW UI (either because it's an old version or because the widgets have been edited by hand at some point in a way that's incompatible with the DW UI). It also needs to be compatible with older browsers (i.e. I could probably do this by assigning multiple classes to the element(s), but I am not sure what browsers would support this). Many of our users are in libraries, so we have to anticipate that the browser may not be up-to-date.

    Don't use Spry.  Adobe abandoned the framework in 2012.  It is no longer supported.
    Best advice, use HTML5 forms alone or with jQuery validation.  In the following example, the number field requires 9 characters.  This works in modern browsers.
    <form id="MyForm">
    <label for="number">Number:</label>
    <input name="number" type="number"  id="number" placeholder="123456789" maxlength="9" minlength="9" required>
    <input id="submit" name="submit" type="submit" value="SEND">
    For older browsers that don't support HTML5 forms, you can add jQuery validation to your forms by adding this to your document's <head> tag.
    <script src="">
    <script src="">
    $(document).ready(function() {
    Nancy O.

  • 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!
    I may not be perfect, but I'm all I got!
    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 Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Tool Pallete - Advanced - Message Handling Script/Script

    We have few clarifications in OEDQ.
    Tool Pallete -> Advanced -> Message Handling Script/Script:
    we can write Java Script to define processing logic that acts across all the records in a message, or that acts selectively on only the first record in the message.
    I tried writing Java Script for Data Validation and to display the message.
    Java Code:
    Public static void main(String[] args)
    int EMPNO;
    if(EMPNO = "123456")
    system.out.println("Invalid EMPNO");
    system.out.println("Valid EMPNO");
    When we try to run the processor, We are getting the below error.
    "error during process preparation
    error in script: Error compiling Script: Missing ; before statement"
    We are not getting error when we try to write a C program for the Message Handling Script.
    C program:
    var res=' '
    var res1=' '
    var res2=' '
    res='Valid Country Code';
    else if (input1=='UK')
    res1='Valid Country Code';
    res2='InValid Country Code';
    Could you please let us know whether Java code can be used in Message handling script and can we have the header "Public static void main(String[] args)" in the script.
    Thanks for your time.

    See the OEDQ online help here
    Search for "Script" and "Message Handling Script"
    You can use JavaScript or Groovy but NOT Java. Also the script needs to adhere to certain interfaces to allow it to be called by EDQ. See the examples provided.

Maybe you are looking for