public void loadengine() { try { HDevProgram program = new HDevProgram(programPath); programCall = new HDevProgramCall(program); } catch { } }
private void HalconTemplateCreator_ParentChanged(object sender, EventArgs e) { if (Parent != null) { ParentForm.Text = "GenTemplate"; ParentForm.AutoSize = true; ParentForm.FormClosing += new FormClosingEventHandler(ParentForm_FormClosing); try { lineGuageParam = (LineGuageParam)FastData.SaveStatic.ReadBin(guagepath); } catch (Exception exp) { MessageBox.Show("读取文件失败!" + guagepath + exp); } transCom.Items.AddRange(new object[3] { CalipTrans.all, CalipTrans.negtive, CalipTrans.positive }); heightTxt.Text = lineGuageParam.CalipHeight.ToString(); widthTxt.Text = lineGuageParam.CalipWidth.ToString(); calipNumTxt.Text = lineGuageParam.CalipNum.ToString(); thresholdTxt.Text = lineGuageParam.CalipThreshold.ToString(); IgnoreTxt.Text = lineGuageParam.CalipIgnore.ToString(); transCom.Text = lineGuageParam.calipTrans.ToString(); if (Image != null) { button1.Enabled = false; button2.Enabled = false; engine = new HDevEngine(); program = new HDevProgram(mPath); programCall = new HDevProgramCall(program); if (impl == null) { impl = new HDevOpMultiWindowImpl(hWindowControltemp.HalconWindow); } engine.SetHDevOperators(impl); //string di = new DirectoryInfo(string.Format("{0}../../../../", Application.StartupPath)).FullName; //string aa = di + "Template"; //if (!Directory.Exists(aa)) // Directory.CreateDirectory(aa); SetTemplateOriginImage(Image); Excute(); } } }
/// <summary> /// 初始化 /// </summary> /// <param name="filePath">文件路径</param> public void Init(string filePath) { try { hDevProgram = new HDevProgram(filePath); hDevProgramCall = hDevProgram.CreateCall(); valueCount = hDevProgram.GetCtrlVarCount(); valueName = hDevProgram.GetCtrlVarNames().SArr; Outputs.Clear(); } catch (Exception) { throw; } }
public void Excute() { if (task.Status == TaskStatus.Created || task.IsCompleted || task.IsFaulted || task.IsCanceled) { task = new Task(() => { engine = new HDevEngine(); program = new HDevProgram(Path); programCall = new HDevProgramCall(program); if (impl == null) { impl = new HDevOpMultiWindowImpl(hSmartWindowControlcamera.HalconWindow); } engine.SetHDevOperators(impl); programCall.Execute(); }, TaskCreationOptions.LongRunning); task.Start(); } }
private void Form1_Load(object sender, EventArgs e) { String path = @".\hdev\ocr_mvtec_using_a_camera.hdev"; String procPath = @".\procedure"; engine.SetProcedurePath(procPath); program = new HDevProgram(path); programCall = new HDevProgramCall(program); ocr_NHP = new HDevProcedure(program, "ocr_NHP"); ocr_NHP_Call = new HDevProcedureCall(ocr_NHP); charArray2String = new HDevProcedure(program, "charArray2String"); charArray2String_Call = new HDevProcedureCall(charArray2String); t = DateTime.Now; dgv = dataGridView1; mainWindowList[0] = hSmartWindowControl1.HalconWindow; mainWindowList[1] = hSmartWindowControl2.HalconWindow; //mainWindowList[2] = hSmartWindowControl3.HalconWindow; //mainWindowList[3] = hSmartWindowControl4.HalconWindow; //hSmartWindowControl5.Hide(); //hSmartWindowControl6.Hide(); sideWindowList[0] = hSmartWindowControl3.HalconWindow; sideWindowList[1] = hSmartWindowControl4.HalconWindow; //sideWindowList[2] = hSmartWindowControl7.HalconWindow; //sideWindowList[3] = hSmartWindowControl8.HalconWindow; //hSmartWindowControl7.Hide(); //hSmartWindowControl8.Hide(); initSetup(); setCamera(); updateSetting(); dgv.AutoSize = false; this.dgv.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells; this.dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells; dgv.RowHeadersDefaultCellStyle.BackColor = Color.DarkSalmon; }
public void button1_Click(object sender, EventArgs e) { button1.Enabled = false; if (GetTaskStatus() == 0) { OpenFileDialog ofd = new OpenFileDialog(); string initdi = new DirectoryInfo(string.Format("{0}../../../../", Application.StartupPath)).FullName; //ofd.Filter = "Excel文件(*.xls;*.xlsx)|*.xls;*.xlsx|所有文件|*.*"; ofd.CheckPathExists = true; ofd.CheckFileExists = true; ofd.InitialDirectory = initdi + "SavePic"; if (ofd.ShowDialog() == DialogResult.OK) { engine = new HDevEngine(); program = new HDevProgram(mPath); programCall = new HDevProgramCall(program); if (impl == null) { impl = new HDevOpMultiWindowImpl(hWindowControltemp.HalconWindow); } engine.SetHDevOperators(impl); //string di = new DirectoryInfo(string.Format("{0}../../../../", Application.StartupPath)).FullName; //string aa = di + "Template"; //if (!Directory.Exists(aa)) // Directory.CreateDirectory(aa); string strFileName = ofd.FileName; SetTemplateOriginPath(strFileName); Excute(); } } else//如已经在运行,将任务先停掉,然后再调用 { OpenFileDialog ofd = new OpenFileDialog(); //ofd.Filter = "Excel文件(*.xls;*.xlsx)|*.xls;*.xlsx|所有文件|*.*"; ofd.CheckPathExists = true; ofd.CheckFileExists = true; if (ofd.ShowDialog() == DialogResult.OK) { StopTask(); Thread.Sleep(500); engine = new HDevEngine(); program = new HDevProgram(mPath); programCall = new HDevProgramCall(program); if (impl == null) { impl = new HDevOpMultiWindowImpl(hWindowControltemp.HalconWindow); } engine.SetHDevOperators(impl); //string di = new DirectoryInfo(string.Format("{0}../../../../", Application.StartupPath)).FullName; //string aa = di + "Template"; //if (!Directory.Exists(aa)) // Directory.CreateDirectory(aa); //textBox1.Text = aa + "\\template.tif"; string strFileName = ofd.FileName; SetTemplateOriginPath(strFileName); Excute(); } } button1.Enabled = true; }