LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

template vi - simultaneous multiple usage

my today problem deals with the profused use of template vis in a main vi.

this might be a nugget for novices.

 

exactly as for a regular vi, template vi (vit) can be used like a reentrant subvi in a main application. LV opens a duplicate vi to the template one for every call, which will close when then main application stops.

This strategy is usefull when dealing simultaneously with several datasets of identical class. for example, in a recent thread someone asked about how to display a number of arrays, not knowing in advance how many would there be. the main application could open n vit displaying n 1D datasets.

 

Also, similar to opening and manipulating a subvi panel in a subpanel of the main vi, it is possible to do so as well with vit, as depicted below:

in this example  the main vi includes several subpanels, which are empty when the vi is not running. in the diagram, we affect a reference to a single copy of the vit to every subpanel. data can be input to / retrieved from the vit via an invoke node. here is how thediagram could look like:

 

we create a vit, with the sole purpose to display and allow user manipulation of an array of clusters. of course such vit can support all the usual LV operations

 

 

When vi is not running, the subpanels are empty. as the main vi runs, the subpanels get filled with the vit front panel:

 

 

 

it is important to point that every panel now has its own dataset, either programmatically input in the main vi, or user-modified. it is subsequently possible to extract data separately from each subvi template.

 

notes and questions ( this is why i wrote all this):

* make sure the name of every control is exactly written for programmatically input-output data. even upper case are important.

* update values of variables in the vit before displaying in front panel. this way one avoid confusion about the values of the variables.

* do not forget to close references. it is even advised toforce deallocate memory.

 

*I do not know how to use the LV8 version of "flatten to string". how to i get the type descriptor?

*in LV7.x, one could hide the scrollbars of the subpanels. not anymore in LV8. do i miss something?

*now is my real problem. in my application i open about 20-30 such vit copies in subpanels. in LV7.x i never had any problems with it. as i upgraded to LV8.2, a bug appeared:

most of the times when i fill the vits with data i can look at their panel with updated values of the variables. however, sometimes (about 30% of cases) the first vit would not get filled with updated data from my main application. in about 5% of cases even the second subpanel would not get updated. meaning, the vit front panel would appear, but not with the data i programmatically input. anywone has an idea?

 

 

dont forget to rate if you liked it! and especially i would like suggestions to make my applications better.

 

 

 

Message Edited by Gabi1 on 05-05-2007 08:16 AM

-----------------------------------------------------------------------------------------------------
... And here's where I keep assorted lengths of wires...
Download All
Message 1 of 13
(4,395 Views)
Gabi1,
 
Thanks for the detailed post. I am quite a bit confused about your post because it is a strange hybrid of:
  1. Design suggestion (nugget).
  2. Request for comments and improvements
  3. Bug report (broken in 8.2!!!).

It would really help if you could also attach e.g. a zip file containing your code so we can actually play with it. 😉 I am confused about quite a few things, so playing with it would help me get started.

Just looking at the posted code image on top, it can be simplified quite a bit:

  1. Too many sequence frames! The first two frames can be combined into one by placing everything in these two frames in one FOR loop.
  2. In the case structure of the second loop, I think it would be sufficient to place only the "subpanel X" node inside the case. The rest is probably duplicated in all frames.
  3. Again, frame 5 (and the FOR loop in it) is not needed at all. Why don't you close the reference directly in the loop of frame 4?
  4. All the methods have error terminals. Use them! If you string the error cluster along and feed it across the polling loop, you can eliminate the sequence structure completely. 😉

 

0 Kudos
Message 2 of 13
(4,383 Views)

Message Edited by Gabi1 on 05-05-2007 02:02 PM

-----------------------------------------------------------------------------------------------------
... And here's where I keep assorted lengths of wires...
Download All
0 Kudos
Message 3 of 13
(4,376 Views)
here is the redesigned diagram (somehow i could not edit the original post anymore).
 
 

Message Edited by Gabi1 on 05-05-2007 01:53 PM

-----------------------------------------------------------------------------------------------------
... And here's where I keep assorted lengths of wires...
0 Kudos
Message 4 of 13
(4,374 Views)

Hello Altenbach,

thanks a lot for your comments. i made a long response, but somehow it got erased...

Anyway, in this example i use flat sequence only to show the steps to do for using vits in this configuration. it is common to use a loop for input output data from those vits, then the reference is only opened and closed once, at beginning and end of vi.

you are right tough about the cases, and i attached a better version of the example vi. about wiring the error terminals: i am not a big fan of it actually, because except in debugging hte kind of add wiring a lot, and in evolved programs this makes the picture messy. dont get me wrong tough, they are vital for debugging.

about what the post is: i dont pretend to make good nuggets, but i did not saw anybody use this feature. i tought then to share it. in the same time, to get new ideas on improvements and bug fixes. i like your ideas and trics. give me some!Smiley Happy

-----------------------------------------------------------------------------------------------------
... And here's where I keep assorted lengths of wires...
0 Kudos
Message 5 of 13
(4,368 Views)
I believe the use of scrollbars for VIs in subpanels changed from 7.1 to 8.0. It is now determined by the VI in the subpanel rather than the subpanel. If the VI in the subpanel shows scrollbars, then they are displayed in the subpanel frame.

I posted an example a while ago that uses an XControl in 8.0 to display data dynamically in any different number of controls that can have separate properties and appearances. It was a fun experiment you can check out here. Unfortunately I seem to be locked out of my account at community.ni.com, so I won't be able to update any bugs that have been found. It's a neat proof of concept though.
Jarrod S.
National Instruments
Message 6 of 13
(4,359 Views)


@Gabi1 wrote:
...about wiring the error terminals: i am not a big fan of it actually, because except in debugging hte kind of add wiring a lot, and in evolved programs this makes the picture messy.
Personally, sequence structures are messier than a nice error cluster in my book. Here's a quick redo with my suggestions (and a few more tips shown in green). You don't really even notice the error cluster! 🙂
 
 
Also, the "subVIT" in this case does not even need any loops. It is sufficient to contain the single control and nothing else. I also hide the scrollbars 🙂
 
I am still not quite sure where I would use all that, though... 😉

Message Edited by altenbach on 05-05-2007 04:57 PM

Download All
Message 7 of 13
(4,350 Views)
Hi altenbach,
 
nice cleanup! i promise to try to use the error cluster.
to my opinion the utilisation of such procedure is interresting especially if there is an interactive utilisation of these datasets. that is why one might think of opening and closing references separately. or do you think that reopening at every reentrance (let say in a while loop) is not too computer effort consuming?
 
i generally do not use flat sequences. i dont think them usefull to me. but i am actually quite a fan of stacked sequences, altough i see all around people despising it. could you expand why?
i never used variants before. can you propose litterature on that?
 
i found the utilisation of the first array element clever. should have tought of that. that lead me to a problem i never solved to myslef: if i change a dataset property in a main vi (lets say i add a variable to a cluster), how could i link that to all my subvis using same dataset? there must be an easy way, and up to now i just waist a lot of time on this kind of issues.
 
Thanks!
-----------------------------------------------------------------------------------------------------
... And here's where I keep assorted lengths of wires...
0 Kudos
Message 8 of 13
(4,332 Views)

Jarrod,

very nice way. i am still learning all the whay how you do it. when i master it i see what i can do with. might be usefull for expandable systems...

-----------------------------------------------------------------------------------------------------
... And here's where I keep assorted lengths of wires...
0 Kudos
Message 9 of 13
(4,326 Views)
The main complaint against stacked sequence structures have been that they make it difficult to visually analyze code, since you have to scroll through multiple frames. Also, sharing data between frames becomes very clumsy. You generally have to use Sequence Locals, which force you to end up wiring right to left in the subsequent frame. Moreover, if you for instance want to transmit the error cluster through 10 sequence frames, you need no less than 10 Sequence Locals, which becomes very confusing very quickly.

People have circumvented these problems by flattening out their sequences (which can be done automatically by right clicking the Stacked Sequence), or by replacing it with a For Loop set to run N times with a case structure inside that has cases 0 ... N-1. That at least allows you to use shift registers to store data.

But in the end it's a matter of preferences 🙂
Jarrod S.
National Instruments
Message 10 of 13
(4,316 Views)