| LB_SmartVision/Forms/Pages/CommunicatorPage/CommunicatorForm.Designer.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| LB_SmartVision/Forms/Pages/CommunicatorPage/CommunicatorForm.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| LB_VisionProcesses/Cameras/HRCameras/HRCamera.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| LB_VisionProcesses/Cameras/LBCameras/LBCamera.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| LB_VisionProcesses/MotionControl/BaseMotionControl.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| LB_VisionProcesses/MotionControl/IMotionControl.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| LB_VisionProcesses/MotionControl/MotionControlConfig.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
LB_SmartVision/Forms/Pages/CommunicatorPage/CommunicatorForm.Designer.cs
@@ -36,10 +36,12 @@ txtSendMsg = new TextBox(); grpSetting = new GroupBox(); txtAddress = new TextBox(); cmbVarType = new ComboBox(); cmbType = new ComboBox(); txtIP = new TextBox(); txtPort = new TextBox(); lblPort = new Label(); lbVarType = new Label(); cmbIP = new ComboBox(); lblType = new Label(); lblAddress = new Label(); @@ -63,9 +65,10 @@ label3.AutoSize = true; label3.Dock = DockStyle.Fill; label3.ForeColor = Color.CornflowerBlue; label3.Location = new Point(3, 100); label3.Location = new Point(4, 125); label3.Margin = new Padding(4, 0, 4, 0); label3.Name = "label3"; label3.Size = new Size(655, 20); label3.Size = new Size(819, 25); label3.TabIndex = 18; label3.Text = "åéä¿¡æ¯"; label3.TextAlign = ContentAlignment.BottomLeft; @@ -81,14 +84,15 @@ tableLayoutPanel1.Controls.Add(label3, 0, 1); tableLayoutPanel1.Dock = DockStyle.Fill; tableLayoutPanel1.Location = new Point(0, 0); tableLayoutPanel1.Margin = new Padding(4); tableLayoutPanel1.Name = "tableLayoutPanel1"; tableLayoutPanel1.RowCount = 5; tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 100F)); tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 20F)); tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 30F)); tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 40F)); tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 125F)); tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 25F)); tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 38F)); tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 50F)); tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); tableLayoutPanel1.Size = new Size(661, 322); tableLayoutPanel1.Size = new Size(827, 402); tableLayoutPanel1.TabIndex = 26; // // grpReceive @@ -96,9 +100,11 @@ grpReceive.Controls.Add(txtReceiveMsg); grpReceive.Dock = DockStyle.Fill; grpReceive.ForeColor = Color.CornflowerBlue; grpReceive.Location = new Point(3, 193); grpReceive.Location = new Point(4, 242); grpReceive.Margin = new Padding(4); grpReceive.Name = "grpReceive"; grpReceive.Size = new Size(655, 126); grpReceive.Padding = new Padding(4); grpReceive.Size = new Size(819, 156); grpReceive.TabIndex = 30; grpReceive.TabStop = false; grpReceive.Text = "é讯记å½"; @@ -106,142 +112,180 @@ // txtReceiveMsg // txtReceiveMsg.Dock = DockStyle.Fill; txtReceiveMsg.Location = new Point(3, 17); txtReceiveMsg.Location = new Point(4, 21); txtReceiveMsg.Margin = new Padding(4); txtReceiveMsg.Multiline = true; txtReceiveMsg.Name = "txtReceiveMsg"; txtReceiveMsg.ReadOnly = true; txtReceiveMsg.ScrollBars = ScrollBars.Both; txtReceiveMsg.Size = new Size(649, 106); txtReceiveMsg.Size = new Size(811, 131); txtReceiveMsg.TabIndex = 0; // // txtSendMsg // txtSendMsg.Dock = DockStyle.Fill; txtSendMsg.Location = new Point(3, 123); txtSendMsg.Location = new Point(4, 154); txtSendMsg.Margin = new Padding(4); txtSendMsg.Name = "txtSendMsg"; txtSendMsg.Size = new Size(655, 21); txtSendMsg.Size = new Size(819, 24); txtSendMsg.TabIndex = 29; // // grpSetting // grpSetting.BackColor = Color.FromArgb(32, 41, 50); grpSetting.Controls.Add(txtAddress); grpSetting.Controls.Add(cmbVarType); grpSetting.Controls.Add(cmbType); grpSetting.Controls.Add(txtIP); grpSetting.Controls.Add(txtPort); grpSetting.Controls.Add(lblPort); grpSetting.Controls.Add(lbVarType); grpSetting.Controls.Add(cmbIP); grpSetting.Controls.Add(lblType); grpSetting.Controls.Add(lblAddress); grpSetting.Controls.Add(lblIP); grpSetting.Dock = DockStyle.Fill; grpSetting.ForeColor = Color.CornflowerBlue; grpSetting.Location = new Point(3, 3); grpSetting.MinimumSize = new Size(261, 61); grpSetting.Location = new Point(4, 4); grpSetting.Margin = new Padding(4); grpSetting.MinimumSize = new Size(326, 76); grpSetting.Name = "grpSetting"; grpSetting.Size = new Size(655, 94); grpSetting.Padding = new Padding(4); grpSetting.Size = new Size(819, 117); grpSetting.TabIndex = 28; grpSetting.TabStop = false; grpSetting.Text = "é讯é ç½®"; // // txtAddress // txtAddress.Location = new Point(251, 60); txtAddress.Location = new Point(314, 75); txtAddress.Margin = new Padding(4); txtAddress.Name = "txtAddress"; txtAddress.Size = new Size(100, 21); txtAddress.Size = new Size(124, 24); txtAddress.TabIndex = 9; txtAddress.TextChanged += txtAddress_TextChanged; // // cmbVarType // cmbVarType.DropDownStyle = ComboBoxStyle.DropDownList; cmbVarType.FormattingEnabled = true; cmbVarType.Location = new Point(533, 32); cmbVarType.Margin = new Padding(4); cmbVarType.Name = "cmbVarType"; cmbVarType.Size = new Size(124, 26); cmbVarType.TabIndex = 8; cmbVarType.SelectedIndexChanged += cmbVarType_SelectedIndexChanged; // // cmbType // cmbType.DropDownStyle = ComboBoxStyle.DropDownList; cmbType.FormattingEnabled = true; cmbType.Location = new Point(251, 23); cmbType.Location = new Point(314, 29); cmbType.Margin = new Padding(4); cmbType.Name = "cmbType"; cmbType.Size = new Size(100, 23); cmbType.Size = new Size(124, 26); cmbType.TabIndex = 8; // // txtIP // txtIP.Location = new Point(79, 22); txtIP.Location = new Point(99, 28); txtIP.Margin = new Padding(4); txtIP.Name = "txtIP"; txtIP.Size = new Size(100, 21); txtIP.Size = new Size(124, 24); txtIP.TabIndex = 7; // // txtPort // txtPort.Location = new Point(79, 60); txtPort.Location = new Point(99, 75); txtPort.Margin = new Padding(4); txtPort.Name = "txtPort"; txtPort.Size = new Size(100, 21); txtPort.Size = new Size(124, 24); txtPort.TabIndex = 6; // // lblPort // lblPort.AutoSize = true; lblPort.Location = new Point(13, 63); lblPort.Location = new Point(16, 79); lblPort.Margin = new Padding(4, 0, 4, 0); lblPort.Name = "lblPort"; lblPort.Size = new Size(31, 15); lblPort.Size = new Size(38, 18); lblPort.TabIndex = 4; lblPort.Text = "端å£"; // // lbVarType // lbVarType.AutoSize = true; lbVarType.Location = new Point(463, 35); lbVarType.Margin = new Padding(4, 0, 4, 0); lbVarType.Name = "lbVarType"; lbVarType.Size = new Size(68, 18); lbVarType.TabIndex = 0; lbVarType.Text = "åéç±»å"; // // cmbIP // cmbIP.FormattingEnabled = true; cmbIP.Location = new Point(79, 21); cmbIP.Location = new Point(99, 26); cmbIP.Margin = new Padding(4); cmbIP.Name = "cmbIP"; cmbIP.Size = new Size(100, 23); cmbIP.Size = new Size(124, 26); cmbIP.TabIndex = 1; // // lblType // lblType.AutoSize = true; lblType.Location = new Point(205, 26); lblType.Location = new Point(246, 32); lblType.Margin = new Padding(4, 0, 4, 0); lblType.Name = "lblType"; lblType.Size = new Size(31, 15); lblType.Size = new Size(38, 18); lblType.TabIndex = 0; lblType.Text = "åå·"; // // lblAddress // lblAddress.AutoSize = true; lblAddress.Location = new Point(205, 63); lblAddress.Location = new Point(242, 79); lblAddress.Margin = new Padding(4, 0, 4, 0); lblAddress.Name = "lblAddress"; lblAddress.Size = new Size(31, 15); lblAddress.Size = new Size(68, 18); lblAddress.TabIndex = 0; lblAddress.Text = "å°å"; lblAddress.Text = "åéå°å"; // // lblIP // lblIP.AutoSize = true; lblIP.Location = new Point(13, 26); lblIP.Location = new Point(16, 32); lblIP.Margin = new Padding(4, 0, 4, 0); lblIP.Name = "lblIP"; lblIP.Size = new Size(31, 15); lblIP.Size = new Size(38, 18); lblIP.TabIndex = 0; lblIP.Text = "å°å"; // // tableLayoutPanel2 // tableLayoutPanel2.ColumnCount = 3; tableLayoutPanel2.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 80F)); tableLayoutPanel2.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 80F)); tableLayoutPanel2.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 100F)); tableLayoutPanel2.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 100F)); tableLayoutPanel2.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); tableLayoutPanel2.Controls.Add(btnRuleSend, 1, 0); tableLayoutPanel2.Controls.Add(btnSend, 0, 0); tableLayoutPanel2.Dock = DockStyle.Fill; tableLayoutPanel2.Location = new Point(3, 153); tableLayoutPanel2.Location = new Point(4, 192); tableLayoutPanel2.Margin = new Padding(4); tableLayoutPanel2.Name = "tableLayoutPanel2"; tableLayoutPanel2.RowCount = 1; tableLayoutPanel2.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); tableLayoutPanel2.Size = new Size(655, 34); tableLayoutPanel2.Size = new Size(819, 42); tableLayoutPanel2.TabIndex = 27; // // btnRuleSend // btnRuleSend.Dock = DockStyle.Fill; btnRuleSend.ForeColor = Color.CornflowerBlue; btnRuleSend.Location = new Point(83, 3); btnRuleSend.Location = new Point(104, 4); btnRuleSend.Margin = new Padding(4); btnRuleSend.Name = "btnRuleSend"; btnRuleSend.Size = new Size(74, 28); btnRuleSend.Size = new Size(92, 34); btnRuleSend.TabIndex = 14; btnRuleSend.Text = "æ ¡éªåé"; btnRuleSend.UseVisualStyleBackColor = true; @@ -251,9 +295,10 @@ // btnSend.Dock = DockStyle.Fill; btnSend.ForeColor = Color.CornflowerBlue; btnSend.Location = new Point(3, 3); btnSend.Location = new Point(4, 4); btnSend.Margin = new Padding(4); btnSend.Name = "btnSend"; btnSend.Size = new Size(74, 28); btnSend.Size = new Size(92, 34); btnSend.TabIndex = 12; btnSend.Text = "åé"; btnSend.UseVisualStyleBackColor = true; @@ -268,11 +313,12 @@ themeForm_Communicator.Font = new Font("Microsoft Sans Serif", 9F); themeForm_Communicator.Image = (Image)resources.GetObject("themeForm_Communicator.Image"); themeForm_Communicator.Location = new Point(0, 0); themeForm_Communicator.Margin = new Padding(4); themeForm_Communicator.Name = "themeForm_Communicator"; themeForm_Communicator.Padding = new Padding(10, 70, 10, 9); themeForm_Communicator.Padding = new Padding(12, 88, 12, 11); themeForm_Communicator.RoundCorners = true; themeForm_Communicator.Sizable = true; themeForm_Communicator.Size = new Size(681, 401); themeForm_Communicator.Size = new Size(851, 501); themeForm_Communicator.SmartBounds = true; themeForm_Communicator.StartPosition = FormStartPosition.WindowsDefaultLocation; themeForm_Communicator.TabIndex = 27; @@ -288,7 +334,8 @@ controlBox1.EnableMaximizeButton = true; controlBox1.EnableMinimizeButton = true; controlBox1.ForeColor = Color.FromArgb(155, 155, 155); controlBox1.Location = new Point(581, 18); controlBox1.Location = new Point(726, 18); controlBox1.Margin = new Padding(4); controlBox1.MaximizeHoverColor = Color.FromArgb(74, 74, 74); controlBox1.MinimizeHoverColor = Color.FromArgb(63, 63, 65); controlBox1.Name = "controlBox1"; @@ -300,19 +347,21 @@ // panel_CommunicatorForm.Controls.Add(tableLayoutPanel1); panel_CommunicatorForm.Dock = DockStyle.Fill; panel_CommunicatorForm.Location = new Point(10, 70); panel_CommunicatorForm.Location = new Point(12, 88); panel_CommunicatorForm.Margin = new Padding(4); panel_CommunicatorForm.Name = "panel_CommunicatorForm"; panel_CommunicatorForm.Size = new Size(661, 322); panel_CommunicatorForm.Size = new Size(827, 402); panel_CommunicatorForm.TabIndex = 27; // // CommunicatorForm // AutoScaleDimensions = new SizeF(96F, 96F); AutoScaleDimensions = new SizeF(120F, 120F); AutoScaleMode = AutoScaleMode.Dpi; ClientSize = new Size(681, 401); ClientSize = new Size(851, 501); Controls.Add(themeForm_Communicator); FormBorderStyle = FormBorderStyle.None; MinimumSize = new Size(261, 61); Margin = new Padding(4); MinimumSize = new Size(326, 76); Name = "CommunicatorForm"; Text = "é讯设置"; TransparencyKey = Color.Fuchsia; @@ -351,5 +400,7 @@ private ComboBox cmbType; private Label lblAddress; private TextBox txtAddress; private ComboBox cmbVarType; private Label lbVarType; } } LB_SmartVision/Forms/Pages/CommunicatorPage/CommunicatorForm.cs
@@ -28,10 +28,14 @@ { InitializeComponent(); cmbType.Items.Clear(); if (communicator != null && !string.IsNullOrEmpty(communicator.CommunicatorConnections["åå·"]?.ToString())) { cmbType.Items.Add(communicator.CommunicatorConnections["åå·"]?.ToString()); } cmbVarType.Items.Clear(); if (!string.IsNullOrEmpty(communicator.CommunicatorConnections["åéç±»å"]?.ToString())) { cmbVarType.Items.Add(communicator.CommunicatorConnections["åéç±»å"]?.ToString()); } } @@ -39,42 +43,37 @@ { InitializeComponent(); if (communicator == null) { return; } cmbIP.Enabled = false; txtIP.Enabled = false; txtPort.Enabled = false; lblType.Visible = false; lblAddress.Visible = false; cmbType.Visible = false; txtAddress.Visible = false; lbVarType.Visible = false; cmbVarType.Visible = false; this.Text = name; if (communicator is UARTPort) { //ç»è®¡å¯ç¨ç«¯å£ SerialPortStream temp = new SerialPortStream(); string[] ArryPort = temp.GetPortNames(); for (int i = 0; i < ArryPort.Length; i++) { cmbIP.Items.Add(ArryPort[i]); } cmbIP.Text = communicator.CommunicatorConnections["å°å"]?.ToString(); txtPort.Text = communicator.CommunicatorConnections["端å£"]?.ToString(); txtIP.Visible = false; cmbIP.Visible = true; this.btnRuleSend.Visible = true; lblType.Visible = false; lblAddress.Visible = false; cmbType.Visible = false; txtAddress.Visible = false; lblIP.Text = "COMå£"; lblPort.Text = "æ³¢ç¹ç"; } @@ -84,15 +83,11 @@ txtPort.SelectedText = communicator.CommunicatorConnections["端å£"]?.ToString(); txtIP.Visible = true; cmbIP.Visible = false; this.btnRuleSend.Visible = false; lblType.Visible = false; lblAddress.Visible = false; cmbType.Visible = false; txtAddress.Visible = false; lblIP.Text = "å°å"; lblPort.Text = "端å£"; } @@ -101,7 +96,6 @@ txtIP.Text = communicator.CommunicatorConnections["å°å"]?.ToString(); txtPort.Text = communicator.CommunicatorConnections["端å£"]?.ToString(); cmbType.Items.Clear(); if (!string.IsNullOrEmpty(communicator.CommunicatorConnections["åå·"]?.ToString())) { cmbType.Items.Add(communicator.CommunicatorConnections["åå·"]?.ToString()); @@ -111,15 +105,20 @@ { txtAddress.Text = communicator.CommunicatorConnections["åéå°å"]?.ToString(); } if (!string.IsNullOrEmpty(communicator.CommunicatorConnections["åéç±»å"]?.ToString())) { cmbVarType.Items.Add(communicator.CommunicatorConnections["åéç±»å"]?.ToString()); cmbVarType.Text = communicator.CommunicatorConnections["åéç±»å"]?.ToString(); } lbVarType.Visible = true; cmbVarType.Visible = true; txtIP.Visible = true; cmbIP.Visible = false; this.btnRuleSend.Visible = false; lblType.Visible = true; lblAddress.Visible = true; cmbType.Visible = true; txtAddress.Visible = true; lblIP.Text = "IP"; lblPort.Text = "æ§½"; } @@ -267,5 +266,18 @@ communicatorChanged(communicator); } } private void cmbVarType_SelectedIndexChanged(object sender, EventArgs e) { if (communicator != null && !communicator.CommunicatorConnections.Contains("åéç±»å")) { communicator.CommunicatorConnections.Add("åéç±»å", cmbVarType.Text); } else if (communicator != null) { communicator.CommunicatorConnections["åéç±»å"] = cmbVarType.Text; communicatorChanged(communicator); } } } } LB_VisionProcesses/Cameras/HRCameras/HRCamera.cs
@@ -1,5 +1,6 @@ using HalconDotNet; using LB_SmartVisionCommon; using LB_VisionProcesses.Cameras.LBCameras; using MVSDK_Net; using System; using System.Collections.Generic; @@ -28,6 +29,8 @@ private Thread _callbackThread; // åè°å¤ççº¿ç¨ private List<IMVDefine.IMV_Frame> _frameList; // å¾åç¼åå表 private readonly object _frameLock = new object(); // 帧ç¼åé // æ°å¢ï¼CollectedImagesæä½éï¼ä¿è¯çº¿ç¨å®å ¨ private readonly object _collectedImagesLock = new object(); private IMVDefine.IMV_EPixelType type = IMVDefine.IMV_EPixelType.gvspPixelMono8; private IMVDefine.IMV_PixelConvertParam stPixelConvertParam = new IMVDefine.IMV_PixelConvertParam(); @@ -217,30 +220,135 @@ } try { // 1. å°å¸§è½¬æ¢ä¸ºBitmap Bitmap bitmap = ConvertFrameToBitmap(frame); // éæ¾å¸§æ°æ® // release frame // éæ¾åå§å¸§æ°æ®ï¼SDKå±é¢éæ¾ï¼ _camera.IMV_ReleaseFrame(ref frame); Task.Factory.StartNew(() => // 2. ç©ºå¼æ ¡éªï¼è½¬æ¢å¤±è´¥åç´æ¥è¿å if (bitmap == null) { CallBackImg = (Bitmap)bitmap.Clone(); if (CallBackImg == null) AsyncLogHelper.Warn(SN + "帧转æ¢ä¸ºBitmap失败ï¼è·³è¿å¤ç"); return; } // 3. 线ç¨å®å ¨å°å°Bitmapæ·»å å°CollectedImagesåå ¸ lock (_collectedImagesLock) { // ç¡®ä¿å½åç¸æºSN对åºçå表åå¨ if (!CollectedImages.ContainsKey(SN)) { return; CollectedImages[SN] = new List<Bitmap>(); } if (GetTriggerMode(out TriggerMode mode, out TriggerSource source)) { if (mode == TriggerMode.On && source != TriggerSource.Software) TriggerRunMessageReceived?.Invoke(SN, source.ToString()); // 触åè¿è¡äºä»¶ } bitmap.Dispose(); }); CollectedImages[SN].Add(bitmap); AsyncLogHelper.Info(SN + $"å¾åå·²å å ¥ç¼åï¼å½åç¼åæ°éï¼{CollectedImages[SN].Count}"); } // 4. å¤çCollectedImagesä¸çå¾åï¼éåæ¶è´¹å表第ä¸ä¸ªå ç´ ç´å°ä¸ºç©º ProcessCollectedImages(); //Task.Factory.StartNew(() => //{ // CallBackImg = (Bitmap)bitmap.Clone(); // if (CallBackImg == null) // { // return; // } // if (GetTriggerMode(out TriggerMode mode, out TriggerSource source)) // { // if (mode == TriggerMode.On && source != TriggerSource.Software) // TriggerRunMessageReceived?.Invoke(SN, source.ToString()); // 触åè¿è¡äºä»¶ // } // bitmap.Dispose(); //}); } catch { } AsyncLogHelper.Info(SN + "Get frame blockId = {0}" + frame.frameInfo.blockId); } /// <summary> /// å¤çCollectedImagesä¸çç¼åå¾å /// æ ¸å¿é»è¾ï¼éåå第ä¸ä¸ªå¾å -> èµå¼ç»CallBackImg -> 触åäºä»¶ -> éæ¾å¹¶ç§»é¤ /// </summary> private void ProcessCollectedImages() { Task.Factory.StartNew(() => { // å éä¿è¯çº¿ç¨å®å ¨ï¼é²æ¢å¤çº¿ç¨åæ¶æä½å表 lock (_collectedImagesLock) { // æ ¡éªå½åç¸æºçå¾åå表æ¯å¦åå¨ä¸ææ°æ® if (!CollectedImages.ContainsKey(SN) || CollectedImages[SN].Count == 0) { AsyncLogHelper.Info(SN + "å½åæ ç¼åå¾åï¼è·³è¿å¤ç"); return; } // 循ç¯å¤çï¼ç´å°å表为空 while (CollectedImages[SN].Count > 0) { try { // 1 åå表第ä¸ä¸ªç´¢å¼çå¾åèµå¼ç»CallBackImg Bitmap firstBitmap = CollectedImages[SN][0]; ImageGrabbed?.Invoke(this, new LBCameraEventArgs(SN, firstBitmap, true)); CallBackImg = (Bitmap)firstBitmap.Clone(); // å éé¿å åå¯¹è±¡è¢«éæ¾åå¼ç¨å¤±æ // 2 è·åè§¦åæ¨¡å¼å¹¶å¤ææ¯å¦è§¦åè¿è¡äºä»¶ if (GetTriggerMode(out TriggerMode mode, out TriggerSource source)) { // ç¡¬è§¦åæ¨¡å¼ä¸è§¦åè¿è¡äºä»¶ if (mode == TriggerMode.On && source != TriggerSource.Software) { AsyncLogHelper.Info(SN + $"触å硬触åäºä»¶ï¼è§¦åæºï¼{source}"); TriggerRunMessageReceived?.Invoke(SN, source.ToString()); } } else { AsyncLogHelper.Warn(SN + "è·åè§¦åæ¨¡å¼å¤±è´¥ï¼è·³è¿äºä»¶è§¦å"); } // 3 éæ¾ç¬¬ä¸ä¸ªå¾åèµæºå¹¶ä»åè¡¨ç§»é¤ // å éæ¾Bitmapå åï¼åç§»é¤å表å ç´ firstBitmap.Dispose(); CollectedImages[SN].RemoveAt(0); AsyncLogHelper.Info(SN + $"å·²æ¶è´¹ç¼åå¾åï¼å©ä½ç¼åæ°éï¼{CollectedImages[SN].Count}"); } catch (Exception ex) { AsyncLogHelper.Error(SN + $"å¤çç¼åå¾åå¼å¸¸ï¼{ex.Message}", ex); // å个å¾åå¤ç失败æ¶ï¼ç§»é¤è¯¥å¾åé¿å é»å¡åç»å¤ç if (CollectedImages[SN].Count > 0) { try { CollectedImages[SN][0]?.Dispose(); // å°è¯éæ¾ CollectedImages[SN].RemoveAt(0); } catch (Exception innerEx) { AsyncLogHelper.Error(SN + $"æ¸ çå¼å¸¸å¾å失败ï¼{innerEx.Message}", innerEx); } } // å个å¾åå¤ç失败ä¸ç»æ¢å¾ªç¯ï¼ç»§ç»å¤çä¸ä¸ä¸ª // 4. ææå¾åå¤ç宿åï¼æ¸ 空CallBackImg if (CallBackImg != null) { CallBackImg.Dispose(); CallBackImg = null; } continue; } // 4. ææå¾åå¤ç宿åï¼æ¸ 空CallBackImg if (CallBackImg != null) { CallBackImg.Dispose(); CallBackImg = null; } } } }); } /// <summary> /// å¾åæ¯å¦ä¸ºMonoæ ¼å¼ /// </summary> /// <param name="enType"></param> LB_VisionProcesses/Cameras/LBCameras/LBCamera.cs
@@ -51,6 +51,8 @@ // 临æ¶è¡ç¼å²ï¼ç¨äºæ¥æ¶åè°æ°æ® private byte[] _tempLineBuffer = null; private bool _isContinuous = false; // æ°å¢ï¼CollectedImagesæä½éï¼ä¿è¯çº¿ç¨å®å ¨ private readonly object _collectedImagesLock = new object(); public LBCamera() { @@ -568,37 +570,140 @@ _frameCount++; AsyncLogHelper.Info($"LBCamera[{SN}]: Frame {_frameCount} generated ({width}x{height})"); // 弿¥è§¦åäºä»¶ï¼é¿å é»å¡SDKåè°çº¿ç¨ Task.Factory.StartNew(() => //ç©ºå¼æ ¡éªï¼è½¬æ¢å¤±è´¥åç´æ¥è¿å if (bmp == null) { try AsyncLogHelper.Warn(SN + "帧转æ¢ä¸ºBitmap失败ï¼è·³è¿å¤ç"); return; } // 线ç¨å®å ¨å°å°Bitmapæ·»å å°CollectedImagesåå ¸ lock (_collectedImagesLock) { // ç¡®ä¿å½åç¸æºSN对åºçå表åå¨ if (!CollectedImages.ContainsKey(SN)) { ImageGrabbed?.Invoke(this, new LBCameraEventArgs(SN, bmp, true)); CallBackImg = (Bitmap)bmp.Clone(); if (CallBackImg == null) { return; } if (GetTriggerMode(out TriggerMode mode, out TriggerSource source)) { if (mode == TriggerMode.On && source != TriggerSource.Software) TriggerRunMessageReceived?.Invoke(SN, source.ToString()); // 触åè¿è¡äºä»¶ } bmp.Dispose(); CollectedImages[SN] = new List<Bitmap>(); } catch (Exception ex) { AsyncLogHelper.Error($"LBCamera: Event Invoke error - {ex.Message}"); bmp.Dispose(); // å¼å¸¸æ¶éæ¾èµæº } }); CollectedImages[SN].Add(bmp); AsyncLogHelper.Info(SN + $"å¾åå·²å å ¥ç¼åï¼å½åç¼åæ°éï¼{CollectedImages[SN].Count}"); } // å¤çCollectedImagesä¸çå¾åï¼éåæ¶è´¹å表第ä¸ä¸ªå ç´ ç´å°ä¸ºç©º ProcessCollectedImages(); //// 弿¥è§¦åäºä»¶ï¼é¿å é»å¡SDKåè°çº¿ç¨ //Task.Factory.StartNew(() => //{ // try // { // ImageGrabbed?.Invoke(this, new LBCameraEventArgs(SN, bmp, true)); // CallBackImg = (Bitmap)bmp.Clone(); // if (CallBackImg == null) // { // return; // } // if (GetTriggerMode(out TriggerMode mode, out TriggerSource source)) // { // if (mode == TriggerMode.On && source != TriggerSource.Software) // TriggerRunMessageReceived?.Invoke(SN, source.ToString()); // 触åè¿è¡äºä»¶ // } // bmp.Dispose(); // } // catch (Exception ex) // { // AsyncLogHelper.Error($"LBCamera: Event Invoke error - {ex.Message}"); // bmp.Dispose(); // å¼å¸¸æ¶éæ¾èµæº // } //}); } catch (Exception ex) { AsyncLogHelper.Error($"LBCamera: CreateBitmap error - {ex.Message}"); } } /// <summary> /// å¤çCollectedImagesä¸çç¼åå¾å /// æ ¸å¿é»è¾ï¼éåå第ä¸ä¸ªå¾å -> èµå¼ç»CallBackImg -> 触åäºä»¶ -> éæ¾å¹¶ç§»é¤ /// </summary> private void ProcessCollectedImages() { Task.Factory.StartNew(() => { // å éä¿è¯çº¿ç¨å®å ¨ï¼é²æ¢å¤çº¿ç¨åæ¶æä½å表 lock (_collectedImagesLock) { // æ ¡éªå½åç¸æºçå¾åå表æ¯å¦åå¨ä¸ææ°æ® if (!CollectedImages.ContainsKey(SN) || CollectedImages[SN].Count == 0) { AsyncLogHelper.Info(SN + "å½åæ ç¼åå¾åï¼è·³è¿å¤ç"); return; } // 循ç¯å¤çï¼ç´å°å表为空 while (CollectedImages[SN].Count > 0) { try { // 1 åå表第ä¸ä¸ªç´¢å¼çå¾åèµå¼ç»CallBackImg Bitmap firstBitmap = CollectedImages[SN][0]; ImageGrabbed?.Invoke(this, new LBCameraEventArgs(SN, firstBitmap, true)); CallBackImg = (Bitmap)firstBitmap.Clone(); // å éé¿å åå¯¹è±¡è¢«éæ¾åå¼ç¨å¤±æ // 2 è·åè§¦åæ¨¡å¼å¹¶å¤ææ¯å¦è§¦åè¿è¡äºä»¶ if (GetTriggerMode(out TriggerMode mode, out TriggerSource source)) { // ç¡¬è§¦åæ¨¡å¼ä¸è§¦åè¿è¡äºä»¶ if (mode == TriggerMode.On && source != TriggerSource.Software) { AsyncLogHelper.Info(SN + $"触å硬触åäºä»¶ï¼è§¦åæºï¼{source}"); TriggerRunMessageReceived?.Invoke(SN, source.ToString()); } } else { AsyncLogHelper.Warn(SN + "è·åè§¦åæ¨¡å¼å¤±è´¥ï¼è·³è¿äºä»¶è§¦å"); } // 3 éæ¾ç¬¬ä¸ä¸ªå¾åèµæºå¹¶ä»åè¡¨ç§»é¤ // å éæ¾Bitmapå åï¼åç§»é¤å表å ç´ firstBitmap.Dispose(); CollectedImages[SN].RemoveAt(0); AsyncLogHelper.Info(SN + $"å·²æ¶è´¹ç¼åå¾åï¼å©ä½ç¼åæ°éï¼{CollectedImages[SN].Count}"); } catch (Exception ex) { AsyncLogHelper.Error(SN + $"å¤çç¼åå¾åå¼å¸¸ï¼{ex.Message}", ex); // å个å¾åå¤ç失败æ¶ï¼ç§»é¤è¯¥å¾åé¿å é»å¡åç»å¤ç if (CollectedImages[SN].Count > 0) { try { CollectedImages[SN][0]?.Dispose(); // å°è¯éæ¾ CollectedImages[SN].RemoveAt(0); } catch (Exception innerEx) { AsyncLogHelper.Error(SN + $"æ¸ çå¼å¸¸å¾å失败ï¼{innerEx.Message}", innerEx); } } // å个å¾åå¤ç失败ä¸ç»æ¢å¾ªç¯ï¼ç»§ç»å¤çä¸ä¸ä¸ª // 4. ææå¾åå¤ç宿åï¼æ¸ 空CallBackImg if (CallBackImg != null) { CallBackImg.Dispose(); CallBackImg = null; } continue; } // 4. ææå¾åå¤ç宿åï¼æ¸ 空CallBackImg if (CallBackImg != null) { CallBackImg.Dispose(); CallBackImg = null; } } } }); } private void SyncConfigFromCamera() { LB_VisionProcesses/MotionControl/BaseMotionControl.cs
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,49 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace LB_VisionProcesses.MotionControl { public class BaseMotionControl : IMotionControl { /// <summary> /// è¿å¨æ§å¶åç§° /// </summary> public string MotionControlName { get; set; } = string.Empty; /// <summary> /// æ¯å¦è¿æ¥ /// </summary> public bool bConnected = true; public bool Connect() { throw new NotImplementedException(); } public bool Disconnect() { throw new NotImplementedException(); } public void Dispose() { throw new NotImplementedException(); } public string ReceiveMsg() { throw new NotImplementedException(); } public void SendHeartbeat() { throw new NotImplementedException(); } public bool SendMessage(string message) { throw new NotImplementedException(); } } } LB_VisionProcesses/MotionControl/IMotionControl.cs
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,42 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace LB_VisionProcesses.MotionControl { public interface IMotionControl : IDisposable { /// <summary> /// è¿æ¥é讯 /// </summary> /// <returns></returns> bool Connect(); /// <summary> /// æå¼è¿æ¥ /// </summary> /// <returns></returns> bool Disconnect(); /// <summary> /// æ¥æ¶æ¶æ¯ /// </summary> /// <returns></returns> string ReceiveMsg(); /// <summary> /// åéæ¶æ¯ /// </summary> /// <param name="message"></param> /// <returns></returns> bool SendMessage(string message); /// <summary> /// åéå¿è·³ä¿¡å· /// </summary> void SendHeartbeat(); } } LB_VisionProcesses/MotionControl/MotionControlConfig.cs
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,189 @@ using LB_VisionProcesses.Communicators; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; namespace LB_VisionProcesses.MotionControl { [Serializable] [Process("è¿å¨æ§å¶æ¨¡å", Category = "è¿å¨æ§å¶å·¥å ·", Description = "å建è¿å¨æ§å¶å·¥å ·")] public class MotionControlConfig : IProcess { /// <summary> /// è¿å¨æ§å¶æ¨¡åéå(Key:é讯åï¼Value:éè®¯å¥æ) /// </summary> public ConcurrentDictionary<string, BaseMotionControl> dicMotionControls { get; set; } /// <summary> /// é讯éå(Key:é讯åï¼Value:éè®¯å¥æ) /// </summary> public ConcurrentDictionary<string, BaseCommunicator> dicCommunicators { get; set; } public MotionControlConfig(ConcurrentDictionary<string, BaseMotionControl> dicMotionControl) { this.dicMotionControls = dicMotionControl; strProcessClass = "LB_VisionProcesses.Communicators.MotionControlConfig"; Params.Inputs.Add("è¿å¨æ§å¶åç§°", ""); //Params.Inputs.Add("Xè½´PLCå°å", ""); //Params.Inputs.Add("Xè½´æ£æµä½ç½®", ""); //Params.Inputs.Add("Yè½´PLCå°å", ""); //Params.Inputs.Add("Zè½´PLCå°å", ""); //Params.Inputs.Add("Wè½´PLCå°å", ""); Params.Outputs.Add("æ¶å°çä¿¡æ¯", ""); } public override object Clone() { return MemberwiseClone(); } public override void Dispose() { return; } public override void InitRunParams() { Result = true; Msg = ""; if (Record != null) { Record.Dispose(); } } /// <summary> /// å è½½ç®æ³ /// </summary> /// <param name="fullPath">宿´è·¯å¾å¸¦.json</param> /// <returns></returns> public override bool Load(string fullPath) { try { if (string.IsNullOrEmpty(fullPath)) return false; if (!fullPath.Contains(".json")) { Debug.WriteLine("æä»¶è·¯å¾ä¸å®æ´"); return false; } if (string.IsNullOrEmpty(fullPath) || fullPath.Trim() == "") { Debug.WriteLine("æä»¶è·¯å¾ä¸å®æ´"); return false; } // è·åä¸å¸¦æä»¶åçç®å½è·¯å¾ string directoryPath = Path.GetDirectoryName(fullPath); strProcessName = Path.GetFileNameWithoutExtension(fullPath); if (!File.Exists(fullPath)) { Debug.WriteLine("æä»¶ä¸åå¨å建空æä»¶"); Save(directoryPath); return true; } string strJson = string.Empty; using (StreamReader streamReader = new StreamReader(fullPath, Encoding.UTF8)) { strJson = streamReader.ReadToEnd(); streamReader.Close(); } Params = JsonConvert.DeserializeObject<ProcessParams>(strJson); if (Params == null) return false; Params.FixDeserializedData(); return true; } catch { return false; } } public override bool Run() { InitRunParams(); Params.Outputs["æ¶å°æ¶æ¯"] = ""; string MotionControlName = Params.Inputs["è¿å¨æ§å¶åç§°"].ToString(); if (!dicMotionControls.ContainsKey(MotionControlName)) { Msg = $"è¿å¨æ§å¶[{MotionControlName}]ä¸åå¨"; Result = false; return Result; } BaseMotionControl BaseMotionControl = dicMotionControls[MotionControlName]; if (BaseMotionControl == null) { Msg = $"è¿å¨æ§å¶[{MotionControlName}]æªå®ä¾å"; Result = false; return Result; } if (!BaseMotionControl.bConnected) { Msg = $"è¿å¨æ§å¶[{MotionControlName}]æªè¿æ¥"; Result = false; return Result; } return true; } /// <summary> /// ä¿åç®æ³ /// </summary> /// <param name="filePath">ä¸å¸¦.json</param> /// <returns></returns> public override bool Save(string filePath = null) { try { if (string.IsNullOrEmpty(filePath) || filePath.Trim() == "") { Debug.WriteLine("æä»¶è·¯å¾ä¸å®æ´"); return false; } string strJson = string.Empty; var settings = new JsonSerializerSettings { Formatting = Newtonsoft.Json.Formatting.Indented, // èªå®ä¹ç¼©è¿ï¼4ç©ºæ ¼ï¼ ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() } }; strJson = JsonConvert.SerializeObject(Params, settings); Params = JsonConvert.DeserializeObject<ProcessParams>(strJson); if (Params == null) return false; //夿æä»¶å¤¹æ¯å¦åå¨ï¼é²åè¾å ¥ä¸ºæä»¶åç§° if (!Directory.Exists(filePath)) { try { Directory.CreateDirectory(filePath); } catch (Exception) { } } File.WriteAllText(filePath + "//" + strProcessName + ".json", strJson, Encoding.UTF8); return true; } catch { return false; } } } }