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

Hi,
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.
Mike...
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

Similar Messages

  • Advantages of Using Queued Message Handler vs. Standard State Machine

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

    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

  • Consumer loop very slow, queue size grows. How to speed up my consumer loop? As the array grows the slower it gets.

    LabView version: 2012
    OS: Windows XP SP3
    Hardware: USB NI cDAQ-9174 NI-9221
    Application: Oscilloscope
    I'm relatively new to LabView and I'm currently experiencing some performance issues with my project. I guess it has something to do with the way it's programmed. I'm hoping to get some tips from you guys.
    This is my producer loop. It should be capable of acquiring 100 000 Samples/s. I guess I've done this the right way and can't really be improved. Or am I mistaking?
    This is (part of) my consumer loop. It's too slow, the number of elements in the queue keeps getting bigger. I'm doing two types of calculations on the queue data. One for changing the scalling (a multiplication), one for changing the y-position (a summation). Because each time there are 10 000 samples acquired I have added an extra loop (inner loop). This loop splits the array into x samples when the requested samples are smaller than 10 000 or adds them when the requested samples are bigger than 10 000. This depends on the user input (time/dev).
    For example: when the user request 100 seconds of data to be plotted on a graph we get an array of 10 000 000 x 8. Is this considered big? Enlarging the array to that size is very very slow, the queue builds up rapidly.
    I don't know what really slows it down or how to 'debug' this properly. Transposing the array twice seems avoidable?
    Maybe I'm doing this in an inefficient way? Any thoughts that might help me?
    The VI's are attached.
    Thanks for your input.
    Attachments:
    Scope.zip ‏199 KB

    Thank you for your replies so far!
    LV_Pro,
    I agree it is a bit silly to plot more than 2000 points. I will change this. But even without a graph, the consumer loop seems to be unable to handle the speed.
    tst,
    1. Ok, I will change this
    2. Thank you for pointing this out. I implemented your technique and have some increased performance.
    Still not the speed I would expect from LabView. The system is 'stable' with a sample rate up to 100 Hz, increasing this makes my queue overflow.
    I must be doing something else wrong... Anymore ideas?
    Latest version of program in attachment.
    Attachments:
    Scope 1.zip ‏211 KB

  • 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?
    Thanks!
    Solved!
    Go to Solution.
    Attachments:
    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

  • Stopping producer consumer loop at the same time

    In my application I am using producer consumer architecture. In the producer loop, I am acquiring data, processing and outputting the result (feedback control system). Also in the same producer loop I am inputting all the data to a queue and then in the consumer loop I am writing data to a file. I have a stop control on the front panel and error from the queue and  error from the data acquisition all wired to OR gate to stop the while loop. ( I attached the picture of the code). Whenever I press stop form the front panel program wont completely stop. I think it is because consumer loop still running. Is there way to stop  the both loops at the same time. I tried creating local variable but it slows the program. Front panel stop control mechanical action is set to switch when released.
    Attachments:
    app.PNG ‏262 KB

    In the consumer loop you should check the error after the Read Queue function.
    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!

  • My daq 6008 wil not drop the 5V after the VI is stopped, i have a digital signal going from the error out on the daq in the while loop to the error in on the daq outside the while loop and a boolean going to the data of the daq outside

    my daq 6008 wil not drop the 5V on a digital output after the VI is stopped, i have a digital signal going from the error out on the daq in the while loop to the error in on the daq outside the while loop and a boolean going to the data of the daq outside, but i can t seemto get it to work

    i attached the block diagram so you can have a look
    Attachments:
    PID Temp control.docx ‏120 KB

  • 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 "main.vi" 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!
    BS

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

    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

  • Where to store data (queued message handler)

    Hello,
    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
    MN

    nollMarvin wrote:
    Hello,
    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
    MN
    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. http://forums.ni.com/t5/LabVIEW/Community-Nugget-4-08-2007-Action-Engines/m-p/503801
    And a basic concept to LabVIEW that attending a training session (or asking questions on these forums) will help you master
    Jeff

  • Queued Message Handler Project Template

    Hello,
    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: http://forums.ni.com/t5/Certification/Car-Wash-REV​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 to get the loop sequence time (i) out of the while loop in the sub-vi to the main vi?

    I tried to search for the answer but no much luck.  My situation is that I used a sub-vi containing a while loop in my main vi. Now I need to see the while loop sequence number (i) from that sub-vi in my main vi.  In the sub-vi I have the indicator to show this loop sequence flawlessly, but that's inside the loop itself.  If I use this indicator as a terminal in the sub-vi, I can only see the last sequence number in the main vi after the loop finished its execution.
    Is there a way to accomplish this? Thanks.

    Hi nobody,
    well easiest (but error prone) way is to use globals to move data from subvi to main vi. You can also give the reference of the main vi indicator to the subvi to write to a "value" property node. You can also use queues, and there are other techniques too
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • How to remove the simulation loop from the block diagram

    hi,
    i have used lap view version 8.6 to design pid system. i have the pid block diagram with daq  on simulation loop. now my supervisor want me to remove the simulation loop. anyone know how to remove the simulation loop without deleting the pid block diagram. i have attached my pid program.
    Attachments:
    Copy of LAP VIEW FINAL for engine dyno.vi ‏221 KB

    logaraj wrote:
    hi,
    i have used lap view (  ) version 8.6 to design pid system. i have the pid block diagram with daq  on simulation loop. now my supervisor want me to remove the simulation loop. anyone know how to remove the simulation loop without deleting the pid block diagram. i have attached my pid program.
    You cannot remove the simulation loop alone because all the functions kept inside that loop will work inside that loop only. If you have to remove means then you have to find another way to inplement the PID control.
    The best solution is the one you find it by yourself

  • Removing the master loop from the menu

    I am trying to make a simple template with none of the design elements from the canned templates.
    I cant figure out how to start a new clean one and I cant figure out how to eliminate all of the elements, mainly the
    Bluemaster_loop_NTSCv2.mov (Video)
    thanks.

    The only way to get rid of it is by resetting your phone, you will need to backup first.
    Try the first code but it's more likely to be the second one that gets rid of it.
    Reset to factory defaults (*#7780#) : Restores settings but preserves user data (photos, 3rd party apps etc)
    Reset (*#7370#) : This reformats completely the C: drive. All applications and files stored on this drive will be lost and clean default files will be rewritten.

  • Please help with the FOR loop and the array..

    I was trying to place some words in the Movie Clip
    "TextPanel" and set a
    random position to each of them.
    But it's not working.
    1) I created a Movie Clip "word" and inside that MC I created
    a text field
    and gave it an identifier "textFiled".
    2) The linkage name for Movie Clip "word" I set to "word".
    3) In the actionscript I created an Array called "aWords".
    4) Then I created a FOR loop that should
    place (attach) Movie Clips "word0", "word1", "word2" and
    "word3" to the
    movie clip TextPanel, and set the textField text for each of
    them to the
    text from the Array.
    But the script attaches 4 Movie Clips with a name
    "Undefined", instead of 4
    different names (from the Array).
    What is wrong with this script?
    var aWords:Array = [apple,banana,orange,mango];
    for(i=0;i<aWords.length;i++){
    var v = TextPanel.attachMovie("word","word"+i,i);
    v.textFiled.text = aWords
    v._x = randomNumber(0,Stage.width);
    v._y = randomNumber(0,Stage.height);
    Thanks in advance

    But in my Post I already wrote v.textFiled.text = aWords
    so I don't understand what were you correcting..
    And one more:
    I have tested it by changing the
    v.textFiled.text = aWords; to v.textFiled.text = "some
    word";
    and it's working fine.
    So there is something wrong with the Array element, and I
    don't know why..
    "aniebel" <[email protected]> wrote in
    message
    news:ft2d5k$lld$[email protected]..
    > Change:
    > v.textFiled.text = aWords;
    >
    > to:
    > v.textFiled.text = aWords
    >
    > It needs to know which element inside the array you want
    to place in the
    > textfield (or textfiled) :)
    >
    > If that doesn't work, double check that your instance
    name is correct
    > inside
    > of "word".
    >

  • To count the number of while loops, do you just have to attach a DBL indicator to the little i box in the while loop of the program?

    I have just followed an example in a book to count while loops and was just want to make sure I havent missed something simple. My program is attached
    Solved!
    Go to Solution.
    Attachments:
    second attempt.vi ‏45 KB

    Hi Ssteel,
    Just some additional observations/tips on your code...
    1. I notice that you have a standard stop button going into a "run if true" stop condition of the while loop. In this cercumstance it is common to have the stop condition set as "stop if true". You can change this by right clicking the stop terminal and enabling the "stop if true" property. Obviously, it somewhat depends on your design preferences.
    2. If you have any issues with the application, perhaps you notice that it is taking over your processor resources, you should add some execution timing into the while loop. You will find the timing functions in the block diagrams functions palette (programming > timing). The Wait (or "wait until next ms") functions will provide your application with "down time", which means that the processor can execute other tasks.
    3. To elaborate what MikeS81 correctly stated, insert an incriment before the numeric indicator as shown below to get the actual number of cycles (i.e. the count terminal of the "while" and "for" loops are 0 indexed). Also note that I have changed the representation of the count to interger (blue). You do not need floating point precion when displaying the inciment count, at a while loop can only execute a "whole number" of times.
    I hope this has been useful to you Ssteel.
    Thanks for your post,
    Rich R
    Applications Engineer
    National Instruments UK & Ireland

Maybe you are looking for

  • Attachments from ECC PO to SRM 7.0

    Hi All We are attaching some URLs in the Purchase Order through Services for Object(Top left Hand Corner) and these attachments are not being created in the SUS system when the Purchase Order is created in SRM 7.0 system through an XML message. We ha

  • Can't add hyperlinks to PDF in Preview?

    Why doesn't Preview in Mountain Lion support hyperlinks. I received a PDF with hyperlinks that work when opened in Adobe Reader, but when opened in Preview the links don't work. There also doesn't seem to be a way to add links to a PDF in Preview. Am

  • Weird happenings on data loss and backup

    Re Q10 At work my blackberry files somehow were synced to my computer even though I never intended them to be.  I deleted my blackberry files off my computer.  A few hours later I was missing a lot of pictures and music files.  Some pictures and musi

  • [SOLVED]problems with syslog-ng after recent update

    system i686 fully updatet today. package version: syslog-ng 3.0.4-3 roor when running logrotate: error: syslog-ng:1 duplicate log entry for /var/log/crond.log                  error: found error in /var/log/messages.log /var/log/auth.log /var/log/mai

  • An error occurred verifying the host credentials

    Hi, I'd like to reorganize a segment in grid control 10g. I go through the reorganize wizard smoothly from the Type, Objects, Options and Impact report. But when I reach the Schedule step, I was asked to enter the host credentials. Though the user I