private void Pause_Cal_Htrs_Click(object sender, EventArgs e) { if (Second_Worker.IsBusy) { Second_Worker.CancelAsync(); } }
private void Connect2_Click(object sender, EventArgs e) { var lines = File.ReadAllLines(@"CalibrationExpiryDates.ini"); for (int i = 0; i < 6; i++) { EXP_Stat[i] = Cal.CalibrationTime.check_stat(i); } datetimeReport = DateTime.Now.ToString("dd-MMM-yyyy,hh:mm tt"); if (!EXP_Stat[0] || !EXP_Stat[1] || !EXP_Stat[2] || !EXP_Stat[3] || !EXP_Stat[4] || !EXP_Stat[5]) { string temp = ""; temp = (!EXP_Stat[0]) ? temp + "Thermistor 1 Calibration is Expired \n" : temp; temp = (!EXP_Stat[1]) ? temp + "Thermistor 2 Calibration is Expired \n" : temp; temp = (!EXP_Stat[2]) ? temp + "Thermistor 3 Calibration is Expired \n" : temp; temp = (!EXP_Stat[3]) ? temp + "Thermistor 4 Calibration is Expired \n" : temp; temp = (!EXP_Stat[4]) ? temp + "PCBA Calibration is Expired \n" : temp; temp = (!EXP_Stat[5]) ? temp + "Heater Bath Calibration is Expired \n" : temp; MessageBox.Show(temp); } else if (LotNum.Text == "") { MessageBox.Show("Lot Number Field is empty, Please Enter the Lot number"); } else if (!tools.open_device(0)) { MessageBox.Show("Failed to Connect to Ontrak"); } else { fireworks.Hide(); Kenny.Show(); LotNum.Enabled = false; Calibration_PB.Enabled = false; datetime = DateTime.Now.ToString("ddMMMyyyyHHmm"); Connect2.Enabled = false; complete_flag = false; complete_calibration = false; init_boards(); for (int m = 0; m < 36; m++) { Array.Clear(Data[m], 0, Data[m].Length); fill_array(Offset[m], Offset[m].Length, 999); Offset[m][0] = 0; Status[m] = false; Status_buffer[m] = false; Offset_Status[m] = false; worker_counter = 0; HTR1_Radio.Enabled = false; HTR2_Radio.Enabled = false; HTR3_Radio.Enabled = false; HTR4_Radio.Enabled = false; HTR5_Radio.Enabled = false; HTR6_Radio.Enabled = false; HTR7_Radio.Enabled = false; HTR8_Radio.Enabled = false; HTR9_Radio.Enabled = false; HTR10_Radio.Enabled = false; HTR11_Radio.Enabled = false; HTR12_Radio.Enabled = false; HTR13_Radio.Enabled = false; HTR14_Radio.Enabled = false; HTR15_Radio.Enabled = false; HTR16_Radio.Enabled = false; HTR1_Radio.Checked = false; HTR2_Radio.Checked = false; HTR3_Radio.Checked = false; HTR4_Radio.Checked = false; HTR5_Radio.Checked = false; HTR6_Radio.Checked = false; HTR7_Radio.Checked = false; HTR8_Radio.Checked = false; HTR9_Radio.Checked = false; HTR10_Radio.Checked = false; HTR11_Radio.Checked = false; HTR12_Radio.Checked = false; HTR13_Radio.Checked = false; HTR14_Radio.Checked = false; HTR15_Radio.Checked = false; HTR16_Radio.Checked = false; if (!Second_Worker.IsBusy) { Second_Worker.RunWorkerAsync(); } Print_PB.Enabled = false; } } }
private void Second_Worker_DoWork(object sender, DoWorkEventArgs e) { string command; double[] temp_temps = new double[4]; for (; ;) { // worker_counter++; if (Second_Worker.CancellationPending) { e.Cancel = true; return; } //_________________________________________Thermostat Reading___________________________________ tools.send_commnad("SK0", 0); for (int k = 0; k < 4; k++) { command = "SPA" + Convert.ToString(k, 2).PadLeft(4, '0');; tools.send_commnad(command, 0); Thread.Sleep(100); DataR[k][worker_counter % SAMPLES] = convert_data_to_R(Convert.ToDouble(tools.read_command("RUC11", 0)), 1.25, 10000); Data[k][worker_counter % SAMPLES] = Cal.SettingsForm.convert_R_to_T(DataR[k][worker_counter % SAMPLES], (k + 1)); Status[k] = (Data[k].Average() <= (37 + THRESH_HOLD_Enviroment)) && (Data[k].Average() >= (37 - THRESH_HOLD_Enviroment)); // MessageBox.Show(Data[k][worker_counter % SAMPLES].ToString()); } temp_avg = ((Data[0].Average() + Data[1].Average() + Data[2].Average() + Data[3].Average()) / 4); tools.send_commnad("RK0", 0); //_______________________________________________________________________________________________ //_______________________________________________________________________________________________ //_________________________________________Heater Reading________________________________________ int kflipr; int kk = 0; int avg_cc = 0; double sum_calculator; double[] Sampler = new double[AVG_SAMPLES]; for (kk = 0; kk < 16; kk++) { kflipr = four_bit_fliprl(kk); for (int p = 0; p < AVG_SAMPLES; p++) { command = "SPA" + Convert.ToString(kflipr, 2).PadLeft(4, '0');; // MessageBox.Show(command); tools.send_commnad(command, 0); Thread.Sleep(40); if (p == 0) { Sampler[p] = convert_data_to_T(Convert.ToDouble(tools.read_command("RUC02", 0))); } else { Sampler[p] = convert_data_to_T(Convert.ToDouble(tools.read_command("RUC02", 0))); } } sum_calculator = 0; avg_cc = 0; for (int p = 0; p < AVG_SAMPLES; p++) { if (Sampler[p] > Sampler.Average()) { sum_calculator += Sampler[p]; avg_cc++; } } Data[kk + 4][worker_counter % SAMPLES] = sum_calculator / avg_cc; Status[kk + 4] = (Data[kk + 4][worker_counter % SAMPLES]) > 20; } //__________________________________________________________________________________________________ for (int k = 0; k < 16; k++) { //_______________________________________offset calculations________________________________________ Offset[k + 4][worker_counter % SAMPLES] = (!Status[k + 4] || Offset_Status[k + 4]) ? Offset[k + 4][worker_counter % SAMPLES] : Data[k + 4][worker_counter % SAMPLES] - temp_avg; //__________________________________________________________________________________________________ //_______________________________________detects if offset is stablised__________________________ double[] temps = { Data[0].Average(), Data[1].Average(), Data[2].Average(), Data[3].Average() }; Offset_Status[k + 4] = ((Math.Abs(Offset[k + 4].Max() - Offset[k + 4].Min())) <= THRESH_HOLD_Stable) && ref_therm_ok; //_______________________________________Log Heater Data__________________________ File.AppendAllText(@"data\" + datetime + "_Offset.txt", Offset[k + 4][worker_counter % SAMPLES].ToString() + "\t"); File.AppendAllText(@"data\" + datetime + "_Data.txt", Data[k + 4][worker_counter % SAMPLES].ToString() + "\t"); } File.AppendAllText(@"data\" + datetime + "_Offset.txt", Environment.NewLine); File.AppendAllText(@"data\" + datetime + "_Data.txt", Environment.NewLine); ref_therm_ok = Status[0] && Status[1] && Status[2] && Status[3]; Cal_Sucess = true; for (int row = 0; row < 16; row++) { Cal_Sucess = Cal_Sucess && (!(Status[row + 4] ^ Offset_Status[row + 4])); //MessageBox.Show(Cal_Sucess.ToString() + "\t" + Status[row + 4].ToString() + "\t" + Offset_Status[row + 4]); } Cal_Sucess = Cal_Sucess && ref_therm_ok; //Cal_Sucess = Cal_Sucess && TimeOut = worker_counter >= TIMEOUT; if ((Cal_Sucess && worker_counter > MINMUM_COUNTS) || TimeOut) { Sound.Play(); Second_Worker.CancelAsync(); while (!Second_Worker.CancellationPending) { System.Threading.Thread.Sleep(1000); } if (Second_Worker.CancellationPending) { e.Cancel = true; } Connect2.Enabled = true; Print_PB.Enabled = true; Calibration_PB.Enabled = true; LotNum.Enabled = true; for (int k = 0; k < 16; k++) { if (k == 0 && Status[k + 4]) { HTR1_Radio.Enabled = true; } if (k == 1 && Status[k + 4]) { HTR2_Radio.Enabled = true; } if (k == 2 && Status[k + 4]) { HTR3_Radio.Enabled = true; } if (k == 3 && Status[k + 4]) { HTR4_Radio.Enabled = true; } if (k == 4 && Status[k + 4]) { HTR5_Radio.Enabled = true; } if (k == 5 && Status[k + 4]) { HTR6_Radio.Enabled = true; } if (k == 6 && Status[k + 4]) { HTR7_Radio.Enabled = true; } if (k == 7 && Status[k + 4]) { HTR8_Radio.Enabled = true; } if (k == 8 && Status[k + 4]) { HTR9_Radio.Enabled = true; } if (k == 9 && Status[k + 4]) { HTR10_Radio.Enabled = true; } if (k == 10 && Status[k + 4]) { HTR11_Radio.Enabled = true; } if (k == 11 && Status[k + 4]) { HTR12_Radio.Enabled = true; } if (k == 12 && Status[k + 4]) { HTR13_Radio.Enabled = true; } if (k == 13 && Status[k + 4]) { HTR14_Radio.Enabled = true; } if (k == 14 && Status[k + 4]) { HTR15_Radio.Enabled = true; } if (k == 15 && Status[k + 4]) { HTR16_Radio.Enabled = true; } } Kenny.Hide(); fireworks.Show(); } worker_counter++; Second_Worker.ReportProgress(0); } }