public int gTimerDrawChart = 0;// /// <summary> /// init form /// </summary> public BatteryTest() { InitializeComponent(); // conbobox comboBoxControl.Items.Clear(); comboBoxControl.DataSource = SerialPort.GetPortNames(); // Auto detect serial port for Control com if (comboBoxControl.Items.Count > 0) { SerialComm serialComm = new SerialComm(); SerialPort detSerial = serialComm.DetectSerial("P[", 115200, 3000); if (detSerial != null) { for (int i = 0; i < comboBoxControl.Items.Count; i++) { if (comboBoxControl.Items[i].ToString() == detSerial.PortName) { comboBoxControl.SelectedIndex = i; break; } } } else { comboBoxControl.SelectedIndex = 0; } } comboBoxData.Items.Clear(); comboBoxData.DataSource = SerialPort.GetPortNames(); // Auto detect serial port for Data com if (comboBoxData.Items.Count > 0) { SerialComm serialComm = new SerialComm(); SerialPort detSerial = serialComm.DetectSerial("\t", 115200, 3000); if (detSerial != null) { for (int i = 0; i < comboBoxData.Items.Count; i++) { if (comboBoxData.Items[i].ToString() == detSerial.PortName) { comboBoxData.SelectedIndex = i; break; } } } else { comboBoxData.SelectedIndex = 0; } } // end of combobox setup // clear button text for (int i = 1; i < 13; i++) { Control currButton = GetControlByName("buttonConfig" + i); if (currButton != null) { Button b = (Button)currButton; b.Text = ""; b.Visible = false; } } // init list battery for (int i = 0; i < Battery.NUMS_BATTERY; i++) { mtListBatStat.Add(new Battery()); } // init Help if (File.Exists(FileUtils.GetFullPath(HELP_FILE))) { textBoxHelp.Text = File.ReadAllText(FileUtils.GetFullPath(HELP_FILE)); } // update battery control batteryDetailControl.UpdateBatStat(mtListBatStat); //oldTextContent = File.ReadAllText(FILE_BUFFER); //ExcelExporter exp = new ExcelExporter(getPathReportFile()); //exp.PasteText(oldTextContent, 1, 1, 1); //exp.Close(); if (!File.Exists(FILE_BUFFER)) { FileStream fs = File.Create(FILE_BUFFER); fs.Close(); } if (!File.Exists(getPathConfigFile())) { MessageBox.Show("Config file not exsited, auto generate config file"); File.Copy(fileConfigBattery_Root, getPathConfigFile()); } foreach (System.Diagnostics.Process myProc in System.Diagnostics.Process.GetProcesses()) { if (myProc.ProcessName == "EXCEL") { myProc.Kill(); break; } } // setup stream writer // create stream overide old content of file mtWriteBufferFile = new StreamWriter(FILE_BUFFER); DateTime dtNow = DateTime.Now; string fileGen = FODER_RESULT + "/" + dtNow.Year + "-" + dtNow.Month + "-" + dtNow.Day + "_" + dtNow.Hour + "h" + dtNow.Minute + "m" + dtNow.Second + "s"; if (!Directory.Exists(FODER_RESULT)) { Directory.CreateDirectory(FODER_RESULT); } if (!File.Exists(fileGen)) { FileStream fs = File.Create(fileGen); fs.Close(); } mWriteResuleBat = new StreamWriter(fileGen); mWriteResuleBat.AutoFlush = true; // background worker mFileSaveWorker.WorkerReportsProgress = true; mFileSaveWorker.WorkerSupportsCancellation = true; mFileSaveWorker.DoWork += fileSaveBackgroundWork; mFileSaveWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(WaitReportComplete); mFileSaveWorker.RunWorkerAsync(); mPasteExcellWorker.WorkerReportsProgress = true; mPasteExcellWorker.WorkerSupportsCancellation = true; mPasteExcellWorker.DoWork += pasteExcellBackgroundWork; mPasteExcellWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(WaitReportComplete); mPasteExcellWorker.RunWorkerAsync(); mUpdateBatStatUIWoker.WorkerReportsProgress = true; mUpdateBatStatUIWoker.WorkerSupportsCancellation = true; mUpdateBatStatUIWoker.DoWork += UpdateBatStatUIWork; mUpdateBatStatUIWoker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(WaitReportComplete); mUpdateBatStatUIWoker.RunWorkerAsync(); // init for test if (!File.Exists(getPathReportFile())) { MessageBox.Show("Generate file not exsisted, Auto generate file"); File.Copy(fileResult_battery_Root, getPathReportFile()); } }