private void ActivityButton_Click(object sender, EventArgs e) { if (false == this.active) { string result = null; SetupParameters busParameters = new SetupParameters(); TestParameters testParameters = new TestParameters(); if (null == result) { result = this.ExtractBusParameters(busParameters); if (null != result) { this.MainTabControl.SelectedTab = this.SetupTabPage; } } if (null == result) { result = this.ExtractTestParameters(testParameters); if (null != result) { this.MainTabControl.SelectedTab = this.TestTabPage; } } if (null == result) { this.testComplete = false; this.dynoTest.Start(busParameters, testParameters, ref result); } if (null == result) { this.StatusLabel.Text = "test started"; this.active = true; this.LockForRun(); } else { this.StatusLabel.Text = result; } } else { this.dynoTest.Stop(); this.StatusLabel.Text = "test stopped"; this.active = false; this.UnlockForIdle(); } }
private string ExtractTestParameters(TestParameters testParameters) { string result = null; #region Runtime Entry Parsing string runtimeString = this.RunTimeTextBox.Text; if (null != runtimeString) { string[] timeValues = runtimeString.Split(new char[] { '/' }); if ((null != timeValues) && (3 == timeValues.Length)) { bool validTime = true; double hours = 0; double minutes = 0; double seconds = 0; double totalTime = 0; if (double.TryParse(timeValues[0], out hours) == false) { validTime = false; } if (double.TryParse(timeValues[1], out minutes) == false) { validTime = false; } if (double.TryParse(timeValues[2], out seconds) == false) { validTime = false; } if (false != validTime) { totalTime = (hours * 3600.0) + (minutes * 60.0) + seconds; if (0 == totalTime) { validTime = false; } } if (false != validTime) { testParameters.RunTime = totalTime; } else { result = "invalid entry"; this.RunTimeTextBox.BackColor = Color.Red; } } else { result = "invalid entry"; this.RunTimeTextBox.BackColor = Color.Red; } } #endregion #region Wheel Speed Entry Parsing string wheelSpeedString = this.WheelSpeedTextBox.Text; if (null != wheelSpeedString) { double wheelSpeed = 0; if (double.TryParse(wheelSpeedString, out wheelSpeed) != false) { if ((wheelSpeed >= -10) && (wheelSpeed <= 10)) { testParameters.WheelSpeed = wheelSpeed; } else { result = "invalid entry, limited to {-10.0 .. +10.0}"; this.WheelSpeedTextBox.BackColor = Color.Red; } } else { result = "invalid entry"; this.WheelSpeedTextBox.BackColor = Color.Red; } } #endregion #region Wheel Start Load Entry Parsing string wheelStartLoadString = this.WheelStartLoadTextBox.Text; if (null != wheelStartLoadString) { double wheelStartLoad = 0; if (double.TryParse(wheelStartLoadString, out wheelStartLoad) != false) { testParameters.WheelStartLoad= wheelStartLoad; } else { result = "invalid entry"; this.WheelStartLoadTextBox.BackColor = Color.Red; } } #endregion #region Wheel Stop Load Entry Parsing string wheelStopLoadString = this.WheelStopLoadTextBox.Text; if (null != wheelStopLoadString) { double wheelStopLoad = 0; if (double.TryParse(wheelStopLoadString, out wheelStopLoad) != false) { testParameters.WheelStopLoad = wheelStopLoad; } else { result = "invalid entry"; this.WheelStopLoadTextBox.BackColor = Color.Red; } } #endregion #region Current Limit Entry Parsing string currentLimitString = this.CurrentLimitTextBox.Text; if (null != currentLimitString) { double currentLimit = 0; if (double.TryParse(currentLimitString, out currentLimit) != false) { testParameters.CurrentLimit= currentLimit; } else { result = "invalid entry"; this.CurrentLimitTextBox.BackColor = Color.Red; } } #endregion #region Thermal Limit Entry Parsing string thermalLimitString = this.ThermalLimitTextBox.Text; if (null != thermalLimitString) { double thermalLimit = 0; if (double.TryParse(thermalLimitString, out thermalLimit) != false) { testParameters.ThermalLimit = thermalLimit; } else { result = "invalid entry"; this.ThermalLimitTextBox.BackColor = Color.Red; } } #endregion #region Slippage Limit Entry Parsing string slippageLimitString = this.SlippageLimitTextBox.Text; if (null != slippageLimitString) { double slippageLimit = 0; if (double.TryParse(slippageLimitString, out slippageLimit) != false) { testParameters.SlippageLimit = slippageLimit; } else { result = "invalid entry"; this.SlippageLimitTextBox.BackColor = Color.Red; } } #endregion return (result); }
private void PopulateTestParameters(TestParameters testParameters) { if (double.IsNaN(testParameters.RunTime) == false) { double totalSeconds = testParameters.RunTime; int hours = (int)(testParameters.RunTime / 3600.0); totalSeconds -= (hours * 3600.0); int minutes = (int)(totalSeconds / 60.0); totalSeconds -= (minutes * 60.0); double seconds = totalSeconds; this.RunTimeTextBox.Text = string.Format("{0}/{1}/{2}", hours, minutes, seconds); this.RunTimeTextBox.BackColor = Color.FromKnownColor(KnownColor.Window); } else { this.RunTimeTextBox.Text = ""; this.RunTimeTextBox.BackColor = Color.Red; } if (double.IsNaN(testParameters.WheelSpeed) == false) { this.WheelSpeedTextBox.Text = testParameters.WheelSpeed.ToString(); this.WheelSpeedTextBox.BackColor = Color.FromKnownColor(KnownColor.Window); } else { this.WheelSpeedTextBox.Text = ""; this.WheelSpeedTextBox.BackColor = Color.Red; } if (double.IsNaN(testParameters.WheelStartLoad) == false) { this.WheelStartLoadTextBox.Text = testParameters.WheelStartLoad.ToString(); this.WheelStartLoadTextBox.BackColor = Color.FromKnownColor(KnownColor.Window); } else { this.WheelStartLoadTextBox.Text = ""; this.WheelStartLoadTextBox.BackColor = Color.Red; } if (double.IsNaN(testParameters.WheelStopLoad) == false) { this.WheelStopLoadTextBox.Text = testParameters.WheelStopLoad.ToString(); this.WheelStopLoadTextBox.BackColor = Color.FromKnownColor(KnownColor.Window); } else { this.WheelStopLoadTextBox.Text = ""; this.WheelStopLoadTextBox.BackColor = Color.Red; } if (double.IsNaN(testParameters.CurrentLimit) == false) { this.CurrentLimitTextBox.Text = testParameters.CurrentLimit.ToString(); this.CurrentLimitTextBox.BackColor = Color.FromKnownColor(KnownColor.Window); } else { this.CurrentLimitTextBox.Text = ""; this.CurrentLimitTextBox.BackColor = Color.Red; } if (double.IsNaN(testParameters.ThermalLimit) == false) { this.ThermalLimitTextBox.Text = testParameters.ThermalLimit.ToString(); this.ThermalLimitTextBox.BackColor = Color.FromKnownColor(KnownColor.Window); } else { this.ThermalLimitTextBox.Text = ""; this.ThermalLimitTextBox.BackColor = Color.Red; } if (double.IsNaN(testParameters.SlippageLimit) == false) { this.SlippageLimitTextBox.Text = testParameters.SlippageLimit.ToString(); this.SlippageLimitTextBox.BackColor = Color.FromKnownColor(KnownColor.Window); } else { this.SlippageLimitTextBox.Text = ""; this.SlippageLimitTextBox.BackColor = Color.Red; } }
private void SaveParametersButton_Click(object sender, EventArgs e) { TestParameters testParameters = new TestParameters(); string extractResult = this.ExtractTestParameters(testParameters); if (null == extractResult) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.RestoreDirectory = true; saveFileDialog.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*"; saveFileDialog.FilterIndex = 0; saveFileDialog.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory; saveFileDialog.FileName = "testParameters.xml"; if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string saveResult = testParameters.Save(saveFileDialog.FileName); if (null == saveResult) { this.StatusLabel.Text = "parameters saved"; } else { this.StatusLabel.Text = saveResult; } } } else { this.StatusLabel.Text = extractResult; } }
private void LoadParametersButton_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.RestoreDirectory = true; openFileDialog.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*"; openFileDialog.FilterIndex = 0; openFileDialog.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory; openFileDialog.FileName = "testParameters.xml"; if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { TestParameters testParameters = new TestParameters(); string result = testParameters.Load(openFileDialog.FileName); if (null == result) { this.PopulateTestParameters(testParameters); this.StatusLabel.Text = "parameters loaded"; } else { this.StatusLabel.Text = result; } } }
public void Start(SetupParameters busParameters, TestParameters testParameters, ref string result) { if (null == result) { this.thread = new Thread(this.TestProcess); this.thread.IsBackground = true; this.thread.Name = "Test Process"; this.setupParameters = busParameters; this.testParameters = testParameters; this.completeEarly = false; this.execute = true; this.thread.Start(); } }