Esempio n. 1
0
        public MainWindow()
        {
            pingResults = new ResultsCollection();

            InitializeComponent();

            System.Threading.Thread.CurrentThread.CurrentCulture =
                System.Globalization.CultureInfo.InvariantCulture;

            //PingList.ItemsSource = pingResults._collection;

            mainWin = this;
            disp    = this.Dispatcher;

            Plot1.Axes.Add(new OxyPlot.Wpf.TimeSpanAxis());
            Plot1.Axes[0].Position = AxisPosition.Bottom;


            var linearAxis = new OxyPlot.Wpf.LinearAxis();

            //linearAxis.Title = "V";
            linearAxis.Key = "V";
            //linearAxis.PositionTier = 1;
            linearAxis.Position = AxisPosition.Left;
            Plot1.Axes.Add(linearAxis);

            // Plot1.Series[0].TrackerFormatString = "{2:0.0},{4:0.0}";

            /*linearAxis = new OxyPlot.Wpf.LinearAxis();
             * linearAxis.Title = "RPM";
             * linearAxis.Key = "RPM";
             * linearAxis.PositionTier = 2;
             * linearAxis.Position = AxisPosition.Right;
             * Plot1.Axes.Add(linearAxis);*/

            /*linearAxis = new OxyPlot.Wpf.LinearAxis();
             * linearAxis.Title = "mAh";
             * linearAxis.Key = "mAh";
             * linearAxis.PositionTier = 2;
             * linearAxis.Position = AxisPosition.Right;
             * Plot1.Axes.Add(linearAxis);
             *
             * linearAxis = new OxyPlot.Wpf.LinearAxis();
             * linearAxis.Title = "Vtot";
             * linearAxis.Key = "Vtot";
             * linearAxis.PositionTier = 2;
             * linearAxis.Position = AxisPosition.Left;
             * Plot1.Axes.Add(linearAxis);
             *
             * linearAxis = new OxyPlot.Wpf.LinearAxis();
             * linearAxis.Title = "C/A";
             * linearAxis.Key = "Temp";
             * linearAxis.PositionTier = 3;
             * linearAxis.Position = AxisPosition.Left;
             * Plot1.Axes.Add(linearAxis);*/

            //c_ThresholdReached += pingResults._collection.CollectionChanged;

            // Get version. Crashes if within visual studio, so we have to catch that.
            try {
                var version = System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion;
                this.Title = "UDPLogger v." + version.ToString();
            } catch (Exception) {
                var version = Assembly.GetExecutingAssembly().GetName().Version;
                this.Title = "UDPLogger development build " + version.ToString();
            }
        }
Esempio n. 2
0
        private void LoadButton_Click(object sender, RoutedEventArgs e)
        {
            try {
                OpenFileDialog load = new OpenFileDialog();
                load.Filter = "CSV|*.csv|Log|*.log";
                string title = "";
                if ((bool)load.ShowDialog())
                {
                    //Plot1.ResetAllAxes();
                    Plot1.Series.Clear();
                    foreach (var p in pingResults._collection)
                    {
                        p.Points.Clear();
                    }

                    pingResults._collection.Clear();

                    if (load.FilterIndex == 2)
                    {
                        XmlSerializer mySerializer = new XmlSerializer(typeof(ResultsCollection));
                        FileStream    myFileStream = new FileStream(load.FileName, FileMode.Open);
                        // Call the Deserialize method and cast to the object type.
                        pingResults = (ResultsCollection)mySerializer.Deserialize(myFileStream);
                    }
                    else
                    {
                        var    f      = File.OpenRead(load.FileName);
                        var    stream = new StreamReader(f);
                        string header = stream.ReadLine();
                        while (header.TrimStart().StartsWith("//"))
                        {
                            title += header;
                            header = stream.ReadLine(); // VESC MOnitor first line is a summary/comment
                        }
                        var columns     = header.Split(',');
                        int columnCount = columns.Count();
                        int lineNumber  = 0;
                        int hasTime     = -1;
                        if (columns[0].ToUpper().Contains("TIME"))
                        {
                            hasTime = 0;
                        }
                        if (columns.Contains("TimePassedInMs"))
                        {
                            hasTime = Array.IndexOf(columns, "TimePassedInMs");
                        }
                        while (!stream.EndOfStream)
                        {
                            var line = stream.ReadLine();
                            int i    = 0;
                            int t    = 0;

                            if (hasTime != -1)
                            {
                                double d;
                                double.TryParse(line.Split(',')[hasTime], out d);
                                t = (int)d;
                            }

                            foreach (var c in line.Split(','))
                            {
                                double d = 0;

                                if (i == hasTime)
                                {
                                    i++;
                                    continue; // don't graph the timestamp
                                }

                                if (double.TryParse(c, out d))
                                {
                                    PingResult temp;
                                    if (hasTime != -1)
                                    {
                                        temp = pingResults.Add(columns[i], d, t / 1000.0);
                                    }
                                    else
                                    {
                                        temp = pingResults.Add(columns[i], d, lineNumber++);
                                    }
                                    if (temp != null)
                                    {
                                        Plot1.Series.Add(temp.Line);
                                        temp.Line.ItemsSource = temp.Points;
                                    }
                                }
                                i++;
                            }
                            //if (lineNumber % columnCount==0)
                            //Plot1.InvalidatePlot(true);
                        }
                    }


                    /*foreach (var p in pingResults._collection)
                     * EnableDisableSeries(p, true);*/

                    Plot1.InvalidatePlot(true);
                    this.Title = Path.GetFileName(load.FileName) + title;
                }
            } catch (Exception ex) {
                MessageBox.Show(ex.ToString());
            }
        }