09-04-2015 07:38 PM - edited 09-04-2015 07:41 PM
Hello,
I have been writing my first more "involved" application which will be taking data and controlling some arbitrary number of instruments; my code uses asynchronously called queued message handler-type VIs and VI Templates to allow for easy reconfiguration before and during runtime. These are dynamically loaded into the front panel of the main VI upon selection, and all control of these VIs happens from that subpanel.
I use event structures and user events to handle front panel events and other data passing within each of these VI, and I am extremely confused about some of the behavior that my event loops are exhibiting.
For example, in some instances a user event generated to stop an event loop will fail to trigger any reaction from said event structure, which would continue to time out. This behavior occurred irregularly, and sometimes my loop terminated fine, which led me to believe that there was a race conditions somewhere in my code. This problem was fixed in each of the culprit VIs by placing the event registration for the user event inside the same initialization subVI which created the event refnum. However, I still have no idea why this fixed the problem, or why it was occuring in the first place.
Currently I am seeing a similar issue where instead of a user event, the event structure fails to respond to value change events in a control.
I would attach some code, however I have been unable to reproduce the behavior in any of the test VIs I wrote to probe this behavior, and I don't see how posting any of my asynchronous VIs would be useful unless I posted the entire application.
Please give me suggestions if anything comes to mind!
Thanks!
Solved! Go to Solution.
09-04-2015 10:24 PM
Try to stay away from multiple event structures in a single VI. If you feel you need them, there is probably something is wrong with your architecture. It' is very difficult to use multiple event structures in one VI without problems.
09-04-2015 10:30 PM
What's causing the value change? is it your interaction with the front panel or is the VI updating the control elsewhere? If it's the latter, take a look at the value signaling property node. That will handle programmatic change of the value.
Check this out as well: http://zone.ni.com/reference/en-XX/help/371361J-01/lvhowto/caveatsrecmndtnsevnts/
09-04-2015 11:50 PM
09-04-2015 11:55 PM
09-05-2015 12:32 AM - edited 09-05-2015 12:33 AM
I would actually direct you to do a search on "multiple event structures". it gives many topics on why you shouldn't normally have multiple event structures in a VI - BUT there are topics that show you exactly how to do it successfully, too! 🙂
09-05-2015 01:24 AM
@smallmediumlarge wrote:
Re billko: Could you mayne tell me more about what you mean by having multiple event structures in the same vi, and why this could cause complications? Thanks.
You can have as many event structures as you want, simply make sure they are all reachable at all times via dataflow and reside in their own loop. (Don't hide event structures inside sequence structures, case structures, or even other event structures, of course.)
09-05-2015 01:48 AM
09-05-2015 03:44 AM
@altenbach wrote:
@smallmediumlarge wrote:
Re billko: Could you mayne tell me more about what you mean by having multiple event structures in the same vi, and why this could cause complications? Thanks.You can have as many event structures as you want, simply make sure they are all reachable at all times via dataflow and reside in their own loop. (Don't hide event structures inside sequence structures, case structures, or even other event structures, of course.)
That was a nice summary. I've never heard it said so short and to the point.
09-05-2015 09:57 AM
@smallmediumlarge wrote:
Re billko: Could you mayne tell me more about what you mean by having multiple event structures in the same vi, and why this could cause complications? Thanks.
Event structures queue events. This happens to grab events that take place while you're not currently sitting and waiting for an event. With this, you're able to catch multiple events being triggered at once and andle them in order.
This also means having multiple event structures looking for the same event can cause strange behavior. It also means if your code can't get back to the event structure, you're still queuing up those events. You want to ensure you handle those.