LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Asynchronous call not working correct

Solved!
Go to solution

Hello everyone.

 

Iam trying to call a SubVi asynchronously but something is not working correctly.

As soon as I call the sub Vi, the Main Vi is stuck....

 

Attached you find an image of my Main vi.

 

Thanks in advance for any help or comment,

 

best regards,

 

Michael

0 Kudos
Message 1 of 12
(4,532 Views)

Well, the "collect" half of the call and collect will wait until the SubVI is finished. Is the SubVI hung up? I might add, if you are calling and collecting in the same state of the same structure, why use an asynch at all? 

 

Another possibility other than the SubVI being hung up is that you could potentially be waiting on the collect before the call is even made. I am not sure the behavior of that scenario, so that might not be an issue. 


Corey Rotunno

0 Kudos
Message 2 of 12
(4,484 Views)

Hi Corey.

 

The SubVi is running just fine. 

I thought I have to use an asyn call in Labview to start a SubVi in parallel, but maybe that is not the case?

 

Best regards,

 

Michael

0 Kudos
Message 3 of 12
(4,476 Views)

So, asynch calls can be used to run things in parellel, yes. Typically you start the asynchronous VI and move on. Later on you might come back and wait for some results from the asynchronous VI, sometimes you might just let it do its own thing.

 

What you are doing is starting the VI, and then waiting for it to finish to give you results back. So if your SubVI is still running, your main VI is going to be held up waiting for the SubVI to finish. In that way you really aren't allowing it to run in parallel. If you start it, then immediatly wait for it to finish to get a result back then you are really running it in series. If you need to do communication between two parellel loops while the SubVI is actually running that will call for a different method, although you are on the right track.

 

Typically when I use asynchronous calls I use a "call and forget" which means I start it and then let it do its own thing. This is how I normally start my hardware reads. I start the hardware reader async and let it populate a buffer queue while my main VI moves on and does other stuff.


Corey Rotunno

Message 4 of 12
(4,465 Views)

@Corey.Rotunno wrote:

Typically when I use asynchronous calls I use a "call and forget" which means I start it and then let it do its own thing. This is how I normally start my hardware reads. I start the hardware reader async and let it populate a buffer queue while my main VI moves on and does other stuff.


So far, "call and forget" has been 100% of my asynch call useage.  If I need to return data from that call to my main application I will just register a user event with my return data.  It is much simpler in my opinion and doesn't require that you either freeze your application with a wait, or require you to poll to see if you have completed execution.

0 Kudos
Message 5 of 12
(4,452 Views)

Thanks for sharing...

I would like to use the SubVi to update settings used in my main program during data aqcuisition.

 

You named that there is a different method... Is there a name for that?

 

Regards,

 

Michael

0 Kudos
Message 6 of 12
(4,446 Views)

Yea, "call and forget". The way that Bowen described above is perfect actually. Put your new data (settings) into the data of a user defined event which you then handle in your main VI.

 

To be honest, without knowing your application it seems like an overly complicated way of moving in a couple values every now and then. But who am I to say?

 

In the example below, the VI's on the left with the green arrows all start VI's asynch. Then I pass small amounts of data to the main panel in the event structure. I think this is called the "event driven state machine" type of architecture or something like that.

AsynchCalls.JPG

 

 


Corey Rotunno

0 Kudos
Message 7 of 12
(4,442 Views)

Thanks...

That seems like a nice way...

 

When I call the SubVi by reference and set the "wait until done" property to false it also seems to work... 

But in that case I have no clue how to get data from my subVi

 

Regards,

 

Michael

0 Kudos
Message 8 of 12
(4,431 Views)
Solution
Accepted by topic author ´MikeSv

End of the day and I'm tired of my real work... so I threw together an example of how I handle asynch calls.  In this case, I set it up as if it was an asynch GUI.  

 

If the subvi is closed, it will open and run it. Once that subvi finishes execution it will return the data through the user event. If the GUI is open, clicking the button again will bring it to foremost.  You can of course modify this to handle the data however you want.

Download All
0 Kudos
Message 9 of 12
(4,405 Views)

That is great!!!!

Thank you so much for this...

 

Best regards,

 

Michael

0 Kudos
Message 10 of 12
(4,385 Views)