/// <summary> /// Not support by usb-1208 /// </summary> /// <param name="Chan"></param> /// <returns></returns> public float ReadTemperature(int Chan) { MccDaq.TempScale MccScale = MccDaq.TempScale.Celsius; float TempValue = 0.0f; MccDaq.ThermocoupleOptions Options = MccDaq.ThermocoupleOptions.WaitForNewData; MccDaq.ErrorInfo ULStat = DaqBoard.TIn(Chan, MccScale, out TempValue, Options); return(TempValue); }
private void tmrConvert_Tick(object eventSender, System.EventArgs eventArgs) { bool ValidChan; tmrConvert.Stop(); // Collect the data with Mccdaq.MccBoard.TIn() // Parameters: // Chan :the A/D and channel number; starts at 16 if using // an EXP (calculated by (ADChan + 1) * 16 + EXPChan) // MccScale :the temperature scale (F, C or K) // DataValue :the name for the value collected // ADChan :usually channel 0 for CIO-EXP16 short ADChan = 0; // If using a device with an EXP attached, // allows access to 16 channels on the EXP board // increasing this number allows access to upper // bank on EXP32 and additional EXP boards MccDaq.TempScale MccScale = MccDaq.TempScale.Celsius; int Chan = 0; ValidChan = int.TryParse(txtExpChan.Text, out Chan); if (ValidChan) { if (UsesEXPs > 0) { Chan = Chan + (ADChan + 1) * 16; } } float TempValue = 0.0f; MccDaq.ThermocoupleOptions Options = MccDaq.ThermocoupleOptions.Filter; MccDaq.ErrorInfo ULStat = DaqBoard.TIn(Chan, MccScale, out TempValue, Options); if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors) { tmrConvert.Start(); } lblShowData.Text = TempValue.ToString("0") + "°C"; // print the value }
// This function changes CHANCOUNT, by detecting the actual number of // working thermocouple inputs connected to the USB-TC board. public void TC_finder() { MccBoard daq = new MccDaq.MccBoard(BoardNum); MccDaq.ErrorInfo RetVal; CHANCOUNT = MAX_CHANCOUNT; float[] temp = new float[MAX_CHANCOUNT]; try { for (int i = 0; i < MAX_CHANCOUNT; i++) { RetVal = daq.TIn(i, TempScale.Celsius, out temp[i], ThermocoupleOptions.Filter); if (RetVal.Value != 0) { CHANCOUNT--; } } if (CHANCOUNT <= 0) { MessageBox.Show("No thermocouples detected!", " " + "ERROR!"); return; } NumThermocouplesBox.Text = " " + CHANCOUNT.ToString(); return; } catch { MessageBox.Show("Function TC_finder has an error!", " " + "ERROR!"); return; } }
// This function updates the GUI's temperature readout and graphs public void update_gui() { while (start_check != 3) { float[] TempData = new float[MAX_CHANCOUNT]; MccBoard daq = new MccDaq.MccBoard(BoardNum); MccDaq.ErrorInfo RetVal; Update_Temperature update_temp_del = new Update_Temperature(update_gui_helper); for (int i = 0; i < MAX_CHANCOUNT; i++) { RetVal = daq.TIn(i, TempScale.Celsius, out TempData[i], ThermocoupleOptions.Filter); } Invoke(update_temp_del, TempData); Thread.Sleep(500); } }
// This function updates the temperature log text file. It returns if // the number of channels is invalid. Otherwise, it uses a while loop to // output temperature readings to a .txt file in the same directory as // the program folder. It shows an error if there is an open channel. public void update_log() { MccBoard daq = new MccDaq.MccBoard(BoardNum); MccDaq.ErrorInfo RetVal; string subject = ""; string body = ""; string separator = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; while (log_check == 0) { if (log_state == 0) { log_state = 1; string[] text1 = {"Temperature and events log file.", " ", "Created on " + date_time.ToString(format), " ","Temperature read approx. every 5 "+ "seconds in degrees Celsius.", " "," "}; System.IO.File.WriteAllLines(directory, text1); string text2 = "Time\t\t\t"; for (int i = 0; i < MAX_CHANCOUNT; i++) { text2 += String.Format("Ch{0}", i) + "\t\t"; } using (StreamWriter sw = File.AppendText(directory)) { sw.WriteLine(text2); sw.WriteLine(" "); } } if (HeatingStarted && !HeatingStarted_logged) { string temp = DateTime.Now.ToString("T") + "\t\t" + "HEATING STARTED!"; using (StreamWriter sw = File.AppendText(directory)) { sw.WriteLine(" "); sw.WriteLine(separator); sw.WriteLine(" "); sw.WriteLine(temp); sw.WriteLine("\t\t\tUser: "******"\t\t\tBatch code: " + BatchCode_copy); sw.WriteLine("\t\t\tMax. Temperature: " + MaxTemp_copy); sw.WriteLine("\t\t\tHold Time: " + HoldTime_copy); sw.WriteLine("\t\t\tCooling method: " + CoolMethod_copy); sw.WriteLine(" "); sw.WriteLine(separator); sw.WriteLine(" "); } subject = "Heating has started on " + OvenName_copy + " oven!"; body = User_copy + ",\n\n" + subject + "\n\nParameters are: \nBatch Code: " + BatchCode_copy + "\nMax.Temp: " + MaxTemp_copy + "\nHold Time: " + HoldTime_copy + "\nCooling Method: " + CoolMethod_copy + "\nTime: " + OvenStartTime_copy; SendEmail(subject, body); HeatingStarted_logged = true; } else if (HeatingStopped && !HeatingStopped_logged) { string temp = DateTime.Now.ToString("T") + "\t\t" + "HEATING STOPPED!"; using (StreamWriter sw = File.AppendText(directory)) { sw.WriteLine(" "); sw.WriteLine(separator); sw.WriteLine(" "); sw.WriteLine(temp); sw.WriteLine(" "); sw.WriteLine(separator); sw.WriteLine(" "); } subject = "Heating has stopped on " + OvenName_copy + " oven!"; body = User_copy + ",\n\n" + subject; SendEmail(subject, body); HeatingStopped_logged = true; } else if (MaxTempReached && !MaxTempReached_logged) { string temp = DateTime.Now.ToString("T") + "\t\t" + "MAX. TEMP REACHED!"; using (StreamWriter sw = File.AppendText(directory)) { sw.WriteLine(" "); sw.WriteLine(separator); sw.WriteLine(" "); sw.WriteLine(temp); sw.WriteLine(" "); sw.WriteLine(separator); sw.WriteLine(" "); } subject = "Max. temp reached on " + OvenName_copy + " oven!"; body = User_copy + ",\n\n" + subject; SendEmail(subject, body); MaxTempReached_logged = true; } else if (CoolingStarted && !CoolingStarted_logged) { string temp = DateTime.Now.ToString("T") + "\t\t" + "COOLING STARTED!"; using (StreamWriter sw = File.AppendText(directory)) { sw.WriteLine(" "); sw.WriteLine(separator); sw.WriteLine(" "); sw.WriteLine(temp); sw.WriteLine(" "); sw.WriteLine(separator); sw.WriteLine(" "); } subject = "Cooling has started on " + OvenName_copy + " oven!"; body = User_copy + ",\n\n" + subject; SendEmail(subject, body); CoolingStarted_logged = true; } else if (IsCriticalError && !IsCriticalError_logged) { string temp = DateTime.Now.ToString("T") + "\t\t" + "CRITICAL ERROR!"; using (StreamWriter sw = File.AppendText(directory)) { sw.WriteLine(" "); sw.WriteLine(separator); sw.WriteLine(" "); sw.WriteLine(temp); sw.WriteLine(" "); sw.WriteLine(separator); sw.WriteLine(" "); } subject = "Critical error on " + OvenName_copy + " oven!"; body = User_copy + ",\n\n" + subject + "\n" + CriticalErrorMessage; SendEmail(subject, body); IsCriticalError_logged = true; } else if (OvenRunDone && !OvenRunDone_logged) { string temp = DateTime.Now.ToString("T") + "\t\t" + "OVEN RUN COMPLETE!"; using (StreamWriter sw = File.AppendText(directory)) { sw.WriteLine(" "); sw.WriteLine(separator); sw.WriteLine(" "); sw.WriteLine(temp); sw.WriteLine("\t\t\tUser: "******"\t\t\tBatch code: " + BatchCode_copy); sw.WriteLine("\t\t\tMax. Temperature: " + MaxTemp_copy); sw.WriteLine("\t\t\tHold Time: " + HoldTime_copy); sw.WriteLine("\t\t\tCooling method: " + CoolMethod_copy); sw.WriteLine(" "); sw.WriteLine(separator); sw.WriteLine(" "); } subject = "Oven run completed on " + OvenName_copy + " oven!"; body = User_copy + ",\n\n" + subject + "\n"; SendEmail(subject, body); OvenRunDone_logged = true; } string text3 = DateTime.Now.ToString("T") + "\t\t"; for (int i = 0; i < MAX_CHANCOUNT; i++) { RetVal = daq.TIn(i, TempScale.Celsius, out LogData[i], ThermocoupleOptions.Filter); IsError(this, RetVal, true); if (RetVal.Value != 0) text3 += "***\t\t"; else text3 += LogData[i].ToString() + "\t\t"; } using (StreamWriter sw = File.AppendText(directory)) { sw.WriteLine(text3); } Thread.Sleep(4800); } }
// This function reads and displays the temperature inputs by detecting // the buttons clicked, by detecting the value of the variable "check". // It runs a while loop to keep checking for button presses, and using // Thread.Sleep(), it checks buttons, reads and displays temperatures in // the selected scale at a set frequency (2 Hz). The loop ends when the // value of check is set to -1 by clicking the Exit button. Temperatures // are read using the TInScan function, and an array is passed to the // update_temp() function to display them using a delegate. private void temp_reader() { while (read_check != -1) { int count = 0; float[] TempData = new float[MAX_CHANCOUNT]; float[] TempData_C = new float[MAX_CHANCOUNT]; MccBoard daq = new MccDaq.MccBoard(BoardNum); MccDaq.ErrorInfo RetVal; Update_Temperature update_temp_del = new Update_Temperature(update_temp); Update_Warning update_warning_del = new Update_Warning(update_warning); Reset_Checkboxes resetcheckboxes_del = new Reset_Checkboxes(resetcheckboxes); for (int i = 0; i < MAX_CHANCOUNT; i++) { if (((CheckBox)this.Controls["Ch" + i.ToString("#0") + "Box"]).Enabled == true && ((CheckBox)this.Controls["Ch" + i.ToString("#0") + "Box"]).Checked == true) { count++; } } if (count == 0) { TempData = new float[MAX_CHANCOUNT] {-9999, -9999, -9999, -9999, -9999, -9999, -9999, -9999}; Array.Copy(TempData, TempData_C, 8); not_showing_temp = true; Invoke(update_temp_del, TempData, TempData_C); } else not_showing_temp = false; if (read_check == 1 && not_showing_temp == false) { for (int i = 0; i < MAX_CHANCOUNT; i++) { if (((CheckBox)this.Controls["Ch" + i.ToString("#0") + "Box"]).Checked == true) { RetVal = daq.TIn(i, TempScale.Celsius, out TempData_C[i], ThermocoupleOptions.Filter); IsError(this,RetVal, true); } else TempData_C[i] = -9999; } switch(my_TempScale) { case TempScale.Fahrenheit: for (int i = 0; i < MAX_CHANCOUNT; i++) { if (((CheckBox)this.Controls["Ch" + i.ToString("#0") + "Box"]).Checked == true) { RetVal = daq.TIn(i, TempScale.Fahrenheit, out TempData[i], ThermocoupleOptions.Filter); IsError(this,RetVal, true); } else TempData[i] = -9999; } break; case TempScale.Kelvin: for (int i = 0; i < MAX_CHANCOUNT; i++) { if (((CheckBox)this.Controls["Ch" + i.ToString("#0") + "Box"]).Checked == true) { RetVal = daq.TIn(i, TempScale.Kelvin, out TempData[i], ThermocoupleOptions.Filter); IsError(this,RetVal, true); } else TempData[i] = -9999; } break; default: for (int i = 0; i < MAX_CHANCOUNT; i++) { if (((CheckBox)this.Controls["Ch" + i.ToString("#0") + "Box"]).Checked == true) { RetVal = daq.TIn(i, TempScale.Celsius, out TempData[i], ThermocoupleOptions.Filter); IsError(this,RetVal, true); } else TempData[i] = -9999; } break; } Invoke(update_temp_del, TempData, TempData_C); Thread.Sleep(500); } if ((read_check == 0 && oven_check == 1) || (not_showing_temp == true && oven_check == 1)) { string temp = String.Format("WARNING! Temperature" + " readings are no longer live during an oven run!\n" + "Automatically fixing this in {0} seconds...", (int)(warning_time/2)); Invoke(update_warning_del, temp, 1); Thread.Sleep(500); warning_time--; if (warning_time <= 0) { read_check = 1; Invoke(resetcheckboxes_del); not_showing_temp = false; Invoke(update_warning_del, " ", 0); warning_time = 20; } } // Make sure that the text is grayed out when the Stop TC button // is in its clicked state. if (read_check == 0 && oven_check != 1) { TempData[0] = 1234; TempData_C[0] = 1234; Invoke(update_temp_del, TempData, TempData_C); Thread.Sleep(500); } } }
// This function changes CHANCOUNT, by detecting the actual number of // working thermocouple inputs connected to the USB-TC board. private void TC_finder() { MccBoard daq = new MccDaq.MccBoard(BoardNum); MccDaq.ErrorInfo RetVal; CHANCOUNT = MAX_CHANCOUNT; float[] temp = new float[MAX_CHANCOUNT]; try { for (int i = 0; i < MAX_CHANCOUNT; i++) { RetVal = daq.TIn(i, TempScale.Celsius, out temp[i], ThermocoupleOptions.Filter); if (RetVal.Value != 0) { CHANCOUNT--; ((CheckBox)this.Controls["Ch" + i.ToString("#0") + "Box"]).Checked = false; ((CheckBox)this.Controls["Ch" + i.ToString("#0") + "Box"]).Enabled = false; } else { ((CheckBox)this.Controls["Ch" + i.ToString("#0") + "Box"]).Checked = true; ((CheckBox)this.Controls["Ch" + i.ToString("#0") + "Box"]).Enabled = true; } } NumThermocouples.Text = " " + CHANCOUNT.ToString(); return; } catch { MessageBox.Show("TC_finder has an error!", " " + "ERROR!"); return; } }
// This function implements PID control in the oven, by using three // USB-TC output channels. It calls the functions channel_out() to // control the heater coils according to the known setup. private void PID_control() { MccBoard daq = new MccDaq.MccBoard(BoardNum); MccDaq.ErrorInfo RetVal;int count = 0; float[] PID_LogData = new float[MAX_CHANCOUNT] {0, 0, 0, 0, 0, 0, 0 ,0};; int PID_max_temp = Convert.ToInt32(MaxTemp.Text); float current_error = 0; // difference between current and target // temperatures float prev_error = PID_max_temp; // the last recorded error; // initialized to the max temp. float time_slice = 1; // any non-zero value, so that we don't have // a divide-by-zero error float derivative_component = 0; // error change rate w.r.t time float integral_component = 0; // total accumulated error bool fill_n2_check = false; TC_channel_out(OvenChanStatusEnum.all_off); // start with all oven channels off air_channel_out(AirChanStatusEnum.air_off); //Start with air switched off while (oven_check == 1) { if (CoolMethod_copy == "1") { // Flow high pressure nitrogen for like 10 seconds to fill // the oven cavity with nitrogen if (fill_n2_check == false) { air_channel_out(AirChanStatusEnum.high_n2); Thread.Sleep(1000); count++; if (count >= 10) { fill_n2_check = true; count = 0; } else continue; } // Low pressure N2 trickle begins air_channel_out(AirChanStatusEnum.low_n2); } // CONTROL HERE !!! ///////////// HEATING BEGINS !!! ////////// Heat_Time = DateTime.Now; if (PID_LogData.Max() <= (0.80 * Convert.ToInt32(MaxTemp.Text))) { TC_channel_out(OvenChanStatusEnum.oven_on); if (HeatingStarted == false) // Reach 80% temp. with { // just direct heating HeatingStarted = true; HeatingStopped = false; HeatingStopped_logged = false; } } else if (MaxTempReached == false) { // The deivative component is degrees / second error change // rate. Let's attempt to keep it at error * 0.01 for now if (derivative_component < current_error * 0.01) TC_channel_out(OvenChanStatusEnum.oven_on); else TC_channel_out(OvenChanStatusEnum.oven_off); if (current_error <= 0) { MaxTempReached = true; } } else TC_channel_out(OvenChanStatusEnum.oven_off); /////////////////////////////////////////////////////////////// for (int i = 0; i < MAX_CHANCOUNT; i++) { RetVal = daq.TIn(i, TempScale.Celsius, out PID_LogData[i], ThermocoupleOptions.Filter); if (RetVal.Value != 0) PID_LogData[i] = 0; } current_error = PID_max_temp - PID_LogData.Max(); time_slice = (float)DateTime.Now.Subtract(Heat_Time).TotalSeconds; integral_component += current_error; derivative_component = (prev_error - current_error) / (time_slice); prev_error = current_error; count++; } TC_channel_out(OvenChanStatusEnum.oven_off); }
// This function changes CHANCOUNT, by detecting the actual number of // working thermocouple inputs connected to the USB-TC board. private void DetectThermoCoupleInputs() { MccBoard daq = new MccDaq.MccBoard(BoardNum); MccDaq.ErrorInfo RetVal; CHANCOUNT = MAX_CHANCOUNT; NUM_WALLCOUNT = 2; float[] temp = new float[MAX_CHANCOUNT]; try { for (int i = 0; i < MAX_CHANCOUNT; i++) { RetVal = daq.TIn(i, TempScale.Celsius, out temp[i], ThermocoupleOptions.Filter); if (RetVal.Value != 0) { CHANCOUNT--; ((CheckBox)this.Controls["Channel" + i.ToString("#0") + "CheckBox"]).Checked = false; ((CheckBox)this.Controls["Channel" + i.ToString("#0") + "CheckBox"]).Enabled = false; if (i == (int)TemperatureVsTimeDataSeriesEnum.Inner || i == (int)TemperatureVsTimeDataSeriesEnum.Outer) { NUM_WALLCOUNT--; } } else { ((CheckBox)this.Controls["Channel" + i.ToString("#0") + "CheckBox"]).Checked = true; ((CheckBox)this.Controls["Channel" + i.ToString("#0") + "CheckBox"]).Enabled = true; } } NumThermocouplesDetectedTextBox.Text = " " + CHANCOUNT.ToString(); return; } catch(Exception e) { MessageBox.Show( String.Format( "ThermoCouple_Finder has encountered an unexpected error!{0}" + "Error Message: {1}{0}" + "Error Source: {2}{0}" + "Stack Trace: {3}{0}", Environment.NewLine, e.Message, e.Source, e.StackTrace) , " " + "ERROR!"); return; } }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { MccDaq.ErrorInfo RetVal; int BoardNum = 0; //locate the USB-TC BoardNum = GetBoardNum(DEVICE); if (BoardNum == -1) { MessageBox.Show("No USB-{0} detected!", DEVICE); return; //exit program } else { MccBoard daq = new MccDaq.MccBoard(BoardNum); float setTemp = (float)Convert.ToDouble(desiredTemp.Text); bool targetTemp = false; int allSamples = 0; float[] tempData = new float[NUM_CHANNELS]; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); string[] filePath = new string[NUM_CHANNELS]; StringBuilder[] fileString = new StringBuilder[NUM_CHANNELS]; for (int j = 0; j < NUM_CHANNELS; j++) { string fileDateTime = string.Format("_{0:yyyy-MM-dd_hh-mm}", DateTime.Now); filePath[j] = "Channel" + j + fileDateTime + ".csv"; fileString[j] = new StringBuilder(); fileString[j].AppendLine(string.Format("Channel{0}", j)); fileString[j].AppendLine(string.Format("Time,Elapsed Time,Temperature (C)")); } while (temp_Read == true && targetTemp == false) { for (int j = 0; j < NUM_CHANNELS; j++) { RetVal = daq.TIn(j, TempScale.Celsius, out tempData[j], ThermocoupleOptions.Filter); IsError(RetVal); // Get the elapsed time as a TimeSpan value. TimeSpan ts = stopWatch.Elapsed; string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); fileString[j].AppendLine(string.Format("{0},{1},{2}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), elapsedTime, tempData[j].ToString("0.000").PadLeft(10))); Console.WriteLine("The temperature is on channel {0}" + " is: {1} " + "at elasped time {2} current time {3} ", j, tempData[j].ToString("0.000").PadLeft(10), elapsedTime, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); } for (int j = 0; j < NUM_CHANNELS; j++) { if ((float)tempData[j] >= setTemp) { allSamples++; } } this.Invoke((MethodInvoker)delegate() { this.textBox1.Text = tempData[0].ToString("0.000"); this.textBox2.Text = tempData[1].ToString("0.000"); this.textBox3.Text = tempData[2].ToString("0.000"); this.textBox4.Text = tempData[3].ToString("0.000"); this.textBox5.Text = tempData[4].ToString("0.000"); this.textBox6.Text = tempData[5].ToString("0.000"); this.textBox7.Text = tempData[6].ToString("0.000"); this.textBox8.Text = tempData[7].ToString("0.000"); }); if (allSamples == NUM_CHANNELS) { targetTemp = true; this.Invoke((MethodInvoker)delegate() { this.start_button.Enabled = true; this.desiredTemp.Enabled = true; this.stop_button.Enabled = false; }); } else { allSamples = 0; } //System.Threading.Thread.Sleep(0); //max rate is 2Hz or 500mS per read. } for (int j = 0; j < NUM_CHANNELS; j++) { File.WriteAllText(filePath[j].ToString(), fileString[j].ToString()); } } }
// Logging function public void update_log() { MccBoard daq = new MccDaq.MccBoard(BoardNum); MccDaq.ErrorInfo RetVal; float[] LogData = new float[NumSamples]; System.TimeSpan TimeSpan = new System.TimeSpan(); int interval = (int)(float.Parse(LogIntervalBox.Text)*1000); string text1 = "Time (in hours),"; for (int i = 1; i <= NumSamples; i++) { text1 += this.Controls["NameBox" + i].Text + ","; text1 += this.Controls["NameBox" + i].Text + " Frozen?"; if (i < NumSamples) { text1 += ","; } } using (StreamWriter sw = File.AppendText(directory)) { sw.WriteLine(text1); } while (start_check != 0) { TimeSpan = DateTime.Now.Subtract(Start_Time); string text2 = TimeSpan.TotalHours.ToString() + ","; for (int i = 0; i < NumSamples; i++) { RetVal = daq.TIn(i, TempScale.Celsius, out LogData[i], ThermocoupleOptions.Filter); text2 += LogData[i].ToString() + ","; if (SamplesStates[i] == 0) { text2 += "-"; } else if (SamplesStates[i] == 1) { text2 += "No"; } else { text2 += "Yes"; } if (i < NumSamples - 1) { text2 += ","; } } using (StreamWriter sw = File.AppendText(directory)) { sw.WriteLine(text2); } Thread.Sleep(interval); } }
// Logging function public void update_log() { MccBoard daq = new MccDaq.MccBoard(BoardNum); MccDaq.ErrorInfo RetVal; float[] LogData = new float[NumSamples]; System.TimeSpan TimeSpan = new System.TimeSpan(); int interval = (int)(float.Parse(LogIntervalBox.Text) * 1000); string text1 = "Time (in hours),"; for (int i = 1; i <= NumSamples; i++) { text1 += this.Controls["NameBox" + i].Text + ","; text1 += this.Controls["NameBox" + i].Text + " Frozen?"; if (i < NumSamples) { text1 += ","; } } using (StreamWriter sw = File.AppendText(directory)) { sw.WriteLine(text1); } while (start_check != 0) { TimeSpan = DateTime.Now.Subtract(Start_Time); string text2 = TimeSpan.TotalHours.ToString() + ","; for (int i = 0; i < NumSamples; i++) { RetVal = daq.TIn(i, TempScale.Celsius, out LogData[i], ThermocoupleOptions.Filter); text2 += LogData[i].ToString() + ","; if (SamplesStates[i] == 0) { text2 += "-"; } else if (SamplesStates[i] == 1) { text2 += "No"; } else { text2 += "Yes"; } if (i < NumSamples - 1) { text2 += ","; } } using (StreamWriter sw = File.AppendText(directory)) { sw.WriteLine(text2); } Thread.Sleep(interval); } }