LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Notifying the end of an Asynchronous call

Solved!
Go to solution

Hello everyone,

 

I am using in my main VI an asynchronous call to a subVI. 

The main VI works as a state machine.

I would like to be able to change the state when the asynchronous call has ended.

How could I do that ? 

I am considering using a "select" logic block and the ending of the asynchronous call would change the value of the boolean entry of the "select", but I don't know how to do that exactly.

Best,

Jeremie

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

Hi Jeremie,

 

you can use any kind of data transfer that is suited for parallel running loops!

 

Your ASync VI can set a global variable, use a notifier or a queue to transfer data to your statemachine.

You could call WaitOnASyncCall in a parallel loop and also send a flag to your statemachine…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 12
(4,275 Views)

Thank you for your answer.

 

Could you further detail the use of a notifier in that case ? 

 

I am having a hard time programming this (beginner with LabVIEW).

Should the "send notification" be placed in the subVI and the "get Notifier status" in the main VI ? 

 

Best,

Jeremie

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

Hi Jeremie,

 

Should the "send notification" be placed in the subVI and the "get Notifier status" in the main VI ? 

Yes.

 

I am having a hard time programming this (beginner with LabVIEW).

LabVIEW comes with a huge library of example VIs. There are also examples explaining the usage of notifiers…

We all started as beginners in LabVIEW. And we all had to learn it's usage and features. So use the help and the examples provided by NI!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 12
(4,251 Views)
 wrote:

 

I am having a hard time programming this (beginner with LabVIEW).

 

Are you sure you're not overdoing something with asynchronous call? While I'm not forbiding anyone on any level to use any features they like, the mix of "asynchronous call" and "beginner" looks to me like you might have completely different problem than you've described. Can you give a little bit more context or even a code fragment?

 

(I also think that, depending on the context, there might be more straightforward way to do it than using notifier).

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

@GerdW wrote:

 

Your ASync VI can set a global variable, use a notifier or a queue to transfer data to your statemachine.

You could call WaitOnASyncCall in a parallel loop and also send a flag to your statemachine…


Or use VI Server to poll the VI state. Or set a control reference input when you start the VI, and when it's done make it send a value signaling event. The main would be able to catch that even in an event structure.

 

Best to avoid this when possible... But it often cannot be avoided. We need more details...

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

Thank you for all your answers.

I'll try to find similar examples with the NI help.

I haven't implemented the asynchronous call yet, therefore sending you the code would not be helpful.

 

My main VI features a state machine, with a case structure and shift register.

 

I know how to switch from one state to another.

But in the second state of the state machine, I want to stay in that state UNTIL some parameter is calculated and only then switch to the third state. This calculation is done by a Matlab script in a subVI and takes around 5 seconds to execute. That is why I want to use an asynchronous call to continue doing what I was doing in my main VI and to wait for the calculation to execute. 

 

Therefore I would like to have something like a boolean, which is false while the subVI is executing and turns TRUE when the subVI has finished its execution.

 

I will look into the help and the examples, but if you have a straightforward idea or a smarter way to do it, I welcome your thoughts on this.

 

Best regards,

 

Jeremie 

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

@Jeremie_technion wrote:

 

I know how to switch from one state to another.

But in the second state of the state machine, I want to stay in that state UNTIL some parameter is calculated and only then switch to the third state. This calculation is done by a Matlab script in a subVI and takes around 5 seconds to execute. That is why I want to use an asynchronous call to continue doing what I was doing in my main VI and to wait for the calculation to execute. 

 


If you want to wait for the result, you need a sub VI! Async is actually only useful if you don't want to wait, e.g. continue in parallel. Starting a VI async and then wait for it is what a sub VI does.

0 Kudos
Message 8 of 12
(4,219 Views)

@Jeremie_technion wrote:

I will look into the help and the examples, but if you have a straightforward idea or a smarter way to do it, I welcome your thoughts on this.


A producer\consumer will also work for this. Your SM is the producer. Your process is the consumer. The SM starts the producer through a queue. The producer could be a loop in the main, or a sub VI running in parallel. Either way, it can signal it's state though a normal indicator or an indicator reference. It's more or less the same as a dynamic VI, but is maybe a bit easier to understand. If you plan on adding a lot of these (different) processes, dynamic VI's start to look better. You don't want to keep adding parallel loops in your main.

0 Kudos
Message 9 of 12
(4,216 Views)

@Jeremie_technion wrote:

My main VI features a state machine, with a case structure and shift register.  I know how to switch from one state to another.  But in the second state of the state machine, I want to stay in that state UNTIL some parameter is calculated and only then switch to the third state. This calculation is done by a Matlab script in a subVI and takes around 5 seconds to execute. That is why I want to use an asynchronous call to continue doing what I was doing in my main VI and to wait for the calculation to execute. 

 

 

  


Jeremie,

     You say two (slightly) contradictory things here.  You want to stay in a state until some parameter is calculated, and then switch states, yet you want to "continue doing what I was doing in my main VI and wait for the calculation to execute".  I agree with Wiebe that the simplest way to wait until the subVI is finished is to simply put the sub-VI in State 2 as a synchronous (i.e. "normal") call, and the rules of Data Flow will mean that State won't finish until the sub-VI returns.  This will "block" the State Machine, but any other parallel process in your code will continue to run.

     So the question comes, what are you wanting to "continue to do" in your main VI that doesn't involve the State Machine (which is waiting for your Matlab calculation to move to State 3)?

 

Bob Schor

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