public PowerTest() { InitializeComponent(); string[] ports = SerialPort.GetPortNames(); foreach (string port in ports) { CMB_ComList.Items.Add(port); } CMB_ComList.Items.Add("Mock"); if (CMB_ComList.Items.Count > 0) { CMB_ComList.SelectedIndex = 0; BTN_ComCtrl.Enabled = true; } CMB_LogLevel.Items.Add("Operation"); CMB_LogLevel.Items.Add("Bus"); CMB_LogLevel.Items.Add("Command"); CMB_LogLevel.SelectedIndex = 0; Logger.mLevel = Logger.Level.Operation; /*Single Command Test*/ if (TB_Cmd.Text.Length == 0) { TB_Cmd.Text = Properties.Settings.Default.DefaultCmd; } /*Multiple Command Test*/ TB_TestFile.Text = Properties.Settings.Default.TestFile; TB_TestTimes.Text = Properties.Settings.Default.TestTimes; if (Properties.Settings.Default.TestMode.Equals("Times")) { RB_TestTimes.Checked = true; } else { RB_TestMinutes.Checked = true; } /*Stability Test*/ string[] StabilityTest = JzhTest.GetAllTests(); for (int i = 0; i < StabilityTest.Length; i++) { CMB_TestType.Items.Add(StabilityTest[i]); } CMB_TestType.SelectedIndex = 0; if (CB_LogEnable.Checked) { Logger.updateUI += new Logger.UpdateUI(log => { TB_Log.Text += "\r\n" + log; }); } CB_ElecModuleEnable.Checked = true; RB_PartA.Checked = true; }
private void BTN_StabilityStart_Click(object sender, EventArgs e) { if (!CB_ElecModuleEnable.Checked) { MessageBox.Show("ElectricModule should be checked"); return; } StabilityTestRunning = true; BTN_StabilityStart.Enabled = false; int option = CMB_TestType.SelectedIndex; int duration = Int32.Parse(TB_Duration.Text); bool forceClose = CB_ForceClose.Checked; bool forceDisconnect = CB_ForceDisconnect.Checked; int maxRange = Int32.Parse(TB_MaxCurrent.Text); JzhTest aTest = null; switch (option) { case 0: { aTest = new SingleCurrentTest(port, maxRange, duration, 1000, CB_LogFileEnable.Checked); aTest.updateUi = UpdateUi; aTest.taskDone = TaskDone; break; } case 1: { double[] tests = new double[] { maxRange / 4, maxRange / 2, maxRange * 3 / 4, maxRange }; aTest = new MultiCurrentTest(port, tests, duration, 1000, CB_LogFileEnable.Checked); aTest.updateUi = UpdateUi; aTest.taskDone = TaskDone; break; } case 2: { aTest = new SetCurrentPartTest(port, maxRange, duration, 1000, CB_LogFileEnable.Checked); aTest.updateUi = UpdateUi; aTest.taskDone = TaskDone; break; } } Thread t = new Thread(new ThreadStart(aTest.Run)); t.Start(); }