[LATER EDIT] Thanks to mje who posted a fully correct solution with all the comments from this thread. You can find the correct solution here.
Posted 30 September 2011 - 09:40 PM
Posted 01 October 2011 - 01:26 AM
Posted 01 October 2011 - 02:22 PM
Posted 01 October 2011 - 05:14 PM
Uhh... straighten out your error wire? (j/kAnyone have any improvements to suggest?
Hasn't NI deprecated occurrences in favor of notifiers?Hmm... My first inclination would be to use an occurrence instead, but that doesn't change the functionality. Tim
Certified LabVIEW Architect
Dak's First Law of Problem Solving: If the solution looks simple, I don't know enough about the problem.
Yes, the QSM is flexible. So is Jello. That doesn't make it good construction material.
There are two secrets to success:
Secret #1 - Never tell everything you know.
Posted 01 October 2011 - 05:22 PM
I hadn't heard that, and would actually find it surprising. Though I haven't used them very many times, I go to occurrences first when I need really simple signalling. DAQ uses them too, doesn't it?Hasn't NI deprecated occurrences in favor of notifiers?
Posted 01 October 2011 - 06:37 PM
One could make two subVI's, "Open FP after delay" that outputs the notifier, and "Close FP" that inputs the notifier (as well as the error out of the rest of the code). Then it would be easy to add to any VI and be quite clear. Internals of the two VIs would need to be more complex, with an async call of a third subVI with the actual wait on notification, and some method of making sure "Open..." is finished before "Close..." actually closes the front panel.Also, rather than the fill-in-the-blank approach, I would have the VI accept a VI reference and use a blocking Run call. It would force you to make all of the potentially-slow code a subVI, but that may not really be a bad thing. On second thought, though, if the potentially-slow code needed any local data (or returned anything), it would take a more work to pull that off.
Posted 01 October 2011 - 06:45 PM
FYI... from LV2009 help, Generate Occurrence Function:I hadn't heard that, and would actually find it surprising.
Certified LabVIEW Architect
Dak's First Law of Problem Solving: If the solution looks simple, I don't know enough about the problem.
Yes, the QSM is flexible. So is Jello. That doesn't make it good construction material.
There are two secrets to success:
Secret #1 - Never tell everything you know.
Posted 01 October 2011 - 08:10 PM
FYI... from LV2009 help, Generate Occurrence Function:
Note National Instruments encourages you to use the Notifier Operations functions in place of occurrences for most operations.
Whether or not that means they deprecated occurrences is subject to interpretation I guess.
Posted 01 October 2011 - 10:38 PM
Posted 03 October 2011 - 04:35 AM
Yeah, that should be added since he's probably calling this as a subVI repeatedly.I'd probably throw in a release primitive in there for good practice, but otherwise all good I'd say.
Posted 03 October 2011 - 05:04 PM
It is very hard for most folks I've worked with to understand how and why occurrences work. The Notifier wrapper (it uses occurrences under the hood, as does all sleep/wake behavior of LV) generally makes things clearer.
Posted 07 October 2011 - 03:11 PM
Rolf Kalbermatter
CIT Engineering Netherlands
A division of Test & Measurement Solutions
Posted 07 October 2011 - 08:38 PM
Posted 07 October 2011 - 08:59 PM
That won't work.I had a conversation with our chief architect whose been working on LV since version 0.1 and who created the occurrences long long ago. Here is THE correct way to use occurrences:
First build a system which polls busily for whatever it is the occurrence will signal. You need to be able to determine the state of things without an occurrence. This creates a correct, but inefficient busy waiting implementation. Once that works, add an occurrence to alleviate the inefficient waiting. Do not remove the actual polling. In other words, use the occurrence only to indicate that "it is probably a good time to check on that thing...".
In other words, start with this:![]()
and then go to this:![]()
As I understand it, occurrences don't have thread safety on their state because they are the building blocks by which thread safety for state in higher level APIs is built.
Posted 07 October 2011 - 11:14 PM
Care to elaborate? (I've never used occurences and I'm finding it a bit confusing.)That won't work.
Certified LabVIEW Architect
Dak's First Law of Problem Solving: If the solution looks simple, I don't know enough about the problem.
Yes, the QSM is flexible. So is Jello. That doesn't make it good construction material.
There are two secrets to success:
Secret #1 - Never tell everything you know.
Posted 08 October 2011 - 12:56 AM
Care to elaborate? (I've never used occurences and I'm finding it a bit confusing.)
Posted 08 October 2011 - 01:43 AM
Because the local variable will be evaluated well before the first loop reaches the large number and will present a FALSE to the stop terminal. Everything (in the second loop) then waits for the occurance. Once Loop 1 actually fires; loop 2 then proceeds with the FALSE, goes around again and then waits, once more, on the occurance-which never arrives since the first loop has already terminated.Care to elaborate? (I've never used occurences and I'm finding it a bit confusing.)
Edited by ShaunR, 08 October 2011 - 01:45 AM.
Posted 08 October 2011 - 02:58 AM
Posted 08 October 2011 - 03:12 AM
I stand correct4ed (when did they add that then?)Occurrences do have a timeout.
IMHO this is how the other primitives should behave (and that includes diagram, project and control refs). I've lost count of the number of times I have had to correct others' code because the refs aren't closed. It is these primitives that are counter and intuitive rather than the occurrence. Oh for the days when Labview meant you didn't have to worry about memory leaks.The main reason occurrences behave differently than the other sync objects is because occurrence refnums are static. The refnum is created when the VI that contains the Generate Occurence function is loaded, not when it is executed. That means that a VI which is reused, say in a loop, the Generate primitive will return the same occurrence on each invocation. This is often counter-intuitive to those that don't understand the mechanics of how occurrences are created and can lead to some serious bugs due to previous values being in the occurrence.
Seems to me that they work similarly to a notifier (since they have a timeout) without the pit-fall of memory leaks.The fact that they're created on load is also the reason there is no need for a destroy primitive. Memory leaks don't happen because repeated calls to Generate Occurrence in the same VI always return a reference to the same instance.
The behavior is very useful if the primitive behaviors are understood though. They just work completely different from all the other synchronization primitives.
Edited by ShaunR, 08 October 2011 - 03:30 AM.