Exemple #1
0
        private void ReadLoop()
        {
            while (!_threadShouldStop)
            {
                if (_port.IsOpen)
                {
                    int bytesToRead = _port.BytesToRead;
                    if (bytesToRead > 0)
                    {
                        byte[] buffer = new byte[bytesToRead];
                        _port.Read(buffer, 0, bytesToRead);

                        SamplePoint[] samples = new SamplePoint[bytesToRead];
                        for (int x = 0; x < bytesToRead; x++)
                        {
                            samples[x].Value      = ((float)buffer[x] / 255) * 5;
                            samples[x].TimeOffset = 20 * Utility.MICROSECOND;
                        }

                        _visualizer.Channel.WriteSamples(samples);
                    }
                }

                Thread.Sleep(10);
            }

            _thread = null;
        }
        /// <summary>
        /// Gets specified amount of samples from the end of the buffer.
        /// </summary>
        /// <param name="length">Number of samples to copy from the current end of the buffer.</param>
        public SamplePoint[] GetLast(int length)
        {
            if (length > _buffer.Length)
            {
                length = _buffer.Length;
            }
            //TODO: refactor... this can be done simpler, in a loop
            SamplePoint[] ret = new SamplePoint[length];

            lock (_locker)
            {
                if (length <= _pointer)
                {
                    //if we have enough in front of the pointer, just return it
                    CopyArray(_buffer, _pointer - length, ret, 0, length);
                }
                else
                {
                    //overflow on the left side
                    //first take the part from the end of the buffer
                    int lenToStart   = _pointer;
                    int partOnTheEnd = length - lenToStart;
                    CopyArray(_buffer, _buffer.Length - partOnTheEnd, ret, 0, partOnTheEnd);

                    //take the rest from the beginning of the buffer
                    CopyArray(_buffer, 0, ret, partOnTheEnd, lenToStart);
                }
            }

            return(ret);
        }
Exemple #3
0
        private void btnDummyProbe_Click(object sender, EventArgs e)
        {
            SamplePoint[] points = new SamplePoint[10];

            for (int x = 0; x < points.Length; x++)
            {
                points[x].Value      = x / 10f;
                points[x].TimeOffset = 20 * Utility.MICROSECOND;
            }

            _visualizer.Channel.WriteSamples(points);
        }