LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Count a certain number of events in a moving window of time

Hello Labview experts,

 

I was wondering if you could help me with a purely software/Labview problem (being new to Labview). I am using Labview 2012 (32-bit) edition.

 

Set-up: I have a device that is communicating to my computer via a virtual serial port. The device sends 41 bytes with each message, and inside the message is a specific character that I am looking for. I know how to parse out the message to check for the presence of that particular ASCII character. 

 

Problem: I want to count the total number of incidences of the ASCII character in a given period of time (say 10 seconds), to know that a certain number of events has occured. But I want to be able to track the number of events within a moving 10-second window, so that I can constatly know the number of events happening in the immediate past 10 seconds.

 

What I tried: I attached what I tried to do... I tried having a counter which reset to zero every 10 seconds, but then it would lose count and take another 10-seconds to get the count correct again. 

 

I hope this question makes sense, if not I'll try to re-explain it. 

 

Thanks in advance for your help.

 

Gord

0 Kudos
Message 1 of 2
(2,316 Views)

First.  Don't configure, open and close your serial port on every loop iteration.  Those functions belong outside the loop.

 

Does your data come in at regular intervals?  Let's say every second you can a new set of data?

 

Let's say you do.  Then every second put the new data into an array.  Add the array elements.  Whenever you get new data and your array lengths is >10, then delete the first element of the array.  Maintain that array in a shift register.

 

If your data comes in more erratically, you may need to maintain two arrays, one of timestamps of when data came in, and one of the data itself.  You will need to search your timestamp array for any timestamps older than 10 seconds, and delete that many elements from both that array and your data array.

0 Kudos
Message 2 of 2
(2,312 Views)