ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Extracting data from "DoubleBufferedQueue"
Posted by Cho on Jul-13-2018 16:01
Hi Peter,

I have a question about "DoubleBufferedQueue<DataPacket> buffer" in the "realtimemultithread" example.
The buffer already has a lot of data needed for the chart.
Once the chart has stopped updating in real time, I want to extract the data of the specified period T1 and T2 from the buffer and display the chart and the grid table.
Is this possible? Would you show me how to extract data?

Regards
Cho

  Re: Extracting data from "DoubleBufferedQueue"
Posted by Peter Kwan on Jul-14-2018 13:57
Hi Cho,

In the realtimemultithread example, the data are mainly stored in the arrays m_timeStamps, m_dataSeriesA and m_dataSeriesB. The DoubleBufferedQueue is used to transfer data between two threads, not as the main data storage. The code basically works as follows:

Data Acquisition Thread:
(a) Get Data from Random number generator
(b) Put data into DoubleBufferQueue
(c) Loop back to (a)

Chart Plotting Thread:
(a) Get data from DoubleBufferQueue
(b) Append data to m_timeStamps, m_dataSeriesA and m_dataSeriesB
(c) Draw Chart
(d) Loop back to (a)

We need the DoubleBufferQueue because the two threads above are not synchronous - they can loop at different speed. Also, between the two threads, we need to use Mutex to avoid concurrent read/write to shared data. DoubleBufferQueue contains the Mutex and also can temporary store some data to allow the two loops to run at different speeds without losing data.

In your case, the data are in m_timeStamps, m_dataSeriesA and m_dataSeriesB. To obtain the data from T1 to T2, you can extract the data like in the drawChart code. In the drawChart subroutine, you can find the following code to extract the data from viewPortStartDate to viewPortEndData.

// Get the array indexes that corresponds to the visible start and end dates
nt startIndex = (int)floor(Chart::bSearch(DoubleArray(m_timeStamps, m_currentIndex), viewPortStartDate));
int endIndex = (int)ceil(Chart::bSearch(DoubleArray(m_timeStamps, m_currentIndex), viewPortEndDate));
int noOfPoints = endIndex - startIndex + 1;

// Extract the visible data
viewPortTimeStamps = DoubleArray(m_timeStamps+ startIndex, noOfPoints);
viewPortDataSeriesA = DoubleArray(m_dataSeriesA + startIndex, noOfPoints);
viewPortDataSeriesB = DoubleArray(m_dataSeriesB + startIndex, noOfPoints);

For your case, just replace viewPortStartDate with T1 and viewPortEndDate with T2.

Regards
Peter Kwan

  Re: Extracting data from "DoubleBufferedQueue"
Posted by Cho on Jul-16-2018 09:10
Hi Peter,

Thank you for your kind help.

Best Regards,
Cho