LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Start Asyn Call function


@Vasilich2004 wrote:

@Bob_Schor

could you, please, attach code.

It's very similar to what I attached previously.  I'll go looking for the old code, and will post an example.

 

Bob Schor

0 Kudos
Message 21 of 40
(543 Views)

This is a bit complex.  The code I posted previously is similar to the code used to launch Clones -- the only differences are (a) the VI whose Static VI Reference (Strictly-typed) you wire to the Open VI Reference function needs to have its Execution Property set to "Pre-allocated clone reentrant execution", and (b) the Option on Open VI Reference has to have bit 40x set to enable it to launch a Clone.  You'll notice I'm passing a Clone-specific Queue as a parameter to each Clone -- this allows the Main to send Messages to the Clones (the Clones are running something similar to a Queued Message Handler) to tell the Clone to Start, to Stop, or to substitute for a Front Panel Control.

To simplify things, my Clones have a "visible Front Panel" showing only indicators, typically Graphs or Charts.  If I want to change, say, a Gain of a Chart, I put the Gain Control on Main, and when a change is noted by Main's Event Loop, it knows which Clone is currently "Active" and sends a "Change Gain" Message, along with the new Gain, to the Clone via the Queue we passed in.

 

So how do I handle getting the correct VI Reference into the sub-Panel control?  As it happens, I'm not showing the Front Panel of my Clone, but rather the Front Panel of a sub-VI (also a Clone) that it calls.  When this latter sub-VI starts, it gets a VI Reference to itself ("This VI") and enqueues it back to the Host.  I do this with what I call an "Invisi-Q", a Queue contained inside a VIG that Creates the Queue when first called and thereafter simply provides the Queue Reference to whomever needs it.  This particular Queue only gets the Front Panel Reference from a known Clone, which it saves in an Array in Main -- when Main needs to show a Clone in its sub-Panel, it retrieves the VI Reference from the Array and wires it into the Insert VI method of the sub-Panel.

 

If Main throws an Error, it sends all of the Clones Messages to Exit, and goes to its own Exit routine, where it waits for all the Clones to Exit before it stops itself.  Also, if Main wants to Exit, it again tells all the Clones to Exit and goes to its Exit routine.

 

If the Clone throws an Error, it uses another "Invisi-Q" to send the Main a message that it exited, and then it goes to its Exit routine.  In general, this might not be necessary unless you want the Main to know about the Error (and maybe close the other Clones and exit, itself).  An early exit of one Clone won't necessarily affect the Main or other Clones -- when Main says "Exit", the Clones that are still running will Exit, and Main will see that all of their References show they've exited, so it can exit.

 

Bob Schor

Message 22 of 40
(530 Views)

@Bob_Schor wrote:

So how do I handle getting the correct VI Reference into the sub-Panel control?  As it happens, I'm not showing the Front Panel of my Clone, but rather the Front Panel of a sub-VI (also a Clone) that it calls.  When this latter sub-VI starts, it gets a VI Reference to itself ("This VI") and enqueues it back to the Host. 

 

Bob Schor


I use a DVR for this purpose; the host has the DVR reference and when the clone starts, "This VI" populates the DVR reference. This way I avoid sending a message back. The clone destroys the DVR reference when it exits.

 

mcduff

0 Kudos
Message 23 of 40
(526 Views)

A program uses Stages.ctl which has

- common parameters for all stages on the same com port

- an array of Stage.ctl

 

At start Top.vi:

1. calls StagesConnect.vi to initializes common parameters and starts async ComPortReadTask.vi to listen COM port and sends events

2. call async StageTask.vi per each stage

 

I want to hide ComPortReadTask.vi reference into Stages.ctl. Now StagesConnect.vi returns

- Stages.ctl without ComPortReadTask.vi reference

- ComPortReadTask.vi reference

and Top.vi uses 2 wires to disconnect each stage and stages at the exit.

0 Kudos
Message 24 of 40
(520 Views)

Instead of Queue, I use Event. In this case, I don't care who are subscribers. For example, on top dialog there are multiply tabs and few of them shows current stage position (directly or inside of subpanel). Main vi and according subpanel vi's (=async launched task) catch event.

0 Kudos
Message 25 of 40
(516 Views)

@Vasilich2004 wrote:

A program uses Stages.ctl which has

- common parameters for all stages on the same com port

- an array of Stage.ctl

 

At start Top.vi:

1. calls StagesConnect.vi to initializes common parameters and starts async ComPortReadTask.vi to listen COM port and sends events

2. call async StageTask.vi per each stage

 

I want to hide ComPortReadTask.vi reference into Stages.ctl. Now StagesConnect.vi returns

- Stages.ctl without ComPortReadTask.vi reference

- ComPortReadTask.vi reference

and Top.vi uses 2 wires to disconnect each stage and stages at the exit.


I do not understand what you are trying to do.

 

ComPortReadTask is called dynamically from StagesConnect. In ComPortReadTask you call StageTask dynamically.

 

When ComPortReadTask returns something in StagesConnect you say you don't have the reference? But you should have the wire reference there because you called it from that VI. Are you trying to use an event, and then read the "return" of the VI? If that is the case, then use call and forget and return all of your data via events. Use a variant and convert to the correct data type.

 

mcduff

0 Kudos
Message 26 of 40
(508 Views)

I give up.  I don't understand what you are trying to do, but see that you really want to "do it your way".  The problem is that I don't have a clear understanding of the whole Project, so don't know how the various piece fit together.

 

I have several suggestions, some of which I've tried, myself, and found very helpful ...

  • Find a colleague (or, better yet, a mentor) and do a detailed "code walkthrough" with him/her, explaining, first, what you are trying to do (a broad descriptive outline, which doesn't need to include any mention of LabVIEW), and only afterwards, explaining how you are trying to accomplish this with LabVIEW.
  • Write (for yourself, and for others who might help you) a description of what you want to accomplish.  Again, it should focus on "what", not "how".  This is a step that the Software Engineers call "Write the Documentation First".  I read about this step more than two decades ago, but first applied it (for my own Projects) about a decade ago, and it made a huge difference.  I won't say that I always do this, but every time I "get stuck", I stop coding and break out the Word Processor, which almost always not only gets me "back on track" but also shows me much better (and simpler, and more logical) ways to accomplish my goals.
  • Consider zipping together your entire Project and attaching it (along with a better description of what you want to do) to this Post.  The more we know, the more we may be able to help.

You might notice my use of "what" and "how".  I have a colleague who frequently consults me when his LabVIEW code isn't working.  My first question is "What are you trying to do", and his first response is to walk me through his (typically messy) code, explaining "how" he is doing so-and-so.  I say "Stop!  Don't tell me how, tell me what you are trying to do".  I then suggest a few VIs that he write that do the steps required (I believe in "hiding the Messy Details", also know as "helping you see the Forest, not just the Trees").

 

Bob Schor

0 Kudos
Message 27 of 40
(484 Views)

@Vasilich2004 wrote:

Instead of Queue, I use Event. In this case, I don't care who are subscribers. For example, on top dialog there are multiply tabs and few of them shows current stage position (directly or inside of subpanel). Main vi and according subpanel vi's (=async launched task) catch event.


Since you keep mentioning subpanels, have you looked at using the MGI Panel Manager library. This solve the issues you are running into.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 28 of 40
(474 Views)

I attached ppt file.

Stages.ctr contains all COM port parameters and it is reasonable to keep ComPortReadTask.vi reference there. (two red narrows)

0 Kudos
Message 29 of 40
(469 Views)

Are you communicating with a single device from two parallel paths of execution? I would imagine that this will cause you issues at some point unless you have lots of synchronization going on.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 30 of 40
(464 Views)