LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling a single re-entrant vi asynchronously and having multiple instances of that single vi run simultaneously on dedicated front panels

Well I know my subject title is probably too long, but that's an attempt to really explain the problem.

First, I had a non-entrant vi that I call asynchronously with flag 80 to fire and forget. Works OK as long as the vi is non-rentrant. (Open vi reference -FP Open- Async call - Close)

 

Now enter re-entrant:  I set execution for the same vi described above to pre-allocated re-entrant" and combine flags 40 and 80. 

The code seems to run but no front panel shows up. (All error in and out indicate no problems) and the cloned reference is valid.

 

So what do I need to differently or in addition for the re-entrant case?

 

Note my objective is to have multiple instances of this single vi running; each with its own dedicated front panel simultaneously accessible. Pretty much like multi-threading I guess.

 

 

[BADGE NAME]

0 Kudos
Message 1 of 6
(2,609 Views)

BlessedK,

     I've done something similar.  I'm monitoring some behavioral experiments, and have 24 "stations" that contain a video camera and a measuring instrument generating a graph of behavior (recording session lasts 2 hours).  I have a Station VI that calls a Camera VI and an Instrument VI -- Station, Camera, and Instrument are all Clones (pre-allocated reentrant VIs).  Station is called with Start Asynchronous, while Camera and Instrument are sub-VIs within Station.  Camera and Instrument have Front Panels (Camera displays the current Video Frame, while Instrument displays a Graph showing behavior over the two-hour testing period).  Rather than having multiple Front Panel displays on my Main, I have a pair of Panels that can show the Camera and Instrument Front Panels of a selected Station.

 

[Sorry, it's a little complicated ...].  Suppose I'm running 24 Stations, and choose Station 1 to view.  I have references to the Front Panels of the 24 Camera and 24 Instrument Clones, so I choose Camera 1 and Instrument 1 and insert their References in the Camera and Instrument sub-Panel.  When I want to view Station 10, I get the references for those Camera and Instruments and update the sub-Panel References.  In your case, if you have multiple sub-Panels, you can view multiple Clones at the same time (instead of one-at-a-time, as I am doing).  All you need is the VI References to the Clones whose Front Panels you wish to view.

 

Bob Schor 

0 Kudos
Message 2 of 6
(2,581 Views)

I think I get what you mean “ by having multiole sub panels. I will try that and get back to you with my results. In the meantime, may I ask:  Can subpanels be created programmatically. I am asking because the program can not proactively pre-determine the number of instances that would run simultaneously. As an alternative I am thinking of having another re-entrant Vi for display purposes that would have  a sub panel, so if I wire the reference(s) to this subpanel within this re-entrant vi, I can have multiple cloned instances showing up simultaneously. Not sure if that’s reasonable but anyway let me try somethings around the “multiple sub panels” you suggested and let you know. 

[BADGE NAME]

0 Kudos
Message 3 of 6
(2,566 Views)

BK,

     A few clarifications and (possibly not 100% correct, but "I think this is right") comments:

  • I think of sub-Panels as "relatively static things that persist on the Main VI's Front Panel" (like an Indicator) and hence unlikely to be created "programmatically".
  • You have a variable number of identical Clones running, hence you are thinking about having a variable number of sub-Panels to look at them.  Here's my question -- do you need to see, say, two of them at the same time (perhaps to compare their respective Front Panels)?  Note that for my application, I wanted to be able to view a selected Clone (to check that things were working OK).
  • If you decide that "simultaneous viewing" of your Clones is important, you can ask a related question -- how many Clones do you need to view simultaneously?  I have a colleague who builds VIs where everything is graphed, everything has a Front Panel control, there are a dozen Tab selections, and the code is a complete mess.  I advise you to not do this!  If you need to compare two (of 5, or of 20) Clones at a time, build a Front Panel with two sub-Panels, and have two "switchable" controls to, say, Show Clone A in sub-Panel 1 and Show Clone B in sub-Panel 2.  This is flexible and can scale with the number of Clones quite easily (only the "Clone Selector" indicator needs to change, and if it is a Dial, it can change programmatically).
  • Do you know K.I.S.S., which means Keep It Simple (and the final S can vary with the occasion)?  It also applies to LabVIEW code ...

Bob "Silly" Schor

0 Kudos
Message 4 of 6
(2,549 Views)

Hahaha, yeah the KISS principle is universal 🙂 Will definitely consider your suggestions. The other thing I am concerned about ( still haven’t implemented test cases for the subpanels) going by your statement that subpanels are “relatively static and like indicators” is that my front panel for each of these clones contains all controls (no indicators ) which the user can change and expect certain  responses. Does this still seem in alignment with what a subpanel can do?

[BADGE NAME]

0 Kudos
Message 5 of 6
(2,537 Views)

Glad you have a Sense of Humor!  Plus a Thank You for reminding me that sub-Panels can actually "present" the sub-VI's Front Panel to its Caller (not unlike a Modal Dialog Box) so that you can, indeed, interact with the Controls [I just wrote myself a 2-VI test system with two Stop Buttons, one in the sub-VI that I pushed "through" the sub-Panel on the caller VI, the other to stop the Caller.  Needless to say, it worked like a charm].

 

So, I'd have to say "Yes, if you write a single sub-Panel and a "Selector" that chooses which Clone has its Front Panel displayed in the sub-Panel, the Clones should be able to do almost anything they want and have the Main be able to interact with all the (Visible) Controls."

 

Here's a Trick that you might find useful for getting the Front Panels of your Clones to "match" the size of your sub-Panel.  Do you know about OpenG, the set of Tools available from LAVA (the LabVIEW Advanced Virtual Architects group)?  If not installed, open VIPM, go find OpenG Toolkit, and install it.  [You need to have TCP/IP enabled in your LabVIEW Development Environment -- Tools, Options, VI Server tab].  There's an OpenG Application Control called "Fit VI Window to Largest Dec" which you put at the beginning of the Clone.  You then go to your Clone's Front Panel and put a Decoration (I use a Frame) around what you want to show as your Front Panel.  I recommend making it "fit" on the Grid Lines and making all your Clones have the same size Decoration.  Make the sub-Panel also the same size.  Now when your Clone runs, it will run this sub-VI, snap its Front Panel down to the Decoration (keep the Error Clusters outside, since who needs to see them?), and everything nicely fits!

 

A few more notes:

  • I'm not 100% certain this is necessary, but I always make sure if I want to replace a VI in the sub-Panel, I remove the old VI.
  • When I launch multiple Clones, I keep their VI References in an Array.  Now when I want to change what shows up in the sub-Panel, however I choose it (whatever type of Control), I use that to index into my Array of References (I can get both the New Value, "going into the sub-Panel" and Old Value, "going out").

 

Good luck.

 

Bob Schor

0 Kudos
Message 6 of 6
(2,531 Views)