LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help with Producer Consumer, and processing signals. (time between peaks)

Hello all,

 

i am working on a project and need some help.  some backround: i have worked with labview, and made some event based programs, but now have a signal processing project.  i have employed an very detailed producer consumer example, and modified it to my needs, but encountering some issues formulating a solution  

 

i using a DAQmx to read pressure transducers that produce cyclic behavior.  i have a few goals.  

1. learn best practices in labview

2. extract time between peaks (amplitude will stay the same for the same session) but will change for a new subject.

 

attached is the main program and processing program. Please let me know how i can solve and improve the VI's

Download All
0 Kudos
Message 1 of 6
(2,205 Views)

Hi evan,

 


@evan.l wrote:

attached is the main program and processing program. Please let me know how i can solve and improve the VI's


No, you did not attach some programs. All we got are two images of parts of your code…

First step to receive substantial help on your VIs is to attach the real VIs!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 6
(2,166 Views)

One of the glaring issues I am seeing is that the consumer should be in full control of the queue.  Your producer should sent a sentinel of some sort through the queue to tell the consumer that no more data is coming.  Then the consumer should destroy the queue when it is done.

 

You might also want to consider moving your consumer loops into subVIs to help organize your code a little better.


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 3 of 6
(2,163 Views)

I agree with crossrulz that you want to use Sentinels to manage the Queue in Producer/Consumer.

 

Here's the idea:

  • The Producer "produces" data and puts it on the Queue.  Only the Producer "knows" when to stop putting data on the Queue -- when this happens, the Producer simply exits.
  • The Consumer "consumes" the data on the Queue.  The Consumer "needs" to process all of the data on the Queue.  The Consumer should not exit until it knows that all the data that can be process has been processed.
  • The simplest way to accomplish these two aims is for the Producer, which knows no more data will be put on the Queue, to signal the Consumer by putting a special element, called the Sentinel, on the Queue.  In cases where Queue elements contain (non-empty) Arrays of data, a "natural" Sentinel is an Empty Array.  If the Queue contains a (non-empty) String, an empty String can be the Sentinel.  If the element is a Cluster and there is no obvious "unique" value to any cluster element, add a "Last Element?" Boolean.  If you take a look at the Stream Asynchronous Data Wire (which resembles a Producer/Consumer Queue), you'll notice it has a Last Element? sentinel built into its structure.
  • You have an Array as part of your cluster.  So when your Producer exits, it puts one more element, with an empty Array, on the Queue, and then finishes, leaving the Queue intact.
  • In the Consumer, as each element is dequeued, you test for Empty Array.  If False, you "consume" the data.  But if True, you simply exit the Consumer loop without processing the data.  Once you exit, you know the Producer is done with the Queue (because it sent the Sentinel), and you are done with the Queue, so the Consumer releases the Queue, knowing (a) it is empty, and (b) it will remain empty.

Bob Schor

0 Kudos
Message 4 of 6
(2,149 Views)

Hello Gerd, 

 

I am also a newb in asking for help 🙂 

 

attached is the mainvi and subVI

 

Thanks for the heads up.

Download All
0 Kudos
Message 5 of 6
(2,145 Views)

Since I've kept this tab open for almost a week out of general interest, I guess it's time to respond.

 

No disagreement with prior comments.  But very generally speaking, your code is mostly a pretty reasonable approach.  Various kinds of cleanup and subvi's will help, but the essential architecture and distribution of responsibility checks out.  (Keep in mind the advice from crossrulz to let the *consumers* be in charge of releasing/destroying the queues.)

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 6 of 6
(2,052 Views)