LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Handing input to / getting output from a dynamic called VI

Hello again everyone,

 

I have a newbie question, but first let me describe my software architecture in two sentences.

I am programming a state machine that mainly calls sub VIs that have their own state machines to react to buttons pressed on their respective frontends. As the main queue freezes until the sub-VI is finished I was looking for another way to call these sub-VIs, and I actually found one (see attached mini state machine). I can allow the main VI to proceed and also use the sub VIs (warning, this sub VI is not reentant and thus will likely crash if you spam the OK button - I only wanted to show you my work around).

 

Now here comes the Question: How do I hand data to the sub-VI or get the wanted output of the sub-VI? If I placed it in the diagram and wired the input and the outputs it would be easy, but I cannot overcome the fact that everything else waits for this VI then.

Working ways I found are:

- global variables

(from all programming languages I learned I kind of want to avoid them (racing conditions))

- notifier

(also not my cup of tea; though better than setting the class I want to wire to my sub-VI to global)

 

I hope I stated my problem clearly and now I look forward to your answers.

0 Kudos
Message 1 of 10
(3,579 Views)

Hi I am not able to open your code as I use labview 2009.

But you can use function global to pass data to and from subvi.

I hope it will help.

Gaurav k
CLD Certified !!!!!
Do not forget to Mark solution and to give Kudo if problem is solved.
Message 2 of 10
(3,575 Views)

This is definetly better than an unprotected global variable. At this moment of time I (ab)use a class as a variable dump strictly using get_* and set_* VIs to access it. Your suggestion is probably compatible with classes and works very similar to it. I could read/write the class by using this. Though I am interested in more possible solutions, as the combination of the FGV with a class seems kind of redundant to me.

 

Thanks for your quick reply!

0 Kudos
Message 3 of 10
(3,568 Views)

Instead of notifiers, I'd suggest queues and/or user events. The latter I'd use if I already have an event structure or I need a one-to-many communication. In all other cases, go with queues.

 

Other option would be to use GetControlVal and SetControlVal property nodes on the VI refnum. There is a nice OpenG encapsulation of these as well (just saves BD space).

 

Felix

Message 4 of 10
(3,565 Views)

Other option to pass the data is "Queue".

 

Gaurav k
CLD Certified !!!!!
Do not forget to Mark solution and to give Kudo if problem is solved.
0 Kudos
Message 5 of 10
(3,563 Views)

Hey Felix,

 

"Other option would be to use GetControlVal and SetControlVal property nodes on the VI refnum."

 

This sounds interesting, but sadly I cannot find something similar to this in my german labview distribution, I guess I am looking at the wrong place or it is named entirely differently. I would be very thankful if you could create a small example showing the proper use or describe in more detail how to do that.

0 Kudos
Message 6 of 10
(3,549 Views)

German:

 

Methodenknoten:

Bedienelementwert.Setzen

Bedienelementwert.Ermitteln

 

Felix

0 Kudos
Message 7 of 10
(3,539 Views)

Thanks for the answer Felix, this might be exactly what I would like to have!

 

I have another question concerning the functional global variable: Would it be meaningful to implement semaphors to avoid colisions while multiple VIs try to access it?

0 Kudos
Message 8 of 10
(3,509 Views)

The SubVI itself is already providing the semaphore functionality. There is only a single instance of the SubVI that can run. But in the case where you can't put the code inside the SubVI, e.g. Read from the FGV, manipulate the data, write it back to the FGV you risk a race condition. In this situation a semaphore might be useful.

 

Felix

0 Kudos
Message 9 of 10
(3,499 Views)

@Questionmarker wrote:

Thanks for the answer Felix, this might be exactly what I would like to have!

 

I have another question concerning the functional global variable: Would it be meaningful to implement semaphors to avoid colisions while multiple VIs try to access it?


I think you may be interested in the Nugget I wrote on Action Engines (see here). Here is a preview

 

 

 

where I explain that LV implements an access scheme that is similar to semaphores.

 

If you put all of the code that acts on data that is shared between threads in an AE you pick-up automatic Race prevention.

 

As I said I think you want to read that Nugget since your question are leading that way.

 

Ben

 

 

 

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 10 of 10
(3,494 Views)