02-09-2011 02:35 AM
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.
02-09-2011 03:19 AM
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.
02-09-2011 03:49 AM
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!
02-09-2011 03:51 AM
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
02-09-2011 03:53 AM - edited 02-09-2011 03:53 AM
Other option to pass the data is "Queue".
02-09-2011 06:29 AM
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.
02-09-2011 07:09 AM
German:
Methodenknoten:
Bedienelementwert.Setzen
Bedienelementwert.Ermitteln
Felix
02-10-2011 05:04 AM
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?
02-10-2011 07:20 AM
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
02-10-2011 07:46 AM
@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