コード例 #1
0
ファイル: ZedGraph.cs プロジェクト: rhsehfm33/_m_test2
        public void drawzed(RealPacket packet)
        {
            // test
            float  fTime = (float)m_sw.ElapsedMilliseconds / 1000.0F;
            Random r     = new Random();

            Datalist[0].Add(fTime, packet.breath);
            Datalist[1].Add(fTime, packet.pressure);
            Datalist[2].Add(fTime, packet.LRPM);
            Datalist[3].Add(fTime, packet.RRPM);

            BreathGraph.GraphPane.AddCurve("", Datalist[0], Color.Orange, SymbolType.None);
            BreathGraph.GraphPane.XAxis.Scale.Max = fTime;
            BreathGraph.GraphPane.XAxis.Scale.Min = fTime - (8.0 * zoomFraction);
            BreathGraph.AxisChange();

            PressureGraph.GraphPane.AddCurve("", Datalist[1], Color.Green, SymbolType.None);
            PressureGraph.GraphPane.XAxis.Scale.Max = fTime;
            PressureGraph.GraphPane.XAxis.Scale.Min = fTime - (8.0 * zoomFraction);
            PressureGraph.AxisChange();

            RPMGraph.GraphPane.AddCurve("L", Datalist[2], Color.Blue, SymbolType.None);
            RPMGraph.GraphPane.AddCurve("R", Datalist[3], Color.Red, SymbolType.None);
            RPMGraph.GraphPane.XAxis.Scale.Max = fTime;
            RPMGraph.GraphPane.XAxis.Scale.Min = fTime - (8.0 * zoomFraction);
            RPMGraph.AxisChange();
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: rhsehfm33/_m_test2
        public void OnDataReceived(RealPacket dataIn)
        {
            //Handle multi-threading
            if (InvokeRequired)
            {
                Invoke(new PacketDelegate(OnDataReceived), new object[] { dataIn });
                return;
            }

            // Read Data
            //DrawGraph(dataIn);          // 그래프는 대기
            if (m_sw2.ElapsedMilliseconds > 200)
            {
                m_sw2.Restart();
                drawzed(dataIn);

                BreathGraph.Invalidate();
                PressureGraph.Invalidate();
                RPMGraph.Invalidate();
                dataGridView.Invalidate();
            }
            if (_bLogging)
            {
                DrawGrid(dataIn);
            }
        }
コード例 #3
0
        private void PortOnDataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            _buffer += port.ReadExisting().Replace("\r", "");
            var off = 0;

            while ((off = _buffer.IndexOf('\n')) != -1)
            {
                var line = _buffer.Substring(0, off);
                _buffer = _buffer.Substring(off + 1);

                var now  = DateTimeOffset.Now.ToUnixTimeMilliseconds() - startTime;
                var text = now + ":nogasm:" + line;
                Console.WriteLine(text);
                w?.WriteLine(text);
                var m = nogasmRegex.Match(line);
                if (m.Success)
                {
                    average.Add(Convert.ToDouble(m.Groups[5].Value, new NumberFormatInfo()));
                    presure.Add(Convert.ToDouble(m.Groups[3].Value, new NumberFormatInfo()));
                    vibe.Add(Convert.ToDouble(m.Groups[1].Value, new NumberFormatInfo()));
                    time.Add(now);
                    OnNogasmDataPoint?.Invoke(this, new NogasmDataPointArgs(now,
                                                                            Convert.ToDouble(m.Groups[3].Value, new NumberFormatInfo()),
                                                                            Convert.ToDouble(m.Groups[5].Value, new NumberFormatInfo()),
                                                                            Convert.ToDouble(m.Groups[1].Value, new NumberFormatInfo())));

                    if (average.Count > 10000)
                    {
                        var range = average.Count - 1000;
                        average.RemoveRange(0, range);
                        presure.RemoveRange(0, range);
                        vibe.RemoveRange(0, range);
                        time.RemoveRange(0, range);
                    }
                }
            }

            if (DateTimeOffset.Now.Subtract(_last_input).TotalMilliseconds > 100)
            {
                _last_input = DateTimeOffset.Now;
                Dispatcher?.Invoke(() =>
                {
                    AverageGraph.Plot(time, average);
                    PressureGraph.Plot(time, presure);
                    MototGraph.Plot(time, vibe);
                });
            }
        }
コード例 #4
0
        private void MenuFileNew_Click(object sender, RoutedEventArgs e)
        {
            if (port != null)
            {
                StartStop_Click(sender, e);
            }

            logFile = null;
            average = new List <double>();
            presure = new List <double>();
            vibe    = new List <double>();
            time    = new List <double>();

            output  = new List <double>();
            outtime = new List <double>();

            var oGraphs = new List <LineGraph>();

            foreach (var graph in Lines.Children)
            {
                if (graph is LineGraph g && g.Description.Contains("O****m"))
                {
                    oGraphs.Add(g);
                }
            }

            foreach (var g in oGraphs)
            {
                Lines.Children.Remove(g);
            }

            _last_input = DateTimeOffset.Now;
            Dispatcher?.Invoke(() =>
            {
                AverageGraph.Plot(time, average);
                PressureGraph.Plot(time, presure);
                MototGraph.Plot(time, vibe);
                OutputGraph.Plot(outtime, output);
            });
        }
コード例 #5
0
        private void MenuFileOpen_Click(object sender, RoutedEventArgs e)
        {
            //ToDo: Dirty check

            var open = new Microsoft.Win32.OpenFileDialog
            {
                DefaultExt = ".log",
                Filter     = "Logs (.log)|*.log"
            };

            // Process save file dialog box results
            if (open.ShowDialog() == true)
            {
                if (port != null)
                {
                    StartStop_Click(sender, e);
                }

                logFile = null;
                average = new List <double>();
                presure = new List <double>();
                vibe    = new List <double>();
                time    = new List <double>();

                output  = new List <double>();
                outtime = new List <double>();

                var oGraphs = new List <LineGraph>();
                foreach (var graph in Lines.Children)
                {
                    if (graph is LineGraph g && g.Description.Contains("O****m"))
                    {
                        oGraphs.Add(g);
                    }
                }

                foreach (var g in oGraphs)
                {
                    Lines.Children.Remove(g);
                }

                _last_input = DateTimeOffset.Now;
                Dispatcher?.Invoke(() =>
                {
                    AverageGraph.Plot(time, average);
                    PressureGraph.Plot(time, presure);
                    MototGraph.Plot(time, vibe);
                    OutputGraph.Plot(outtime, output);
                });

                //ToDo: Background this?
                StreamReader stream = null;
                try
                {
                    stream = new StreamReader(File.OpenRead(open.FileName));
                }
                catch (ArgumentException ex)
                {
                    MessageBox.Show($"Error on opening file: {ex.Message}", "Error Opening File", MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                }

                try
                {
                    string line;
                    while ((line = stream?.ReadLine()) != null)
                    {
                        //ToDo: Abstract log event consumer
                        var m = logRegex.Match(line.ToLower(CultureInfo.CurrentCulture));
                        if (m.Success)
                        {
                            if (!long.TryParse(m.Groups[1].Value, out var t))
                            {
                                continue;
                            }

                            switch (m.Groups[2].Value)
                            {
                            case "nogasm:":
                                var m2 = nogasmRegex.Match(m.Groups[3].Value);
                                if (m2.Success)
                                {
                                    average.Add(Convert.ToDouble(m2.Groups[5].Value, new NumberFormatInfo()));
                                    presure.Add(Convert.ToDouble(m2.Groups[3].Value, new NumberFormatInfo()));
                                    vibe.Add(Convert.ToDouble(m2.Groups[1].Value, new NumberFormatInfo()));
                                    time.Add(t);

                                    if (time.Count > 2 &&
                                        Math.Abs(average[average.Count - 2] - average[average.Count - 1]) < 0.001 &&
                                        Math.Abs(presure[presure.Count - 2] - presure[presure.Count - 1]) < 0.001 &&
                                        Math.Abs(vibe[vibe.Count - 2] - vibe[vibe.Count - 1]) < 0.001)
                                    {
                                        time.RemoveAt(time.Count - 1);
                                        average.RemoveAt(time.Count - 1);
                                        presure.RemoveAt(time.Count - 1);
                                        vibe.RemoveAt(time.Count - 1);
                                    }
                                }

                                break;

                            case "user:o****m":
                                var oGraph = new LineGraph();
                                oGraph.Description = "O****m";
                                Dispatcher?.Invoke(() =>
                                {
                                    Lines.Children.Add(oGraph);
                                    oGraph.Plot(new double[] { t, t }, new double[] { 0, 4000 });
                                });
                                break;

                            case "output:":
                                if (double.TryParse(m.Groups[3].Value, out var val))
                                {
                                    output.Add(val * 1000);
                                    outtime.Add(t);
                                }
                                break;
                            }
                        }
                    }

                    Dispatcher?.Invoke(() =>
                    {
                        AverageGraph.Plot(time, average);
                        PressureGraph.Plot(time, presure);
                        MototGraph.Plot(time, vibe);
                        OutputGraph.Plot(outtime, output);
                    });
                }
                catch (IOException ex)
                {
                    MessageBox.Show($"Error parsing file: {ex.Message}", "Error Opening File", MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                }
                catch (OutOfMemoryException ex)
                {
                    MessageBox.Show($"Error parsing file: {ex.Message}", "Error Opening File", MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                }
                catch (ArgumentNullException ex)
                {
                    MessageBox.Show($"Error parsing file: {ex.Message}", "Error Opening File", MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                }
                catch (RegexMatchTimeoutException ex)
                {
                    MessageBox.Show($"Error parsing file: {ex.Message}", "Error Opening File", MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                }

                stream?.Close();
            }
        }