02-25-2015 02:40 PM
Hello,
I am willing to learn good LV practices from the more experianced ones. Therefore I am asking about how you handle the following scenario. I often use a kind of queued msg design pattern with dynamic user events and queues to handle comm between loops. I do it similarly as for example in the "cont. logging and acquisition (daqmx)" design template. Last year i got the info from NI that they will create documentation in the close future, however as much as i know it is not done yet. I have a kind of feeling about that design it is somehow "patched", i do not find it elegant how the possible race conditions are eliminated in the msg handling loop (for example to avoid double hw init, etc.).
How do you solve these issues in your applications? For example nowadays i tend to use AEs which contains some state memory to avoid double init or close operations. Or it can also avoid the possible problem if there is still one more read HW state in the queue after closing reference (the AE ignores read request if the hw is already closed). Do you think it is a good practice to protect AEs in this internal way, instead of checking state status in the main vi? I find the above design template difficult to read with the nested enum checks in the gui msg handler loop. Are there better ways/ templates to use for such tasks?
Thanks for any idea and thoughts!
02-25-2015 03:00 PM - edited 02-25-2015 03:05 PM
I'm not finding that example. Can you either link it, or throw together a mockup vi showing what you mean?
Edit: Scratch that. It is a project template, not an example.
02-25-2015 03:08 PM - edited 02-25-2015 03:10 PM
Continuous Measurement and Logging (NI-DAQmx) Documentation.html
Yes, sorry this is a project not a template.
02-25-2015 03:34 PM - edited 02-25-2015 03:35 PM
Yea, sorry - I finally found it. The version in 2014 looks a little bit different though. Perhaps NI finally updated it.
I'm going to preface this with: I'm not exactly an expert. I have been working on learning design practices as well and this messague caught my attention.
OK, so looking at it, I'm not sure how you would run in to "race conditions". The "UI Message Loop" and "Data Display Loop" are purely queue driven - which by definition can't have race conditions.
That having been said, I don't like this architecture for several reasons.
My method to do something very similar was as follows:
Anyway, again: not an expert. Just my comments.
Edit: A word.
02-25-2015 03:41 PM
hm, tomorrow i will have a look on the LV2014 version too.
02-25-2015 04:07 PM
@Blokk wrote:
hm, tomorrow i will have a look on the LV2014 version too.
Don't bother. I didn't have the "DaqMX" version open. The two are almost identical.
I also didnt look at the project close enough. They actually do acquisition and data logging in their own separate loops, so one of my comments is null. They also went out of their way to not stop those loops with just queue destroy, but instead put logic in to make sure all of the data was collected.
02-25-2015 05:15 PM
02-25-2015 09:22 PM - last edited on 04-05-2024 01:37 PM by Content Cleaner
One of the reasons the standard QMH is the standard QMH is that it lets you talk to it from anywhere. If you take a a look at some of the RT sample projects you'll notice the same exact pattern over and over again because you can have your main loop sent messages from a UI thread, from the network, or from any random process running in your code. Thats the advantage. A good example of this would be the RT sample projects or this cRIO vibration logger (https://forums.ni.com/t5/Example-Code/Embedded-High-Speed-Data-Logger-Reference-Design/ta-p/3996474)... Also, in most applications I've worked on the QMH typically acts as the supervisor for the system but doesn't have a ton of the logic.
On the flip side there are many situations where you don't really need that flexibility, and its better to just use one event loop with some worker threads, or use user events to send type-safe data between processes.
You might also take a look at TLB prime which is a different kind of state machine template which distinguishes carefully between the state machine conceps and the QMH concept. I tend to think its overkill but then I primarily work on cRIO-type-applictions while the developer (Norm) tends to work on more complex front end applications. Worth a look, anyway.
02-26-2015 02:31 AM
"or use user events to send type-safe data between processes."
But for that, we need an Event structure in the separate process in order to receive Dynamic user events from the MAIN vi, yes?
thanks for all for the comments and ideas, I will also have a look on the LAVA template...
Best Regards,
02-26-2015 03:33 AM - last edited on 04-05-2024 01:38 PM by Content Cleaner
Personally I recommend the JK I "State Machine" as a great design of a queued event handler, adding User Events to carry messages. I am not a fan of the NI sample project for multiple reasons. In fact, I redid "Continuous Measurement and Logging" (2012 version) as an alternate sample project available after one installs my "Messenger Library" (it will be available as "Messenging: Continuous Measurement and Logging" if you install "Messenger Library").