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: 

Dequeue the last element?

 

 

I want to continuously take measurements to monitor operating conditions (100mS update) and safely shutdown if safe operating limits are exceed. If a shutdown occurs I need to dump the measurements from a few seconds before the shutdown to a file.

 

So I imagine using a fixed size queue to keep the last few seconds of measurements in memory so I can dump them to a file if needed. (Will this work? Will a fixed queue remove the oldest element and add the new one once the size limit is reached)

 

But I also need to log measurements at regular intervals. 

 

Is there a way to dequeue the last element in a queue so I have the most recent measurement when a log interval occurs? 

 

Or is there a better way?

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 1 of 5
(1,718 Views)

@RTSLVU wrote:

Will a fixed queue remove the oldest element and add the new one once the size limit is reached


If you use the Lossy Enqueue function, this is what happens.

 


@RTSLVU wrote:

Is there a way to dequeue the last element in a queue so I have the most recent measurement when a log interval occurs?


I think using Flush Queue will do what you are wanting.  It will dump all of the elements to you for logging purposes.  You could then use Delete From Array to reduce the number of samples you want to log from the queue.


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
Message 2 of 5
(1,692 Views)

For the array of most recent data, the lossy enqueue is a good option. If you use the regular enqueue, once the queue fills up it will wait until room is available before putting the next element on. (This is what the timeout input on enqueue is for).

 

For the most recent data, a notifier would be perfect. Functionally it will be similar to lossy enqueue with a queue size of 1. You also have the option of waiting on the notifier in multiple places and they will all receive the notification.

0 Kudos
Message 3 of 5
(1,673 Views)

If I follow your use case correctly, you'd like to get an occasional sneak peak at some recent data while retaining that data in the fixed-size queue for the sake of logging (in case a shutdown happens to be imminent).

 

Instead of Flush Queue, I'd recommend one of the following:

 

"Get Queue Status" which allows you to wire a True to retrieve a *copy* of all queue elements without removing any of them from the queue.

 

"Preview Queue Element" which returns a *copy* of the single element at the front of the queue without removing it from the queue.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 4 of 5
(1,657 Views)

Another option is to just use 2 queues.

 

One regular queue for logging.

One fixed, lossy queue for keeping a "DVR" history of the recent data.  Just put the same data into both queues as acquired.

Message 5 of 5
(1,608 Views)