From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Code looping unintentionally in state

Hi Folks. 

 

In the attached VI the code in the "Save Data" state is getting implemented over and over in a loop, whereas it should only get executed only once and then go back to the "Wait for Start" state and wait for button press. When the program enters the "Save Data" state the data is written to the spreadsheet until I stop the program. Why is this happening and how do I stop it?

 

Thanks,

 

Mark.

0 Kudos
Message 1 of 8
(3,208 Views)

What is the default value for the enum that you have not included? (i.e. what value comes out of the timeout case of the inner event structure?)

0 Kudos
Message 2 of 8
(3,200 Views)

The timeout of the inner event structure is empty. Should it be populated?

0 Kudos
Message 3 of 8
(3,183 Views)

Yes, and the output tunnel for the state is unwired, meaning you get the default value of the state enum, which is "Save data". Thus this state executes whenever 100ms have passed and no otter event got triggered. What else do you expect?

 

Why is your diagram so big? I cannot effectively look at it on my laptop.

0 Kudos
Message 4 of 8
(3,159 Views)

Let me offer two tips that could help cleanup some code.

 

 

1.  The compound arithemetic node.  You can set it for AND mode, and expand it for as many inputs as necessary.  The you won't need all of the individual binary AND functions you have to combine multiple boolean values.  The AND Array Elements might also be useful.

 

2.  Index array automatically increments the indices as you go down the list.  So you don't need i-1, i, i+1, i+2, ...    Just wire the i-1 into the top terminal, then by default, each terminal below that will be the successive indices. Now you've eliminated a dozen other wires and half dozen math nodes.

0 Kudos
Message 5 of 8
(3,153 Views)

altenbach. I put the "wait for start" state in the timeout case which did the trick. Why is save "save data" the default when "wait for start" is set as default.

 

state.png

I know my diagram is large, apologies. I will start to reduce it. But when I make changes it just gets bigger.

0 Kudos
Message 6 of 8
(3,097 Views)

Ravensfan. Thanks for the tips. I will start tidying this up when I get everything working.

0 Kudos
Message 7 of 8
(3,095 Views)

The default case means 'use this case if none of the case values match the selector value'. However, the value from the wire DOES match a case- the save case. The default value returned from an unwired node is a totally separate concept from the default case. The default value from the node is the 'zero value'. I assume SAVE is the first enumerated value in your enum.

0 Kudos
Message 8 of 8
(3,070 Views)