From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

Produce\Consurmer, While loop and Queues -Timing schedule clarification

Hello,

I'm trying to build an application that collects data and uploads a plot.

Originally the application was monolithic but than I decided to convert it into a Producer\Consumer application.

The timing constrains are not strict: an uploat of a plot could be required at most every 200ms.

I have splitted the diagrams and placed the plotting part within another while (the consumer). The consumer while is set as an infinite cycle, no timing is applied. Data from producer to consumer is passed through a queue and it seems to work fine (I mean, data is passed correctly and with the right timing).

 

My question regards the while loop of the Consumer. Since I havn't used any "wait # ms" block inside this while, it should run at the highest speed possible but when I connected an indicator to the iteration number, it increased only at the speed the while was receiving the data through the queue.

Than I placed a "wait 10 ms" inside the while but still the indicator was increasing at the speed of the receiving data.

So, what am I getting wrong here? How is the while supposed to be scheduled? Is the dequeueing operation blocking?

 

I am asking because inside the consumer I would like to be sensitive also to some actions the user can take and even without incoming data the graphs have to be updated. That's why I need the consumer to run at higher speed than the incoming data, to do some polling on the GUI inputs. Should I create another while that runs in parallel at higher speed and collects the user interface inputs?

 

I am running labview 2009 Base version (without the event structure).

Please consider that this is my third day of Labview overall, and only today I discovered the parallel programming.

I am thus forced to guess most of the things: on monday I the program must be working and I haven't access to labview for the whole weekend (I'm kinda of worried by that but if I could clear my mind about some concepts I think I could do it). That's also why I'm mostly asking through words and not by attaching VIs or screens, sorry for that.

 

Thanks for any help and best regards!

 

Dario.

0 Kudos
Message 1 of 10
(3,029 Views)

Any loop that has a dequeue in will only run as fast as the data arrives unless you put a timeout on the dequeue. I generally don't like to place timeouts on the dequeue since that is effectively creating a polling loop. What you probably want to do is to use a queued message handler in the consumer. When a data message arrives from the procuder you can update the display. You would then need to post a message to yourself to do whatever other work you want to achieve. You could use a Wait if you want to control the timing and how often you perform you other work. I would look at examples or search the forums for exampls of queued message handlers (also called queued stata machines).



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
0 Kudos
Message 2 of 10
(3,021 Views)

Well without an Event structure you are going to be reduced to polling the GUI.  You should not use your data processing loop to manage the user interaction.  A third loop dedicated to interacting with user input and directing commands to the consumer loop is the better architecture in this case.

 

LabVIEW 2012 ships with a similar project template (Continuous Measurement and logging) to accomplish a task like you describe.  You would need to replace the event loop with polling on the user controls.  If you can get your hands on a copy of 2012 (Even an eval copy) the help in this sample project would be a great place to learn more about the code than a snippet will show

 

Main_BD.png


"Should be" isn't "Is" -Jay
0 Kudos
Message 3 of 10
(3,016 Views)

I have heard that an event structure can be used in the base version if they are given a VI with it already there. They cannot create one but they can use one. I have never tried this since I have never had just the base version. This might work for him.

 

 



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
0 Kudos
Message 4 of 10
(3,009 Views)

@Mark_Yedinak wrote:

I have heard that an event structure can be used in the base version if they are given a VI with it already there. They cannot create one but they can use one. I have never tried this since I have never had just the base version. This might work for him.

 

 


That might not be exactly kosher.  NI does like to get paid for their products.  We'll see for sure, if that post gets a huge edit.


"Should be" isn't "Is" -Jay
Message 5 of 10
(3,001 Views)

@JÞB wrote:

@Mark_Yedinak wrote:

I have heard that an event structure can be used in the base version if they are given a VI with it already there. They cannot create one but they can use one. I have never tried this since I have never had just the base version. This might work for him.

 

 


That might not be exactly kosher.  NI does like to get paid for their products.  We'll see for sure, if that post gets a huge edit.


I can understand that. However they may not be as concerned now that the event structure is included in all versions. Point taken though.



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
0 Kudos
Message 6 of 10
(2,997 Views)

Thank you very much for both the quick answers!

 

Unfortunately I won't have the opportunity of installing labview 2012.

 

In few words both of you suggest of using Queued State Machines (Yah, it's really a scaring name XD)

The snapshot seems to confirm that example is some sort of QSM.

 

Let me first ask a quick question. If the consumer is reached by two different asinchronous queues, how is then scheduled the related while?

 

@Mark Yes, I successfully opened a vi containing an event structure (downloaded by the NI site). Suprisingly Labview wasn't complaining when I tried to run it, even though I was aware that the event structure was not included in that version. Only later I realized that it was not possible to modify the different states of the event structure. Anyhow, I couldn't check properly whether it worked or not but I somewhat tried on the fly and it seemed not.

0 Kudos
Message 7 of 10
(2,992 Views)

Hello again,

I pretty much got the meaning of a QSM. The states are properly spread to the other processes with a Queue and an high frequency 10ms. The other processes are provided with a IDLE state where they rest the most of the time. When an event occurs (both an incoming of the data or a user interface event) the main FSM change their state and data is processed. But then, how is data shared? With another queue or along with the states? And again my question above, if the consumer is reached by two different asinchronous queues, how is then scheduled the related while?

 

Thanks and best regards.

0 Kudos
Message 8 of 10
(2,929 Views)

Knyquist wrote:if the consumer is reached by two different asinchronous queues, how is then scheduled the related while?

Your consumer loop should only have 1 queue.  You can enqueue your data from multiple locations.  Then it is a first-come-first-serve of what will get processed.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 10
(2,917 Views)

Oh!

Thank you very much!

I got it!

0 Kudos
Message 10 of 10
(2,912 Views)