LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can you use Use create user event, generate user event, etc. to pass data from one VI to another VI, kind of like global variable? Is it possible?

Solved!
Go to solution

I know how to use queue, global variable, functional global variable, etc. to pass data from one VI to another, but can the same be done with event structure (generate user event,...)?

0 Kudos
Message 1 of 14
(1,211 Views)
Solution
Accepted by GRCK5000

Yes. Attached are excellent examples from years ago that still apply from a presentation by a LabVIEW expert. Look at it, then come back with additional questions if you have any.

 

I almost exclusively use User Event for Communications; they take a little more work, but are highly flexible.

 

Message 2 of 14
(1,181 Views)

Thanks McDuff for sharing. These are great examples. I will definitely come with more questions. 

0 Kudos
Message 4 of 14
(1,116 Views)

@GRCK5000 wrote:

I know how to use queue, global variable, functional global variable, etc. to pass data from one VI to another, but can the same be done with event structure (generate user event,...)?


I see you are off exploring again.  🙂

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 5 of 14
(1,106 Views)

😂 Yeah Bill, I'm back. The forum is my refueling spot. Haha

Message 6 of 14
(1,068 Views)

Most programmers advise not to pass data between two or more VIs using global variables. I had a post some time ago and I asked if it was possible to pass data between two VIs and @mcDuff said that it was possible and even provided great examples. In these examples, events are being used to pass data between two loops, more like producer-consumer architecture, but not between VIs. 

I have attached a VI called sender and I would like to pass string "hello" to receiver.vi

 

Sender

GRCK5000_0-1722560923055.png

 

Receiver

GRCK5000_1-1722561003316.png

 

Also, if anyone knows of a better way of accomplishing this besides using global variables and events, please share. 

 

 

 

Download All
0 Kudos
Message 7 of 14
(584 Views)

@GRCK5000 wrote:

Most programmers advise not to pass data between two or more VIs using global variables. I had a post some time ago and I asked if it was possible to pass data between two VIs and @mcDuff said that it was possible and even provided great examples. In these examples, events are being used to pass data between two loops, more like producer-consumer architecture, but not between VIs. 

I have attached a VI called sender and I would like to pass string "hello" to receiver.vi


Events can send data between different VI's but there are some caveats:

  1. Your User Event can be thought of as the "mail". The Event Structure registered for the User Event is the "mailbox". Before sending the mail, the mailbox needs to be registered, otherwise you will lose the mail.
  2. In your example the "Receiver" is registered to a "User Event Constant". It needs to be registered to "The User Event of your Sender". Just because the user event constant and sender are the same data type does NOT mean they are the same.
  3. If you don't want to connect your VIs with wires, than you would need something like a FGV etc, to register events in other loops. I prefer wires.

In the picture below I wire the "Main Message Bus" which is my User Event to multiple loops. Then I can send and receive messages in any of the loops that use that User Event.

 

mcduff_0-1722562499706.png

 

Message 9 of 14
(573 Views)

As a side-note, you can look into DQMH. This has tools to automate the creation of user events, and uses Queued Message Handlers as the main VIs which communicate with each other.

 

https://www.vipm.io/package/delacor_lib_dqmh_toolkit/

0 Kudos
Message 10 of 14
(512 Views)