LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Pause execution of a Vi

Solved!
Go to solution

Hello,

 

I'm trying to do an aplication with two main Vi's. The first Vi is the responsible of the configuration of different instruments. On the other hand, the second Vi is the responsible of doing different measurements of an electronic circuit. 

 

My problem is that I want to pause the first Vi when the configurations have been done and then go to the second Vi and do the measurements. When the measurements have been done, the execution should return to the first Vi and continues since the point where the program have been paused. 

 

I'm trying to solve this with queues and a while loop to pause the execution, but it doesn't work properly. 

 

In the following image I have attached the while loop. This loop communicates with the second Vi to check if the measurements have been finished or not. But it doesn't work properly and I don't know why. My question is: is this method good to solve this problem or there are other method better than this? Or simply, the pause execution of a Vi can't be done.

 

Sin título.png

 

Any help is appreciated.

 

Thank you.

0 Kudos
Message 1 of 9
(6,069 Views)

Usually to make a program appear to pause (it's still running, just in an IDLE state) and wait to some event or a task to complete before continuing on we use a State Machine architecture.  Just search for that term to get some background.  There is also a state-machine template available with LabVIEW for convenience but I suggest you roll your own so you understand how to build them.  They're VERY useful. Smiley Wink

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019
0 Kudos
Message 2 of 9
(6,058 Views)

Like the other poster said, the easiest implementation is probably going to be a state machine with shift registers reserved to pass data between the configuration and measurement states.

 

States:

Initialization

Configuration

Measurement (and likely logging)

Shutdown

 

You can loop between config and measurement until you're ready to shutdown.  You can use the first and last states to get your state machine running smoothly and shutting down cleanly.

 

It looks like you've started the general idea of the Queued Message Handler in your code.  If that's a route you're interested in, you should google that term.  Both architectures are suitable to your task and have a template in the "New" dialog found in the File Menu.

 

Something to keep in mind, you're liking looking to run a single VI with parallel loops.  If you want to abstract to a second VI, you're probably better using a subVI instead of trying to use two VIs.  The main VI could configure the data and pass inputs to the subVI.  The subVI handles the measurements and passes the results back to the main VI.  If this logic is held within a while loop, the main VI will wait until the subVI is complete before it regains control.

 

Basically, there's lots of ways to perform the task you're looking at.  It's up to you to determine which you believe is best for your situation.

Message 3 of 9
(6,033 Views)

Don't continually obtain a queue in a loop.  When you include the fact you never release that queue reference, you are going to burn up your memory with endless queue creation.  Using Flush Queue doesn't make sense either.  And having a True/False case structure to output a boolean true (and I'm guessing a boolean false constant in the other case) is a Rube Goldberg.  Just wire the ouput of the equals comparison to the stop terminal and get rid of the case structure.

0 Kudos
Message 4 of 9
(6,016 Views)

Thank you very much, your answers are very useful for me. I have understand that the state machine is the best method to perform the task proposed. But I have a problem, if I decided to do this in two differents Vi is for problems of space. I think that I can't do this in only one Vi. Is possible to have two front panels from one same Vi?

 

I'm going to attach two images from the front panels of the Vis for you can understand my problem. 

 

In this first image I have attached the front panel of the Vi that takes care of the configuration of the instruments. The table are the values of the configurations, and each row means a different iteration. As you can see the number of rows can be configured ( sorry is in Spanish in the image), and this means that the space can be larger than this. 

 

1.png

 

In this second image I have attached the front panel of the VI that takes care of the measurements. The table should be written while the measurements are performed. Each row of this table corresponds to the iteration of the row of the first configuration table. Then, the number of rows should be the same of the number of rows of the table of configurations. 

 

2.png

 

As you can see, I need two different Vis to perform this automazation. I have read tutorials about the state machine and I also have looked the template that is very useful and understandable. However, I don't see that this method can be used in a communication between two different Vis. Certainly I'm very confused and now I don't know that I have to do. 

 

Sorry because the first question was how pause the execution of a program (idle state) and now I'm adding these questions and the need of two different Vis.

 

Thank you for your attention! If you have any idea I will be very glad that you help me.

0 Kudos
Message 5 of 9
(5,990 Views)

If I have two VIs running in parallel and I wish to have one wait until the other's complete before it carries out some code, I would probably use notifiers with 'Wait on Notification' or one of the other Wait types.

 

However, if you're having to compromise on your architecture because you have to have two separate front panels, then you've probably not explored options with your UI. Two relatively simple options are subpanels and tab controls.

---
CLA
0 Kudos
Message 6 of 9
(5,977 Views)
Solution
Accepted by topic author luisi

@luisi wrote:

Thank you very much, your answers are very useful for me. I have understand that the state machine is the best method to perform the task proposed. But I have a problem, if I decided to do this in two differents Vi is for problems of space. I think that I can't do this in only one Vi. Is possible to have two front panels from one same Vi?

 

I'm going to attach two images from the front panels of the Vis for you can understand my problem. 

 

In this first image I have attached the front panel of the Vi that takes care of the configuration of the instruments. The table are the values of the configurations, and each row means a different iteration. As you can see the number of rows can be configured ( sorry is in Spanish in the image), and this means that the space can be larger than this. 

 

As you can see, I need two different Vis to perform this automazation. I have read tutorials about the state machine and I also have looked the template that is very useful and understandable. However, I don't see that this method can be used in a communication between two different Vis. Certainly I'm very confused and now I don't know that I have to do. 

 

Sorry because the first question was how pause the execution of a program (idle state) and now I'm adding these questions and the need of two different Vis.

 

Thank you for your attention! If you have any idea I will be very glad that you help me.


There are several solutions to this. If you have a main executable (state machine) it can pop up the settings-window (your first picture) and send out the settings as an output (or make the settings the main state machine and hide itself while the other is running). The main VI then pops up the measurement window which uses the settings as input. Once the measurement is done, you Save file and return to Settings. 

As a note you'll probably need alot more than 3 VI's, to get a well structured and modular program i'm guessing at 50, luckily it's dead easy to do. 🙂

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 7 of 9
(5,963 Views)

You can handle those configs by using a 2D array or an array of clusters.  Then, each element is a different device.  This lets you configure the devices without leaving the entire thing on your FP at all times.  You generally want to avoid having two FPs.  One User Interface makes more sense than expecting the user to use multiple UIs.

 

If you want to run the config once before each run, you should look at CSV or INI files.  Use one VI to write to a shared CSV/INI file.  Use the second to read from it and go.

0 Kudos
Message 8 of 9
(5,939 Views)

As you say, there are several manners to solve this problem. Finally, I decided to do a state machine with different states, that each do a specific functionality. Fortunately, I have achieved that it works.

 

I wanna thank you for your answers that have been really useful for me. 

Message 9 of 9
(5,778 Views)