LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use "Start synchronous Call" to run a subVi and keep timeout event in Main vi still running?

Solved!
Go to solution

Hi, All

 

I have a application need periodically check an instrument status and I put it in the "Timeout Event" in main vi. I also need call some subVis for configuration etc. Somehow when I called those subvi, the Timeout event in my main vi was not running. Then I use " Start Asynchronous Call" function to call the subVis. Turns out it works fine with some subvis without return value, but not as expected with "return value-needed" subvis. 

 

I attached a simple test, my main vi call two dlg subvis: AboutDlg.vi and SettingsDlg.vi. In the timeout event, I just use a counter for simulation. When you run it, you can see the counter keep counting when the AboutDlg.vi was called, but stopped when SettingsDlg.vi was called. 

 

As I remembered, someone suggested to use Queue to pass return value, but I don't know how to implement it here. 

 

Anyone has any suggestions about it? 

 

Thank you very much. 

 

 


CQ
0 Kudos
Message 1 of 7
(3,028 Views)
Solution
Accepted by topic author CQ_Li

Try playing with this - I have modified  your code to poke a Q in there.

You will want to change the clusters to more useful datatypes (maybe enum and variant so you can unbundle variants depending on enum input), you will want to type def the clusters to make it easier to maintain and you will NEED to handle the sitaution where the called VI is left open on program close - i couldn't be bothered as this was not your immediate issue)

 

Hope this give you some Ideas - totalyy untested but should work.

 

James

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
Message 2 of 7
(2,993 Views)

Thank you very much! it works


CQ
0 Kudos
Message 3 of 7
(2,977 Views)

Here I added some code with checking the Dlg vi exec.state. 

In "Stop" event, close the Refs of each Dlg. 

Untitled.png


CQ
0 Kudos
Message 4 of 7
(2,938 Views)
Closing the references is not going to stop the vis running if the front panel is not being displayed. You need to check the vi execution state and cause it to stop when the main vi that called it closes otherwise you will end up with a memory leak and funny behavior.
James
CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
0 Kudos
Message 5 of 7
(2,919 Views)

Thanks, James

 

Will "Abort Vi" work? Here I check the Exec.state and use "Abort VI" to stop the Dlgs. 

 

another question: which Labview tool helps to check the memory leak? 

 

regards

 

CQ

 

Untitled.png


CQ
0 Kudos
Message 6 of 7
(2,913 Views)

Yes it will - this is the same as pressing the Abort button on the front panel so it is not a recommended technique as it could leave any H/W controlled by the VI in an undefined state and is not good programming practice.

 

(Personally I would use this only on VIs which have the state "Running" at the end of the main VI as a secondary stopping technique. the Primary technique I would use would be to set the value of a Control (Invoke node) for the VI and then name the control and pass in the value by variant. - This allows you to press the subVI STOP button from the calling VI!)

 

James

 

(You are doing very well so far picking up lots of complex architechtural stuff very quickly - it took me years to find all these techniques.)

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
Message 7 of 7
(2,876 Views)