private void btnContinuGrab_Click(object sender, EventArgs e) { if (vision == null) { MessageBox.Show("请选择流程"); return; } if (continuGrab) { return; } else { btnGrabOne.Enabled = false; btnContinuGrab.Enabled = false; continuGrab = true; } Task.Run(() => { while (continuGrab) { VisionMgr.GetInstance().GetCam(camera).Grab(); vision.imgSrc = VisionMgr.GetInstance().GetCam(camera).m_image; if (vision is ProcessSideMea) { vision.Process(); } visionControl1.DisplayResults(); } }); }
public static void cameraSnap() { // CameraGige Camera = new CameraGige("test"); string item; HObject img = null; while (!s._go.IsCompleted) { if (s._go.TryTake(out item)) { if (item == "s") { img = VisionMgr.GetInstance().CameraSnap("test"); if (img == null) { continue; } // m_visioncontrol1.DispImageFull(Camera.GetImage()); c._go.TryAdd(img, 5000); } // Console.WriteLine(item); } System.Threading.Thread.Sleep(10); } c._go.CompleteAdding(); }
public static void AddVisionStep() { //加入一个相机采集类, 加入步骤前必须先添加相机采集 VisionMgr.GetInstance().AddCamera(new CameraGige("test")); //加入视觉步骤类, 并将其绑定到指定的相机采集类上 VisionMgr.GetInstance().AddVisionStep("test", new Process_Test("Process_Test")); }
private void AutoForm_FormClosing(object sender, FormClosingEventArgs e) { SaveParam(); //获取相机名称 string fileName = $@"{System.Environment.CurrentDirectory}\Product\CameraName.ini"; IniTool.Set(fileName, "CameraName", "MainCamera", CameraName.MainCamera); IniTool.Set(fileName, "CameraName", "SideCamera", CameraName.SideCamera); //关闭所有相机 VisionMgr.GetInstance().CloseCameraAll(); }
public SideCameraForm(string cameraName, string visionStepName) { InitializeComponent(); //添加相机并绑定到窗口 camera = cameraName; VisionMgr.GetInstance().BindWindow(visionStepName, visionControl1); visionControl1.InitWindow(); visionControl1.RegisterUpdateInterface(vision); cmbProcess.Items.Add(visionStepName); cmbProcess.SelectedIndex = 0; }
private void AutoForm_FormClosing(object sender, FormClosingEventArgs e) { SaveParam(); //获取相机名称 string fileName = $@"{System.Environment.CurrentDirectory}\Product\CameraName.ini"; IniTool.Set(fileName, "CameraName", "MainCamera", CameraName.MainCamera); IniTool.Set(fileName, "CameraName", "SideCamera", CameraName.SideCamera); foreach (var cam in VisionMgr.GetInstance().m_dicCamera.Values) { cam.Close(); } }
public void ChangeProduct(string name, string path) { //先切换产品管理类产品 //ProductMgr.GetInstance().ChangeProduct(name); //后切换流程管理类产品 VisionMgr.GetInstance().m_strConfigDir = path; VisionMgr.GetInstance().OnProductChanged(); Text = $"RUIFEI VISION {name}"; Form fainForm; m_dicForm.TryGetValue(btnMainCamera, out fainForm); ((MainCameraForm)fainForm)?.ChangeProduct(name, path); }
private void cmbProcess_SelectedIndexChanged(object sender, EventArgs e) { //获得当前图像处理流程 vision = VisionMgr.GetInstance().GetVisionBase(cmbProcess.Text); visionControl1.RegisterUpdateInterface(vision); //获取曝光 nudExposure.Value = vision.m_ExposureTime; var v = vision as ProcessSideMea; nudSigma.Value = (decimal)v.Sigma.D; nudThreshold.Value = (decimal)v.Threshold.D; HOperatorSet.ClearWindow(visionControl1.GetHalconWindow()); visionControl1.DisplayResults(); }
private void SideCameraForm_Load(object sender, EventArgs e) { //添加相机并绑定到窗口 VisionMgr.GetInstance().BindWindow(VisionStepName.SideMea, visionControl1); visionControl1.InitWindow(); visionControl1.RegisterUpdateInterface(vision); cmbProcess.Items.Add(VisionStepName.SideMea); cmbProcess.SelectedIndex = 0; for (int i = 0; i < 2; i++) { DataGridViewRow row = new DataGridViewRow(); row.Cells.AddRange(new DataGridViewTextBoxCell(), new DataGridViewTextBoxCell(), new DataGridViewTextBoxCell(), new DataGridViewTextBoxCell()); dgvCalib.Rows.Add(row); } }
/// <summary> /// 解析指令 /// </summary> /// <param name="data"></param> public static void Parse(string data) { DateTime t1 = DateTime.Now; Log.Show($"接收:{data}"); bool result = false; //清理数据 SendData.Clear(); //平台定位 if (data == CommandType.T1) { result = VisionMgr.GetInstance().GetVisionBase(VisionStepName.MainPos).Process(); string temp; if (result) { /* 12345678-数值必须用8位表示 * 12-前2位表示数值的符号,00-正,11-负 * 3456-中间4位表示数值的整数部分 * 78-后2位表示数值的小数部分 */ string x = $"{SendData.X:000000.00}".Replace(".", "").Replace("-00", "11"); string y = $"{SendData.Y:000000.00}".Replace(".", "").Replace("-00", "11"); string u = $"{SendData.Angle:000000.00}".Replace(".", "").Replace("-00", "11"); temp = $"01,,01,,01,,{x},,{y},,{u}"; } else { temp = $"01,,01,,00,,00000000,,00000000,,00000000"; } TcpClientMgr.GetInstance().Send(temp); Log.Show($"发送:{temp}"); } //机械手定位 else if (data == CommandType.T2) { result = VisionMgr.GetInstance().GetVisionBase(VisionStepName.MainMea).Process(); string temp; if (result) { string x = $"{SendData.X:000000.00}".Replace(".", "").Replace("-00", "11"); string y = $"{SendData.Y:000000.00}".Replace(".", "").Replace("-00", "11"); string areaNgCount = $"{SendData.CountAreaNG:0000}"; string posNgCount = $"{SendData.CountPosNG:0000}"; //面积NG数量 位置NG数量 temp = $"01,,02,,01,,{x},,{y},,{areaNgCount}{posNgCount}"; } else { temp = $"01,,02,,00,,00000000,,00000000,,00000000"; } TcpClientMgr.GetInstance().Send(temp); Log.Show($"发送:{temp}"); } //针脚测量 else if (data == CommandType.T4) { result = VisionMgr.GetInstance().GetVisionBase(VisionStepName.PinMea).Process(); string temp; if (result) { string resPin = SendData.PinCountOK ? "11" : "22"; //面积NG数量 位置NG数量 temp = $"01,,01,,01,,00000000,,00000000,,000000{resPin}"; } else { temp = $"01,,01,,00,,00000000,,00000000,,00000022"; } TcpClientMgr.GetInstance().Send(temp); Log.Show($"发送:{temp}"); } TimeSpan time = DateTime.Now - t1; Log.Show($"用时:{time.TotalMilliseconds}"); }
private void AutoForm_Load(object sender, EventArgs e) { //btnSystemConfig.Enabled = false; btnSideCamera.Enabled = false; RoundButton_Communication.Enabled = false; btnImageFile.Enabled = false; BtnRun.Enabled = false; RoundButton_Login.Enabled = false; //BtnRun.BaseColorEnd = BtnRun.BaseColor = Color.FromArgb(230, 216, 216); //btnSystemConfig.BaseColor = Color.DarkGray; RoundButton_Communication.BaseColor = Color.DarkGray; btnImageFile.BaseColor = Color.DarkGray; BtnRun.BaseColor = Color.DarkGray; RoundButton_Login.BaseColor = Color.DarkGray; tlbVer.Alignment = ToolStripItemAlignment.Right; tlbVer.Text = $"V2.1:{System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location)}"; _autoForm = this; //获取相机名称 string fileName = $@"{System.Environment.CurrentDirectory}\Product\CameraName.ini"; CameraName.MainCamera = IniTool.GetString(fileName, "CameraName", "MainCamera", "MainCam"); CameraName.SideCamera = IniTool.GetString(fileName, "CameraName", "SideCamera", "HE012A1GM"); #if JAI //添加相机并绑定到窗口 foreach (var cam in CameraJai.FindCamera()) { if (cam.ModelName == CameraName.MainCamera || cam.ModelName == CameraName.SideCamera) { VisionMgr.GetInstance().AddCamera(new CameraJai(cam.ModelName, cam)); } } #else //添加相机并绑定到窗口 //VisionMgr.GetInstance().AddCamera(new CameraGige(CameraName.MainCamera)); //VisionMgr.GetInstance().AddCamera(new CameraGige(CameraName.SideCamera)); VisionMgr.GetInstance().AddCamera(new CameraMVision(CameraName.MainCamera)); VisionMgr.GetInstance().AddCamera(new CameraMVision(CameraName.SideCamera)); #endif //添加视觉步骤 VisionMgr.GetInstance().AddVisionStep(CameraName.MainCamera, new ProcessMainPos(VisionStepName.MainPos)); VisionMgr.GetInstance().AddVisionStep(CameraName.MainCamera, new ProcessMainMea(VisionStepName.MainMea)); VisionMgr.GetInstance().AddVisionStep(CameraName.SideCamera, new ProcessSideMea(VisionStepName.SideMea)); //加载系统参数 LoadParam(); //切换产品 ProductMgr.GetInstance().ProductChangedMethod += ChangeProduct; ProductMgr.GetInstance().ChangeProduct(Param.ProductName); //关联页面和按钮 m_dicForm.Add(btnMainCamera, new MainCameraForm()); //m_dicForm.Add(RoundButton_Login, new LoginForm()); m_dicForm.Add(RoundButton_Communication, new CommunicationForm()); m_dicForm.Add(btnSideCamera, new SideCameraForm()); m_dicForm.Add(btnSystemConfig, new SystemConfigForm()); //初始化页面属性 foreach (KeyValuePair <RoundButton, Form> kp in m_dicForm) { kp.Value.TopLevel = false; kp.Value.Parent = this.panel_main; kp.Value.Dock = DockStyle.Fill; } btnMainCamera.PerformClick(); //切换用户 //((LoginForm)m_dicForm[RoundButton_Login]).UserChangingMethod = ChangeUser; //ChangeUser(UserMode.Operator, Param.OperatorPassword); //设置日志显示 Log.Show = ((MainCameraForm)m_dicForm[btnMainCamera]).ShowLog; Data.Show = ((MainCameraForm)m_dicForm[btnMainCamera]).ShowData; //连接服务器 ((SystemConfigForm)m_dicForm[btnSystemConfig]).SetServerMethod = SetServer; ConnectServer(); }