LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Question about re-usuing subVIS.

Solved!
Go to solution

Hello Jack,

 

I posted above an observation after making new tests.

 

In that case above, can you please tell me what is the difference between an FGV with a read and write action engine and a SubVI with a simple shift register and no action engine. So far as I see it, they are behaving the same: as the SubVI is by default non reentrant and it is reading correctly the latest value input to it. Even if the second VI is started much later, it is giving the correct updated value of the first VI.

 

I thank you for your clarifications 🙂

0 Kudos
Message 11 of 33
(2,001 Views)

@rajiv85 wrote:

Hello Yameada,

 

Thank you for your valued inputs. Nevertheless, today I was able to replicate the observation I made which led me to my assumptions.

So attached are 2 Vis having the same SubVI. As you will see even when run separately they output the same result. Even when I reset one, the other is reset as well.

Since it is non reentrant by default, it looks like it is working like an FGV, just without the action engine.

But as Jack pointed out, it does have a shift register in that particular case.

While in the previous case I posted, there was no shift register and yet data from the second channel was inserted in the array within the SubVI of the first channel in a race condition like behaviour. This I will need to replicate again and show (I will come back to this.)

However in that case here, clearly a better understanding of the working of the SubVI is needed to avoid these. But from what I see here, it looks like this simple SubVi is working like an FGV=> as it is non reentrant so it has by default the non race condition behavior and since it is always reading the same values?


Since you failed to upload the subvi(s) it is difficult to see what's going on in your examples. It seems that you have a basic misunderstanding of what an FGV is. An FGV is a simple subVI that holds data in a shift register from one call to the next. Any subVI with an uninitialized shift register will function like an FGV, however, without controls over when data is written to the FGV there can be unintended results. If a subVI is not structured as an FGV then I would not use an uninitialized shift register.

0 Kudos
Message 12 of 33
(1,983 Views)

@rajiv85 wrote:

Hello Yameada,

 

Thank you for your valued inputs. Nevertheless, today I was able to replicate the observation I made which led me to my assumptions.

So attached are 2 Vis having the same SubVI. As you will see even when run separately they output the same result. Even when I reset one, the other is reset as well.

Since it is non reentrant by default, it looks like it is working like an FGV, just without the action engine.

But as Jack pointed out, it does have a shift register in that particular case.

While in the previous case I posted, there was no shift register and yet data from the second channel was inserted in the array within the SubVI of the first channel in a race condition like behaviour. This I will need to replicate again and show (I will come back to this.)

However in that case here, clearly a better understanding of the working of the SubVI is needed to avoid these. But from what I see here, it looks like this simple SubVi is working like an FGV=> as it is non reentrant so it has by default the non race condition behavior and since it is always reading the same values?


You havent attached your subVI so it's difficult to comment on what you're doing here, but I can make a number of assumptions based on what your outer VI's look like.

 

I can see from the layout of your main VI's that your subVI will need to have some form of memory in order to function, otherwise it could never store the current elapsed time. If it is a subVI that has memory, then it is a FGV. An FGV is a simple and specific kind of action engine which allows you to write a value to it, or read a value from it.

 

In your case, it looks as though your subVI is counting seconds for you, and also has a reset button. This means that it has functionality beyond what a normal FGV has; i.e. it has more than just the ability to store and return a variable. Therefore, what you've created is probably an action engine.

 

I've attached a quick example of what I consider to be a standard FGV to help clarify. I've then edited this FGV to have additional functionality, the ability to replace the stored value with "Hello", to create an action engine. Finally, I've created a normal SubVI which adds "Hello " to the beginning of whatever string you put into it.

 

Importantly, this normal SubVI has no uninitialised shift registers, which means that you could reuse this throughout your VI without the inputs from individual instances of the SubVI ever interfering with each other. The other two, however, are 'Global' variables which means that if you used the SubVI in many places throughout your program you will be accessing the same stored information.

 

Hopefully that clarifies your issue.

 

Jack

Download All
Message 13 of 33
(1,965 Views)

I cannot understand why the uploaded VIs are not visible.. as a proof that I indeed uploaded them, here is a printscreen.

 

Am uploading them again.

 

Please if you cannot open it let me know.

 

So I checked your vis.. believe me I know what these are. 

The point is: the attached SubVIs only have an uninitialised shift register. Am asking myself how can a subVI configured in that way with no action engine behave 'exactly' as an FGV with an action engine with read and write. This is what am trying to understand. It is compiled in LV 2017. If you cannot open it I will save it as a snippet and make printscreens.

 

 

 

 

subvis attached.JPG

Download All
0 Kudos
Message 14 of 33
(1,948 Views)

@rajiv85  ha scritto:

I cannot understand why the uploaded VIs are not visible.. as a proof that I indeed uploaded them, here is a printscreen.

 

Am uploading them again.

subvis attached.JPG


Both vi's call a subvi Elapsed Time.vi which is the main thing we are discussing about (and you did not upload).

 

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 15 of 33
(1,941 Views)

Ah thanks for clarifying here it is.

 

Thanks for the follow up!!

 

 

Message 16 of 33
(1,938 Views)

As has already been suggested your Elapsed Time.vi is not a standard subVI. It is an Action Engine. You have a while loop that runs once with an uninitialized shift register which will hold the value from one call of the vi to the next. To make this a standard subVI you would need to remove the while loop and add an input for the previous time. 

0 Kudos
Message 17 of 33
(1,925 Views)

My understanding is that we write an FGV to avoid a race-condition and to implement a non re-entrant writing. But it seems that a simple Sub Vi with a while loop and no enum (with read and write) is accomplishing the same result as an FGV. Am trying to understand the difference. Not clear to me.

0 Kudos
Message 18 of 33
(1,918 Views)

You can still have race conditions with FGVs. An FGV is just a simple subVI with a while loop and an uninitialized shift register. An enum (or some other method) is generally used with an FGV to tell the subVI what action to take (read, write, initialize, reset, etc). What you have written is an action engine. It is essentially the same thing as an FGV except that you always have input and output. The key to an FGV or an Action Engine is a loop that runs once with an uninitialized shift register. The value from the previous call of the subVI is retained in the shift register. It is the while loop set to run once with the uninitialized shift register that makes the FGV and the Action Engine. A standard subVI will not have these features. A standard subVI normally doesn't even have a while loop at all. 

Message 19 of 33
(1,912 Views)

Thank you for the clarification!

0 Kudos
Message 20 of 33
(1,908 Views)