LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to get 2 SubVI's to work one at a time

Solved!
Go to solution

Hello All,

 

I have a question about running two different SubVI’s in my program, one at a time.

 

Both SubVI’s are for the user to input information. I am working with the NI cDAQ-9178 and the NI 9214. I wanted to open the first SubVI, titled ”Input Parameters(SubVI).vi” and have it close, when I click “OK”. Second, I wanted to have the SubVI, titled “RemoveWhiteSpaceArrays_DAQchannel.vi” open and close when I click “OK” and finally I wanted to have the Main VI Temperature Measurments_rev1.vi” to take the temperature measurement and close.

 

I had this working with the “RemoveWhiteSpaceArrays_DAQchannel.vi” and the “Temperature Measurments_rev1.vi”  … but after I added the “Input Parameters(SubVI).vi” both SubVI are opening together and the Input Parameters(SubVI).vi” does not respond when I click "OK". How can I force one SubVI to open at a time? Also, is there a better method for forcing my windows to open and prompt the user to input information, before my main test begans?? I was unsuccessful with using a dialog box. Thanks

0 Kudos
Message 1 of 9
(3,738 Views)

Have you heard of the event structure?  It makes making dialogs much much easier.  The UI is just idle until an action is taken taht you make.  So when the user clicks OK you can read the values from the controls and do stuff, but you don't do anything else until that happens.  

 

As for the order it looks like the way it is coded running Temperature Measurments_rev1.vi will run RemoveWhitespaceArrays_DAQchannels.vi, then one of the first things it does is run Input Parameters(SubVI).vi.  When the user confirms the settings in that VI it returns to RemoveWhitespaceArrays_DAQchannels.vi where it will wait for the user to confirm the settings and then return to Temperature Measurments_rev1.vi.  Of course RemoveWhitespaceArrays_DAQchannels.vi isn't set to be shown when called so I'm not sure how you would do this at all.

 

Could you explain what you actually want.  I see about 40 property nodes that I'm guessing you don't need but I'm not quite sure what their supposed to be doing for you.  I think I see the purpose of them, but a better design might be to put into a tab all the controls for a set of questions, then go to the next tab when they click OK or Next, then they have more settings to enter, instead of trying to show and hide all these controls based on the mode.

 

You setup a sampling rate that the user specifies, but then you read one sample at a time in a timed loop for some reason.  This means you will only get one sample every 5s, if the user picks a rate faster than once a second.  If they pick one that is lower then it will be slower.  If they pick one that is faster then your hardware buffer will fillup and error out.

 

What's that sequence structure doing for you to?

 

If you really just want to prompt for settings, and then once the user clicks OK to start taking samples, this can be done in a simple state machine in one VI.

0 Kudos
Message 2 of 9
(3,728 Views)

Thanks for your input Hooovahh.

 

I know that my code is messy. My only excuse is that I'm new to LabVIEW. I was trying to have different windows open to ask the user for input and then close, when the user clicks the "OK" button. 

 

The order was to be the following:

1.  Window opens for user to input Name, Sample Rate, Min/Max temp, File Name/Location and Thermocouple Type .. close when click OK

2.  Window opens for user to input Number of Channels ... close when click OK

3.  Channels disapper and Table appears for user to enter DAQ Channel Number and Channel Name ... close when click OK

4.  Main VI take temperature measurements on specified channels and output to excel spreadsheet.

 

Believe it or not ... it was working, until I tried adding the SubVI stated in #1. So you're saying that Event Structure will accomplish this??

0 Kudos
Message 3 of 9
(3,709 Views)
Solution
Accepted by topic author mzlhb

Attached is the quick re-write which uses the event stucture and tab as I described before.  I can't say it will work exactly like you had but it should show several ways of doing the same thing.

 

Run the VI and it will have the first tab shown where you enter the user information.  Then click Next and it prompts for channel information.  Adding channels should work like before but based on events, so when you add or remove channels it adds and removes them as the control value changes.  Then clicking next again starts the DAQ and in the timeout case it will read data and graph it.

 

The state machine helps organize code as well, so I can have an init case, that could get re-called if you wanted to start over again which resets control values and goes back to the first tab.

 

You could also have a previous tab if you wanted, or an explore button to go to the file that was saved.

 

Oh and what about exit?  Notice how my version you just close the window and the VI stops running (like a normal program) this is because of the event structure.

 

You say you're new to LabVIEW so here are a few free links. (at the bottom)

 

https://decibel.ni.com/content/docs/DOC-40451

Message 4 of 9
(3,682 Views)

Thank you, Hooovahh. This is great!! One question ... in the Default Case of the case structure, what does the Running, 10 and -1 inputs to the Select Function do??

0 Kudos
Message 5 of 9
(3,570 Views)

The input to the event structure is the timeout.  If no event is generated in the specified amount of time, it will got to the timeout case.  When the DAQ task is not running, there is no need to ever go into the timeout case.  This can be achieved by wiring a -1 to the timeout.  But if the task is running we want to go into the timeout case once in a while, to read the DAQ data that is waiting in the buffer.  So if it is running, I put in a small amount of time that will check for new data.

 

An alternate and better design might be to register for a dynamic event, based on the DAQ task, which can be triggered whenever N samples have been acquired.  This design is a bit more complicated, and if you've never seen the event structure before, discussing dynamic events can be even more overwhelming. 

 

Many of these topics of event structures, timeout, and DAQ are covered in the free training links I mentioned earlier.

0 Kudos
Message 6 of 9
(3,545 Views)

I'm trying to incorporate your Event structure into my program. When I run your vi the start/stop buttons disappear and it runs continuously. How can I place a timer, so that it runs for a specific amount of time and then stops?? Thanks

0 Kudos
Message 7 of 9
(3,529 Views)

@mzlhb wrote:

When I run your vi the start/stop buttons disappear and it runs continuously. 


This is by design, do you see a stop button in Internet Explorer?  These are debug tools and should not be seen by the user of the software.

 


@mzlhb wrote:

How can I place a timer, so that it runs for a specific amount of time and then stops?? Thanks


The simplest is probably to use the Elapsed Timer express VI, which will return a True once, after an amount of time has gone by.  Use this to add a state to the state machine to exit after that amount of time has passed.  Another more scalable method is to store a timer value in the shift register and you can start it when you want, recording the start time, then subtract the current time periodcially (in the timeout) and when the value is greater than your set amount of time go to the exit case in the state machine in the same way.

Message 8 of 9
(3,519 Views)

Thanks for your help today, Hooovahh

0 Kudos
Message 9 of 9
(3,492 Views)