From 47938cc0b09966ba0ecb0510634599f28c9891c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20M=C3=BCssig?= Date: Fri, 3 Jul 2020 21:15:14 +0200 Subject: [PATCH] Fixed various bugs Fixes #6 and various other issues. --- ParksideView/MainWindow.Designer.cs | 16 +- ParksideView/MainWindow.cs | 334 +++++++++++++----------- ParksideView/Properties/AssemblyInfo.cs | 4 +- 3 files changed, 185 insertions(+), 169 deletions(-) diff --git a/ParksideView/MainWindow.Designer.cs b/ParksideView/MainWindow.Designer.cs index eb9f74a..27bfa70 100644 --- a/ParksideView/MainWindow.Designer.cs +++ b/ParksideView/MainWindow.Designer.cs @@ -148,7 +148,7 @@ private void InitializeComponent() // // recordToggleButton // - this.recordToggleButton.Location = new System.Drawing.Point(9, 18); + this.recordToggleButton.Location = new System.Drawing.Point(8, 18); this.recordToggleButton.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.recordToggleButton.Name = "recordToggleButton"; this.recordToggleButton.Size = new System.Drawing.Size(101, 22); @@ -185,7 +185,7 @@ private void InitializeComponent() // // intervalLabel // - this.intervalLabel.Location = new System.Drawing.Point(7, 50); + this.intervalLabel.Location = new System.Drawing.Point(5, 50); this.intervalLabel.Name = "intervalLabel"; this.intervalLabel.Size = new System.Drawing.Size(94, 13); this.intervalLabel.TabIndex = 10; @@ -224,7 +224,7 @@ private void InitializeComponent() // // acquisitionStatusLabel // - this.acquisitionStatusLabel.Location = new System.Drawing.Point(6, 76); + this.acquisitionStatusLabel.Location = new System.Drawing.Point(5, 73); this.acquisitionStatusLabel.Name = "acquisitionStatusLabel"; this.acquisitionStatusLabel.Size = new System.Drawing.Size(292, 13); this.acquisitionStatusLabel.TabIndex = 5; @@ -394,7 +394,7 @@ private void InitializeComponent() // maxValueLabel // this.maxValueLabel.AutoSize = true; - this.maxValueLabel.Location = new System.Drawing.Point(149, 21); + this.maxValueLabel.Location = new System.Drawing.Point(150, 21); this.maxValueLabel.Name = "maxValueLabel"; this.maxValueLabel.Size = new System.Drawing.Size(11, 13); this.maxValueLabel.TabIndex = 4; @@ -403,7 +403,7 @@ private void InitializeComponent() // minValueLabel // this.minValueLabel.AutoSize = true; - this.minValueLabel.Location = new System.Drawing.Point(49, 21); + this.minValueLabel.Location = new System.Drawing.Point(41, 21); this.minValueLabel.Name = "minValueLabel"; this.minValueLabel.Size = new System.Drawing.Size(11, 13); this.minValueLabel.TabIndex = 3; @@ -422,7 +422,7 @@ private void InitializeComponent() // maxLabel // this.maxLabel.AutoSize = true; - this.maxLabel.Location = new System.Drawing.Point(112, 21); + this.maxLabel.Location = new System.Drawing.Point(113, 21); this.maxLabel.Name = "maxLabel"; this.maxLabel.Size = new System.Drawing.Size(31, 13); this.maxLabel.TabIndex = 1; @@ -431,7 +431,7 @@ private void InitializeComponent() // minLabel // this.minLabel.AutoSize = true; - this.minLabel.Location = new System.Drawing.Point(13, 21); + this.minLabel.Location = new System.Drawing.Point(5, 21); this.minLabel.Name = "minLabel"; this.minLabel.Size = new System.Drawing.Size(30, 13); this.minLabel.TabIndex = 0; @@ -456,7 +456,7 @@ private void InitializeComponent() this.MaximizeBox = false; this.Name = "MainWindow"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "ParksideView v1.4"; + this.Text = "ParksideView v1.5"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainWindow_FormClosing); this.readoutLayout.ResumeLayout(false); this.readoutLayout.PerformLayout(); diff --git a/ParksideView/MainWindow.cs b/ParksideView/MainWindow.cs index 16f8eba..2da09c0 100644 --- a/ParksideView/MainWindow.cs +++ b/ParksideView/MainWindow.cs @@ -34,6 +34,8 @@ public MainWindow() windowGroup.Text = Language.WindowHeading; topMostCheck.Text = Language.TopMostCheckBox; minimizeButton.Text = Language.MinimizeButton; + // Statistics group + statisticsGroup.Text = Language.StatisticsHeading; // Acquisition group acquisitionGroup.Text = Language.AcquisitionHeading; intervalLabel.Text = Language.Interval; @@ -136,9 +138,10 @@ private void acquisitionTimer_Tick(object sender, EventArgs e) UpdateTimer(); // Read all available packets + Packet sample = new Packet(); + bool success = false; while (meter.IsAvailable) { - Packet sample; if (!meter.Receive(out sample)) { // Update the blank screen count @@ -153,175 +156,187 @@ private void acquisitionTimer_Tick(object sender, EventArgs e) if (!sample.ChecksumValid) continue; - // Clear the blank screen count and set the alive flag after a successful reception - blankCount = 0; - if (!isAlive) - { - isAlive = true; - UpdateStatusLabels(); - } + // Set the success flag + success = true; + } - // Handle regular display - // Set the mode label accordingly first - bool validMode = true; - bool valueMode = true; - switch (sample.Mode) - { - case Mode.Ampere: - modeLabel.Text = Language.ModeCurrent; - break; - - case Mode.AmpereMicro: - modeLabel.Text = Language.ModeCurrent; - break; - - case Mode.AmpereMilli: - modeLabel.Text = Language.ModeCurrent; - break; - - case Mode.ContinuityOhm: - modeLabel.Text = Language.ModeContinuity; - break; - - case Mode.DiodeVolt: - modeLabel.Text = Language.ModeDiode; - break; - - case Mode.ResistanceOhm: - modeLabel.Text = Language.ModeResistance; - break; - - case Mode.VoltAC: - modeLabel.Text = Language.ModeVoltageAC; - break; - - case Mode.VoltDC: - modeLabel.Text = Language.ModeVoltageDC; - break; - - case Mode.Squarewave: - modeLabel.Text = Language.ModeSquarewave; - valueMode = false; - break; - - default: - modeLabel.Text = Language.ModeUnknown; - valueMode = false; - validMode = false; - break; - } + // Check, if the reception was successful + if (!success) + { + // Start the timer again + acquisitionTimer.Start(); + return; + } - // Compare the last range with the current one - if (lastMode != sample.Mode) - { - ClearStatistics(); - lastMode = sample.Mode; - } + // Clear the blank screen count and set the alive flag after a successful reception + blankCount = 0; + if (!isAlive) + { + isAlive = true; + UpdateStatusLabels(); + } - // Allocate variables for the number parsing - bool negative = false; - int integer = 0, fractional = 0, exponent = 0, precision = 0; - char unit = '\0', unitPrefix = '\0'; + // Handle regular display + // Set the mode label accordingly first + bool validMode = true; + bool valueMode = true; + switch (sample.Mode) + { + case Mode.Ampere: + modeLabel.Text = Language.ModeCurrent; + break; + + case Mode.AmpereMicro: + modeLabel.Text = Language.ModeCurrent; + break; + + case Mode.AmpereMilli: + modeLabel.Text = Language.ModeCurrent; + break; + + case Mode.ContinuityOhm: + modeLabel.Text = Language.ModeContinuity; + break; + + case Mode.DiodeVolt: + modeLabel.Text = Language.ModeDiode; + break; + + case Mode.ResistanceOhm: + modeLabel.Text = Language.ModeResistance; + break; + + case Mode.VoltAC: + modeLabel.Text = Language.ModeVoltageAC; + break; + + case Mode.VoltDC: + modeLabel.Text = Language.ModeVoltageDC; + break; + + case Mode.Squarewave: + modeLabel.Text = Language.ModeSquarewave; + valueMode = false; + break; + + default: + modeLabel.Text = Language.ModeUnknown; + valueMode = false; + validMode = false; + break; + } - // Attempt to parse the number - if (validMode && valueMode) - validMode = Multimeter.Parse(sample, out negative, out integer, out fractional, out exponent, out precision, out unit, out unitPrefix); + // Compare the last range with the current one + if (lastMode != sample.Mode) + { + ClearStatistics(); + lastMode = sample.Mode; + } - // Check, if the mode is invalid or that the number is OL - bool overloaded = Multimeter.IsOverloaded(sample); - if (overloaded && valueMode) // Overload - { - // Update the value and unit labels - valueLabel.Text = "OL"; - unitLabel.Text = unit.ToString(); + // Allocate variables for the number parsing + bool negative = false; + int integer = 0, fractional = 0, exponent = 0, precision = 0; + char unit = '\0', unitPrefix = '\0'; - // Fill the bargraph - FillBargraph(); - } - else if (!validMode || !valueMode) - { - // No valid mode - valueLabel.Text = ""; - unitLabel.Text = ""; + // Attempt to parse the number + if (validMode && valueMode) + validMode = Multimeter.Parse(sample, out negative, out integer, out fractional, out exponent, out precision, out unit, out unitPrefix); - // Clear the bargraph - ClearBargraph(); + // Check, if the mode is invalid or that the number is OL + bool overloaded = Multimeter.IsOverloaded(sample); + if (overloaded && valueMode) // Overload + { + // Update the value and unit labels + valueLabel.Text = "OL"; + unitLabel.Text = unit.ToString(); - // Continue and skip the rest - continue; - } - else - { - // Just format the value according to the precision - valueLabel.Text = precision < 1 ? integer.ToString() : - string.Format("{0}{1}.{2:D" + precision.ToString() + "}", negative ? "-" : "", integer, fractional); - // Also update the unit label - unitLabel.Text = unitPrefix == '\0' ? unit.ToString() : string.Format("{0}{1}", unitPrefix, unit); - } + // Fill the bargraph + FillBargraph(); + } + else if (!validMode || !valueMode) + { + // No valid mode + valueLabel.Text = ""; + unitLabel.Text = ""; + + // Clear the bargraph + ClearBargraph(); + + // Cancel and skip the rest + acquisitionTimer.Start(); + return; + } + else + { + // Just format the value according to the precision + valueLabel.Text = precision < 1 ? integer.ToString() : + string.Format("{0}{1}.{2:D" + precision.ToString() + "}", negative ? "-" : "", integer, fractional); + // Also update the unit label + unitLabel.Text = unitPrefix == '\0' ? unit.ToString() : string.Format("{0}{1}", unitPrefix, unit); + } - // Update the UI - if (!overloaded) + // Update the UI + if (!overloaded) + { + // Update the bargraph + bargraphBar.Minimum = 0; + bargraphBar.Maximum = sample.Value < 0 ? Math.Abs(Multimeter.RangeMin(sample.Mode, sample.Range)) : Multimeter.RangeMax(sample.Mode, sample.Range); + bargraphBar.Value = Math.Abs(sample.Value); + + // Calculate the double value + double currentValue = Math.Pow(10, exponent) * (integer + (fractional * Math.Pow(10, -precision))); + if (negative) + currentValue = -currentValue; + + // Update the min statistics + if (resetStatistics || minValue > currentValue) { - // Update the bargraph - bargraphBar.Minimum = 0; - bargraphBar.Maximum = sample.Value < 0 ? Math.Abs(Multimeter.RangeMin(sample.Mode, sample.Range)) : Multimeter.RangeMax(sample.Mode, sample.Range); - bargraphBar.Value = Math.Abs(sample.Value); - - // Calculate the double value - double currentValue = Math.Pow(10, exponent) * (integer + (fractional * Math.Pow(10, -precision))); - if (negative) - currentValue = -currentValue; - - // Update the min statistics - if (resetStatistics || minValue > currentValue) - { - minValue = currentValue; - minValueLabel.Text = valueLabel.Text + unitLabel.Text; - } - - // Update the max statistics - if (resetStatistics || maxValue < currentValue) - { - maxValue = currentValue; - maxValueLabel.Text = valueLabel.Text + unitLabel.Text; - } - - // Unset the statistics flag - if (resetStatistics) - resetStatistics = false; + minValue = currentValue; + minValueLabel.Text = valueLabel.Text + unitLabel.Text; } - // Handle record mode only for valid value modes - if (isRecording) + // Update the max statistics + if (resetStatistics || maxValue < currentValue) { - // Calculate the offset in seconds - TimeSpan delta = sample.ReceptionTime - recordingStart; - - // Assemble the line, e.g.: 4.32,12.34E-3,V - // Start with the time offset - recordingBuffer.AppendFormat(new NumberFormatInfo() { NumberDecimalSeparator = GetCSVFractionalSeparator().ToString(), NumberDecimalDigits = 2 }, - "{0:E}", delta.TotalSeconds); - // Followed by the delimiter - recordingBuffer.Append(GetCSVDelimiter()); - // Followed by the value - if (overloaded) // Overload - recordingBuffer.Append("OL"); - else if (precision < 1) // Integer value - recordingBuffer.AppendFormat("{0}E{1}", integer, exponent); - else // Fixed point value - recordingBuffer.AppendFormat("{0}{1}{2}{3:D" + precision.ToString() + "}E{4}", negative ? "-" : "", integer, - GetCSVFractionalSeparator(), fractional, exponent); - // Followed by the delimiter - recordingBuffer.Append(GetCSVDelimiter()); - // Followed by the unit - recordingBuffer.Append(unit); - // And a final line break - recordingBuffer.AppendLine(); - - // Update the running for label and increment the sample counter - recordingCount++; - UpdateStatusLabels(); + maxValue = currentValue; + maxValueLabel.Text = valueLabel.Text + unitLabel.Text; } + + // Unset the statistics flag + if (resetStatistics) + resetStatistics = false; + } + + // Handle record mode only for valid value modes + if (isRecording) + { + // Calculate the offset in seconds + TimeSpan delta = sample.ReceptionTime - recordingStart; + + // Assemble the line, e.g.: 4.32,12.34E-3,V + // Start with the time offset + recordingBuffer.AppendFormat(new NumberFormatInfo() { NumberDecimalSeparator = GetCSVFractionalSeparator().ToString(), NumberDecimalDigits = 2 }, + "{0:E}", delta.TotalSeconds); + // Followed by the delimiter + recordingBuffer.Append(GetCSVDelimiter()); + // Followed by the value + if (overloaded) // Overload + recordingBuffer.Append("OL"); + else if (precision < 1) // Integer value + recordingBuffer.AppendFormat("{0}E{1}", integer, exponent); + else // Fixed point value + recordingBuffer.AppendFormat("{0}{1}{2}{3:D" + precision.ToString() + "}E{4}", negative ? "-" : "", integer, + GetCSVFractionalSeparator(), fractional, exponent); + // Followed by the delimiter + recordingBuffer.Append(GetCSVDelimiter()); + // Followed by the unit + recordingBuffer.Append(unit); + // And a final line break + recordingBuffer.AppendLine(); + + // Update the running for label and increment the sample counter + recordingCount++; + UpdateStatusLabels(); } // Start the timer again @@ -484,7 +499,7 @@ private void RefreshPorts() /// /// The regex used to match skippable entries in a ports list /// - private readonly Regex skippablePortsRegex = new Regex("^/dev/tty(?:[a-rt-z]?[0-9]+)$", + private readonly Regex skippablePortsRegex = new Regex("^/dev/tty[a-rt-z]?[0-9]+$", RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.IgnoreCase); /// @@ -726,8 +741,9 @@ private void ChangeUI(bool isConnected, bool isPaused, bool isRecording) intervalNumeric.Enabled = !isRecording; resetButton.Enabled = isConnected; - // Clear the statistics - ClearStatistics(); + // Clear the statistics if not connected + if (!isConnected) + ClearStatistics(); // Clear the readout and bargraph after disconnecting if (!isConnected) diff --git a/ParksideView/Properties/AssemblyInfo.cs b/ParksideView/Properties/AssemblyInfo.cs index d9f2649..72f556f 100644 --- a/ParksideView/Properties/AssemblyInfo.cs +++ b/ParksideView/Properties/AssemblyInfo.cs @@ -33,6 +33,6 @@ // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // übernehmen, indem Sie "*" eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.0.0")] -[assembly: AssemblyFileVersion("1.4.0.0")] +[assembly: AssemblyVersion("1.5.0.0")] +[assembly: AssemblyFileVersion("1.5.0.0")] [assembly: NeutralResourcesLanguageAttribute("")]