LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to execute a case statement only once when a sub VI is called

HI,

 

the issue I am having is that I have a large "Main" VI which contains several "Sub" VI's all of which are called in certain situations. In some of the "sub" VI's I want to write to a common Excel file. What I find is happening is that everytime I call one of the Sub VI's it writes tot he excel file. This is not what I want to happen.

 

What I would like to happen is that when a "button" is pressed on the front panel the sub VI will then write tot he excel file once. I can then call the VI as many times as I want and it will not write to the VI again until I press the button again.

 

I have attached an example of one of the VI's I use and the issue occurs in.

You will see in stack "1" in the bottom right of the block diagram I am trying to set 2 indicators called "stamped in" and Stamped out" to true (ON) when the control "Stamp IN" or "stamped out" is pressed. what happens however is that if the button was pressed once and I reenter the VI it re-writes to the excel file.

 

I have tried several senarios, like registers etc but none seem to work. I have also tried numerous different button mechanisms and again this does not seem to fix the issue.

 

can anyone help?

 

thanks in advance.

 

Seamus

 

0 Kudos
Message 1 of 5
(3,421 Views)

Use Event-structure. When button is pressed, save file. If timeout, check and update as is currently done. (you can probably extract more events cleaning up the final timeout-case.

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 5
(3,410 Views)

Dear SOC,

First, you need to attach the .lvproj file which should contain all the subVIs in it.
Second, have you tried using Event Structure to trigger a process whenever an event occurs ( in your case a button pressed is an event )? 

Regards.


0 Kudos
Message 3 of 5
(3,406 Views)

Are you sure you have the right mechanical action for those buttons?  You have them set to "Switch until Released" which I find to be a very uncommon button action.  Your code may read the state of the button press, once, many times, or even not at all depending on when you press and release the button, where it is in the loop execution, and how long it takes for the loop to execute.

 

Typical mechanical action for a button you want to make sure is read once is "Latch Until Released".  Once the button is read, it will pop back up to its default state.

 

PS.  Correct spelling is "Technician",  no extra "h".

0 Kudos
Message 4 of 5
(3,401 Views)

Put a while loop in your main VI.  Then put the subVI within a case structure, and "trigger" it using a button.  When the button is pressed (True), it fires the code in the case structure.

 

Also, your code is kind of messy and hard to read (trying to be polite here).  Maybe try using a simple state machine architecture.  If you have a newer version of LV, you can use the template provided with LabVIEW.  Here is another example:

 

http://zone.ni.com/devzone/cda/epd/p/id/1959

 

 

http://www.medicollector.com
Message 5 of 5
(3,400 Views)