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: 

Producer Consumer with Dynamic Data

Hi all,

For a project I am working on, I would like to use the Producer/Consumer model to take measurements from a DAQ. The processing order as I imagine it is:

1) Four queues are created to communicate between producer (data acquiring) and consumer (data analyzing) loops. (I use an arbitrary dynamic signal at the start just to tell obtain queue what kind of queue to make).
2) Inside Producer: Using DAQ assistant, I take four dynamic signals and continuously append them to their respective queue. There are 4 because I am using an XYZ accelerometer and a microphone.

3) Inside Consumer: Every 1 minute, I want to flush each queue and find the maximum value during that one minute period. I want to log the maximum of the set to a file as well. But I have left this part out because it does not pertain to the trouble I am having. 

I have attached a VI which I believe does the producer consumer on a single channel. I would like to extend it to work for all four and I will do so as soon as I can fix this. I keep getting Error(1) when enqueue-ing!

Best, and thank you,
Victor

0 Kudos
Message 1 of 8
(3,319 Views)

Hi Victor,

 

there is so much wrong in using ExpressVIs and DDT wires I had to rework your VI in most parts:

check.png

Learn to use basic LabVIEW functions, they will make your life a lot easier!

Note 1: you don't want to store 4 channels at 25.6kHz samplerate for a whole minute in memory (4*25600*60*8~=50MB!) for just calculating a MinMax!

Note 2: to calculate the MinMax of your data packages you need to count for 60 packages, when each is getting the samples for 1 second…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 8
(3,304 Views)

GerdW,

Thank you so much for the help. It is true that I am still learning the fundamentals of LabView (it is thanks to people like you that I press onward!). I have copied what I could from your code and done my best to understand it. I see the way you are storing arrays which constantly keep track of the min and max. This makes a lot of sense to me and I can see why that would be a huge memory save.

I have attached my attempt at recreating your VI. I was unable to find three of the elements in your diagram, since I do not know what they are called or what they do. If you wouldn't mind explaining their function, I think it could help me make a huge jump in understanding. The elements I am missing are shown in the picture attached, so you don't have to go looking. 

Download All
0 Kudos
Message 3 of 8
(3,272 Views)

Hi vjc,

 

BuildArray, FromDDT, tunnel at a loop border...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 8
(3,266 Views)

Thank you again,


I believe I have the program working properly, as I get both a maximum and minimum on all four channels. It exits pretty quickly, though-- the dequeue object throws an error after a couple of cycles. (Maybe because there are no more elements in the queue? DAQ Assistant seems to stop. )I get the error: 

"Error 1 occurred at Dequeue Element in sos_part2.vi

Possible reason(s):

LabVIEW: An input parameter is invalid. For example if the input is a path, the path might contain a character not allowed by the OS such as ? or @."

 

In order to take the maximum every minute (and reset the min/max arrays every minute), can I just wrap this entire code in a while loop and append to a giant array that I turn into a .csv? 

Kudos is not enough. I will name my first born child GerdW.

0 Kudos
Message 5 of 8
(3,254 Views)

@vjc777 wrote:

Thank you again,


I believe I have the program working properly, as I get both a maximum and minimum on all four channels. It exits pretty quickly, though-- the dequeue object throws an error after a couple of cycles. (Maybe because there are no more elements in the queue? DAQ Assistant seems to stop. )I get the error: 

"Error 1 occurred at Dequeue Element in sos_part2.vi

Possible reason(s):

@Labview: An input parameter is invalid. For example if the input is a path, the path might contain a character not allowed by the OS such as ? or @."




 

 

 It looks like the error was thrown because you had the wrong configuration of From DDT and with part 3 you realized you needed the queue to be of type Array of waveform.  (Another case of DDT's throwing riders)

 

In order to take the maximum every minute (and reset the min/max arrays every minute), can I just wrap this entire code in a while loop and append to a giant array that I turn into a .csv? 

 

That's not a real good idea and I'll tell you why.  You have NO WAY to Exit the code the way you've shown it without hitting the ABORT Button!  We can address that by make the PoC (Proof of Concept) code into a true state machine with "Start Collection", Reset Data, Exit, etc...states


Kudos is not enough. I will name my first born child GerdW.

Your child may never forgive you





"Should be" isn't "Is" -Jay
0 Kudos
Message 6 of 8
(3,237 Views)

Thank you both for your time and brainpower.

I feel I am on the final steps now. Although conceptually I may have wandered from the initial question...

I am successfully sampling and recording global maxima and writing to the file whenever the top loop executes. I have attached a photo of example text output which correctly shows four columns one for each channel. The advice to draw a state machine was very helpful. Of course, there are two main problems left for me to deal with:

1) I need to reset the maxima array every 1 minute, since right now the maxima is compared to previous maxima as well as new ones
2) I need to record every minute but this one records every second (see the timestamps on the output file). Does this mean I need to switch from Dequeue to Flush?

I have a feeling these are both best tackled with the Wait statement or Timer + conditionals, but I wanted to ask your advice as to where I should implement those. Like Jeff said, I wouldn't want my logic to get me stuck in a place where I had to abort the process and risk losing the recorded data file.

My OB-GYN has informed me that I in fact have twins on the way. I will raise JeffÞ and GerdW to live with the wisdom and generosity of their namesakes.

Download All
Message 7 of 8
(3,222 Views)

Hi vjc,

 

1) I need to reset the maxima array every 1 minute, since right now the maxima is compared to previous maxima as well as new ones
2) I need to record every minute but this one records every second (see the timestamps on the output file). Does this mean I need to switch from Dequeue to Flush?

Both points are related to my hints given before: when you know for how MANY data packets you want to MinMax you only need to count them!

1) After getting the desired amount of data you simply re-initialize the shift registers with those ±Inf-Arrays!

2) You only save the data when the desired amount fo data is collected. IF-THEN-ELSE is usually a case structure in LabVIEW…

 

Btw.

- You don't need to create a 2D array just for ArrayToSpreadsheetString, it accepts 1D arrays too…

- Cleaning up your code is recommended. Ever used AutoCleanup?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 8
(3,190 Views)