public void Measuring(SpectrCondition cond, MeasuringResultFinalCall final_call) { if (File.Exists(USBConDev.MLogFileName)) { File.Delete(USBConDev.MLogFileName); } if (FinalCall != null) { throw new Exception(Common.MLS.Get("Dev", "Start new measuring before previous finished.")); } WaitTimeOutDlg.checkTimeOut(); Aborted = false; FinalCall = final_call; Cond = cond; if (final_call != null) { MeasuringThread = new Thread(new ThreadStart(MeasuringTech)); MeasuringThread.Start(); //gui.MainForm.MForm.Enabled = false; gui.MainForm.MForm.EnableToolExit(false, Common.MLS.Get(MlsConst, "Измерения...")); } else { MeasuringTech(); } }
void MeasuringTech() { try { Reg.NullMeasuringEnabled = false; while (Reg.NullMeasuring == true && Common.IsRunning) { Thread.Sleep(10); } if (Common.IsRunning == false) { return; } SpectrCondition cond = Cond; List <SpectrDataView> ret = new List <SpectrDataView>(); CheckConnection(); BeforeMeasuring(); int common_time_i = 1; int[] exps_i; if (IsUSBConsole()) { int[] line_sizes = Reg.GetSensorSizes(); float time_step = Common.Conf.MinTick * (Common.Conf.Divider2 + 1); string program = "n" + line_sizes.Length + ";s4096;d" + Common.Conf.Divider2 + ";"; int measuring_index = 0; cond.saveExtra(Common.Env.DefaultDisp); int[] orientations = Common.Conf.USBOrientationVals; for (int i = 0; i < cond.Lines.Count; i++) { switch (cond.Lines[i].Type)//SpectrCondition.ParseStringType(line)) { case SpectrCondition.CondTypes.FillLight: Fill.SetFillLight(cond.Lines[i].IsFillLight); break; case SpectrCondition.CondTypes.Comment: break; case SpectrCondition.CondTypes.Empty: break; case SpectrCondition.CondTypes.Unexpected: break; case SpectrCondition.CondTypes.Prespark: program += "p" + cond.Lines[i].CommonTime + ";"; break; case SpectrCondition.CondTypes.Exposition: CorrectExposition(cond.Lines[i], out common_time_i, out exps_i); cond.Lines[i].TmpInteger = measuring_index; if (cond.Lines[i].IsGenOn) { program += "E"; } else { program += "e"; } program += cond.Lines[i].TmpInteger + "_" + common_time_i + "_"; int[] exps = new int[16]; for (int ei = 0; ei < exps.Length && ei < orientations.Length; ei++) { if (exps_i[ei] > 255) { throw new Exception("Exposition is too bit!"); } exps[(int)Math.Abs(orientations[ei]) - 1] = exps_i[ei]; } for (int l = 0; l < 16; l++) { program += exps[l] + " "; //if (l < exps_i.Length) // program += exps_i[l] + " "; //else // program += "0 "; } program += ";"; measuring_index++; break; } } FileStream fs = new FileStream("cur_prog.txt", FileMode.Create); byte[] array = Encoding.ASCII.GetBytes(program); fs.Write(array, 0, array.Length); fs.Flush(); fs.Close(); //Process proc = Process.Start("USBDataCollector.exe", "cur_prog.txt"); //Process proc = Process.Start("USBMiner.exe", "cur_prog.txt"); //Process proc = Process.Start("measuring.bat"); System.Diagnostics.ProcessStartInfo proc = new System.Diagnostics.ProcessStartInfo("measuring.bat"); proc.RedirectStandardOutput = false; proc.UseShellExecute = false; // Do not create the black window. proc.CreateNoWindow = true; proc.WindowStyle = ProcessWindowStyle.Hidden; System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = proc; process.Start(); process.WaitForExit(); int exit_code = process.ExitCode; if (exit_code != 0) { throw new Exception("Measuring error: " + exit_code); } //((USBConDev)this).CollectDataMiner(ret, cond); //uncomment if use USBDataCollector.exe ((USBConDev)this).CollectDataMiner(ret, cond); } else { string source = cond.SourceCode; int i = 0; //string line = SpectrCondition.GetLine(source, ref i); int[] ssize = Reg.GetSensorSizes(); double[] exps = new double[ssize.Length]; float[][] data; short[][] datas; SpectrDataView cur_spview; for (i = 0; i < cond.Lines.Count; i++)//(line != null) { if (Aborted || Common.CancelFlag == true) { try { Common.Dev.Gen.SetStatus(false); } catch { } return; } try { gui.MainForm.MForm.SetupPersents(i * 100 / cond.Lines.Count); switch (cond.Lines[i].Type)//SpectrCondition.ParseStringType(line)) { case SpectrCondition.CondTypes.FillLight: Fill.SetFillLight(cond.Lines[i].IsFillLight); break; case SpectrCondition.CondTypes.Comment: break; case SpectrCondition.CondTypes.Empty: break; case SpectrCondition.CondTypes.Unexpected: break; case SpectrCondition.CondTypes.Prespark: Common.Log(Common.MLS.Get("Dev", "Start prespark. ") + cond.Lines[i].CommonTime); //gui.MainForm.MForm.SetupTimeOut(cond.Lines[i].CommonTime); /*common_time_i = (int)(cond.Lines[i].CommonTime / Tick); * exps_i = new int[exps.Length]; * for (int j = 0; j < exps.Length; j++) * exps_i[j] = 1;*/ exps_i = null; for (int t = 0; t < cond.Lines.Count; t++) { if (cond.Lines[t].IsActive && cond.Lines[t].Expositions != null) { CorrectExposition(cond.Lines[i].CommonTime, cond.Lines[t].Expositions, out common_time_i, out exps_i); break; } } Gen.SetStatus(true); Reg.RegFrame(common_time_i, exps_i); break; case SpectrCondition.CondTypes.Exposition: bool nul; CorrectExposition(cond.Lines[i], out common_time_i, out exps_i); string msg; if (cond.Lines[i].IsActive) { msg = Common.MLS.Get("Dev", "Spark. "); nul = false; } else { msg = Common.MLS.Get("Dev", "Null. "); nul = true; } msg += +common_time_i + " [ "; for (int j = 0; j < exps_i.Length; j++) { msg += exps_i[j] + " "; } msg += "] " + Math.Round(cond.Lines[i].CommonTime, 2); Common.Log(msg); //gui.MainForm.MForm.SetupTimeOut(cond.Lines[i].CommonTime); Gen.SetStatus(cond.Lines[i].IsGenOn); short[][] bb, ba; if (nul == false) { datas = Reg.RegFrame(common_time_i, exps_i, out bb, out ba); } else { datas = Reg.GetNull(cond.Lines[i], out bb, out ba); } data = new float[datas.Length][]; for (int s = 0; s < datas.Length; s++) { int size = datas[s].Length; data[s] = new float[size]; for (int j = 0; j < size; j++) { data[s][j] = datas[s][j]; } } cur_spview = new SpectrDataView(new SpectrCondition(Tick, cond.Lines[i]), data, bb, ba, Common.Dev.Reg.GetMaxValue(), Common.Dev.Reg.GetMaxLinarValue()); ret.Add(cur_spview); break; } } catch (Exception ex) { Common.Log(ex); break; } } Gen.SetStatus(false); } AfterMeasuring(); LetestResult = ret; if (FinalCall != null) { FinalCall(ret, Cond); } //gui.MainForm.MForm.SetupTimeOut(0); gui.MainForm.MForm.SetupPersents(-1); } catch (Exception ex) { Common.Log(ex); } finally { try { Reg.NullMeasuringEnabled = true; gui.MainForm.MForm.SetupTimeOut(0); } catch { } try { FinalCall = null; //gui.MainForm.MForm.Enabled = true; gui.MainForm.MForm.EnableToolExit(); } catch { } try { Reg.Reset(); } catch (Exception ex) { Common.LogNoMsg(ex); } } }