LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Producer/Consumer Design Pattern + DAQmx + Event Structure

Highlighted

Dear community users,

 

at the moment I try to implement the Producer/Consumer Design Pattern into my current project. For this purpose I am trying to make a "minimal-example" in which I use the Producer/Consumer Design Pattern for the data acquisition and analysis (display in GraphXY, calculation etc..) process. In the Producer Loop I perform the data readings via DAQmxRead.VI and in the Consumer Loop, in this example only, I display the data in a GraphXY. At the same time I want to control the data acquisition via an Event Structure, for example Start Measurement/Stop Measurement Buttons. To configure the measurement time, for example if the user only wants to measure 150 sec, I use the Time Out Event of the Event Structure. This is a technique which is often used, when data acquisition and Event Structures are used at the same time (Excuse me if this is wrong!). Due to understand the Producer/Consumer Design Pattern I looked up in the Template\Framework of LabVIEW.

 

In the attachment you will find my "minimal-example", which -sadly-, not working. What should I do ? 

 

Thank you.

 

Best regards,

tugrul öztürk

0 Kudos
Message 1 of 5
(2,782 Views)
Highlighted

Hi Tugrul,

 

Unfortunately I don't have the DAQmx drivers installed (or the spare time) to go through and debug this code, but thought I would share a few general LabVIEW tips that might help you out and give you code that is easier to read.

 

1) Try to limit a block diagram to a single screen. I don't think yours is too bad, it's probably just the fact I'm looking at it on a little laptop.

2) I'm not quite sure why you're using a flat frame structure. From what I can see it isn't enforcing data flow so get rid of it! It's generally best to minimise use of flat frame structures. If I can find a way of not using them I will... which brings me nicely on to the third point...

3) Use the error terminals to enforce data flow! I see you have had a good attempt at this, but there are a few things you can improve:

3a) You use a merge errors function, which is good. But you are merging two lots of errors that could run consequtively and not sequentially. Get rid of the merge errors function and have the errors flow in sequence unless there is a need for things to execute simultaneously. Similarly in other places you have branched the errors into two separate paths when one would have been plenty.

3b) Use error in and error out clusters on everything other than your top VI. It's just good practice 🙂

 

Olly

 

**********************************************************************************************
The day is quickly coming when every knee will bow down to a silicon fist, and you will all beg your binary gods for mercy.
0 Kudos
Message 2 of 5
(2,768 Views)
Highlighted

Hello,

 

> In "Start : value change" event, the queue reference wire is not linked...you must link this wire.

> You should add a "OK : value change" event to exit application instead of reading the button at timeout (as you probably planned to do...but in fact, you do NOT read button state at timeout because the OK button is outside the while loop ! Do not forget data flow concept in LabVIEW).

 

 

0 Kudos
Message 3 of 5
(2,763 Views)
Highlighted

Your VI will never stop due to the Ok Button that stops the producer loop is read OUTSIDE of the loop.  Add an event case for it.

 

Move the Start and the Ok Button inside of their respective event cases.  This will allow the latch to reset when they are read.

 

Change the Ok Button to a stop button.

 

Use a Greater Or Equal instead of Equal for the measurement time comparison.  What if somebody randomly changes it to 0 on you?  Again, you will never stop.

 

Is the DAQ only supposed to read for "Measurement Time".  Right now, it constantly reads.  So if you don't use the DAQmx Read, you will get a buffer overflow error.  You need to put the DAQmx Start Task inside of the Start event case and then the Stop DAQmx Task inside of the Timeout event case when the measurement time is exceeded.  You should also perform the read regardless inside of the Timeout event case.

 

I HATE telling the consumer loop to stop by destroying the queue.  You can look data that way.  Instead, send something an empty array.  In the consumer, check for an empty array.  If it is empty, stop.  Destroy the queue only AFTER BOTH LOOPS HAVE COMPLETED.

 

You should also report your errors in some way.  Simple Error Handler at the minimum.

 

Since you are using Continous Samples, don't limit the buffer.  Leave the Samples per Channel unwired on the DAQmx Timing VI.


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 4 of 5
(2,761 Views)
Highlighted

Dear community users,

 

thank you for the replies ! I am realy sorry, that I just reply to you so lately, but I was busy with exam preparation....

 

I just edit the VI. Do I go the right way now ? ;-).

 

Best regards,

opcode

0 Kudos
Message 5 of 5
(2,648 Views)