I am working on a multithreaded application where the acquisition and chart display run on different threads. I am attempting to collect samples and plot only when I have 100 samples available to have less resource consumption and keep the application responsive. However, when I change the number of samples in the block, my FIFO capacity seems to change, allowing significantly less amount of samples than the ones I need. The current FIFO capacity should allow for at least 16 mins worth of data, but it only shows less than a second
If I set the block size to 1 (single sample appending) I obtain the results I need, but I am seeing performance issues in other areas of the program, hence the need of appending in blocks.
See the attachments for more clarity. Any suggestions?
EDIT: Adding code
private void DisplayNPD()
{
XyDataSeries<float, float> npdRawDataSeries = new XyDataSeries<float, float>();
int fifoSize = 1000000;
npdRawDataSeries.FifoCapacity = fifoSize;
npdRawData_RS.DataSeries = npdRawDataSeries;
double npdRaw = 0;
bool successfulDequeue = false;
int samplesQueued = 0;
int samplesInBlock = 100;
float[] rawSamples = new float[samplesInBlock];
float[] time = new float[samplesInBlock];
while (!ImagingSession.terminateThreads)
{
if (ImagingSession.laserOnOff && !graphRestarted)
{
int npdElementsInQueue = npdDisplayQueue.Count;
if (npdElementsInQueue > 0)
successfulDequeue = npdDisplayQueue.TryDequeue(out npdRaw);
if (successfulDequeue)
{
currentTime = graphStopwatch.ElapsedMilliseconds * 0.001;
time[samplesQueued] = (float) currentTime;
rawSamples[samplesQueued] = (float) (npdRaw * 1000);
samplesQueued++;
if (samplesQueued == samplesInBlock)
{
using (npdRawDataSeries.SuspendUpdates())
npdRawDataSeries.Append(time, rawSamples);
samplesQueued = 0;
if (currentTime > upperLimit)
{
lowerLimit = upperLimit;
upperLimit += xAxisWidth;
AdjustXAxis(currentHorizontalScale);
}
}
}
}
}
}
- Matthew Beatty asked 9 months ago
- last edited 9 months ago
-
Hi Matt, code sample? I don’t have any ideas from the description, please share some working code and we’ll take a look.
-
Hi Andrew, please see the edited post for code. Thanks!
- You must login to post comments
Thanks fior the code sample Matt
dataSeries.FifoCapacity
won’t change unless you change it. The capacity is a number of data-points so if you have 1 sample per microsecond and 1,000,000 samples this will display 1s of data.
If you append data point-by-point or append in blocks of 100 it won’t make any difference to the FifoCapacity
of the dataseries. As soon as dataSeries.Count
exceeds FifoCapacity
old points will be trimmed.
You can’t dynamically change FifoCapacity
at runtime – internally this is implemented as a circular (ring) buffer so a resize requires rebuilding the whole array.
If the waveform is not fully showing I’m not sure what the issue is – possibly multi threading or some other problem in your code?
-Andrew
- Andrew Burnett-Thompson answered 9 months ago
- You must login to post comments
Please login first to submit.