private void btMeasuringNewSpectr_Click_Final(List <SpectrDataView> rez, SpectrCondition cond) { try { //string sel = (string)LastName.Clone(); Spectr sp = new Spectr(cond, Common.Env.DefaultDisp, Common.Env.DefaultOpticFk, "ChangeSpectrCollectionControl"); for (int i = 0; i < rez.Count; i++) { sp.Add(rez[i]); } //string path = Folder.CreateRecordPath(sel); sp.SaveAs(CurTag.GetPath()); ReLoadList(); //SelectSpectr(sel); if (AfterMeasuringProc != null) { AfterMeasuringProc(); } //SpView.ReDrawNow(); //SpView.Invalidate(); } catch (Exception ex) { Common.Log(ex); } }
private void MMMeasuringExp_Click(object sender, EventArgs e) { try { string bpath = Common.Db.GetFoladerPath(Common.DbNameProbSort) + "\\условия.bin"; FileStream fs; SpectrCondition cond; if (File.Exists(bpath)) { fs = new FileStream(bpath, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); cond = new SpectrCondition(br); br.Close(); } else { cond = null; } cond = SpectrCondEditor.GetCond(MainForm.MForm, cond); if (cond == null) { return; } fs = new FileStream(bpath, FileMode.Create, FileAccess.Write); BinaryWriter bw = new BinaryWriter(fs); cond.Save(bw); bw.Flush(); bw.Close(); } catch (Exception ex) { Common.Log(ex); } }
Spectr Measuring(int sp_num, float common) { Common.Dev.CheckConnection(); SpectrCondition cond = new SpectrCondition(Common.Dev.Tick, SpectrCondition.GetDefaultCondition(false, false, (float)nmExpFrom.Value, (float)nmExpTo.Value, (float)(nmExpFrom.Value + nmExpTo.Value) * 9, 10)); Common.Dev.Measuring(cond, null); Dispers disp = new Dispers(); OpticFk fk = new OpticFk(); Spectr sp = new Spectr(cond, disp, fk, "SensTest"); for (int i = 0; i < Common.Dev.LetestResult.Count; i++) { sp.Add(Common.Dev.LetestResult[i]); } Sp[sp_num] = sp; string file_name = GetSpectrName(sp_num); Sp[sp_num].SaveAs(file_name); Common.Log(Common.MLS.Get(MLSConst, "Done...")); return(sp); }
private void btReMeasuringSpectr_Click_Final(List <SpectrDataView> rez, SpectrCondition cond) { try { Spectr sp = CurSp;// new Spectr(Folder, LastName); sp.SetMeasuringCondition(cond); sp.Clear(); for (int i = 0; i < rez.Count; i++) { sp.Add(rez[i]); } sp.SetDispers(Common.Env.DefaultDisp); sp.OFk = Common.Env.DefaultOpticFk; sp.Save(); ReLoadList(); if (AfterMeasuringProc != null) { AfterMeasuringProc(); } SpView.ReDrawNow(); } catch (Exception ex) { Common.Log(ex); } }
private void btMeasuringNewSpectr_Click_Final(List <SpectrDataView> rez, SpectrCondition cond) { try { Spectr sp = new Spectr(cond, Common.Env.DefaultDisp, Common.Env.DefaultOpticFk, "SortCalibr"); for (int i = 0; i < rez.Count; i++) { sp.Add(rez[i]); } sp.SaveAs(MeasuringFile); LoadTree(); int ind = MeasuringFile.Length - 3; if (MeasuringFile[ind] != '.' || MeasuringFile[ind] != 's' || MeasuringFile[ind] != 's') { MeasuringFile += ".ss"; } Select(tvDirView.Nodes, MeasuringFile); sortProbProperty1.Save(); //sortProbProperty1.InitByPath((string)e.Node.Tag); } catch (Exception ex) { Common.Log(ex); } }
static public SpectrCondition GetCond(Form master, SpectrCondition src, bool just_setup) { SpectrCondEditor ed = new SpectrCondEditor(); ed.JustSetup = just_setup; string src_code; if (src == null || src.SourceCode == null || src.SourceCode.Trim().Length == 0) { src_code = SpectrCondition.GetDefaultCondition(); } else { src_code = src.SourceCode; } if (ed.chbShowSourceCode.Checked) { ed.tbSourceCode.Text = src_code; } else { ed.scSimpleEditor.Setup(src_code, ed); } DialogResult dr = ed.ShowDialog(master); if (dr == DialogResult.OK) { return(ed.Cond); } return(null); }
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(); } }
public void btReMeasuringSpectr_Click(object sender, EventArgs e) { try { if (Selected == null) { MessageBox.Show(MainForm.MForm, Common.MLS.Get(MLSConst, "Выберите спектр который нужно перемерить"), Common.MLS.Get(MLSConst, "Предупреждение"), MessageBoxButtons.OK, MessageBoxIcon.Warning ); return; } //LastName = (string)Selected.Text; LastPath = SelectedTag.GetPath(); //LastName DialogResult dr = MessageBox.Show(MainForm.MForm, Common.MLS.Get(MLSConst, "Вы действительно хотите перемерить спектр: ") + LastPath, Common.MLS.Get(MLSConst, "Осторожно!!!"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dr == DialogResult.No) { return; } CurSp = new Spectr(LastPath);//(Folder, LastName); SpectrCondition cond; if (DefaultCondition == null) { SpectrCondition spc = CurSp.GetMeasuringCondition(); cond = SpectrCondEditor.GetCond(MainForm.MForm, spc); if (cond == null) { return; } } else { cond = DefaultCondition; } Dev.MeasuringResultFinalCall final_call = new Dev.MeasuringResultFinalCall(btReMeasuringSpectr_Click_Final); Common.Dev.Measuring(cond, final_call); } catch (Exception ex) { Common.Log(ex); } }
private void MMMeasuringReMeasuring_Click(object sender, EventArgs e) { try { string bpath = Common.Db.GetFoladerPath(Common.DbNameProbSort) + "\\условия.bin"; if (File.Exists(bpath) == false) { MMMeasuringExp_Click(sender, e); } if (File.Exists(bpath) == false) { return; } SpectrCondition cond; FileStream fs = new FileStream(bpath, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); cond = new SpectrCondition(br); br.Close(); if (tvDirView.SelectedNode == null) { return; } string base_path = (string)(tvDirView.SelectedNode.Tag); int ind = base_path.IndexOf(".ss"); if (ind < 0) { MessageBox.Show(MainForm.MForm, "Выбранный элемент не является спектром. Перемерить невозможно", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } else { base_path = base_path.Substring(0, ind); } Spectr.RemoveSpectr(base_path); MeasuringFile = base_path; Dev.MeasuringResultFinalCall final_call = new Dev.MeasuringResultFinalCall(btMeasuringNewSpectr_Click_Final); Common.Dev.Measuring(cond, final_call); } catch (Exception ex) { Common.Log(ex); } }
private void btCycleMeasuring_Click(object sender, EventArgs e) { try { if (CycleThread == null && sender != null) { Spectr sp = Control.GetSelectedSpectrCT(); if (sp == null) { return; } SpectrCondition spc = sp.GetMeasuringCondition(); CCond = SpectrCondEditor.GetCond(MainForm.MForm, spc); if (CCond == null) { return; } CycleThread = new Thread(btCycleMeasuring_Thread); CycleThread.Start(); PrevName = btCycleMeasuring.Text; btCycleMeasuring.Text = Common.MLS.Get(MLSConst, "Остановить"); MainForm.MForm.EnableToolExit(false, null); btCycleMeasuring.Enabled = true; } else { CycleThread = null; btCycleMeasuring.Text = PrevName; MainForm.MForm.EnableToolExit(true, null); if (chbGenOn.Checked) { chbGenOn.Checked = false; } if (chbFillLight.Checked) { chbFillLight.Checked = false; } } } catch (Exception ex) { Common.Log(ex); } }
private void MMMeasuringAddBase_Click(object sender, EventArgs e) { try { string bpath = Common.Db.GetFoladerPath(Common.DbNameProbSort) + "\\условия.bin"; if (File.Exists(bpath) == false) { MMMeasuringExp_Click(sender, e); } if (File.Exists(bpath) == false) { return; } SpectrCondition cond; FileStream fs = new FileStream(bpath, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); cond = new SpectrCondition(br); br.Close(); if (tvDirView.SelectedNode == null) { return; } string base_path = (string)(tvDirView.SelectedNode.Tag); if (base_path.IndexOf(".ss") > 0) { base_path = (string)(tvDirView.SelectedNode.Parent.Tag); } string str = "base"; MeasuringFile = base_path + "\\" + str; Dev.MeasuringResultFinalCall final_call = new Dev.MeasuringResultFinalCall(btMeasuringNewSpectr_Click_Final); Common.Dev.Measuring(cond, final_call); } catch (Exception ex) { Common.Log(ex); } }
protected internal void ReInitResultWindow(SpectrCondition cond) { string res = ""; btSave.Enabled = true; for (int i = 0; i < cond.Lines.Count; i++) { if (cond.Lines[i].CompilationError != null) { res += Common.MLS.Get(MLSConst, " Ошибка: ") + cond.Lines[i].CompilationError + serv.Endl; if (chUseChecking.Checked == false) { btSave.Enabled = false; } } else { res += cond.Lines[i].ToString() + serv.Endl; } } tbResultCode.Text = res; tbResultCode.ForeColor = SystemColors.WindowText; if (cond.Warning == null) { lbWarning.Text = Common.MLS.Get(MLSConst, "Успешно проверенно..."); lbWarning.ForeColor = SystemColors.ControlText; lbWarning.BackColor = SystemColors.Control; } else { lbWarning.Text = cond.Warning; if (chUseChecking.Checked == false) { btSave.Enabled = false; } lbWarning.ForeColor = Color.Red; lbWarning.BackColor = Color.White; } }
private void MMMeasuringAddMeasuring_Click(object sender, EventArgs e) { try { string bpath = Common.Db.GetFoladerPath(Common.DbNameProbSort) + "\\условия.bin"; if (File.Exists(bpath) == false) { MMMeasuringExp_Click(sender, e); } if (File.Exists(bpath) == false) { return; } SpectrCondition cond; FileStream fs = new FileStream(bpath, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); cond = new SpectrCondition(br); br.Close(); if (tvDirView.SelectedNode == null) { return; } string base_path = (string)(tvDirView.SelectedNode.Tag); if (base_path.IndexOf(".ss") > 0) { base_path = (string)(tvDirView.SelectedNode.Parent.Tag); } if (base_path[base_path.Length - 1] != 'p' || base_path[base_path.Length - 2] != '.') { MessageBox.Show(MainForm.MForm, "Это не проба. Выберите пробу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } DateTime now = new DateTime(DateTime.Now.Ticks); string def_name = "" + (now.Year - 2000); int tmp = now.Month; if (tmp < 10) { def_name += "0"; } def_name += tmp; tmp = now.Day; if (tmp < 10) { def_name += "0"; } def_name += tmp; def_name += " "; tmp = now.Hour; if (tmp < 10) { def_name += "0"; } def_name += tmp + "."; tmp = now.Minute; if (tmp < 10) { def_name += "0"; } def_name += tmp + "."; tmp = now.Second; if (tmp < 10) { def_name += "0"; } def_name += tmp; string def_path = base_path + "\\" + def_name + ".ss"; if (File.Exists(def_path) == true) { int at = 0; while (File.Exists(def_path) == true) { at++; def_path = base_path + "\\" + def_name + "_" + at + ".ss"; } def_name += "_" + at; } string str = StringDialog.GetString(MainForm.MForm, Common.MLS.Get(MLSConst, "Введите имя пробы"), Common.MLS.Get(MLSConst, "Создание пробы"), def_name, true); if (str == null) { return; } MeasuringFile = base_path + "\\" + str; Dev.MeasuringResultFinalCall final_call = new Dev.MeasuringResultFinalCall(btMeasuringNewSpectr_Click_Final); Common.Dev.Measuring(cond, final_call); } catch (Exception ex) { Common.Log(ex); } }
protected short[][] MeasuringMonoExp(double common_time, double exp_time, string file_name, Spectr add_to, bool is_on, out string cond, int split_k) { float tick = Common.Dev.Tick; int exp = (int)(exp_time / tick); if (exp < 1) { exp = 1; } int common = (int)(common_time / exp_time) * exp; if (common < exp) { common = exp; } cond = "e:" + (common * tick) + "( "; int[] exps = Common.Dev.Reg.GetSensorSizes(); for (int i = 0; i < exps.Length; i++) { if (i != 0) { cond += ';'; } exps[i] = exp; cond += (exps[i] * tick); } if (is_on) { cond += ")On()"; } else { cond += ")Off()"; } int com_i = common / exp; if (com_i < 1) { com_i = 1; } common = com_i * exp; int tmp = common / split_k; tmp /= exp; if (tmp * exp * split_k != common) { throw new Exception("Системные проблемы. Экспозиция не кратна общему времени..."); } common /= split_k; short[][][] data = new short[split_k][][]; short[][] bs, be; SpectrCondition sp_cond = new SpectrCondition(tick, cond); for (int att = 0; att < split_k; att++) { Common.Dev.Gen.SetStatus(false); //gui.MainForm.MForm.SetupTimeOut(common * tick); Common.Log("Mono exp measuring: " + common + " [" + exp + "]"); //short[][] data[att] = Common.Dev.Reg.RegFrame(common, exps, out bs, out be); //gui.MainForm.MForm.SetupTimeOut(0); } if (split_k > 1) { double[] buf = new double[split_k]; for (int sn = 0; sn < data[0].Length; sn++) { for (int pix = 0; pix < data[0][sn].Length; pix++) { for (int i = 0; i < split_k; i++) { buf[i] = data[i][sn][pix]; } data[0][sn][pix] = (short)SpectroWizard.analit.Stat.GetEver(buf); } } } Spectr sp; DbFolder folder = Common.Db.GetFolder(Common.DbNameTestingFolder); if (add_to == null) { sp = new Spectr(sp_cond, new Dispers(), new OpticFk(), "DevTest"); } else { sp = add_to; } sp.Add(new SpectrDataView(sp_cond, data[0], null, null, Common.Dev.Reg.GetMaxValue(), Common.Dev.Reg.GetMaxLinarValue())); sp.SaveAs(folder.GetRecordPath(file_name)); return(data[0]); }
static public SpectrCondition GetCond(Form master, SpectrCondition src) { return(GetCond(master, src, false)); }
public bool Run() { Report = ""; DateTime from = new DateTime(DateTime.Now.Ticks); SpectrCondition cond = new SpectrCondition(Common.Dev.Tick, SpectrCondition.GetDefaultCondition(false, false, 0.1F, 0.1F, 20)); int[] ss = Common.Dev.Reg.GetSensorSizes(); do { Common.Dev.Measuring(cond, null); for (int s = 0; s < ss.Length; s++) { for (int sh = 0; sh < Common.Dev.LetestResult.Count; sh++) { float[] dt = Common.Dev.LetestResult[sh].GetFullData()[s]; Complex[] cdt = new Complex[dt.Length]; for (int i = 0; i < dt.Length; i++) { cdt[i] = new Complex(dt[i]); } FourierTransform.DFT(cdt, FourierTransform.Direction.Forward); double max = cdt[0].Length; int max_ind = 0; for (int i = 1; i < dt.Length / 2 - 1; i++) { if (max < cdt[i].Length) { max = cdt[i].Length; max_ind = i; } } if (max_ind > 0) { Report = "Found garmonic with period " + cdt.Length / max_ind + " pixels on sensor " + s + " and exposition " + sh + serv.Endl; } } for (int p = 0; p < ss[s]; p++) { double[] data = new double[Common.Dev.LetestResult.Count]; for (int sh = 0; sh < Common.Dev.LetestResult.Count; sh++) { data[sh] = Common.Dev.LetestResult[sh].GetFullDataNoClone()[s][p]; } double ever = 0; for (int i = 0; i < data.Length; i++) { ever += data[i]; } ever /= data.Length; double dlt = 0; for (int i = 0; i < data.Length; i++) { dlt += Math.Sqrt(Math.Abs(data[i] - ever)); } dlt *= dlt; dlt /= data.Length; dlt *= (int)nmStep.Value; for (int i = 0; i < data.Length && Report.Length < 4000; i++) { if (Math.Abs(ever - data[i]) > dlt) { Report += "Splash found at " + (i) + " on data ["; for (int j = 0; j < data.Length; j++) { if (i != j) { Report += " " + data[j] + " "; } else { Report += "!" + data[j] + "!"; } } Report += "]" + serv.Endl; } } } } } while ((DateTime.Now.Ticks - from.Ticks) / 10000000 < nmTimeOut.Value && Report.Length == 0); Spectr sp = new Spectr(cond, Common.Env.DefaultDisp, Common.Env.DefaultOpticFk, "RundomSplashTest"); for (int i = 0; i < Common.Dev.LetestResult.Count; i++) { sp.Add(Common.Dev.LetestResult[i]); } sp.SaveAs(Common.DbNameSienceSensFolder + "\\null_noise_test"); spView.ClearSpectrList(); spView.AddSpectr(sp, ""); if (Report.Length == 0) { return(true); } else { return(false); } }//*/
public void CollectData(List <SpectrDataView> data, SpectrCondition cond) { float max_level = Common.Conf.MaxLevel; byte[] bbuffer = new byte[4096 * 2 * 15]; int[] line_sizes = Reg.GetSensorSizes(); int[] orientations = Common.Conf.USBOrientationVals; for (int step = 0; step < cond.Lines.Count; step++) { if (cond.Lines[step].Type == SpectrCondition.CondTypes.Exposition) { FileStream fs = new FileStream("data" + cond.Lines[step].TmpInteger, FileMode.Open, FileAccess.Read); int size = fs.Read(bbuffer, 0, bbuffer.Length); fs.Close(); short[] sbuffer = new short[size / 2]; for (int i = 0; i < size; i += 2) { short val = (short)(bbuffer[i + 1] & 0xFF); if (val > 0xF) { throw new Exception("Val is too big"); } val <<= 8; val |= (short)(bbuffer[i] & 0xFF); sbuffer[i / 2] = val; } /*int ever = 0; * for(int i = 0;i<4096;i++) * ever += sbuffer[i]; * ever /= 4096;//*/ if (size < 4096 * line_sizes.Length) { throw new Exception("No data for expoistion " + step + "-" + cond.Lines[step].TmpInteger); } float[][] line_data = new float[line_sizes.Length][]; short[][] bb = new short[line_sizes.Length][]; short[][] be = new short[line_sizes.Length][]; int[] index_in_data = new int[line_sizes.Length]; for (int i = 0; i < orientations.Length; i++) { index_in_data[i] = (int)Math.Abs(orientations[i]) - 1; } for (int i = 0; i < index_in_data.Length; i++) { bool found = false; for (int j = 1; j < index_in_data.Length; j++) { if (index_in_data[j - 1] > index_in_data[j]) { int tmp = index_in_data[j - 1]; index_in_data[j - 1] = index_in_data[j]; index_in_data[j] = tmp; found = true; } } if (found == false) { break; } } for (int li = 0; li < line_sizes.Length; li++) { int l = 0; int or = (int)Math.Abs(orientations[li]) - 1; for (int i = 0; i < orientations.Length; i++) { if (or == index_in_data[i]) { l = i; break; } } int orient = orientations[li]; int index; int beg_blank_size, end_blank_size; if (orient < 0) { //index = -orient; beg_blank_size = Common.Conf.BlakPixelEnd; end_blank_size = Common.Conf.BlakPixelStart; } else { //index = orient; end_blank_size = Common.Conf.BlakPixelEnd; beg_blank_size = Common.Conf.BlakPixelStart; } index = l; //index--; int pos = index * 4096; short[] rez = new short[4096]; for (int i = 0; i < 4096; i++) { //short val = (short)(buffer[pos+i+1]&0xFF); //val <<= 8; //val |= (short)((buffer[pos+i])&0xFF); if (orient > 0) { rez[i] = sbuffer[pos + i]; } else { rez[4095 - i] = sbuffer[pos + i]; } } int base_level = 0, bl = 0; for (int i = 0; i < 15; i++, bl++) { base_level += sbuffer[pos + i]; } base_level /= bl; int blank_level = 0; bl = 0; for (int i = 17; i < 28; i++, bl++) { blank_level += sbuffer[pos + i]; } blank_level /= bl; int ever = blank_level - base_level + 10; line_data[li] = new float[4096 - end_blank_size - beg_blank_size]; bb[li] = new short[beg_blank_size]; be[li] = new short[end_blank_size]; int ind; //int collect_to; //if(beg_blank_size for (ind = 0; ind < beg_blank_size; ind++) { bb[li][ind] = rez[ind]; } int index_from = ind; for (; ind < 4096 - end_blank_size; ind++) { line_data[li][ind - index_from] = rez[ind]; } index_from = ind; for (; ind < 4096; ind++) { be[li][ind - index_from] = rez[ind]; } /*short[] to_sum; * int to_sum_from = 0; * if (be[li].Length < 100)//> 400) * { * to_sum = be[li]; * to_sum_from = to_sum.Length - 18;//50; * } * else * { * to_sum = bb[li]; * to_sum_from = 0; * } * int ever = 0; * /*for (int i = 0; i < 18; i++) * ever += to_sum[i + to_sum_from]; * ever /= 18;*/ if (Common.Conf.BlankSub == false) { ever = 0; } for (int i = 0; i < line_data[li].Length; i++) { if (line_data[li][i] > max_level) { line_data[li][i] = max_level + 1; } else { line_data[li][i] = line_data[li][i] - ever;//*/ } } } SpectrDataView cur_spview = new SpectrDataView(new SpectrCondition(Tick, cond.Lines[step]), line_data, bb, be, Common.Dev.Reg.GetMaxValue(), Common.Dev.Reg.GetMaxLinarValue()); data.Add(cur_spview); } } }
public void CollectDataMiner(List <SpectrDataView> data, SpectrCondition cond) { float max_level = Common.Conf.MaxLevel; int[] line_sizes = Reg.GetSensorSizes(); int[] orientations = Common.Conf.USBOrientationVals; int line_size; if (line_sizes[0] > 3048) { line_size = 4096; } else { line_size = 2048; } for (int step = 0; step < cond.Lines.Count; step++) { if (cond.Lines[step].Type == SpectrCondition.CondTypes.Exposition) { /*byte[] bbuffer = new byte[4096 * 2 * 15]; * short[] bbuffer_sub_count = new short[4096 * 2 * 15]; * FileStream fs = new FileStream("data" + cond.Lines[step].TmpInteger, FileMode.Open, FileAccess.Read); * int size = fs.Read(bbuffer, 0, bbuffer.Length); * fs.Close(); * * short[] sbuffer = new short[size / 2]; * for (int i = 0; i < size; i += 2) * { * short val = (short)(bbuffer[i + 1] & 0xFF); * if (val > 0xF) * throw new Exception("Val is too big"); * val <<= 8; * val |= (short)(bbuffer[i] & 0xFF); * sbuffer[i / 2] = val; * }*/ FileStream fs = new FileStream("data" + cond.Lines[step].TmpInteger, FileMode.Open, FileAccess.Read); long[] sbuffer = new long[15 * line_size]; short[] sbuffer_counter = new short[sbuffer.Length]; short[] sbuffer_fill_counter = new short[15]; bool[] sbuffer_fill_flag = new bool[15]; byte[] bbuffer = new byte[line_size * 2]; do { int size = fs.Read(bbuffer, 0, bbuffer.Length); if (size == 0) { break; } if (size != bbuffer.Length) { throw new Exception("Can't load full data..."); } for (int i = 0; i < bbuffer.Length; i += 2) { short val = (short)(bbuffer[i + 1] & 0xF); val <<= 8; val |= (short)(bbuffer[i] & 0xFF); if (val < 0) { throw new Exception("Negative value"); } int sn = (bbuffer[i + 1] >> 4); sbuffer_fill_flag[sn] = true; int index = line_size * sn + sbuffer_fill_counter[sn]; sbuffer[index] += val; if (sbuffer[index] < 0) { throw new Exception("Negative value"); } sbuffer_counter[index]++; sbuffer_fill_counter[sn]++; if (sbuffer_fill_counter[sn] >= line_size) { sbuffer_fill_counter[sn] = 0; } } } while (true); fs.Close(); for (int i = 0; i < sbuffer.Length; i++) { if (sbuffer_counter[i] > 0) { sbuffer[i] /= sbuffer_counter[i]; } else { sbuffer[i] = -1; } } int sbuffer_shift = 0; for (int s = 0; s < 15; s++) { if (sbuffer_fill_flag[s] == false) { sbuffer_shift += line_size; } else { if (sbuffer_shift == 0) { continue; } int from = s * line_size; int to = from - sbuffer_shift; for (int i = 0; i < line_size; i++) { sbuffer[to + i] = sbuffer[from + i]; } } } //if (size < 4096 * line_sizes.Length) // throw new Exception("No data for expoistion " + step + "-" + cond.Lines[step].TmpInteger); float[][] line_data = new float[line_sizes.Length][]; short[][] bb = new short[line_sizes.Length][]; short[][] be = new short[line_sizes.Length][]; int[] index_in_data = new int[line_sizes.Length]; for (int i = 0; i < orientations.Length; i++) { index_in_data[i] = (int)Math.Abs(orientations[i]) - 1; } for (int i = 0; i < index_in_data.Length; i++) { bool found = false; for (int j = 1; j < index_in_data.Length; j++) { if (index_in_data[j - 1] > index_in_data[j]) { int tmp = index_in_data[j - 1]; index_in_data[j - 1] = index_in_data[j]; index_in_data[j] = tmp; found = true; } } if (found == false) { break; } } for (int li = 0; li < line_sizes.Length; li++) { int l = 0; int or = (int)Math.Abs(orientations[li]) - 1; for (int i = 0; i < orientations.Length; i++) { if (or == index_in_data[i]) { l = i; break; } } int orient = orientations[li]; int index; int beg_blank_size, end_blank_size; if (orient < 0) { beg_blank_size = Common.Conf.BlakPixelEnd; end_blank_size = Common.Conf.BlakPixelStart; } else { end_blank_size = Common.Conf.BlakPixelEnd; beg_blank_size = Common.Conf.BlakPixelStart; } index = l; int pos = index * 4096; short[] rez = new short[4096]; for (int i = 0; i < 4096; i++) { short val = (short)sbuffer[pos + i]; if (orient > 0) { rez[i] = val;//(short)sbuffer[pos + i]; } else { rez[4095 - i] = val;//(short)sbuffer[pos + i]; } } int base_level = 0, bl = 0; for (int i = 0; i < 15; i++, bl++) { base_level += (short)sbuffer[pos + i]; } base_level /= bl; int blank_level = 0; bl = 0; for (int i = 17; i < 28; i++, bl++) { blank_level += (short)sbuffer[pos + i]; } blank_level /= bl; int ever = blank_level - base_level + 10; line_data[li] = new float[4096 - end_blank_size - beg_blank_size]; bb[li] = new short[beg_blank_size]; be[li] = new short[end_blank_size]; int ind; //int collect_to; //if(beg_blank_size for (ind = 0; ind < beg_blank_size; ind++) { bb[li][ind] = rez[ind]; } int index_from = ind; for (; ind < 4096 - end_blank_size; ind++) { line_data[li][ind - index_from] = rez[ind]; } index_from = ind; for (; ind < 4096; ind++) { be[li][ind - index_from] = rez[ind]; } if (Common.Conf.BlankSub == false) { ever = 0; } for (int i = 0; i < line_data[li].Length; i++) { if (line_data[li][i] > max_level) { line_data[li][i] = max_level + 1; } else { line_data[li][i] = line_data[li][i] - ever;//*/ } if (line_data[li][i] < 0) { throw new Exception("Negative value..."); } } } SpectrDataView cur_spview = new SpectrDataView(new SpectrCondition(Tick, cond.Lines[step]), line_data, bb, be, Common.Dev.Reg.GetMaxValue(), Common.Dev.Reg.GetMaxLinarValue()); data.Add(cur_spview); } } }
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); } } }
private void btCycleMeasuring_ThreadTech() { bool prev_gen = IsGenOn, prev_fl = IsFillLightOn; Spectr sp = Control.GetSelectedSpectrCT(); if (sp == null) { return; } SpectrConditionCompiledLine con = null; SpectrCondition cond = CCond;//sp.GetMeasuringCondition(); int sp_index = 0; for (int i = 0; i < cond.Lines.Count; i++) { if (cond.Lines[i].Type == SpectrCondition.CondTypes.Exposition && cond.Lines[i].IsActive) { con = cond.Lines[i]; sp_index = con.SpectrViewIndex; break; } } if (con == null) { return; } Common.Dev.CheckConnection(); Common.Dev.BeforeMeasuring(); sp.SetDispers(Common.Env.DefaultDisp); sp.OFk = Common.Env.DefaultOpticFk; int common_time_i; int[] exps_i; Common.Dev.CorrectExposition(con, out common_time_i, out exps_i); short[][] bb, be; while (CycleThread != null && Common.IsRunning) { try { short[][] datas = Common.Dev.Reg.RegFrame(common_time_i, exps_i, out bb, out be); float[][] 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]; } } SpectrDataView cur_spview = new SpectrDataView(new SpectrCondition(Common.Dev.Tick, con), data, bb, be, Common.Dev.Reg.GetMaxValue(), Common.Dev.Reg.GetMaxLinarValue()); sp.Set(cur_spview, sp_index); SpView.ReLoadSpectr(sp, 0); SpView.ReDraw(); if (prev_fl != IsFillLightOn) { prev_fl = IsFillLightOn; Common.Dev.Fill.SetFillLight(chbFillLight.Checked); } if (prev_gen != IsGenOn) { prev_gen = IsGenOn; Common.Dev.Gen.SetStatus(chbGenOn.Checked); } Thread.Sleep(500); } catch (Exception ex) { Common.Log(ex); break; } } sp.Save(); }