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: 

how to implement this suggestion I was given

I was talking to a CLA who gave me the following suggestion:

1)      :  Don’t have any data intensive operations in the event loop, use a read controls and write controls state (or read FP data/write FP data) in the consumer to get FP/user data into your main shifter and always call these two states.  E.g. user hits a button that fires an event which enqueues the read FP controls state and the FP control data gets updated into the main shifter.  The consumer loop, as it is churning through the states, periodically calls write FP data, to update indicator values to the user.

 

However, right now I can't get ahold of him so I figured i'd see what you all had to say. 

 

I have a queued state machine (producer-consumer). My question is, I have my controls inside the event structure in the producer loop. I change a value of a control, which fires an event and queues up read fp data state in the consumer loop. How then, do I read this new value in the consumer loop like he suggests? Is my best bet in this case a functional global that holds a cluster of all controls? Bundle up the new value in the "set" case of the functional global (do this in the producer loop whe an event is fired), Then get the functional global data in the "read fp data state" in the consumer loop and feed it to a shift register to be read by all cases?

 

Thoughts?

0 Kudos
Message 1 of 6
(2,442 Views)
I like to use a typedefed cluster for my state data for the queued state machine. The typedef consists of a typedefed ENUM which is the next state. The cluster also contains a variant. Using this cluster you can pass any type of data between states or from the producer loop to the consumer loop. In your case your event structure could read the value of the control and then simply pass it as data in the state machine queue. You could define a cluster that that would contain the name of the control so that you will know which control you are working with and what the data is. This is one case where using a property node or a local variable would be acceptable.


Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 2 of 6
(2,435 Views)

for(imstuck) wrote:

I was talking to a CLA who gave me the following suggestion:

1)      :  Don’t have any data intensive operations in the event loop, use a read controls and write controls state (or read FP data/write FP data) in the consumer to get FP/user data into your main shifter and always call these two states.  E.g. user hits a button that fires an event which enqueues the read FP controls state and the FP control data gets updated into the main shifter.  The consumer loop, as it is churning through the states, periodically calls write FP data, to update indicator values to the user.

 

However, right now I can't get ahold of him so I figured i'd see what you all had to say. 

 

I have a queued state machine (producer-consumer). My question is, I have my controls inside the event structure in the producer loop. I change a value of a control, which fires an event and queues up read fp data state in the consumer loop. How then, do I read this new value in the consumer loop like he suggests? Is my best bet in this case a functional global that holds a cluster of all controls? Bundle up the new value in the "set" case of the functional global (do this in the producer loop whe an event is fired), Then get the functional global data in the "read fp data state" in the consumer loop and feed it to a shift register to be read by all cases?

 

Thoughts?


That sounds good to me.

 

One note...

 

Think about "where is the master copy of my data?". If using a FG, the master copy should be in the FG. Be careful with taking a copy out of teh FG and acting on it since once out of the FG, you could create a race condition.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 3 of 6
(2,418 Views)

Ben wrote:

 

One note...

 

Think about "where is the master copy of my data?". If using a FG, the master copy should be in the FG. Be careful with taking a copy out of teh FG and acting on it since once out of the FG, you could create a race condition.

 

Ben


I was just doing this Smiley Surprised Thanks!

0 Kudos
Message 4 of 6
(2,413 Views)
In a case like this, is it ok for the controls to be in the consumer loop rather than inside their respective cases in the event structure? Assuming of course, I set the correct mechanical action for booleans. Or is this a no-no in all situation?
0 Kudos
Message 5 of 6
(2,399 Views)

As an example of the approach Mark mentioned, you can look here.  Feel free to ignore the limericks.  Smiley Wink

 

I will often have my controls outside of their event case, and put them in my UI update loop (assuming that the UI requires regular updating of some of the front panel objects...since I do a lot of DAQ, this is often the case).  If the event structure needs to use the control value to perform an operation (as is usually the case), you can use the "NewVal" event data node to obtain the current value of the control.  Of course, as you already know, you have to set your Booleans appropriately.  My "stop" button is the one control that I ALWAYS have inside the event structure.

 

Message Edited by DianeS on 03-01-2010 11:43 AM
0 Kudos
Message 6 of 6
(2,392 Views)