08-10-2020 08:53 AM
I have a VI with a while loop which constantly checks and updates values in the VI. In the loop I have an event structure that executes when the "update" button is pressed, which performs some calculations which is returned to the wire, "Errors," which is highlighted in yellow:
I noticed that once the "timeout" event is executed after "Update value change", the data is lost and when the loop exits, the "Errors" wire is reverted to all 0. To my knowledge, there isn't a shift register for case structures. How can this data be saved after the "timeout" event executes?
Solved! Go to Solution.
08-10-2020 08:56 AM
Shift register on your loop and wire through all event cases.
08-10-2020 09:00 AM
Ah, thank you!
08-10-2020 09:01 AM
Hi dan,
@danthecoffeecan wrote:
I noticed that once the "timeout" event is executed after "Update value change", the data is lost and when the loop exits, the "Errors" wire is reverted to all 0.
THINK DATAFLOW: you set those tunnels to "default if unwired"!
@danthecoffeecan wrote:
To my knowledge, there isn't a shift register for case structures.
But for loops. Like this WHILE loop…
08-10-2020 09:33 AM
@GerdW wrote:
Hi dan,
<snip>
<snip>
THINK DATAFLOW: you set those tunnels to "default if unwired"!
Warning: Pet Peeve ahead!
I HATE that the event structure default tunnel is "default if unwired". It's an unnecessary point of failure. I can only think of one possible reason you would want this, and that's so you can be lazy and use that for your loop exit - e.g., "Exit" Boolean default to FALSE, you only need to wire a TRUE constant to the event (or events) that are supposed to exit the loop after executing. IMO, anything else being "default if unwired" is asking for trouble of the subtlest (and therefore hard to find) kind. Having it this way for one use case is not the best strategy. I'd much rather the default behavior being an "open" tunnel like all the other structures. (This wasn't always the case, but that's a story for another topic.)
08-10-2020 09:36 AM
It looks like you got your reply, but I have one observation. From what you posted there does not appear to be any code inside the timeout case. If there is not code in the timeout case then you should get rid of the timeout completely.
08-12-2020 08:02 AM
Without the timeout, the VI gets stuck at the event structure if the button isn't pressed. The solution I implemented was to use a shift register on the while loop with the "max errors" wire going straight through the timeout event with a 10ms timeout.
08-12-2020 08:45 AM
Are you running other code in the same loop as your event structure? Is that what you mean by getting stuck? An event structure is normally the only code in a loop.
08-13-2020 01:20 PM
@billko wrote:
@GerdW wrote:
Hi dan,
<snip>
<snip>
THINK DATAFLOW: you set those tunnels to "default if unwired"!Warning: Pet Peeve ahead!
I HATE that the event structure default tunnel is "default if unwired". It's an unnecessary point of failure. I can only think of one possible reason you would want this, and that's so you can be lazy and use that for your loop exit - e.g., "Exit" Boolean default to FALSE, you only need to wire a TRUE constant to the event (or events) that are supposed to exit the loop after executing. IMO, anything else being "default if unwired" is asking for trouble of the subtlest (and therefore hard to find) kind. Having it this way for one use case is not the best strategy. I'd much rather the default behavior being an "open" tunnel like all the other structures. (This wasn't always the case, but that's a story for another topic.)
For those who haven't seen it, there's an Idea Exchange to change this:
Output tunnels from event structure should default to NOT "Use Default if Unwired"
Loosely related Idea Exchange posts