From 37aff9db0932e3e274b3c26650060f7d2d336888 Mon Sep 17 00:00:00 2001
From: C3032 <C3032@BC3032>
Date: 星期五, 09 一月 2026 10:07:30 +0800
Subject: [PATCH] 添加增益选择下拉框并优化相机初始化逻辑
---
LB_SmartVision/Forms/Pages/MotionControlPage/MotionControlEditPage.cs | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 152 insertions(+), 3 deletions(-)
diff --git a/LB_SmartVision/Forms/Pages/MotionControlPage/MotionControlEditPage.cs b/LB_SmartVision/Forms/Pages/MotionControlPage/MotionControlEditPage.cs
index 6ef3551..2048868 100644
--- a/LB_SmartVision/Forms/Pages/MotionControlPage/MotionControlEditPage.cs
+++ b/LB_SmartVision/Forms/Pages/MotionControlPage/MotionControlEditPage.cs
@@ -1,4 +1,7 @@
-锘縰sing LB_VisionControl;
+锘縰sing LB_SmartVision.Forms.Pages.CameraPage;
+using LB_SmartVision.Forms.Pages.MotionControlPage;
+using LB_VisionControl;
+using LB_VisionProcesses.Cameras;
using OpenCvSharp.Flann;
using System;
using System.Collections.Concurrent;
@@ -11,7 +14,6 @@
{
public Action<string, LogInfoType> LogInfo;
-
public MotionControlEditPage()
{
InitializeComponent();
@@ -22,9 +24,156 @@
private void MESEditPage_Paint(object sender, PaintEventArgs e)
{
- uiFlowLayoutPanel1.Controls.Clear();
+ uiMCLayoutPanel1.Controls.Clear();
+
+ if (GlobalVar.dicCameras.Count <= 0)
+ return;
+
+ foreach (var item in GlobalVar.dicCameras)
+ {
+ string CameraSN = item.Key;
+ string CameraBrand = item.Value.Brand.ToString();
+
+ if (string.IsNullOrEmpty(CameraSN) || string.IsNullOrEmpty(CameraBrand))
+ return;
+
+ UserItem flow = new UserItem(new string[] { "杩愬姩鎺у埗", "鍒锋柊", "绉婚櫎" });
+ flow.Name = CameraSN;
+ flow.Text = $"[{CameraBrand}]";
+ if (item.Value.isGrabbing)
+ flow.state = State.Pass;
+ else
+ flow.state |= State.Error;
+ LoadFlowEvent(flow);
+
+ uiMCLayoutPanel1.Controls.Add(flow);
+ }
}
+ private void uiButton1_Click(object sender, System.EventArgs e)
+ {
+ CreateCameraForm createCameraForm = new CreateCameraForm();
+ createCameraForm.ShowDialog();
+ if (createCameraForm.bCreate)
+ {
+ BaseCamera camera = createCameraForm.camera;
+ if (GlobalVar.dicCameras.ContainsKey(camera.SN))
+ {
+ MessageBox.Show($"鐩告満[{camera.SN}]宸插瓨鍦�!", "寮傚父");
+ return;
+ }
+
+ string CameraSN = camera.SN;//"127.0.0.1"
+ string CameraBrand = camera.Brand.ToString();//"1111"
+
+ if (string.IsNullOrEmpty(CameraSN) || string.IsNullOrEmpty(CameraBrand))
+ return;
+
+ GlobalVar.dicCameras.TryAdd(CameraSN, camera);
+ LogInfo?.Invoke(string.Format("娣诲姞鐩告満[{0}][{1}]鎴愬姛", CameraBrand, CameraSN), LogInfoType.PASS);
+ }
+ this.Invalidate();
+ }
+
+ private void uiButton2_Click(object sender, System.EventArgs e)
+ {
+ //娓呴櫎鐢–lear鏂规硶
+ uiMCLayoutPanel1.Controls.Clear();
+ foreach (var camera in GlobalVar.dicCameras.Values)
+ {
+ camera.CloseDevice();
+ }
+ GlobalVar.dicCameras.Clear();
+ }
+
+ private void LoadFlowEvent(UserItem flow)
+ {
+ //鎸夐敭1涓烘祴璇�
+ flow.MenuItem1ClickedEvent += MCEvent;
+ //鎸夐敭2涓哄埛鏂�
+ flow.MenuItem2ClickedEvent += ReconnectEvent;
+ //鎸夐敭3涓虹Щ闄�
+ flow.MenuItem3ClickedEvent += DeleteEvent;
+
+ }
+
+ private void RemoveFlowEvent(UserItem flow)
+ {
+ //鎸夐敭1涓烘祴璇�
+ flow.MenuItem1ClickedEvent -= MCEvent;
+ //鎸夐敭2涓哄埛鏂�
+ flow.MenuItem2ClickedEvent -= ReconnectEvent;
+ //鎸夐敭3涓虹Щ闄�
+ flow.MenuItem3ClickedEvent -= DeleteEvent;
+ }
+
+ // 杩愬姩鎺у埗
+ private void MCEvent(string Name, string Text)
+ {
+ for (int i = 0; i < uiMCLayoutPanel1.Controls.Count; i++)
+ {
+ UserItem flow = (UserItem)uiMCLayoutPanel1.Controls[i];
+ string name = flow.Name;
+ if (name != Name)
+ continue;
+
+ if (GlobalVar.dicCameras.ContainsKey(name))
+ {
+ MotionControlPage.MotionControlForm cameraForm = new MotionControlPage.MotionControlForm(GlobalVar.dicCameras[name]);
+ cameraForm.Show();
+ }
+ }
+ }
+
+ // 绉婚櫎鐩告満
+ private void DeleteEvent(string Name, string Text)
+ {
+ for (int i = 0; i < uiMCLayoutPanel1.Controls.Count; i++)
+ {
+ UserItem flow = (UserItem)uiMCLayoutPanel1.Controls[i];
+ string name = flow.Name;
+ if (name != Name)
+ continue;
+
+ RemoveFlowEvent(flow);
+ uiMCLayoutPanel1.Controls.Remove(uiMCLayoutPanel1.Controls[i]);
+ if (GlobalVar.dicCameras.TryRemove(name, out BaseCamera BaseCamera))
+ {
+ BaseCamera.Dispose();
+ LogInfo?.Invoke(string.Format("绉婚櫎鐩告満[{0}]", name), LogInfoType.INFO);
+ }
+ else
+ LogInfo?.Invoke(string.Format("绉婚櫎鐩告満[{0}]澶辫触", name), LogInfoType.ERROR);
+
+ }
+ }
+
+ // 閲嶈繛鐩告満
+ private void ReconnectEvent(string Name, string Text)
+ {
+ for (int i = 0; i < uiMCLayoutPanel1.Controls.Count; i++)
+ {
+ UserItem flow = (UserItem)uiMCLayoutPanel1.Controls[i];
+ string name = flow.Name;
+ if (name != Name)
+ continue;
+
+ GlobalVar.dicCameras[name].CloseDevice();
+ Thread.Sleep(50);
+ GlobalVar.dicCameras[name].InitDevice(name, this.Handle);
+ if (GlobalVar.dicCameras[name].isGrabbing)
+ {
+ flow.state = State.Pass;
+ LogInfo?.Invoke(string.Format("閲嶈繛鐩告満[{0}]鎴愬姛", name), LogInfoType.PASS);
+ }
+ else
+ {
+ flow.state = State.Error;
+ LogInfo?.Invoke(string.Format("閲嶈繛鐩告満[{0}]澶辫触", name), LogInfoType.ERROR);
+ }
+ flow.Refresh();
+ }
+ }
}
}
--
Gitblit v1.9.3