Ejemplo n.º 1
0
 /// <summary>
 /// Displays raw time series data.
 /// </summary>
 /// <param name="samples">Audio input samples.</param>
 private void ProcessTimeSeriesAudioSample(float[] samples)
 {
     using (sciChart.SuspendUpdates())
     {
         _audioSeriesSource.Clear();
         _audioSeriesSource.Append(_xSeries, samples);
     }
 }
Ejemplo n.º 2
0
        private void UpdateData()
        {
            lock (this)
            {
                for (int i = 0; i < Count; i++)
                {
                    _re[i] = 2.0 * Math.Sin(2 * Math.PI * i / 20) +
                             5.0 * Math.Sin(2 * Math.PI * i / 10) +
                             2.0 * _random.NextDouble();
                    _im[i] = IsFrequencyDomain ? 0.0 : i;
                }

                if (IsFrequencyDomain)
                {
                    _transform.run(_re, _im);
                    for (int i = 0; i < Count; i++)
                    {
                        double mag = Math.Sqrt(_re[i] * _re[i] + _im[i] * _im[i]);
                        _re[i] = 20 * Math.Log10(mag / Count);
                        _im[i] = i;
                    }
                }

                _dataSeries.SeriesName = YAxisTitle;
                _dataSeries.Clear();
                _dataSeries.Append(_im, _re);
            }
        }
Ejemplo n.º 3
0
        private void ClearDataSeries()
        {
            if (series0 == null)
            {
                return;
            }

            using (sciChart.SuspendUpdates())
            {
                series0.Clear();
                series1.Clear();
                series2.Clear();
            }
        }
Ejemplo n.º 4
0
        private void ClearDataSeries()
        {
            if (_series0 == null)
            {
                return;
            }

            using (sciChartSurface.SuspendUpdates())
            {
                _series0.Clear();
                _series1.Clear();
                _series2.Clear();
            }
        }
 private void OnData(StateMonitorLineChartData info)
 {
     if (temp_index <= info.Time)
     {
         PosSeries.Append(info.Time, info.Pos);
         SpeedSeries.Append(info.Time, info.Speed);
         temp_index = info.Time;
     }
     else
     {
         PosSeries.Clear();
         SpeedSeries.Clear();
         temp_index = info.Time;
     }
 }
Ejemplo n.º 6
0
        private void OnTick(object sender, EventArgs e)
        {
            lock (this)
            {
                // Generate data at this phase depending on data source type
                var dataSource = SelectedDataSource == "Lissajous"
                                     ? DataManager.Instance.GetLissajousCurve(0.12, _phase1, _phase0, 2500)
                                     : DataManager.Instance.GetFourierSeries(2.0, _phase0, 1000);

                _phase0 += _phaseIncrement;
                _phase1 += _phaseIncrement * 0.005;

                // Lock the data-series and clear / re-add new data
                using (this.ChartData.SuspendUpdates())
                {
                    _series0.Clear();
                    _series0.Append(dataSource.XData, dataSource.YData);
                }
            }
        }
Ejemplo n.º 7
0
        //public void prepareDataReceiver(){
        //    _ploted = new TripleSeries(50000);
        //    _receivedPackets = new List<List<byte[]>>(40);
        //    for (int i = 0; i < 40; i++){
        //        _receivedPackets.Add(new List<byte[]>(50000));
        //    }
        //    _receivingPackets = _receivedPackets[0];
        //}

        public void finishedReadingData()
        {
            IsScrollingVisible = true;
            IsShowingHistory   = true;

            Task.Factory.StartNew(
                () =>
            {
                /*do a last refreshing of graph cuz scichart seems to not work properly sometimes*/
                try
                {
                    //give time for
                    Thread.Sleep((int)(RefreshTime * 3));
                    double[] y_1;
                    double[] y_2;
                    double[] xs;
                    lock (MonitorupdateSeries)
                    {
                        lock (MonitordataReceived)
                        {
                            y_1 = _ploted.Select(y1 => y1.Y1).ToArray();
                            y_2 = _ploted.Select(y2 => y2.Y2).ToArray();
                            xs  = _ploted.Select(x => x.X).ToArray();
                            using (_series0.SuspendUpdates())
                            {
                                using (_series1.SuspendUpdates())
                                {
                                    _series0.Clear();
                                    _series1.Clear();
                                    _series0.Append(xs, y_1);
                                    _series1.Append(xs, y_2);
                                }
                            }
                        }
                    }
                }
                catch { Debugger.Break(); }
                Thread.Sleep(250);
                ResetZoom();
            });
        }
Ejemplo n.º 8
0
        private void Init()
        {
            Sthetho.IsStreaming    = true;  //Block Streaming Button
            checkboxFile.IsEnabled = false; //Disable CheckBox
            SerialDataIn.OpenSerialPort();  //Open Serial Data Por

            //Setup Sound plot
            SoundSeries.DataSeries = SoundData;
            YAxis.VisibleRange     = new DoubleRange(-32000, 32000);
            this.sciChartSurface.XAxis.AutoRange = SciChart.Charting.Visuals.Axes.AutoRange.Always;
            SoundData.Clear();

            //Check if File will be written
            if (Sthetho.WriteToFile)
            {
                if (File.Exists(outputfile))
                {
                    File.Delete(outputfile);
                }
                tmpFile = File.OpenWrite(outputfile);
            }

            timer = new MultimediaTimer()
            {
                Interval = 1
            };

            Console.WriteLine("Running graphing system");
            //Observable to output to observer

            System.Reactive.Subjects.IConnectableObservable <byte> dataStream = null;
            if (Sthetho.Demo)
            {
                dataStream = Observable.Create <byte[]>(ob =>
                {
                    timer.Elapsed += (source, e) =>
                    {
                        if (reader.BaseStream.Position < reader.BaseStream.Length)
                        {
                            ob.OnNext(reader.ReadBytes(32));  //Call connected, subscribed observables.
                        }
                        else
                        {
                            Console.WriteLine("timer: ready to stop");
                            timer.Stop();
                            Console.WriteLine("timer: stopped");
                        }
                    };
                    timer.Start();
                    return(Disposable.Empty);
                })
                             .SelectMany(data => data.ToObservable())
                             .Publish();
            }
            else
            {
                //Observable to output to observer - SerialPort
                dataStream = Observable.FromEventPattern <SerialDataReceivedEventHandler, SerialDataReceivedEventArgs>(
                    h => SerialDataIn.SerialPortFTDI.DataReceived += h,
                    h => SerialDataIn.SerialPortFTDI.DataReceived -= h)
                             .Select(arg =>
                {
                    byte[] buf = new byte[SerialDataIn.SerialPortFTDI.BytesToRead];
                    SerialDataIn.SerialPortFTDI.Read(buf, 0, buf.Length);
                    return(buf);
                })
                             .SelectMany(data => data.ToObservable())
                             .Publish();
            }

            // Save to file
            dataStream
            .Buffer(2)
            .Buffer(1000)
            .SubscribeOn(NewThreadScheduler.Default)
            .Subscribe(data =>
            {
                var res = data.ToArray();
                foreach (var t in res)
                {
                    StethoPlayer.AddData(new byte[] { t[1], t[0] });
                }
                //StethoPlayer.AddData(res);
                StethoPlayer.Play();

                //tmpFile.WriteByte(data[0]);
                //tmpFile.Write(res, 0, res.Length);
                //tmpFile.WriteByte(data[1]);
                //tmpFile.Flush();
            });


            /*
             * if (Sthetho.WriteToFile)
             * {
             *  dataStream.Buffer(2).Subscribe(data =>
             *  {
             *      tmpFile.WriteByte(data[0]);
             *      tmpFile.WriteByte(data[1]);
             *      //tmpFile.Flush();
             *  });
             * }
             */
            //Graphing
            dataStream
            .Buffer(2)
            .Buffer(153)
            .Subscribe(values =>
            {
                // draw
                using (sciChartSurface.SuspendUpdates())
                {
                    //Console.WriteLine("Data Received");
                    foreach (var v in values)
                    {
                        short s = BitConverter.ToInt16(new byte[2] {
                            (byte)v[1], (byte)v[0]
                        }, 0);
                        tmpFile.WriteByte(v[0]);
                        tmpFile.WriteByte(v[1]);
                        //WriteFileASync(v);
                        if (StethoPlayer.PlayBackState == PlaybackState.Playing)
                        {
                            Sthetho.AnnotationX = plotCount - (16000);
                        }
                        if (Sthetho.FilterHeart)
                        {
                            SoundData.Append(plotCount++, (short)BandPassfilter.ProcessSample((double)s));
                            //SoundData.Append(plotCount++, (short) s);
                        }
                        else
                        {
                            SoundData.Append(plotCount++, s);
                        }
                    }
                }
            });

            dataStream.Connect();  //For the .Publish on the observable
        }
Ejemplo n.º 9
0
 public void Reset()
 {
     _channelDataSeries.Clear();
 }