03-24-2010 09:46 AM
I need advice on how to structure a complex interaction loop. There are some things that need attention only if a particular control is changed. There are also calculations that need to be done, and a graph updated, every time ANY control is changed. But no reason to waste processor time doing those calculations when the user has not done anything. How can I structure such a loop to work efficiently? The "Event" structure seems almost, but not quite suitable.
I also find myself wishing that the event structure had an "Initial" case that runs exactly once the first time the structure is entered. It would let me put code comfortably in there, together with all other related code, instead of having to stick it someplace off to the left. Anybody got some good tricks for this one?
Ken
03-24-2010 09:51 AM
Hi Ken,
you should try a (event driven) state machine to decouple events (like control change) from actions (like generating plot). Then you could have several events (like single control vs all controls) starting the same action...
When "firing" a value change event via property node ("Value.signalling") you could easily generate an event on startup of your VI to "call" the event structure!
03-24-2010 09:52 AM
03-24-2010 09:55 AM
03-24-2010 09:58 AM
03-24-2010 10:02 AM
Lucither wrote:
Like Mark said, you need to look at the Producer/Consumer loop. As for your 'Initial' state, this would be implemented in your case structure in your consumer loop. Before entering the Consumer 'While Loop' you would create and then fill a queue with an 'Initialisation' State. This is generally used to set all initialisation code, like setting control states, reading ini files etc........
Depending on the initialization this may be done before both tasks are started. For instance if you need to create any LVOOP objects that are used in each of the tasks this is best done before starting the task so the wire can be wired directly to both loops. Where the initialization occurs really depnds on exactly what is being initialized and how much needs to be shared between the tasks.
03-24-2010 10:05 AM
Ken Brooks wrote:...
I also find myself wishing that the event structure had an "Initial" case that runs exactly once the first time the structure is entered. It would let me put code comfortably in there, together with all other related code, instead of having to stick it someplace off to the left. Anybody got some good tricks for this one?
Ken
In really simple code like a user dialog I have used the Time Out case to do that using a trick I learned from Christian.
Feed the Time out value from a Shift Register.
THe loops should start with a TO value of "0' to fire the Time Out and do the init stuff. When the TO event completes it returns a value "inf" to the SR so the TO event never fires again.
Ben
03-24-2010 10:08 AM