From 8ba233a930a7ea3b1af8d6a0768e49eb5bf1987a Mon Sep 17 00:00:00 2001 From: lhiven Date: Tue, 2 Jan 2024 19:05:53 +0900 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9C=80=E5=90=8E=E4=B8=80?= =?UTF-8?q?=E7=9B=98=E6=96=99=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Rs.SkyLine/Flow/Camera/VisionManager.cs | 3 +- Rs.SkyLine/Flow/NormalFlow/DischargeFlow.cs | 83 +++++++++-------- .../Recipe/StockTrayHaveOrNot.Designer.cs | 91 +++++++++++-------- Rs.SkyLine/Recipe/StockTrayHaveOrNot.cs | 37 ++++++++ .../Recipe/TurnoverTrayHaveOrNot.Designer.cs | 77 ++++++++-------- Rs.SkyLine/Recipe/TurnoverTrayHaveOrNot.cs | 53 ++++++++--- 6 files changed, 214 insertions(+), 130 deletions(-) diff --git a/Rs.SkyLine/Flow/Camera/VisionManager.cs b/Rs.SkyLine/Flow/Camera/VisionManager.cs index fc8d303..b424ee8 100644 --- a/Rs.SkyLine/Flow/Camera/VisionManager.cs +++ b/Rs.SkyLine/Flow/Camera/VisionManager.cs @@ -133,7 +133,8 @@ namespace Rs.MotionPlat.Flow.Camera ImageProcess.ClearManualTrigger(); HikCamera.Instance.SetTrigger(cameraName, ETriggerMode.Manual); - HikCamera.Instance.SetGain(cameraName, 5); + HikCamera.Instance.SetExposure(cameraName, GlobalVar.UpCameraExposureTime); + HikCamera.Instance.SetGain(cameraName, GlobalVar.UpCameraGain); AxisControl.LoadX.ComparePulse(2, false); //LightName = SysConfigParam.GetValue(cameraName + "LightName"); //if (!string.IsNullOrEmpty(LightName)) diff --git a/Rs.SkyLine/Flow/NormalFlow/DischargeFlow.cs b/Rs.SkyLine/Flow/NormalFlow/DischargeFlow.cs index 14f5377..383b22c 100644 --- a/Rs.SkyLine/Flow/NormalFlow/DischargeFlow.cs +++ b/Rs.SkyLine/Flow/NormalFlow/DischargeFlow.cs @@ -130,10 +130,6 @@ namespace Rs.MotionPlat.Flow /// private int undoTaskNum = 0; int scanNum = 0; - /// - /// 料仓是否可以上料 - /// - private bool stockCanLoadFlag = true; public override void Run() { @@ -212,54 +208,63 @@ namespace Rs.MotionPlat.Flow } else { - if(stockCanLoadFlag) + //上料完成后判断是否时最后一盘料 + //while (true) { - logInfo = GetClassName() + $"{curTask.FromType.ToString()}盘无料,准备切换料盘"; - MessageQueue.Instance.Insert(logInfo); - TakeTrayFlow.Instance.Take(ETrayType.Input, ETrayType.Empty1, - () => + if (Ops.IsOff("2号料仓缺盘光电检测")) + { + logInfo = "Input料仓最后一盘料,请确认是否继续上料?"; + msgBox = MsgBox.ShowDialog(111, logInfo, (ETipButton.Yes | ETipButton.No),new Dictionary() { { ETipButton.Yes, "是|Yes" },{ETipButton.No, "结束上料|EndInput" } }); + if (msgBox.Button == ETipButton.Yes) { - Task.Run(() => - { - StockManager.Instance.GetStock(ETrayType.Input).Load(EStockTrayLoadMode.Whole, null); - }); - }, null, - () => + flowStep = EDischargeFlowStep.到取料位上方; + } + else { - Task.Run(() => + //结束上料 + TestCenter.Instance.EndInput(); + LoadAndUnloadTask.Instance.ClearUndoTask(); + if (NozzleManager.GetNozzlesByStatus(ENozzleStatus.ToUnload).Count > 0) { - StockManager.Instance.GetStock(ETrayType.Empty1).Unload(EStockTrayUnLoadMode.Whole, null); - }); - }); - StockManager.Instance.GetStock(ETrayType.Input).WaitFinished(); - //上料完成后判断是否时最后一盘料 - Task.Run(() => { - while (true) - { - if (Ops.IsOn("")) + flowStep = EDischargeFlowStep.到下相机拍照起始位; + } + else { - stockCanLoadFlag = false; - logInfo = "Input料仓最后一盘料,请确认是否继续上料?"; - msgBox = MsgBox.ShowDialog(111, logInfo, ETipButton.Yes | ETipButton.No); - if (msgBox.Button == ETipButton.Yes) + if (LoadAndUnloadTask.Instance.GetUnDealedTask().Count > 0) { - //继续上料,这时需要继续检测料仓是否有料 + StockTrayToTurnoverTray = !StockTrayToTurnoverTray; + flowStep = EDischargeFlowStep.到取料位上方; } else { - //点击了最后一盘料 - break; + flowStep = EDischargeFlowStep.任务结束到安全位; } } - else - { - stockCanLoadFlag = true; - break; - } + break; } - }); + } + else + { + logInfo = GetClassName() + $"{curTask.FromType.ToString()}盘无料,准备切换料盘"; + MessageQueue.Instance.Insert(logInfo); + TakeTrayFlow.Instance.Take(ETrayType.Input, ETrayType.Empty1, + () => + { + Task.Run(() => + { + StockManager.Instance.GetStock(ETrayType.Input).Load(EStockTrayLoadMode.Whole, null); + }); + }, null, + () => + { + Task.Run(() => + { + StockManager.Instance.GetStock(ETrayType.Empty1).Unload(EStockTrayUnLoadMode.Whole, null); + }); + }); + StockManager.Instance.GetStock(ETrayType.Input).WaitFinished(); + } } - break; } } diff --git a/Rs.SkyLine/Recipe/StockTrayHaveOrNot.Designer.cs b/Rs.SkyLine/Recipe/StockTrayHaveOrNot.Designer.cs index 78308ce..e24ccf3 100644 --- a/Rs.SkyLine/Recipe/StockTrayHaveOrNot.Designer.cs +++ b/Rs.SkyLine/Recipe/StockTrayHaveOrNot.Designer.cs @@ -29,17 +29,17 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle10 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle8 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle9 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); this.panelEx1 = new Rs.Controls.PanelEx(); this.panel4 = new System.Windows.Forms.Panel(); this.groupBox4 = new System.Windows.Forms.GroupBox(); this.btnCheck = new System.Windows.Forms.Button(); this.txtStockTrayHaveOrNotGrayMax = new System.Windows.Forms.TextBox(); - this.button1 = new System.Windows.Forms.Button(); + this.btnGrab = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.btnDrawRegion = new System.Windows.Forms.Button(); this.btnSaveRegion = new System.Windows.Forms.Button(); @@ -101,6 +101,7 @@ this.takeProductToolStripMenuItem8 = new System.Windows.Forms.ToolStripMenuItem(); this.dumpProductToolStripMenuItem8 = new System.Windows.Forms.ToolStripMenuItem(); this.moveToolStripMenuItem8 = new System.Windows.Forms.ToolStripMenuItem(); + this.lblProductCheckResult = new System.Windows.Forms.Label(); this.panelEx1.SuspendLayout(); this.panel4.SuspendLayout(); this.groupBox4.SuspendLayout(); @@ -135,9 +136,10 @@ // // groupBox4 // + this.groupBox4.Controls.Add(this.lblProductCheckResult); this.groupBox4.Controls.Add(this.btnCheck); this.groupBox4.Controls.Add(this.txtStockTrayHaveOrNotGrayMax); - this.groupBox4.Controls.Add(this.button1); + this.groupBox4.Controls.Add(this.btnGrab); this.groupBox4.Controls.Add(this.label1); this.groupBox4.Controls.Add(this.btnDrawRegion); this.groupBox4.Controls.Add(this.btnSaveRegion); @@ -185,19 +187,19 @@ this.txtStockTrayHaveOrNotGrayMax.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; this.txtStockTrayHaveOrNotGrayMax.KeyUp += new System.Windows.Forms.KeyEventHandler(this.txtSysParam_KeyUp); // - // button1 + // btnGrab // - this.button1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(56)))), ((int)(((byte)(56)))), ((int)(((byte)(56))))); - this.button1.FlatAppearance.BorderColor = System.Drawing.Color.White; - this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.button1.ForeColor = System.Drawing.Color.White; - this.button1.Location = new System.Drawing.Point(22, 53); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(103, 36); - this.button1.TabIndex = 8; - this.button1.Text = "相机取图"; - this.button1.UseVisualStyleBackColor = false; - this.button1.Click += new System.EventHandler(this.btnCheck_Click); + this.btnGrab.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(56)))), ((int)(((byte)(56)))), ((int)(((byte)(56))))); + this.btnGrab.FlatAppearance.BorderColor = System.Drawing.Color.White; + this.btnGrab.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.btnGrab.ForeColor = System.Drawing.Color.White; + this.btnGrab.Location = new System.Drawing.Point(22, 53); + this.btnGrab.Name = "btnGrab"; + this.btnGrab.Size = new System.Drawing.Size(103, 36); + this.btnGrab.TabIndex = 8; + this.btnGrab.Text = "相机取图"; + this.btnGrab.UseVisualStyleBackColor = false; + this.btnGrab.Click += new System.EventHandler(this.btnGrab_Click); // // label1 // @@ -381,9 +383,9 @@ this.dgvBasePoints.AllowUserToDeleteRows = false; this.dgvBasePoints.AllowUserToResizeColumns = false; this.dgvBasePoints.AllowUserToResizeRows = false; - dataGridViewCellStyle6.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(56)))), ((int)(((byte)(56)))), ((int)(((byte)(56))))); - dataGridViewCellStyle6.ForeColor = System.Drawing.Color.White; - this.dgvBasePoints.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle6; + dataGridViewCellStyle1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(56)))), ((int)(((byte)(56)))), ((int)(((byte)(56))))); + dataGridViewCellStyle1.ForeColor = System.Drawing.Color.White; + this.dgvBasePoints.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1; this.dgvBasePoints.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; this.dgvBasePoints.BackgroundColor = System.Drawing.Color.FromArgb(((int)(((byte)(11)))), ((int)(((byte)(16)))), ((int)(((byte)(36))))); this.dgvBasePoints.ColumnHeadersHeight = 30; @@ -399,14 +401,14 @@ this.dgvBasePoints.MultiSelect = false; this.dgvBasePoints.Name = "dgvBasePoints"; this.dgvBasePoints.ReadOnly = true; - dataGridViewCellStyle10.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; - dataGridViewCellStyle10.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(11)))), ((int)(((byte)(16)))), ((int)(((byte)(36))))); - dataGridViewCellStyle10.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - dataGridViewCellStyle10.ForeColor = System.Drawing.Color.White; - dataGridViewCellStyle10.SelectionBackColor = System.Drawing.Color.White; - dataGridViewCellStyle10.SelectionForeColor = System.Drawing.Color.White; - dataGridViewCellStyle10.WrapMode = System.Windows.Forms.DataGridViewTriState.True; - this.dgvBasePoints.RowHeadersDefaultCellStyle = dataGridViewCellStyle10; + dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; + dataGridViewCellStyle5.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(11)))), ((int)(((byte)(16)))), ((int)(((byte)(36))))); + dataGridViewCellStyle5.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + dataGridViewCellStyle5.ForeColor = System.Drawing.Color.White; + dataGridViewCellStyle5.SelectionBackColor = System.Drawing.Color.White; + dataGridViewCellStyle5.SelectionForeColor = System.Drawing.Color.White; + dataGridViewCellStyle5.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.dgvBasePoints.RowHeadersDefaultCellStyle = dataGridViewCellStyle5; this.dgvBasePoints.RowHeadersVisible = false; this.dgvBasePoints.RowHeadersWidth = 30; this.dgvBasePoints.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing; @@ -428,8 +430,8 @@ // X // this.X.DataPropertyName = "X"; - dataGridViewCellStyle7.Format = "0.000"; - this.X.DefaultCellStyle = dataGridViewCellStyle7; + dataGridViewCellStyle2.Format = "0.000"; + this.X.DefaultCellStyle = dataGridViewCellStyle2; this.X.FillWeight = 35F; this.X.HeaderText = "X"; this.X.Name = "X"; @@ -438,8 +440,8 @@ // Y // this.Y.DataPropertyName = "Y"; - dataGridViewCellStyle8.Format = "0.000"; - this.Y.DefaultCellStyle = dataGridViewCellStyle8; + dataGridViewCellStyle3.Format = "0.000"; + this.Y.DefaultCellStyle = dataGridViewCellStyle3; this.Y.FillWeight = 35F; this.Y.HeaderText = "Y"; this.Y.Name = "Y"; @@ -448,10 +450,10 @@ // Move // this.Move.ActiveLinkColor = System.Drawing.Color.White; - dataGridViewCellStyle9.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; - dataGridViewCellStyle9.BackColor = System.Drawing.Color.Silver; - dataGridViewCellStyle9.ForeColor = System.Drawing.Color.White; - this.Move.DefaultCellStyle = dataGridViewCellStyle9; + dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; + dataGridViewCellStyle4.BackColor = System.Drawing.Color.Silver; + dataGridViewCellStyle4.ForeColor = System.Drawing.Color.White; + this.Move.DefaultCellStyle = dataGridViewCellStyle4; this.Move.FillWeight = 20F; this.Move.HeaderText = "Move"; this.Move.LinkBehavior = System.Windows.Forms.LinkBehavior.NeverUnderline; @@ -787,6 +789,16 @@ this.moveToolStripMenuItem8.Size = new System.Drawing.Size(156, 22); this.moveToolStripMenuItem8.Text = "Move"; // + // lblProductCheckResult + // + this.lblProductCheckResult.BackColor = System.Drawing.Color.Red; + this.lblProductCheckResult.Location = new System.Drawing.Point(134, 366); + this.lblProductCheckResult.Name = "lblProductCheckResult"; + this.lblProductCheckResult.Size = new System.Drawing.Size(129, 44); + this.lblProductCheckResult.TabIndex = 52; + this.lblProductCheckResult.Text = "无"; + this.lblProductCheckResult.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // // StockTrayHaveOrNot // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); @@ -863,7 +875,7 @@ private System.Windows.Forms.ToolStripMenuItem dumpProductToolStripMenuItem8; private System.Windows.Forms.ToolStripMenuItem moveToolStripMenuItem8; private System.Windows.Forms.Panel panel4; - private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button btnGrab; private System.Windows.Forms.Panel panel3; private System.Windows.Forms.TextBox txtStockTrayHaveOrNotGrayMax; private System.Windows.Forms.Label label1; @@ -882,5 +894,6 @@ private System.Windows.Forms.DataGridViewTextBoxColumn X; private System.Windows.Forms.DataGridViewTextBoxColumn Y; private System.Windows.Forms.DataGridViewLinkColumn Move; + private System.Windows.Forms.Label lblProductCheckResult; } } \ No newline at end of file diff --git a/Rs.SkyLine/Recipe/StockTrayHaveOrNot.cs b/Rs.SkyLine/Recipe/StockTrayHaveOrNot.cs index 8f56f66..768d4c4 100644 --- a/Rs.SkyLine/Recipe/StockTrayHaveOrNot.cs +++ b/Rs.SkyLine/Recipe/StockTrayHaveOrNot.cs @@ -1,5 +1,7 @@ using HalconDotNet; +using NPOI.SS.Formula.PTG; using NPOI.SS.UserModel; +using Rs.Camera; using Rs.Controls; using Rs.DataAccess; using Rs.Framework; @@ -136,13 +138,27 @@ namespace Rs.MotionPlat.Recipe { hWindow_Final1.ClearWindow(); hWindow_Final1.HobjectToHimage(showImage); + hWindow_Final1.DispObj(searchRegion); HOperatorSet.ReduceDomain(showImage, searchRegion, out HObject imageReduced); HOperatorSet.Threshold(imageReduced,out HObject resultRegion,GlobalVar.StockTrayHaveOrNotGrayMin,GlobalVar.StockTrayHaveOrNotGrayMax); HOperatorSet.AreaCenter(resultRegion,out HTuple area,out HTuple row,out HTuple col); HOperatorSet.SetDraw(winHandle, "fill"); hWindow_Final1.DispObj(resultRegion, "red"); lblCheckResult.Text = area.D.ToString("0.00"); + + if (area.D > GlobalVar.TurnoverTrayHaveOrNotGrayArea) + { + lblProductCheckResult.BackColor = Color.Green; + lblProductCheckResult.Text = "有产品"; + } + else + { + lblProductCheckResult.BackColor = Color.Red; + lblProductCheckResult.Text = "无产品"; + } } + + //Task.Run(() => //{ // Invoke(new Action(() => { @@ -206,5 +222,26 @@ namespace Rs.MotionPlat.Recipe Msg.ShowInfo("please select region"); } } + + private void btnGrab_Click(object sender, EventArgs e) + { + string cameraName = "upCamera"; + ImageProcess.ClearManualTrigger(); + HikCamera.Instance.SetTrigger(cameraName, ETriggerMode.Manual); + HikCamera.Instance.SetExposure(cameraName, GlobalVar.UpCameraExposureTime); + HikCamera.Instance.SetGain(cameraName, GlobalVar.UpCameraGain); + AxisControl.LoadX.ComparePulse(2, false); + + bool cameraOk = ImageProcess.manualTriggerEvent.WaitOne(3000); + if (cameraOk) + { + HObject image = ImageProcess.GetManualImage(); + if (cameraName == SysConfigParam.GetValue("UpCameraName")) + { + HOperatorSet.RotateImage(image, out showImage, SysConfigParam.GetValue("UpCameraRotate"), "constant"); + } + hWindow_Final1.HobjectToHimage(showImage); + } + } } } diff --git a/Rs.SkyLine/Recipe/TurnoverTrayHaveOrNot.Designer.cs b/Rs.SkyLine/Recipe/TurnoverTrayHaveOrNot.Designer.cs index d7e8f8e..16f6d36 100644 --- a/Rs.SkyLine/Recipe/TurnoverTrayHaveOrNot.Designer.cs +++ b/Rs.SkyLine/Recipe/TurnoverTrayHaveOrNot.Designer.cs @@ -29,11 +29,11 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle10 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle8 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle9 = new System.Windows.Forms.DataGridViewCellStyle(); this.panelEx1 = new Rs.Controls.PanelEx(); this.panelEx2 = new Rs.Controls.PanelEx(); this.panel4 = new System.Windows.Forms.Panel(); @@ -41,7 +41,7 @@ this.lblProductCheckResult = new System.Windows.Forms.Label(); this.btnCheck = new System.Windows.Forms.Button(); this.txtTurnoverTrayHaveOrNotGrayMax = new System.Windows.Forms.TextBox(); - this.button1 = new System.Windows.Forms.Button(); + this.btnGrab = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.btnDrawRegion = new System.Windows.Forms.Button(); this.btnSaveRegion = new System.Windows.Forms.Button(); @@ -114,7 +114,7 @@ this.groupBox4.Controls.Add(this.lblProductCheckResult); this.groupBox4.Controls.Add(this.btnCheck); this.groupBox4.Controls.Add(this.txtTurnoverTrayHaveOrNotGrayMax); - this.groupBox4.Controls.Add(this.button1); + this.groupBox4.Controls.Add(this.btnGrab); this.groupBox4.Controls.Add(this.label1); this.groupBox4.Controls.Add(this.btnDrawRegion); this.groupBox4.Controls.Add(this.btnSaveRegion); @@ -172,18 +172,19 @@ this.txtTurnoverTrayHaveOrNotGrayMax.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; this.txtTurnoverTrayHaveOrNotGrayMax.KeyUp += new System.Windows.Forms.KeyEventHandler(this.txtSysParam_KeyUp); // - // button1 + // btnGrab // - this.button1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(56)))), ((int)(((byte)(56)))), ((int)(((byte)(56))))); - this.button1.FlatAppearance.BorderColor = System.Drawing.Color.White; - this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.button1.ForeColor = System.Drawing.Color.White; - this.button1.Location = new System.Drawing.Point(22, 53); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(103, 36); - this.button1.TabIndex = 8; - this.button1.Text = "相机取图"; - this.button1.UseVisualStyleBackColor = false; + this.btnGrab.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(56)))), ((int)(((byte)(56)))), ((int)(((byte)(56))))); + this.btnGrab.FlatAppearance.BorderColor = System.Drawing.Color.White; + this.btnGrab.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.btnGrab.ForeColor = System.Drawing.Color.White; + this.btnGrab.Location = new System.Drawing.Point(22, 53); + this.btnGrab.Name = "btnGrab"; + this.btnGrab.Size = new System.Drawing.Size(103, 36); + this.btnGrab.TabIndex = 8; + this.btnGrab.Text = "相机取图"; + this.btnGrab.UseVisualStyleBackColor = false; + this.btnGrab.Click += new System.EventHandler(this.btnGrab_Click); // // label1 // @@ -367,9 +368,9 @@ this.dgvBasePoints.AllowUserToDeleteRows = false; this.dgvBasePoints.AllowUserToResizeColumns = false; this.dgvBasePoints.AllowUserToResizeRows = false; - dataGridViewCellStyle1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(56)))), ((int)(((byte)(56)))), ((int)(((byte)(56))))); - dataGridViewCellStyle1.ForeColor = System.Drawing.Color.White; - this.dgvBasePoints.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1; + dataGridViewCellStyle6.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(56)))), ((int)(((byte)(56)))), ((int)(((byte)(56))))); + dataGridViewCellStyle6.ForeColor = System.Drawing.Color.White; + this.dgvBasePoints.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle6; this.dgvBasePoints.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; this.dgvBasePoints.BackgroundColor = System.Drawing.Color.FromArgb(((int)(((byte)(11)))), ((int)(((byte)(16)))), ((int)(((byte)(36))))); this.dgvBasePoints.ColumnHeadersHeight = 30; @@ -385,14 +386,14 @@ this.dgvBasePoints.MultiSelect = false; this.dgvBasePoints.Name = "dgvBasePoints"; this.dgvBasePoints.ReadOnly = true; - dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; - dataGridViewCellStyle5.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(11)))), ((int)(((byte)(16)))), ((int)(((byte)(36))))); - dataGridViewCellStyle5.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - dataGridViewCellStyle5.ForeColor = System.Drawing.Color.White; - dataGridViewCellStyle5.SelectionBackColor = System.Drawing.Color.White; - dataGridViewCellStyle5.SelectionForeColor = System.Drawing.Color.White; - dataGridViewCellStyle5.WrapMode = System.Windows.Forms.DataGridViewTriState.True; - this.dgvBasePoints.RowHeadersDefaultCellStyle = dataGridViewCellStyle5; + dataGridViewCellStyle10.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; + dataGridViewCellStyle10.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(11)))), ((int)(((byte)(16)))), ((int)(((byte)(36))))); + dataGridViewCellStyle10.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + dataGridViewCellStyle10.ForeColor = System.Drawing.Color.White; + dataGridViewCellStyle10.SelectionBackColor = System.Drawing.Color.White; + dataGridViewCellStyle10.SelectionForeColor = System.Drawing.Color.White; + dataGridViewCellStyle10.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.dgvBasePoints.RowHeadersDefaultCellStyle = dataGridViewCellStyle10; this.dgvBasePoints.RowHeadersVisible = false; this.dgvBasePoints.RowHeadersWidth = 30; this.dgvBasePoints.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing; @@ -414,8 +415,8 @@ // X // this.X.DataPropertyName = "X"; - dataGridViewCellStyle2.Format = "0.000"; - this.X.DefaultCellStyle = dataGridViewCellStyle2; + dataGridViewCellStyle7.Format = "0.000"; + this.X.DefaultCellStyle = dataGridViewCellStyle7; this.X.FillWeight = 35F; this.X.HeaderText = "X"; this.X.Name = "X"; @@ -424,8 +425,8 @@ // Y // this.Y.DataPropertyName = "Y"; - dataGridViewCellStyle3.Format = "0.000"; - this.Y.DefaultCellStyle = dataGridViewCellStyle3; + dataGridViewCellStyle8.Format = "0.000"; + this.Y.DefaultCellStyle = dataGridViewCellStyle8; this.Y.FillWeight = 35F; this.Y.HeaderText = "Y"; this.Y.Name = "Y"; @@ -434,10 +435,10 @@ // Move // this.Move.ActiveLinkColor = System.Drawing.Color.White; - dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; - dataGridViewCellStyle4.BackColor = System.Drawing.Color.Silver; - dataGridViewCellStyle4.ForeColor = System.Drawing.Color.White; - this.Move.DefaultCellStyle = dataGridViewCellStyle4; + dataGridViewCellStyle9.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; + dataGridViewCellStyle9.BackColor = System.Drawing.Color.Silver; + dataGridViewCellStyle9.ForeColor = System.Drawing.Color.White; + this.Move.DefaultCellStyle = dataGridViewCellStyle9; this.Move.FillWeight = 20F; this.Move.HeaderText = "Move"; this.Move.LinkBehavior = System.Windows.Forms.LinkBehavior.NeverUnderline; @@ -558,7 +559,7 @@ private System.Windows.Forms.GroupBox groupBox4; private System.Windows.Forms.Button btnCheck; private System.Windows.Forms.TextBox txtTurnoverTrayHaveOrNotGrayMax; - private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button btnGrab; private System.Windows.Forms.Label label1; private System.Windows.Forms.Button btnDrawRegion; private System.Windows.Forms.Button btnSaveRegion; diff --git a/Rs.SkyLine/Recipe/TurnoverTrayHaveOrNot.cs b/Rs.SkyLine/Recipe/TurnoverTrayHaveOrNot.cs index a62535a..a2abfc6 100644 --- a/Rs.SkyLine/Recipe/TurnoverTrayHaveOrNot.cs +++ b/Rs.SkyLine/Recipe/TurnoverTrayHaveOrNot.cs @@ -1,4 +1,6 @@ -using HalconDotNet; +using ChoiceTech.Halcon.Control; +using HalconDotNet; +using Rs.Camera; using Rs.Controls; using Rs.DataAccess; using Rs.Framework; @@ -51,20 +53,20 @@ namespace Rs.MotionPlat.Recipe BindPoints(); PositionHelper.BindPosition(groupBox4, "int"); string filePath = Path.Combine(dirPth, "default.bmp"); - HOperatorSet.ReadImage(out showImage, filePath); - hWindow_Final1.HobjectToHimage(showImage); - if (File.Exists(Path.Combine(dirPth, "搜索区域.reg"))) + if(File.Exists(filePath)) { - //把区域都出来 - HOperatorSet.ReadRegion(out searchRegion, Path.Combine(dirPth, "搜索区域.reg")); - //show region - HOperatorSet.SetDraw(winHandle, "margin"); - HOperatorSet.SetColor(winHandle, "green"); - hWindow_Final1.DispObj(searchRegion, "green"); + HOperatorSet.ReadImage(out showImage, filePath); + hWindow_Final1.HobjectToHimage(showImage); + if (File.Exists(Path.Combine(dirPth, "搜索区域.reg"))) + { + //把区域都出来 + HOperatorSet.ReadRegion(out searchRegion, Path.Combine(dirPth, "搜索区域.reg")); + //show region + HOperatorSet.SetDraw(winHandle, "margin"); + HOperatorSet.SetColor(winHandle, "green"); + hWindow_Final1.DispObj(searchRegion, "green"); + } } - - - } private void rsTray1_SlotClickEvent(TraySlot arg1, MouseEventArgs arg2) @@ -140,6 +142,10 @@ namespace Rs.MotionPlat.Recipe if (searchRegion != null && searchRegion.IsInitialized()) { + if(!Directory.Exists(dirPth)) + { + Directory.CreateDirectory(dirPth); + } HOperatorSet.WriteImage(showImage, "bmp", 0, Path.Combine(dirPth, "default.bmp")); HOperatorSet.WriteRegion(searchRegion, Path.Combine(dirPth, "搜索区域.reg")); Msg.ShowInfo("save success!!!"); @@ -175,5 +181,26 @@ namespace Rs.MotionPlat.Recipe } } } + + private void btnGrab_Click(object sender, EventArgs e) + { + string cameraName = "upCamera"; + ImageProcess.ClearManualTrigger(); + HikCamera.Instance.SetTrigger(cameraName, ETriggerMode.Manual); + HikCamera.Instance.SetExposure(cameraName, GlobalVar.UpCameraExposureTime); + HikCamera.Instance.SetGain(cameraName, GlobalVar.UpCameraGain); + AxisControl.LoadX.ComparePulse(2, false); + + bool cameraOk = ImageProcess.manualTriggerEvent.WaitOne(3000); + if (cameraOk) + { + HObject image = ImageProcess.GetManualImage(); + if (cameraName == SysConfigParam.GetValue("UpCameraName")) + { + HOperatorSet.RotateImage(image, out showImage, SysConfigParam.GetValue("UpCameraRotate"), "constant"); + } + hWindow_Final1.HobjectToHimage(showImage); + } + } } }