From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

register event in producer consumer design pattern

Hello wire workers,

I am fairly green when it comes to dynamic event registration, so my understanding of it is probably quite flawed, but what I have implemented seems to work fine.

Assuming a fairly typical queued producer/consumer state machine architecture.
Up till now, I have done the dynamic event registration outside (i.e. to the left of) the UI loop, so all events get registered before the UI loop starts to run.

My question is:
How can I register events from inside one of the consumer loops? I cannot wire it...

Maybe an example will make my scenario more clear.

I have a DAQ loop (queued state machine). In the init state of this loop I want to register a digital input such that changes on a line are handled by my main event structure (in the totally separate UI loop). Is this possible?

I look forward to hearing positive answers Smiley Tongue
0 Kudos
Message 1 of 8
(3,082 Views)
I think the best way to handle this is to create and register a user event at the same time that you do the dynamic event registration that you then trigger in your init state of the consumer loop. This would probably end up being more flexible in the long run.
0 Kudos
Message 2 of 8
(3,073 Views)
I am sorry, I have lead you astray.

I did not mean to say user events. I was wondering if it is possible to do the dynamic event registration in another loop. See attached crude diagram.




Message Edited by nrp on 04-21-2008 05:53 PM

Ideally I would like all the DAQ stuff to live inside the DAQ state machine loop


Message Edited by nrp on 04-21-2008 05:54 PM
0 Kudos
Message 3 of 8
(3,062 Views)
The best way to send data from the Consumer Loop to the Producer Loop is through User Events. What you will want to do is create a User Event whose data type is the registered DAQmx event refnum. Then when you register the DAQmx event in the Consumer Loop, fire the User Event with that new refnum and update the registration in the Producer Loop. That's probably hard to wrap your head around in words, so I'll attach a dummy example and pic below. Hope this helps!

VI Saved in LV85.




Message Edited by Jarrod S. on 04-21-2008 12:54 PM
Jarrod S.
National Instruments
Download All
Message 4 of 8
(3,047 Views)
Hard to understand in words, hard to understand in pictures! Smiley Surprised

But thanks a lot for your input, gives me something to do tonight instead of washing the dinner dishes...  Smiley Very Happy

I think I need to take a step back and figure out how to properly use user events.

A question though, how did you "make" the DAQmx event ref constant?


Message Edited by nrp on 04-21-2008 09:07 PM
0 Kudos
Message 5 of 8
(3,030 Views)
I can't argue you on the "Hard to Understand" poing Smiley Tongue

But User Events are very powerful and (I believe) worth learning. I created the DAQmx registered user event ref constant by right clicking the output of the Register Events Node and selecting Create >> Constant. If you change the User Event you're registering in any way, you'll have to recreate the constant, since it doesn't maintain any link to the node after it's created.
Jarrod S.
National Instruments
0 Kudos
Message 6 of 8
(3,020 Views)
Jarrod, the cogs are starting to turn for me now Smiley Happy

This technique seems to get around another problem I had in that if I put several control references into an array, to register them all at the same time to fire off the same event, the event structure would display <?> as the array was not named. I never did figure out how to coerce an array generated using build array into having its own name that the IDE picked up on.

I have thrown together a quick example of what I am trying to accomplish. I suppose for each "group" of controls that I want to have respond with the same event I will need to have a create user event and a register event. I would appreciate you casting your eye over it to spot anything silly.

The next step would be to put all the event constants and create user events into a subVI to tidy things up.

Thanks!
0 Kudos
Message 7 of 8
(3,003 Views)
> I never did figure out how to coerce an array generated using build array
into having its own name that the IDE picked up on.

Perhaps if you concatenate an empty array constant with a name? I never ran
into this problem, but I usually get my control arrays form a sub VI.

Regards,

Wiebe.


0 Kudos
Message 8 of 8
(2,982 Views)