/* --------------------------------------------------------------------------- * test_control.cs (c) 2009 Micro-key bv * --------------------------------------------------------------------------- * Micro-key bv * Industrieweg 28, 9804 TG Noordhorn * Postbus 92, 9800 AB Zuidhorn * The Netherlands * Tel: +31 594 503020 * Fax: +31 594 505825 * Email: support@microkey.nl * Web: www.microkey.nl * --------------------------------------------------------------------------- * Description: This file handles all Actions of the "Test" Group * --------------------------------------------------------------------------- * Version(s): 0.1, Jan 08, 2009, MMi * Creation. * --------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------- * System use files * --------------------------------------------------------------------------- */ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.IO.Ports; using System.Threading; /* --------------------------------------------------------------------------- * Local function definitions * --------------------------------------------------------------------------- */ namespace QUA_2475_designtest { public partial class mainWindow { private void increment_passed() { /* If called, increment the TestPassed counter */ L_stats_numberpassed.Text = Convert.ToString(TotalPassedNumber++); } private void increment_failed() { /* If called, increment the TestFailed counter */ L_stats_numberfailed.Text = Convert.ToString(TotalFailedNumber++); } private void TestIsUntested(System.UInt32 TestID) { if (TestID > 18) { } else { /* Resets the to the parameter corresponding Textbox */ TestTextBoxes[TestID].Text = "untested"; TestTextBoxes[TestID].BackColor = System.Drawing.Color.White; } } private void TestIsActive(System.UInt32 TestID) { if (TestID > 18) { } else { /* Sets status of the corresponding TextBox to active */ TestTextBoxes[TestID].Text = "Active"; TestTextBoxes[TestID].BackColor = System.Drawing.Color.Yellow; } } private void CalibrationFinished() { MessageBox.Show("Calibration Finished"); TestTimeoutThread.Abort(); /* Abort Timeout Thread */ globalActivities(true); /* If Test was called by automatic test routine, go back there */ if (activeAutomatictest == true) { automaticTest(); } } private void TestIsCanceled(System.UInt32 TestID) { if (TestID > 18) { } else { /* Sets status of the corresponding TextBox to active */ TestTextBoxes[TestID].Text = "Canceled"; TestTextBoxes[TestID].BackColor = System.Drawing.Color.DarkOrange; globalActivities(true); } } private void TestIsPassed(System.UInt32 TestID) { if (TestID > 18) { } else { /* Sets status of the corresponding TextBox to a passed test */ TestTimeoutThread.Abort(); /* Abort Timeout Thread */ TestTextBoxes[TestID].Text = "Passed"; TestTextBoxes[TestID].BackColor = System.Drawing.Color.Green; globalActivities(true); /* If Test was called by automatic test routine, go back there */ if (activeAutomatictest == true) { automaticTest(); } } } private void TestIsFailed(System.UInt32 TestID) { if (TestID > 18) { } else { /* Sets status of the corresponding TextBox to a failed test */ TestTimeoutThread.Abort(); /* Abort Timeout Thread */ TestTextBoxes[TestID].Text = "Failed"; TestTextBoxes[TestID].BackColor = System.Drawing.Color.Red; globalActivities(true); /* If Test was called by automatic test routine, go back there */ if (activeAutomatictest == true) { automaticTest(); } } } private void TestIsSkipped(System.UInt32 TestID) { if (TestID > 18) { TestResult[TestID] = true; /* If Test was called by automatic test routine, go back there */ if (activeAutomatictest == true) { automaticTest(); } } else { /* Sets status of the corresponding TextBox to a passed test */ TestTextBoxes[TestID].Text = "skipped"; TestTextBoxes[TestID].BackColor = System.Drawing.Color.CornflowerBlue; TestResult[TestID] = true; /* If Test was called by automatic test routine, go back there */ if (activeAutomatictest == true) { automaticTest(); } } } private void TestIsUnavailable(System.UInt32 TestID) { if (TestID > 18) { } else { /* Sets status of the corresponding TextBox to unreachable test */ TestTimeoutThread.Abort(); /* Abort Timeout Thread */ TestTextBoxes[TestID].Text = "unavailable"; TestTextBoxes[TestID].BackColor = System.Drawing.Color.CornflowerBlue; /* If Test was called by automatic test routine, go back there */ if (activeAutomatictest == true) { automaticTest(); } } } delegate void TestIsTimeoutCallback(System.UInt32 TestID); private void TestIsTimeout(System.UInt32 TestID) { if (TestID > 18) { } else { /* Check if Application is called from a subThread */ if (this.TestTextBoxes[TestID].InvokeRequired) { /* Handle Parameters to main Thread */ TestIsTimeoutCallback d = new TestIsTimeoutCallback(TestIsTimeout); this.Invoke(d, new object[] { TestID }); } else { /* Set corresponding TextBox to Timeout Status */ TestTextBoxes[TestID].Text = "Timeout"; TestTextBoxes[TestID].BackColor = System.Drawing.Color.DarkOrange; activeTest = false; /* If Test was called by automatic test routine, go there */ if (activeAutomatictest == true) { automaticTest(); } } } } private void C_test_VCC_CheckedChanged(object sender, EventArgs e) { if (C_test_VCC.Checked == true) { ActivateTest[(int)TestType.VCC] = true; } else { ActivateTest[(int)TestType.VCC] = false; } } private void C_test_VDDAT_CheckedChanged(object sender, EventArgs e) { if (C_test_VDDAT.Checked == true) { ActivateTest[(int)TestType.VDDAT] = true; } else { ActivateTest[(int)TestType.VDDAT] = false; } } private void C_test_VBAT_CheckedChanged(object sender, EventArgs e) { if (C_test_VBAT.Checked == true) { ActivateTest[(int)TestType.VBAT] = true; } else { ActivateTest[(int)TestType.VBAT] = false; } } private void C_test_VCORE_CheckedChanged(object sender, EventArgs e) { if (C_test_VCORE.Checked == true) { ActivateTest[(int)TestType.VCORE] = true; } else { ActivateTest[(int)TestType.VCORE] = false; } } private void C_test_TEMP_CheckedChanged(object sender, EventArgs e) { if (C_test_TEMP.Checked == true) { ActivateTest[(int)TestType.TEMP] = true; } else { ActivateTest[(int)TestType.TEMP] = false; } } private void C_test_REVNUM_CheckedChanged(object sender, EventArgs e) { if (C_test_REVNUM.Checked == true) { ActivateTest[(int)TestType.REVNUM] = true; } else { ActivateTest[(int)TestType.REVNUM] = false; } } private void C_test_MB_LED_CheckedChanged(object sender, EventArgs e) { if (C_test_MB_LED.Checked == true) { ActivateTest[(int)TestType.LED_MB] = true; } else { ActivateTest[(int)TestType.LED_MB] = false; } } private void C_test_MB_EEPROM_CheckedChanged(object sender, EventArgs e) { if (C_test_MB_EEPROM.Checked == true) { ActivateTest[(int)TestType.EEPROM_MB] = true; } else { ActivateTest[(int)TestType.EEPROM_MB] = false; } } private void C_test_eth0_CheckedChanged(object sender, EventArgs e) { if (C_test_eth0.Checked == true) { ActivateTest[(int)TestType.ETH0] = true; } else { ActivateTest[(int)TestType.ETH0] = false; } } private void C_test_eth1_CheckedChanged(object sender, EventArgs e) { if (C_test_eth1.Checked == true) { ActivateTest[(int)TestType.ETH1] = true; } else { ActivateTest[(int)TestType.ETH1] = false; } } private void C_test_USB_CheckedChanged(object sender, EventArgs e) { if (C_test_USB.Checked == true) { ActivateTest[(int)TestType.USB] = true; } else { ActivateTest[(int)TestType.USB] = false; } } private void C_test_MB_DIO_CheckedChanged(object sender, EventArgs e) { if (C_test_MB_DIO.Checked == true) { ActivateTest[(int)TestType.DIO_MB] = true; } else { ActivateTest[(int)TestType.DIO_MB] = false; } } private void C_test_MB_AIO_CheckedChanged(object sender, EventArgs e) { if (C_test_MB_AIO.Checked == true) { ActivateTest[(int)TestType.AIO_MB] = true; } else { ActivateTest[(int)TestType.AIO_MB] = false; } } private void C_test_MB_RLY_CheckedChanged(object sender, EventArgs e) { if (C_test_MB_RLY.Checked == true) { ActivateTest[(int)TestType.RLY_MB] = true; } else { ActivateTest[(int)TestType.RLY_MB] = false; } } private void C_test_EB_LED_CheckedChanged(object sender, EventArgs e) { if (C_test_EB_LED.Checked == true) { ActivateTest[(int)TestType.LED_EB] = true; } else { ActivateTest[(int)TestType.LED_EB] = false; } } private void C_test_EB_EEPROM_CheckedChanged(object sender, EventArgs e) { if (C_test_EB_EEPROM.Checked == true) { ActivateTest[(int)TestType.EEPROM_EB] = true; } else { ActivateTest[(int)TestType.EEPROM_EB] = false; } } private void C_test_EB_DIO_CheckedChanged(object sender, EventArgs e) { if (C_test_EB_DIO.Checked == true) { ActivateTest[(int)TestType.DIO_EB] = true; } else { ActivateTest[(int)TestType.DIO_EB] = false; } } private void C_test_EB_AIO_CheckedChanged(object sender, EventArgs e) { if (C_test_EB_AIO.Checked == true) { ActivateTest[(int)TestType.AIO_EB] = true; } else { ActivateTest[(int)TestType.AIO_EB] = false; } } private void C_test_EB_RLY_CheckedChanged(object sender, EventArgs e) { if (C_test_EB_RLY.Checked == true) { ActivateTest[(int)TestType.RLY_EB] = true; } else { ActivateTest[(int)TestType.RLY_EB] = false; } } private void B_test_VCC_Click(object sender, EventArgs e) { /* CallTestRoutine corresponding TestResult with Parameter */ CallTestRoutine((int)TestType.VCC); } private void B_test_VDDAT_Click(object sender, EventArgs e) { /* CallTestRoutine corresponding TestResult with Parameter */ CallTestRoutine((int)TestType.VDDAT); } private void B_test_VBAT_Click(object sender, EventArgs e) { /* CallTestRoutine corresponding TestResult with Parameter */ CallTestRoutine((int)TestType.VBAT); } private void B_test_VCORE_Click(object sender, EventArgs e) { /* CallTestRoutine corresponding TestResult with Parameter */ CallTestRoutine((int)TestType.VCORE); } private void B_test_TEMP_Click(object sender, EventArgs e) { /* CallTestRoutine corresponding TestResult with Parameter */ CallTestRoutine((int)TestType.TEMP); } private void B_test_REVNUM_Click(object sender, EventArgs e) { /* CallTestRoutine corresponding TestResult with Parameter */ CallTestRoutine((int)TestType.REVNUM); } private void B_test_MB_LED_Click(object sender, EventArgs e) { /* CallTestRoutine corresponding TestResult with Parameter */ CallTestRoutine((int)TestType.LED_MB); } private void B_test_MB_EEPROM_Click(object sender, EventArgs e) { /* CallTestRoutine corresponding TestResult with Parameter */ CallTestRoutine((int)TestType.EEPROM_MB); } private void B_test_eth0_Click(object sender, EventArgs e) { /* CallTestRoutine corresponding TestResult with Parameter */ CallTestRoutine((int)TestType.ETH0); } private void B_test_eth1_Click(object sender, EventArgs e) { /* CallTestRoutine corresponding TestResult with Parameter */ CallTestRoutine((int)TestType.ETH1); } private void B_test_USB_Click(object sender, EventArgs e) { /* CallTestRoutine corresponding TestResult with Parameter */ CallTestRoutine((int)TestType.USB); } private void B_test_MB_DIO_Click(object sender, EventArgs e) { /* CallTestRoutine corresponding TestResult with Parameter */ CallTestRoutine((int)TestType.DIO_MB); } private void B_test_MB_AIO_Click(object sender, EventArgs e) { /* CallTestRoutine corresponding TestResult with Parameter */ CallTestRoutine((int)TestType.AIO_MB); } private void B_test_MB_RLY_Click(object sender, EventArgs e) { /* CallTestRoutine corresponding TestResult with Parameter */ CallTestRoutine((int)TestType.RLY_MB); } private void B_test_EB_LED_Click(object sender, EventArgs e) { /* CallTestRoutine corresponding TestResult with Parameter */ CallTestRoutine((int)TestType.LED_EB); } private void B_test_EB_EEPROM_Click(object sender, EventArgs e) { /* CallTestRoutine corresponding TestResult with Parameter */ CallTestRoutine((int)TestType.EEPROM_EB); } private void B_test_EB_DIO_Click(object sender, EventArgs e) { /* CallTestRoutine corresponding TestResult with Parameter */ CallTestRoutine((int)TestType.DIO_EB); } private void B_test_EB_AIO_Click(object sender, EventArgs e) { /* CallTestRoutine corresponding TestResult with Parameter */ CallTestRoutine((int)TestType.AIO_EB); } private void B_test_EB_RLY_Click(object sender, EventArgs e) { /* CallTestRoutine corresponding TestResult with Parameter */ CallTestRoutine((int)TestType.RLY_EB); } private void B_test_STOP_Click(object sender, EventArgs e) { if (activeTest == true) { TestTimeoutThread.Abort(); /* Abort Timeout Thread */ activeTest = false; activeAutomatictest = false; TestIsCanceled(actualTest); globalActivities(true); testcnt = 0; } else { activeAutomatictest = false; globalActivities(true); testcnt = 0; } } private void B_test_clear_Click(object sender, EventArgs e) { /* If no Test is Active: */ if (activeTest == false) { /* Reset all Test TextBoxes to untested status */ for (uint loopcnt = 0; loopcnt < NrOfTests; loopcnt++) { T_MasterOutput.BackColor = System.Drawing.Color.White; TestIsUntested(loopcnt); } } } private void B_test_TESTALL_Click(object sender, EventArgs e) { automaticTest(); } private void CallTestRoutine(uint TestID) { /* Call Test just if no other Test is active */ if (activeTest == false) { globalActivities(false); actualTest = TestID; /* Set actual Test ID to active Test*/ TestMessage[actualTest] = ""; /* Define and Start Timeout Thread */ TestTimeoutThread = new Thread(new ThreadStart(TimeoutThread)); TestTimeoutThread.Start(); activeTest = true; /* Set Test to global active */ com1.Write(TestCallCommands[actualTest]); /* Call Test */ TestIsActive(actualTest); /* Set Test TextBox */ globalActivities(true); } } private void automaticTest() { activeAutomatictest = true; /* Set autoTest to global active */ globalActivities(false); /* Reset all Test Results and Test TextBoxes */ if (testcnt == 0) { AllTestResult = false; for (uint loopcnt = 0; loopcnt < NrOfTests; loopcnt++) { T_MasterOutput.BackColor = System.Drawing.Color.White; TestIsUntested(loopcnt); TestResult[loopcnt] = false; } } if (testcnt < NrOfTests) { Thread.Sleep(500); /* Call single Test */ if (ActivateTest[testcnt] == true) { CallTestRoutine(testcnt++); } else { TestIsSkipped(testcnt++); } } else if (testcnt == NrOfTests) { if (setRTC == true) { remoteRTCset(); } //if (cal_Analogue == true) //{ // TestTimeoutThread = new Thread(new ThreadStart(TimeoutThread)); // TestTimeoutThread.Start(); // calibrateAnalogue(); //} testcnt = 0; /* reset Test counter to zero */ /* Increment Number of Totals Test */ calculateAllResult(); /* Calculate autoTest Result */ if (AllTestResult == false) { // /* If one or more tests failed */ // InfoBox infobox = new InfoBox(); /* Ask if user wants to restart test */ // if (infobox.ShowDialog() == DialogResult.OK) { /* If user wants to restart, break out of algorithm * and return to idle stat. Do not increment counters * or the automatically calculated values */ // return; } /* Test failed - Increment FAILED- and overall Counter */ increment_failed(); L_stats_numbertotal.Text = Convert.ToString(TotalTestNumber++); } else { /* Test passed - Increment PASSED- and overall Counter */ increment_passed(); L_stats_numbertotal.Text = Convert.ToString(TotalTestNumber++); } activeAutomatictest = false; /* set autoTest to global off */ globalActivities(true); } } private void calculateAllResult() { if ((TestResult[0] & TestResult[1] & TestResult[2] & TestResult[3] & TestResult[4] & TestResult[5] & TestResult[6] & TestResult[7] & TestResult[8] & TestResult[9] & TestResult[10] & TestResult[11] & TestResult[12] & TestResult[13] & TestResult[14] & TestResult[15] & TestResult[16] & TestResult[17] & TestResult[18] & TestResult[19] & TestResult[20] & TestResult[21] & TestResult[22]) == true) { AllTestResult = true; T_MasterOutput.BackColor = System.Drawing.Color.Green; MessageBox.Show("Automatic Test Sequence finished\n\rSUCCESSFULLY"); } else { AllTestResult = false; T_MasterOutput.BackColor = System.Drawing.Color.Red; MessageBox.Show("Automatic Test Sequence finished\n\rwith ERRORS"); } } private void globalActivities (bool control) { /* Control checkboxes for Test-Controls */ C_test_VCC.Enabled = control; C_test_VDDAT.Enabled = control; C_test_VBAT.Enabled = control; C_test_VCORE.Enabled = control; C_test_TEMP.Enabled = control; C_test_REVNUM.Enabled = control; C_test_MB_LED.Enabled = control; C_test_MB_EEPROM.Enabled = control; C_test_eth0.Enabled = control; C_test_eth1.Enabled = control; C_test_USB.Enabled = control; C_test_MB_DIO.Enabled = control; C_test_MB_AIO.Enabled = control; C_test_MB_RLY.Enabled = control; C_test_EB_LED.Enabled = control; C_test_EB_EEPROM.Enabled = control; C_test_EB_DIO.Enabled = control; C_test_EB_AIO.Enabled = control; C_test_EB_RLY.Enabled = control; /* Control Buttons of test section */ B_test_VCC.Enabled = control; B_test_VDDAT.Enabled = control; B_test_VBAT.Enabled = control; B_test_VCORE.Enabled = control; B_test_TEMP.Enabled = control; B_test_REVNUM.Enabled = control; B_test_MB_LED.Enabled = control; B_test_MB_EEPROM.Enabled = control; B_test_eth0.Enabled = control; B_test_eth1.Enabled = control; B_test_USB.Enabled = control; B_test_MB_DIO.Enabled = control; B_test_MB_AIO.Enabled = control; B_test_MB_RLY.Enabled = control; B_test_EB_LED.Enabled = control; B_test_EB_EEPROM.Enabled = control; B_test_EB_DIO.Enabled = control; B_test_EB_AIO.Enabled = control; B_test_EB_RLY.Enabled = control; /* Control Configuration Buttons */ B_conf_addall.Enabled = control; B_conf_removeall.Enabled = control; B_conf_addMB.Enabled = control; B_conf_removeMB.Enabled = control; B_conf_addEB.Enabled = control; B_conf_removeEB.Enabled = control; B_conf_resettotal.Enabled = control; /* Control String Input Text Box for Device */ T_MasterInput.Enabled = control; } private void B_master_init_Click(object sender, EventArgs e) { com1.Write("initForC_S\r"); } private void B_masterY_Click(object sender, EventArgs e) { com1.Write("y"); } private void B_master_N_Click(object sender, EventArgs e) { com1.Write("n"); } private void B_master_ENTER_Click(object sender, EventArgs e) { com1.Write("\r"); } private void B_conf_addall_Click(object sender, EventArgs e) { C_test_VCC.Checked = true; C_test_VDDAT.Checked = true; C_test_VBAT.Checked = true; C_test_VCORE.Checked = true; C_test_TEMP.Checked = true; C_test_REVNUM.Checked = true; C_test_MB_LED.Checked = true; C_test_MB_EEPROM.Checked = true; C_test_eth0.Checked = true; C_test_eth1.Checked = true; C_test_USB.Checked = true; C_test_MB_DIO.Checked = true; C_test_MB_AIO.Checked = true; C_test_MB_RLY.Checked = true; C_test_EB_LED.Checked = true; C_test_EB_EEPROM.Checked = true; C_test_EB_DIO.Checked = true; C_test_EB_AIO.Checked = true; C_test_EB_RLY.Checked = true; } private void B_conf_addMB_Click(object sender, EventArgs e) { C_test_VCC.Checked = true; C_test_VDDAT.Checked = true; C_test_VBAT.Checked = true; C_test_VCORE.Checked = true; C_test_TEMP.Checked = true; C_test_REVNUM.Checked = true; C_test_MB_LED.Checked = true; C_test_MB_EEPROM.Checked = true; C_test_eth0.Checked = true; C_test_eth1.Checked = true; C_test_USB.Checked = true; C_test_MB_DIO.Checked = true; C_test_MB_AIO.Checked = true; C_test_MB_RLY.Checked = true; } private void B_conf_addEB_Click(object sender, EventArgs e) { C_test_EB_LED.Checked = true; C_test_EB_EEPROM.Checked = true; C_test_EB_DIO.Checked = true; C_test_EB_AIO.Checked = true; C_test_EB_RLY.Checked = true; } private void B_conf_removeall_Click(object sender, EventArgs e) { C_test_VCC.Checked = false; C_test_VDDAT.Checked = false; C_test_VBAT.Checked = false; C_test_VCORE.Checked = false; C_test_TEMP.Checked = false; C_test_REVNUM.Checked = false; C_test_MB_LED.Checked = false; C_test_MB_EEPROM.Checked = false; C_test_eth0.Checked = false; C_test_eth1.Checked = false; C_test_USB.Checked = false; C_test_MB_DIO.Checked = false; C_test_MB_AIO.Checked = false; C_test_MB_RLY.Checked = false; C_test_EB_LED.Checked = false; C_test_EB_EEPROM.Checked = false; C_test_EB_DIO.Checked = false; C_test_EB_AIO.Checked = false; C_test_EB_RLY.Checked = false; } private void B_conf_removeMB_Click(object sender, EventArgs e) { C_test_VCC.Checked = false; C_test_VDDAT.Checked = false; C_test_VBAT.Checked = false; C_test_VCORE.Checked = false; C_test_TEMP.Checked = false; C_test_REVNUM.Checked = false; C_test_MB_LED.Checked = false; C_test_MB_EEPROM.Checked = false; C_test_eth0.Checked = false; C_test_eth1.Checked = false; C_test_USB.Checked = false; C_test_MB_DIO.Checked = false; C_test_MB_AIO.Checked = false; C_test_MB_RLY.Checked = false; } private void B_conf_removeEB_Click(object sender, EventArgs e) { C_test_EB_LED.Checked = false; C_test_EB_EEPROM.Checked = false; C_test_EB_DIO.Checked = false; C_test_EB_AIO.Checked = false; C_test_EB_RLY.Checked = false; } private void B_conf_resettotal_Click(object sender, EventArgs e) { TotalFailedNumber = 0; TotalPassedNumber = 0; TotalTestNumber = 0; L_stats_numberfailed.Text = Convert.ToString(TotalFailedNumber); L_stats_numberpassed.Text = Convert.ToString(TotalPassedNumber); L_stats_numbertotal.Text = Convert.ToString(TotalTestNumber); } private void C_conf_settings_RTC_CheckedChanged(object sender, EventArgs e) { if (C_conf_settings_RTC.Checked) { setRTC = true; } else { setRTC = false; } } private void C_conf_cal_AOMB_CheckedChanged(object sender, EventArgs e) { if (C_conf_cal_AOMB.Checked) { ActivateTest[(int)TestType.CAL_AOMB] = true; } else { ActivateTest[(int)TestType.CAL_AOMB] = false; } } private void C_conf_cal_AIMB_CheckedChanged(object sender, EventArgs e) { if (C_conf_cal_AOMB.Checked) { ActivateTest[(int)TestType.CAL_AIMB] = true; } else { ActivateTest[(int)TestType.CAL_AIMB] = false; } } private void C_conf_cal_AOEB_CheckedChanged(object sender, EventArgs e) { if (C_conf_cal_AOMB.Checked) { ActivateTest[(int)TestType.CAL_AOEB] = true; } else { ActivateTest[(int)TestType.CAL_AOEB] = false; } } private void C_conf_cal_AIEB_CheckedChanged(object sender, EventArgs e) { if (C_conf_cal_AOMB.Checked) { ActivateTest[(int)TestType.CAL_AIEB] = true; } else { ActivateTest[(int)TestType.CAL_AIEB] = false; } } } }