Exemplo n.º 1
0
        /// <summary>
        /// Stops the read.
        /// </summary>
        public void Stop()
        {
            if (IsReading && CurReadWaitResult != null && !CurReadWaitResult.IsCompleted &&
                (CounterReader != null || AnalogReader != null))
            {
                try
                {
                    if (IsCounter)
                    {
                        CounterReader.EndReadMultiSampleUInt32(CurReadWaitResult);
                    }
                    else
                    {
                        AnalogReader.EndReadMultiSample(CurReadWaitResult);
                    }
                }
                catch (Exception ex)
                {
                    /// attempt to end he read failed.
                }

                // clear the async result.
                CurReadWaitResult = null;
            }
            IsReading = false;

            DestroyReaderTask();
            DestroyTimebaseTask();
        }
Exemplo n.º 2
0
        /// <summary>
        /// On data was read.
        /// </summary>
        /// <param name="rslt"></param>
        protected void OnDataRead(IAsyncResult rslt)
        {
            if (!rslt.IsCompleted || !IsReading)
            {
                return;
            }

            DataChunk c      = null;
            TimeSpan  offset = TimeSpan.FromSeconds(ReadTicks * 1.0 / SamplingFrequency);

            if (IsCounter)
            {
                // data is counter.
                uint[,] data = CounterReader.EndReadMultiSampleUInt32(rslt);
                ReadTicks   += data.GetLength(1);
                c            = new DataChunk(offset, data);
            }
            else
            {
                // data is analog.
                double[,] data = AnalogReader.EndReadMultiSample(rslt);

                // adding to the read ticks.
                ReadTicks += data.GetLength(1);
                c          = new DataChunk(offset, data);
            }

            // call async again.
            if (IsReading)
            {
                ReadData();
            }

            // No data.
            if (c.DataCount == 0)
            {
                return;
            }

            m_dataQ.Enqueue(c);

            // call to process the queue if needed.
            DoQueueProcessing();
        }