using LB_VisionProcesses.Cameras; using LB_VisionProcesses.Cameras.HRCameras; using LB_VisionProcesses.Cameras.LBCameras; using RJCP.IO.Ports; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO.Ports; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace LB_SmartVision.Forms.Pages.CameraPage { public partial class CreateCameraForm : Form { public BaseCamera camera { get; set; } public bool bCreate = false; public CreateCameraForm(ICamera camera = null) { InitializeComponent(); // 禁止修改窗口大小 this.FormBorderStyle = FormBorderStyle.FixedDialog; if (camera == null) camera = new HRCamera(); uiButtonCreate.Enabled = false; } private void uiButtonTest_Click(object sender, EventArgs e) { uiButtonCreate.Enabled = false; if (string.IsNullOrEmpty(uiComboBoxSN.Text)) MessageBox.Show($"初始化相机[{uiComboBoxSN.Text}]为空!", "异常"); if (camera == null) { MessageBox.Show("请先选择相机品牌!", "异常"); return; } camera.CloseDevice(); if (camera.InitDevice(uiComboBoxSN.Text, this.Handle)) { uiButtonCreate.Enabled = true; camera.CloseDevice(); } else MessageBox.Show($"初始化相机[{uiComboBoxSN.Text}]失败!", "异常"); } private void uiButtonCreate_Click(object sender, EventArgs e) { if (camera.InitDevice(uiComboBoxSN.Text, this.Handle)) { bCreate = true; this.Close(); } else MessageBox.Show($"初始化相机[{uiComboBoxSN.Text}]失败!", "异常"); } private void uiButtonCancel_Click(object sender, EventArgs e) { if (camera != null) camera.CloseDevice(); bCreate = false; this.Close(); } private void uiComboBoxBrand_MouseClick(object sender, MouseEventArgs e) { uiComboBoxBrand.Items.Clear(); foreach (CameraBrand brand in Enum.GetValues(typeof(CameraBrand))) { if (brand != CameraBrand.UNSUPPORTED) uiComboBoxBrand.Items.Add(brand.ToString()); } } private void uiComboBoxBrand_SelectedIndexChanged(object sender, EventArgs e) { uiButtonCreate.Enabled = false; uiComboBoxSN.Text = string.Empty; if (camera != null) camera.CloseDevice(); Enum.TryParse(uiComboBoxBrand.Text, out CameraBrand brand); switch (brand) { case CameraBrand.HRCamera: camera = new HRCamera(); break; case CameraBrand.LBCamera: camera = new LBCamera(); break; default: return; } } private void uiComboBoxSN_MouseClick(object sender, MouseEventArgs e) { uiButtonCreate.Enabled = false; uiComboBoxSN.Text = string.Empty; uiComboBoxSN.Items.Clear(); var list = camera.GetListEnum(); foreach (string sn in list) uiComboBoxSN.Items.Add(sn); } } }