LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event structure impact in While Loop

I'm trying to understand the logic behind this. As you can see below, in main while loop I'm generating two random numbers

event_structure_while_loop.png

1. Display number 1 is controlled by Event structure (which if user press the Start button then it should generate the random number)
2. Display number 2 is freely (without any control or event structure)

Question:
1. When I'm running this VI, if I pressed Start button, I can see the Display Number1 get updated (this is expected because the case structure is TRUE when pressed). But my main question is that why Display Number2 also only get updated after I pressed the Start button? Supposedly Display Number2 don't have any dependency on Start button. Am I missed anything here?

2. How can i make Display Number1 always get updated continuously after pressed the Start button? Now it looks like it only get updated once after I'm pressing the Start button

0 Kudos
Message 1 of 7
(241 Views)

 add a timeout case into your event structure. set the timeout to 999. This should give you your desired behaviour. 


Otherwise your event structure doesn't 'return' without a recieved event.

 

 

0 Kudos
Message 2 of 7
(230 Views)

A structure cannot finish until all components are finished. In this case the While loop cannot iterate until the Event structure is finished ...

Connect a timeout value and place your random number and indicator in that event case (the timeout event in the same structure, not another event case, that'd be even worse).

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

Qestit Systems
Certified-LabVIEW-Developer
Message 3 of 7
(205 Views)

@Yamaeda wrote:

A structure cannot finish until all components are finished.


Except a flat sequence structure 😈 (that you shouldn't use (much) anyway).

Flat Sequence Structure.gif

0 Kudos
Message 4 of 7
(194 Views)

As a silly alternative to adding a time out, you could simply remove the event structure.

 

You're mixing two idioms:

+ pollling a value

+ event driver development

 

They don't mix (well).

 

Removing the event structure you'd be polling (which is typically undesired, but sometimes what you want\need).

 

Adding a time out you're still polling. You'd also have to store the start button's state somewhere. The time out will return a default Boolean (false) by default. You'd have to put a local of start in the TO, or store the start value in a shift register. But this would be a Rube Goldberg polling mechanism. 

 

To suggest what's best, we'd obviously need to know all your exact requirements.

0 Kudos
Message 5 of 7
(191 Views)

I'm trying to replicate issue that I'm faced in my producer consumer design pattern.

As a background, I'm trying to pass some data from my producer (which is data acquisition, command etc.) loop to consumer loop.
And I noticed that the data only get updated to consumer loop once if i pressed the button. My expectation is that once I press the Start button, the producer should keep continuously generating the data and passing to the consumer loop for further processing. 

Initially, I think that i cannot remove the event structure because this will be used to handle event from user (e.g start, stop)

 

Attach is my vi. Let me know if you've any feedback on this. Thanks!

 

 

0 Kudos
Message 6 of 7
(172 Views)

@fazlilut wrote:

As a background, I'm trying to pass some data from my producer (which is data acquisition, command etc.) loop to consumer loop.
And I noticed that the data only get updated to consumer loop once if i pressed the button. My expectation is that once I press the Start button, the producer should keep continuously generating the data and passing to the consumer loop for further processing. 


The event structure works as explains. It waits for events. If TO is an event, that won't stall execution. It might still not work as expected, a TO used that way isn't a reliable timing source (e.g. if you do trigger an event the timing will be less that the TO.

 


@fazlilut wrote:

Initially, I think that i cannot remove the event structure because this will be used to handle event from user (e.g start, stop)


But your event structure doesn't handle events at all.

 

It waits for events, and depending on a Boolean output, handles the event outside the event structure.

 

The way you're using the event structure is not only helping (handle event stuff in the structure), it's actually hurting (because it's stalling).

 


@fazlilut wrote:

Attach is my vi. Let me know if you've any feedback on this. Thanks!


You'd do yourself a favor by sticking to left to right programming. I know it's probably just a WIP, but it is harder to see what's going on.

0 Kudos
Message 7 of 7
(164 Views)