LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Communication between 2 VIs scenario realisation

Hello,

 

Here is simplified realisation of a real setup.

Here are keypoints:

  • 2 VIs ... let say MASTER and SLAVE
  • In SLAVE VI two values are generated at the same time: aaa and bbb
  • In MASTER VI these 2 values are used consequently: 1st aaa, then bbb

Here are keypoints of realisation:

  • for aaa and bbb transmission a global variable was created Global 1.vi
  • in order to match loop cadence in MASTER & SLAVE, variable loop_delay was added to Global 1.vi
  • in order to stop SLAVE from MASTER, variable stop was added to Global 1.vi

Is such approach the only one to communicate between VIs ?

 

Thanks

 

Pavel

 

MASTER.png

 

SLAVE.png

 

0 Kudos
Message 1 of 15
(3,692 Views)

Pavel,

 

you should learn about queues and architectures based on queues (Producer/Consumer, Queued Message Handler, ...).

No variable needed at all!!!!!

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 2 of 15
(3,687 Views)

Norbert_B a écrit :

Pavel,

 

you should learn about queues and architectures based on queues (Producer/Consumer, Queued Message Handler, ...).

No variable needed at all!!!!!

 

Norbert


Thanks Norbert,

 

It seems that Producer/Consummer architectures is for communicate data between loops that run inside the same VI, whereas in my case the two loops that run in different VIs.

At least I understood Producer/Consummer concept in this way while trying to create new VI from template.

Or I missed something

 

 

0 Kudos
Message 3 of 15
(3,676 Views)

@Pavel_47 wrote:

It seems that Producer/Consummer architectures is for communicate data between loops that run inside the same VI, whereas in my case the two loops that run in different VIs.

At least I understood Producer/Consummer concept in this way while trying to create new VI from template.

Or I missed something


You missed something.  Imagine the consumer loop being in a subVI and you have your situation.

 

You should also look into the Queued Message Handler, which is a very useful architecture.  Just do a search on the forums.  There have been plenty of discussions about them lately.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 15
(3,670 Views)

crossrulz a écrit :

@Pavel_47 wrote:

It seems that Producer/Consummer architectures is for communicate data between loops that run inside the same VI, whereas in my case the two loops that run in different VIs.

At least I understood Producer/Consummer concept in this way while trying to create new VI from template.

Or I missed something


You missed something.  Imagine the consumer loop being in a subVI and you have your situation.

 

You should also look into the Queued Message Handler, which is a very useful architecture.  Just do a search on the forums.  There have been plenty of discussions about them lately.


Here is producer-consumer template

In this single VI example 2 loops are connetcted by queout wire.

In the case when 2 loops are located in different VIs how they are connected ?

 

producer-consumer.png

0 Kudos
Message 5 of 15
(3,660 Views)

You can pass the queue reference per conntector pane. Or use named queues and each VI obtains the same queue.

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 6 of 15
(3,656 Views)

If you don't want to use a producer-consumer architecture, you can instead implement functional global variables and use those.

0 Kudos
Message 7 of 15
(3,643 Views)

@Daikataro wrote:

If you don't want to use a producer-consumer architecture, you can instead implement functional global variables and use those.


Might as well use Global Variables if you go that route.  FGVs still have the race condition issues and are slower.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 15
(3,639 Views)

Really? I thought the reason to go FGV was specifically to avoid race conditions. How and why is that still an issue with FGV?

0 Kudos
Message 9 of 15
(3,629 Views)

There is a term called "critical section". If the FGV does not only contain (encapsulate) the data but also the critical section, the FGV is thread save and won't create race conditions.

However, experience shows that most developers do not include the critical section in the FGV or this is not possible at all. In that cases, Tim's statement is correct: FGV does not protect from race conditions and are simply a (negative) performance impact.

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 10 of 15
(3,624 Views)