示例#1
0
        /// <summary>
        /// Write data to the Event Server. This write operation is used when the sampleIndicies in the newData buffer
        /// correspond to the start of a DAQ buffer poll rather than the start of the recording.
        /// </summary>
        /// <param name="newData"></param>
        /// <param name="taskNo"></param>
        internal void WriteToBufferRelative(EventBuffer <T> newData, int taskNo)
        {
            lock (lockObj)
            {
                // First we must remove the expired samples (we cannot assume these are
                // in temporal order since for 64 channels, we have to write 2x, once for
                // each 32 channel recording task)
                if (minCurrentSample > bufferSizeInSamples)
                {
                    dataBuffer.Buffer.RemoveAll(x => x.SampleIndex < minCurrentSample - (ulong)bufferSizeInSamples);
                }

                // Move time stamps to absolute scheme
                for (int i = 0; i < newData.Buffer.Count; ++i)
                {
                    // Convert time stamps to absolute scheme
                    T tmp = (T)newData.Buffer[i].DeepClone();
                    tmp.SampleIndex = tmp.SampleIndex + currentSample[taskNo];
                    dataBuffer.Buffer.Add(tmp);

                    // Only add to the NewData buffer it is going to be cleared later
                    if (NewData != null)
                    {
                        newDataBuffer.Buffer.Add(tmp);
                    }
                }

                // Update current read-head position
                currentSample[taskNo] += (ulong)numSamplesPerWrite;
                if (serverLagSamples < currentSample.Min())
                {
                    minCurrentSample = currentSample.Min() - serverLagSamples;
                }
                else
                {
                    minCurrentSample = 0;
                }

                // Fire the new data event (only fire if the incoming buffer was not empty and somebody is listening)
                if (NewData != null && taskNo == 0)
                {
                    eventArgs = new NewEventDataEventArgs <T>(newDataBuffer);
                    NewData(this, eventArgs);
                    newDataBuffer.Buffer.Clear();
                }
            }
        }
示例#2
0
        /// <summary>
        /// Write data to the Event Server
        /// </summary>
        /// <param name="newData">An event buffer containing the events to add to the server</param>
        /// <param name="taskNo"> The NI task that created these new data</param>
        internal void WriteToBuffer(EventBuffer <T> newData, int taskNo)
        {
            lock (lockObj)
            {
                // First we must remove the expired samples (we cannot assume these are
                // in temporal order since for 64 channels, we have to write 2x, once for
                // each 32 channel recording task)
                if (minCurrentSample > bufferSizeInSamples)
                {
                    dataBuffer.Buffer.RemoveAll(x => x.SampleIndex < (minCurrentSample - (ulong)bufferSizeInSamples));
                }

                // Add new data to main buffer
                dataBuffer.Buffer.AddRange(newData.Buffer);

                // Update current read-head position
                currentSample[taskNo] += (ulong)numSamplesPerWrite;

                //The most up to date read position in the buffer is determined by the slowest input task
                if (serverLagSamples < currentSample.Min())
                {
                    minCurrentSample = currentSample.Min() - serverLagSamples;
                }
                else
                {
                    minCurrentSample = 0;
                }

                // Fire the new data event (only fire if the incoming buffer was not empty and somebody is listening)
                if (NewData != null)
                {
                    // Create space to sore new data
                    newDataBuffer.Buffer.AddRange(newData.Buffer);

                    if (taskNo == 0)
                    {
                        eventArgs = new NewEventDataEventArgs <T>(newDataBuffer);
                        NewData(this, eventArgs);
                        newDataBuffer.Buffer.Clear();
                    }
                }
            }
        }