LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple User Events

Solved!
Go to solution

How can I implement multiple user events?

 

I am using the FileSystemWatcher (exactly as it is implemented in the attachment) as a mechanism to detect changes to a file that I need to notify my Consumer loop using the Producer/Consumer architecture via an Event Structure with a MessageID/Data cluster as the message mechanism.

 

I want to use an additional user event using the same MessageID/Data cluster to notify my producer loop of changes to the Consumer loop if it needs to know about them.

 

My challenge is creating another user event and tying that into the existing user event already created within the File System Watcher...essentially having multiple user events.

 

Has anyone done this?

0 Kudos
Message 1 of 8
(2,537 Views)

Are you saying you want your producer and consumer loop to both have an event structure and be able to send data back and forth? That doesn't sound like producer / consumer, and may be a race condition waiting to happen.
But, it is very routine to have an event structure registered for multiple user events.

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

No, just the producer would be the one handling the user events. Pretty much all it does is two things:

 

  • When a changed or renamed event is captured via the FileSystemWatcher (FSW), trigger the User Event
  • When a notification from the Consumer Loop happens, trigger an event

 

I can't seem to get past how to have multiple user events happen when the FSW is encapsulated within the SubVI.

0 Kudos
Message 3 of 8
(2,504 Views)

I don't think I've used event callbacks before, but this is what I think I see: right now you create your Event Ref inside your FSW code.  You pass this Event Ref to your callback vi as an input parameter.  The callback vi can then send this User Event out, and any Event Structure that's registered for it will receive it.

 

So I *think* you're wondering how your producer code can get access to this Event Ref so it can register for it and receive it?

 

And the answer feels kinda beginner-ish which makes me think I might be misinterpreting you, but here goes anyway.  Why not create the Event Ref one level higher so you can pass it to both the FSW subvi *and* to your producer?

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 4 of 8
(2,483 Views)
Solution
Accepted by topic author Eric1977

I usually create (or copy and paste) a user event library for every new user event I need. The user event reference is stored in a shift register, so it is globally available in that sense. Here is a non-functioning example showing how you could do something similar:

User Events Example.PNG

0 Kudos
Message 5 of 8
(2,476 Views)

@Eric1977 wrote:

How can I implement multiple user events?

 

I am using the FileSystemWatcher (exactly as it is implemented in the attachment) as a mechanism to detect changes to a file that I need to notify my Consumer loop using the Producer/Consumer architecture via an Event Structure with a MessageID/Data cluster as the message mechanism.

 

I want to use an additional user event using the same MessageID/Data cluster to notify my producer loop of changes to the Consumer loop if it needs to know about them.

 

My challenge is creating another user event and tying that into the existing user event already created within the File System Watcher...essentially having multiple user events.

 

Has anyone done this?


No sure I understand the question correctly; I believe you want multiple loops to handle the same event. I do this all the time. What you need to do is have EACH loop have its OWN Event Registration Refnum. That way multiple loops can receive the same event. See Below (I just wired an Event structure, obviously you can add a while loop, destroy refnum etc.)

 

For you case you only need ONE place when you destroy the .NET references, this should be AFTER all of the loops it depends on, are finished.

 

mcduff

 

PS If I misunderstood your question then sorry.

 

Snap53.png

Message 6 of 8
(2,432 Views)

@Eric1977 wrote:

How can I implement multiple user events?

 

I am using the FileSystemWatcher (exactly as it is implemented in the attachment) as a mechanism to detect changes to a file that I need to notify my Consumer loop using the Producer/Consumer architecture via an Event Structure with a MessageID/Data cluster as the message mechanism.

 

I want to use an additional user event using the same MessageID/Data cluster to notify my producer loop of changes to the Consumer loop if it needs to know about them.

 

My challenge is creating another user event and tying that into the existing user event already created within the File System Watcher...essentially having multiple user events.

 

Has anyone done this?


Going through some of my code now, and got to thinking maybe this is what you want? (Once again not sure) In this case I use the SAME user event for BOTH my callback and for other communications for the event loop. No need for separate user events. See screenshot below.

 

The user event data load is a cluster, "loop address", string command, and variant payload. The callback gets the same user event, so now I am only subscribed to one user event that can be generated in multiple parts of the program. The callback fires the user event when needed.

 

Snap54.png

mcduff

0 Kudos
Message 7 of 8
(2,413 Views)

The key was looking at Gregory's image.

 

I took the Register for Events function outside of the FileSystemWatcher subVI (I've re-created that to not mess with the one I downloaded from the NI site), massaging that VI a little bit, and then placed that into it's own state. If I need more User Events, I'll just place them in an array and when I'm ready to register for all of them, I'll just do it in one spot.

 

Eric1977_1-1604606086101.png

 

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