/// <summary>
        /// Returns up to MaxCount points added to circular buffer since a given InputIndex
        /// </summary>
        /// <param name="SinceIndex">Return points starting at this InputIndex</param>
        /// <param name="MaxCount">Max. number of points to return; actual returned points may be less!</param>
        /// <param name="PointsSince">Array in which points are passed back</param>
        public void GetPointsSince(long SinceIndex, int MaxCount, Samples PointsSince)
        {
            int NumPointsSince;         // number of points being returned

            lock (this)                 // To avoid the buffer changing while we are reading it!
            {
                //test for index
                if (SinceIndex < 0)
                {
                    //Invalid SinceIndex; throw an exception
                    throw (new ArgumentOutOfRangeException("SinceIndex", SinceIndex, "Invalid SinceIndex: "
                                                           + SinceIndex.ToString() + ". Must be 0 or greater."));
                }

                //test to see if SinceIndex is too high
                if (SinceIndex > CurrInputIndex + 1)
                {
                    //Bad index; throw an exception
                    throw (new ArgumentOutOfRangeException("SinceIndex", SinceIndex, "SinceIndex ("
                                                           + SinceIndex.ToString() + ") greater than current signal index + 1 ("
                                                           + (CurrInputIndex + 1).ToString() + ")."));
                }

                NumPointsSince = (int)(nextInputIndex - SinceIndex);

                //test to see if we're being asked to return too many points
                if (NumPointsSince > buffer.size)
                {
                    // Too many points;  must truncate:
                    NumPointsSince = buffer.size;
                    SinceIndex     = nextInputIndex - NumPointsSince;
                    ////too many points; throw an exception
                    //throw (new ArgumentOutOfRangeException("SinceIndex", SinceIndex, "Starting point ("
                    //    + SinceIndex + ") implies a range of samples (" + NumPointsSince
                    //    + ") greater than circular buffer length (" + buffer.size + ")."));
                }
                if (NumPointsSince > PointsSince.maxSize)
                {
                    //too many points; throw an exception
                    throw (new ArgumentOutOfRangeException("MaxCount", MaxCount, "Requesting more points ("
                                                           + NumPointsSince + ") greater than passed buffer max. size (" + PointsSince.maxSize + ")."));
                }

                //Inputs are OK
                MaxCount = Math.Min(NumPointsSince, MaxCount);

                OpenMedICUtils.debugPrint("Returning " + MaxCount + " points starting from " + SinceIndex);

                //Let's get the points!
                PointsSince.size = MaxCount;
                int BuffIndex;                 //points to the index of the circular buffer that we're operating on
                for (int i = 0; i != MaxCount; i++)
                {
                    BuffIndex = (int)((SinceIndex + i) % buffer.size);
                    PointsSince[i].copyFrom(buffer[BuffIndex]);

                    OpenMedICUtils.debugPrint(" - Returning point at index " + BuffIndex + ": value = " + PointsSince[i].sampleValue);
                }
            }
        }
        /// <summary>
        /// Adds a single point to the end of the buffer
        /// </summary>
        /// <param name="point">Point being added</param>
        public void AddPoint(Sample point)
        {
            lock (this)
            {
                // Copy over the value:
                buffer[nextBufferIndex].copyFrom(point);

                OpenMedICUtils.debugPrint("Added a point with value " + point.sampleValue
                                          + " at position " + nextBufferIndex);

                // Update nextBufferIndex, WITH WRAPPING:
                if (nextBufferIndex == (buffer.size - 1))
                {
                    nextBufferIndex = 0;
                }
                else
                {
                    nextBufferIndex++;
                }
                // update next input index:
                nextInputIndex++;
                if (nextInputIndex < 0)
                {                       // Overflowed and wrapped around:
                    nextInputIndex = 0; // This is the only practical thing to do...
                }
                hasData = true;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Draws points acquired since last draw
        /// </summary>
        public void DrawNew()
        {
            if (AutoRedraw)
            {
                long StartIndex;

                lock (this)
                {
                    //get the points we need from the waveform
                    try
                    {
                        if (wfThis == null)
                        {
                            OpenMedICUtils.debugPrint("wfThis null! In RTDisp.DrawNew()");
                        }
                        else if (InSamples == null)
                        {
                            OpenMedICUtils.debugPrint("InSamples null! In RTDisp.DrawNew()");
                        }
                        else
                        {
                            StartIndex = wfThis.getPoints(
                                InSamples,
                                this.xAxisDispMax,
                                lastAbsIndexDisplayed);
                            //Debug.WriteLine(StartIndex.ToString() + ", " + InSamples.size.ToString());

                            NewGraphPoints(StartIndex, InSamples);
                        }
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine(
                            "Exception: \n"
                            + e.Message
                            + "\nStack trace:\n\n"
                            + e.StackTrace);
                    }
                }
            }
        }