10-21-2017 09:16 AM
Hello Community,
after some research in different posts here with seemingly similar but as it turns out different problems, I find myself at a point where I can´t find a solution to the following Problem, so I hope for help from the community:
I am playing around with the queued message handler to get used to it´s possibilities for later implementation.
In my current program (see attached) I am simulating a possible error with a boolean switch during the initialisation of devices.
Apart from the occurance of an error, the program acts as espected (boolean switch = false) - the slave loop changes cases as the master commands and also stopping the program by clicking the stop button is no problem.
BUT: If the boolean switch says true (before starting the program), the program does not stop.
With the higlight executiion I could identify the master loop as the reason, which is waiting in the idle case for an event to happen wihtout changing to the stop case.
Why is that and how can I realize the program stop after an initialisation error? - the event structure is needed though, because of possible additional actions independent of the slave loop.
Two Versions of my program: for LV16 and for LV10...hope everyone interested to help can open it.
Solved! Go to Solution.
10-21-2017 10:42 AM
The event structure starts waiting for a value signaling when it's executed. So that is after the queue element is received. You can change that with a dynamic event registration if you really want to (events are registered when registering the dynamic event). But I thing you're making things too complicated with two queues. You try to make a (producer\consumer)\(consumer\producer) construction. Both loops are producer and consumer. That's asking for deadlocks and\or livelocks. I thing you want to change the slave queue to a state, not a queue. Maybe a channel wire, set to 'tag' with an enum type def? I'd recommend an enum type def as queue data type as well. Strings are painful when you need to change them.
10-21-2017 12:52 PM
Please forgive me for wearing my Professor Hat, but every once in a while, there is Another Chance to Teach. So I'm attaching my version of your Program, with lots of (minor) modifications, that I'll try to explain. Note that this does not invalidate Wiebe's response -- I agree that a Dynamic Event is the "better" way to get certain kinds of data "injected" into an Event Loop, but I'm going to try to stick with simple Value Changed and Timeout Events.
The first thing is to realize that this is basically a Producer/Consumer design, with the "Master" (top) loop generating most of the "Messages" and the "Slave" (lower) loop both "consuming" and, in some instances, also "generating" them. I confess that it wasn't until I started modifying your code that the "Aha!" light went on in my head -- I realized that at least part of the problem you had was the old "Stopping" Problem of how to get the Producer to stop when the Consumer encounters an Error. This is often a slightly tricky problem, and the solution can look a little messy, but I hope to show you it's not too bad.
So let's dive in. I'm going to put a Snippet here for reference, but will also attach the VI (2016) for you to really examine and test.
Whew. Hope that all makes sense and you find it useful.
Bob Schor
10-21-2017 03:07 PM
One thing Bob said can't be stressed enough. Do not name queues unless you have to. Naming queues has it's usefulness: when other threads need access to the queue. Therein lies the problem. You naming the queue tells others the queue is potentially accesses somewhere else. Also, other queues (in code made by others) might use the same name but be completely unrelated. Some use the vi name as queue name. This can cause the most obscure bugs... Don't name queues if you don't need to.
Also, give the data type of the queue a label and the context help will show that label. Useful when debugging if you have lots of queues.
10-22-2017 05:56 AM - edited 10-22-2017 05:58 AM
Hey Bob,
thanks for your remarks so far.
The program you attached contained no changes.
I would like to work through your remarks along with your version of my program so it is easier for me to understand.
Could you upload the changed version?
Regards
10-22-2017 06:16 AM - edited 10-22-2017 06:16 AM
Hey wiebe,
I am not familliar with dynamic events but after reading the LabVIEW Help on this topic, I am wondering if it is possible to have the slave loop create the value change event for the media stop button,
Wiebe and/or Bob do you have an idea?
I am really thankfull for every helpfull advice.
Please waer all your "Professor hats". 🙂
Regards
10-22-2017 09:13 AM - edited 10-22-2017 09:14 AM
That's very odd! I checked the file of that name on my PC, and it was, indeed, the file I showed in the Snippet. But when I downloaded it, myself, it was your original file. Weird. I'm going to try again ...
Bob Schor
10-22-2017 09:17 AM
I just checked -- this time it is the right file.
Incidentally, do you know how to use Snippets (the "picture" in my earlier post)? Open a blank VI, go to its Block Diagram, and drag the picture into it. It should "automagically" transform into the LabVIEW VI that was used to create it. This is a feature NI introduced a few years ago, and can be found on the Edit menu (Create VI Snippet from Selection).
BS
10-22-2017 10:37 AM - edited 10-22-2017 10:38 AM
Bob,
after understanding what you have done in your version of my program, I got it working!
There are many (little) things I did not know so far so I learned a lot through your help.
For example I now used the Value (Signaling) Property Node for the first time, which was exactly what I needed.
Furthermore I was (again) reminded to keep things simple...just one Queue named only when needed with no state machine in the master loop.
Also thanks to wiebe for giving me a push into the direction of dynamic events...the example vi from NI where you can drag a picture is pretty nice.
I attached the working version so maybe people with a similar problem can have a look.
Regards