LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

user event or event structure time-out

Hi,

 

I have two VIs one is a producer, one consumer.

The consumer VI is called programatically (i.e. not wired) when the producer VI is run

Both have user interfaces using an event structure.

 

I have a control on the producer that i wish to use to trigger an event in/pass a value to the consumer VI. I have implemented this in two ways, but am not sure which is the 'preffered solution'.

 

Solution 1:

Detect  control activation in the producer VI using event structure, load new value in to a global variable.

Use the time out event case in the consumer VI to load the value from the global variable.

 

Solution 2:

Set up a user event in the producer VI, load the Event Registration Refnum in to a global variable, use the event structure to create a new event when the control value is changed by the user.

Use  Event Registration Refnum global variable in the consumer VI to trigger the event structure (loaded once, when the VI is first loaded).

 

 

Solution two means the time-out event case does not need to be active, meaning the consumer VI will be doing nothing except waiting for either the user event, or direct user interaction. It will also not have the potential time delay of up to 1 x the time-out value of the event structure. It does require a sequenced start of each VI for the Event Registration Refnum to be loaded in to the global variable before the global variable is read by the consumer VI.

 

My end application will be utilising a number of consumer VIs and will require user interaction information from the producer to be passed to them. Which proposed structure would be the generally accepted better practice? 

...or if i've missed the best solution, where should i be looking? 

 

Thanks,

 

Blue 

 

(xp, LV 8.6) 

 

0 Kudos
Message 1 of 18
(3,238 Views)

I think a queue transmitting the data would be a better solution than global variables.

 

In another current thread ("Is there a way to set priorities in an event structure?") I just found the following link which gives a detailed description: http://expressionflow.com/2007/10/01/labview-queued-state-machine-architecture/

 

Jörn

 

Message 2 of 18
(3,223 Views)
Thanks for the 'heads up' Jörn. I'm working through that description, but it seems more complex than what i may need... or maybe i just haven't understood what i need yet!
0 Kudos
Message 3 of 18
(3,204 Views)

Example of Queue based function Globals.To store the events and data.

 

http://forums.ni.com/ni/board/message?board.id=170&message.id=240328#M240328

Balaji PK (CLA)
Ever tried. Ever failed. No matter. Try again. Fail again. Fail better

Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved.
Download All
Message 4 of 18
(3,201 Views)
Thanks Baji. Think i will go for user events, and loading the refnums once via globals on start up. It is not a large app, and there will only be an occasional use of the user events.
0 Kudos
Message 5 of 18
(3,158 Views)

I didn't read the entire post and description, just browsed quickly through it.

 

Using two Event Structures may cause problems, especially using it in the consumer loop.  Why did you implement it this way?

0 Kudos
Message 6 of 18
(3,147 Views)

BlueTwo wrote:

I have implemented this in two ways, but am not sure which is the 'preffered solution'.

 

Solution 1:

Detect  control activation in the producer VI using event structure, load new value in to a global variable.

Use the time out event case in the consumer VI to load the value from the global variable.

 

Solution 2:

Set up a user event in the producer VI, load the Event Registration Refnum in to a global variable, use the event structure to create a new event when the control value is changed by the user.

Use  Event Registration Refnum global variable in the consumer VI to trigger the event structure (loaded once, when the VI is first loaded).


 


They are both bad ideas.  Neither solution 1 or 2 is preferred, desirable, or proper.

 

All you need a one Event Structure in the producer loop (vi).  Try not to use Globals. Investigate using queues instead.

 

R

Message 7 of 18
(3,139 Views)

gulp!

 

One event structure per VI. A GUI event in the 'main' VI triggers a user event that is read in the 'secondary' VI. 

The 'event reg refnum' specific to that event is set up in the initialisation of the main VI and passed once (as a global Variable) to the secondary VI as it initialises.

 

To send a GUI event in the secondary VI back to the main VI i have created a second user event in the main VI, and passed the 'User event' (i.e. the data required by the 'Generate User Event' VI) to the secondary VI via a global variable. This global is also written/read once, during initialisation of the two VIs.

 

So i am only looking for a given event in one event structure, and i am only triggering each event in one place.

 

Obviously the secondary VI has to be started after the main, but this occurs programatically, in the main VI after the initialisation.

 

Blue 

0 Kudos
Message 8 of 18
(3,133 Views)

Ray.R wrote:

 


They are both bad ideas.  Neither solution 1 or 2 is preferred, desirable, or proper.

 


Hi Ray,
So reading between the lines, passing user events between VIs is a bad idea?  
...unless directly wired?
Or is the use of a global variable that is undesireable? (i'm familiar with the arguments for and against variables)
 
I have 2 VIs both with GUIs, i want a button press in one to trigger a GUI event in the other, a queued system is best for this?

Cheers,
Blue 

 

0 Kudos
Message 9 of 18
(3,128 Views)

Hi Blue,

 

what you are describing is best performed using queues instead of an event structure. The event structure in one of the sub VI might be waiting for an event which does not occur and thus block the whole application.

 

Just an idea: I think you could use the event structure in your sub VI if you wire the time out event with 0 (Zero) and call all your sub VI regularly from the main VI. If an (user) event exist for one sub VI it will be executed otherwise the sub VI will immediately return to the main VI. I think XControls work in this way whereby the caller for all XControls is hidden in the environment. But I haven't tried this idea.

 

To NI people: Please let me know if I am wrong.

 

Jörn

0 Kudos
Message 10 of 18
(3,123 Views)