在UserManagementEditPage.cs界面为修改按钮添加了指令,实现用户信息的修改
在HistoricalDataEditPage.cs界面为导出按钮添加了指令,还未完成
已修改7个文件
600 ■■■■ 文件已修改
LB_SmartVision/Forms/Pages/HistoricalDataPage/HistoricalDataEditPage.Designer.cs 81 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LB_SmartVision/Forms/Pages/HistoricalDataPage/HistoricalDataEditPage.cs 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LB_SmartVision/Forms/Pages/UserManagementPage/UserManagementEditPage.Designer.cs 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LB_SmartVision/Forms/Pages/UserManagementPage/UserManagementEditPage.cs 166 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LB_SmartVision/VisionForm.cs 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LB_VisionProcesses/Cameras/BaseCamera.cs 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LB_VisionProcesses/Cameras/HRCameras/HRCamera.cs 257 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LB_SmartVision/Forms/Pages/HistoricalDataPage/HistoricalDataEditPage.Designer.cs
@@ -46,8 +46,8 @@
            labelStartTime = new Label();
            dataGridViewHD = new DataGridView();
            tableLayoutPanel4 = new TableLayoutPanel();
            hopeButton1 = new ReaLTaiizor.Controls.HopeButton();
            hopeButton2 = new ReaLTaiizor.Controls.HopeButton();
            btnHisDataFind = new ReaLTaiizor.Controls.HopeButton();
            btnHisDataExport = new ReaLTaiizor.Controls.HopeButton();
            grpHisData.SuspendLayout();
            tableLayoutPanel1.SuspendLayout();
            tableLayoutPanel2.SuspendLayout();
@@ -285,8 +285,8 @@
            tableLayoutPanel4.ColumnCount = 2;
            tableLayoutPanel4.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
            tableLayoutPanel4.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
            tableLayoutPanel4.Controls.Add(hopeButton1, 0, 0);
            tableLayoutPanel4.Controls.Add(hopeButton2, 1, 0);
            tableLayoutPanel4.Controls.Add(btnHisDataFind, 0, 0);
            tableLayoutPanel4.Controls.Add(btnHisDataExport, 1, 0);
            tableLayoutPanel4.Location = new Point(657, 509);
            tableLayoutPanel4.Name = "tableLayoutPanel4";
            tableLayoutPanel4.RowCount = 1;
@@ -294,43 +294,44 @@
            tableLayoutPanel4.Size = new Size(200, 39);
            tableLayoutPanel4.TabIndex = 1;
            // 
            // hopeButton1
            // btnHisDataFind
            // 
            hopeButton1.BorderColor = Color.FromArgb(220, 223, 230);
            hopeButton1.ButtonType = ReaLTaiizor.Util.HopeButtonType.Primary;
            hopeButton1.DangerColor = Color.FromArgb(245, 108, 108);
            hopeButton1.DefaultColor = Color.FromArgb(255, 255, 255);
            hopeButton1.Font = new Font("Segoe UI", 12F);
            hopeButton1.HoverTextColor = Color.FromArgb(48, 49, 51);
            hopeButton1.InfoColor = Color.FromArgb(144, 147, 153);
            hopeButton1.Location = new Point(3, 3);
            hopeButton1.Name = "hopeButton1";
            hopeButton1.PrimaryColor = Color.FromArgb(64, 158, 255);
            hopeButton1.Size = new Size(94, 33);
            hopeButton1.SuccessColor = Color.FromArgb(103, 194, 58);
            hopeButton1.TabIndex = 0;
            hopeButton1.Text = "查询";
            hopeButton1.TextColor = Color.White;
            hopeButton1.WarningColor = Color.FromArgb(230, 162, 60);
            btnHisDataFind.BorderColor = Color.FromArgb(220, 223, 230);
            btnHisDataFind.ButtonType = ReaLTaiizor.Util.HopeButtonType.Primary;
            btnHisDataFind.DangerColor = Color.FromArgb(245, 108, 108);
            btnHisDataFind.DefaultColor = Color.FromArgb(255, 255, 255);
            btnHisDataFind.Font = new Font("Segoe UI", 12F);
            btnHisDataFind.HoverTextColor = Color.FromArgb(48, 49, 51);
            btnHisDataFind.InfoColor = Color.FromArgb(144, 147, 153);
            btnHisDataFind.Location = new Point(3, 3);
            btnHisDataFind.Name = "btnHisDataFind";
            btnHisDataFind.PrimaryColor = Color.FromArgb(64, 158, 255);
            btnHisDataFind.Size = new Size(94, 33);
            btnHisDataFind.SuccessColor = Color.FromArgb(103, 194, 58);
            btnHisDataFind.TabIndex = 0;
            btnHisDataFind.Text = "查询";
            btnHisDataFind.TextColor = Color.White;
            btnHisDataFind.WarningColor = Color.FromArgb(230, 162, 60);
            // 
            // hopeButton2
            // btnHisDataExport
            // 
            hopeButton2.BorderColor = Color.FromArgb(220, 223, 230);
            hopeButton2.ButtonType = ReaLTaiizor.Util.HopeButtonType.Primary;
            hopeButton2.DangerColor = Color.FromArgb(245, 108, 108);
            hopeButton2.DefaultColor = Color.FromArgb(255, 255, 255);
            hopeButton2.Font = new Font("Segoe UI", 12F);
            hopeButton2.HoverTextColor = Color.FromArgb(48, 49, 51);
            hopeButton2.InfoColor = Color.FromArgb(144, 147, 153);
            hopeButton2.Location = new Point(103, 3);
            hopeButton2.Name = "hopeButton2";
            hopeButton2.PrimaryColor = Color.FromArgb(64, 158, 255);
            hopeButton2.Size = new Size(94, 33);
            hopeButton2.SuccessColor = Color.FromArgb(103, 194, 58);
            hopeButton2.TabIndex = 1;
            hopeButton2.Text = "导出";
            hopeButton2.TextColor = Color.White;
            hopeButton2.WarningColor = Color.FromArgb(230, 162, 60);
            btnHisDataExport.BorderColor = Color.FromArgb(220, 223, 230);
            btnHisDataExport.ButtonType = ReaLTaiizor.Util.HopeButtonType.Primary;
            btnHisDataExport.DangerColor = Color.FromArgb(245, 108, 108);
            btnHisDataExport.DefaultColor = Color.FromArgb(255, 255, 255);
            btnHisDataExport.Font = new Font("Segoe UI", 12F);
            btnHisDataExport.HoverTextColor = Color.FromArgb(48, 49, 51);
            btnHisDataExport.InfoColor = Color.FromArgb(144, 147, 153);
            btnHisDataExport.Location = new Point(103, 3);
            btnHisDataExport.Name = "btnHisDataExport";
            btnHisDataExport.PrimaryColor = Color.FromArgb(64, 158, 255);
            btnHisDataExport.Size = new Size(94, 33);
            btnHisDataExport.SuccessColor = Color.FromArgb(103, 194, 58);
            btnHisDataExport.TabIndex = 1;
            btnHisDataExport.Text = "导出";
            btnHisDataExport.TextColor = Color.White;
            btnHisDataExport.WarningColor = Color.FromArgb(230, 162, 60);
            btnHisDataExport.Click += btnHisDataExport_Click;
            // 
            // HistoricalDataEditPage
            // 
@@ -363,8 +364,8 @@
        private TableLayoutPanel tableLayoutPanel3;
        private DataGridView dataGridViewHD;
        private TableLayoutPanel tableLayoutPanel4;
        private ReaLTaiizor.Controls.HopeButton hopeButton1;
        private ReaLTaiizor.Controls.HopeButton hopeButton2;
        private ReaLTaiizor.Controls.HopeButton btnHisDataFind;
        private ReaLTaiizor.Controls.HopeButton btnHisDataExport;
        private TableLayoutPanel tableLayoutPanel5;
        private Label labelSearchBasis;
        private TableLayoutPanel tableLayoutPanelSN;
LB_SmartVision/Forms/Pages/HistoricalDataPage/HistoricalDataEditPage.cs
@@ -57,7 +57,7 @@
            }
            // 设置列标题
            dataGridViewHD.Columns[0].Name = "SN号";
            dataGridViewHD.Columns[0].Name = "SN号";
            dataGridViewHD.Columns[1].Name = "时间";
            dataGridViewHD.Columns[2].Name = "NG类";
            dataGridViewHD.Columns[3].Name = "缺陷大小";
@@ -151,5 +151,45 @@
        {
            dateTimePickerEnd.MinDate = dateTimePickerStart.Value;
        }
        private void btnHisDataExport_Click(object sender, EventArgs e)
        {
        }
        public void SaveToCSV(string filePath, int rowIndex)
        {
            // 使用 StreamWriter 来写入文件
            using (StreamWriter writer = new StreamWriter(filePath))
            {
                DataGridViewRow row = dataGridViewHD.Rows[rowIndex];
                int rowCount = 10;//10改为采集次数
                writer.WriteLine("SN号, 时间, NG类, 缺陷大小");
                // 遍历每一行数据
                for (int i = 0; i < rowCount; i++)
                {
                    int batchSize = 4;
                    // 写入这一批次的每一列数据
                    for (int k = 0; k < batchSize; k++)
                    {
                        writer.Write($"{row.Cells[k].Value}");
                        // 在元素之间添加逗号,除非这是最后一个元素
                        if (k < batchSize - 1)
                        {
                            writer.Write(",");
                        }
                    }
                    // 写入完一行后,换行
                    writer.WriteLine();
                }
            }
        }
    }
}
LB_SmartVision/Forms/Pages/UserManagementPage/UserManagementEditPage.Designer.cs
@@ -283,6 +283,7 @@
            btnEdit.Text = "修改";
            btnEdit.TextColor = Color.White;
            btnEdit.WarningColor = Color.FromArgb(230, 162, 60);
            btnEdit.Click += btnEdit_Click;
            // 
            // btnFind
            // 
LB_SmartVision/Forms/Pages/UserManagementPage/UserManagementEditPage.cs
@@ -31,10 +31,13 @@
            InitializeComboBox();
        }
        /// <summary>
        /// 表格初始化
        /// </summary>
        private void InitializeDataGridView()
        {
            // 设置DataGridView列宽
            dataGridViewUM.ColumnCount = 5;
            dataGridViewUM.ColumnCount = 4;
            int totalWidth = dataGridViewUM.ClientSize.Width;
            int columnCount = dataGridViewUM.ColumnCount;
@@ -54,10 +57,10 @@
            // 设置列标题
            dataGridViewUM.Columns[0].Name = "用户名";
            dataGridViewUM.Columns[1].Name = "密码";
            dataGridViewUM.Columns[2].Name = "姓名";
            dataGridViewUM.Columns[3].Name = "工号";
            dataGridViewUM.Columns[4].Name = "权限";
            //dataGridViewUM.Columns[1].Name = "密码";
            dataGridViewUM.Columns[1].Name = "姓名";
            dataGridViewUM.Columns[2].Name = "工号";
            dataGridViewUM.Columns[3].Name = "权限";
            dataGridViewUM.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
@@ -71,6 +74,9 @@
            dataGridViewUM.RowHeadersVisible = true;
        }
        /// <summary>
        /// 权限下拉框初始化
        /// </summary>
        private void InitializeComboBox()
        {
            // 添加权限选项
@@ -90,7 +96,7 @@
            textBoxPassword.Clear();
            textBoxName.Clear();
            textBoxEmployeeID.Clear();
            comboBoxPermission.SelectedIndex = 1;
            comboBoxPermission.SelectedIndex = 0;
            textBoxUsername.Focus(); // 将焦点设置回用户名输入框
        }
        private void btnAdd_Click(object sender, EventArgs e)
@@ -110,7 +116,7 @@
            string[] row = new string[]
            {
                textBoxUsername.Text,
                textBoxPassword.Text, // 实际应用中密码应该加密
                //textBoxPassword.Text, // 实际应用中密码应该加密
                textBoxName.Text,
                textBoxEmployeeID.Text,
                comboBoxPermission.SelectedItem.ToString()
@@ -150,7 +156,153 @@
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private int editingRowIndex = -1;
        private bool isEditingMode = false;
        private string originalButtonText = "修改";
        private void btnEdit_Click(object sender, EventArgs e)
        {
            // 单元格可编辑
            //dataGridViewUM.ReadOnly = false;
            // 第一次点击:进入修改模式
            if (!isEditingMode)
            {
                // 检查是否选择了行
                if (dataGridViewUM.SelectedRows.Count == 0)
                {
                    MessageBox.Show("请先选择要修改的行!", "提示",
                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                // 获取选中的行索引
                editingRowIndex = dataGridViewUM.SelectedRows[0].Index;
                // 将选中行的数据填充到TextBox中
                FillFormWithRowData(editingRowIndex);
                // 更改按钮文本
                btnEdit.Text = "完成";
                // 进入编辑模式
                isEditingMode = true;
                // 禁用添加按钮(可选)
                btnAdd.Enabled = false;
                // 设置焦点到用户名输入框
                textBoxUsername.Focus();
                // 高亮显示正在编辑的行(可选)
                dataGridViewUM.Rows[editingRowIndex].DefaultCellStyle.BackColor = Color.LightYellow;
            }
            // 第二次点击:保存修改
            else
            {
                // 验证输入
                if (string.IsNullOrWhiteSpace(textBoxUsername.Text) ||
                    string.IsNullOrWhiteSpace(textBoxName.Text) ||
                    string.IsNullOrWhiteSpace(textBoxEmployeeID.Text))
                {
                    MessageBox.Show("请填写所有必填字段!", "提示",
                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                // 更新DataGridView中的行数据
                UpdateRowData(editingRowIndex);
                // 恢复按钮文本
                btnEdit.Text = originalButtonText;
                // 退出编辑模式
                isEditingMode = false;
                editingRowIndex = -1;
                // 启用添加按钮(可选)
                btnAdd.Enabled = true;
                // 恢复行颜色(可选)
                dataGridViewUM.DefaultCellStyle.BackColor = Color.White;
                // 清空输入框
                ClearInputFields();
                MessageBox.Show("修改完成!", "提示",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private void FillFormWithRowData(int rowIndex)
        {
            if (rowIndex >= 0 && rowIndex < dataGridViewUM.Rows.Count)
            {
                DataGridViewRow row = dataGridViewUM.Rows[rowIndex];
                // 填充用户名
                if (row.Cells[0].Value != null)
                    textBoxUsername.Text = row.Cells[0].Value.ToString();
                else
                    textBoxUsername.Text = "";
                // 填充姓名
                if (row.Cells[1].Value != null)
                    textBoxName.Text = row.Cells[1].Value.ToString();
                else
                    textBoxName.Text = "";
                // 填充工号
                if (row.Cells[2].Value != null)
                    textBoxEmployeeID.Text = row.Cells[2].Value.ToString();
                else
                    textBoxEmployeeID.Text = "";
                // 填充权限
                if (row.Cells[3].Value != null)
                {
                    string permission = row.Cells[3].Value.ToString();
                    int index = comboBoxPermission.FindString(permission);
                    if (index >= 0)
                        comboBoxPermission.SelectedIndex = index;
                    else
                        comboBoxPermission.SelectedIndex = 0;
                }
                else
                {
                    comboBoxPermission.SelectedIndex = 0;
                }
                // 密码框清空(通常不会显示密码)
                textBoxPassword.Clear();
                // 如果需要修改密码,可以添加注释或占位符
                //textBoxPassword.PlaceholderText = "如需修改密码请填写";
            }
        }
        private void UpdateRowData(int rowIndex)
        {
            if (rowIndex >= 0 && rowIndex < dataGridViewUM.Rows.Count)
            {
                DataGridViewRow row = dataGridViewUM.Rows[rowIndex];
                // 更新用户名
                row.Cells[0].Value = textBoxUsername.Text;
                // 如果密码不为空,则更新密码(实际应用中应加密)
                if (!string.IsNullOrWhiteSpace(textBoxPassword.Text))
                {
                    // 这里可以添加密码加密逻辑
                    // row.Cells[1].Value = EncryptPassword(textBoxPassword.Text);
                }
                // 更新姓名
                row.Cells[1].Value = textBoxName.Text;
                // 更新工号
                row.Cells[2].Value = textBoxEmployeeID.Text;
                // 更新权限
                row.Cells[3].Value = comboBoxPermission.SelectedItem.ToString();
            }
        }
    }
}
LB_SmartVision/VisionForm.cs
@@ -66,6 +66,7 @@
            Assembly_LB_VisionProcessesDll = Assembly.Load(Assembly_LB_VisionProcessesBytes);
            GlobalVar.dicCommunicators.DictionaryChanged += CommunicatorsChanged;
            GlobalVar.dicCameras.DictionaryChanged += CamerasChanged;
            GlobalVar.dicProcesses.DictionaryChanged += ProcessRunBllChanged;
            //最开始就清空所有Tab页
@@ -239,7 +240,30 @@
        private void CommunicatorsChanged(object? sender, DictionaryChangedEventArgs<string, BaseCommunicator> e)
        {
            try
            {
                switch (e.ChangeType)
                {
                    case DictionaryChangeType.Added:
                        e.NewValue.TriggerRunMessageReceived += TriggerRunMessageReceived;
                        LogInfo($"通讯口[{e.NewValue.CommunicatorName}]加载触发通讯", LogInfoType.INFO);
                        e.NewValue.CommunicatorName = e.NewKey;
                        break;
                    case DictionaryChangeType.Renamed:
                        string OldCommunicatorName = e.OldKey;
                        string NewCommunicatorName = e.NewKey;
                        LogInfo(string.Format("重命名通讯口名[{0}]修改为[{1}]", OldCommunicatorName, NewCommunicatorName), LogInfoType.INFO);
                        e.NewValue.CommunicatorName = NewCommunicatorName;
                        break;
                    case DictionaryChangeType.Removed:
                        if (e.OldValue != null && e.OldValue is BaseCommunicator)
                            e.OldValue.Disconnect();
                        e.OldValue.TriggerRunMessageReceived -= TriggerRunMessageReceived;
                        LogInfo($"通讯口[{e.OldValue.CommunicatorName}]移除触发通讯", LogInfoType.INFO);
                        break;
                }
            }
            catch { }
        }
        private void LogInfo(string strLog, LogInfoType infoType)
@@ -526,6 +550,28 @@
            }
        }
        private void CamerasChanged(object sender, DictionaryChangedEventArgs<string, BaseCamera> e)
        {
            try
            {
                switch (e.ChangeType)
                {
                    case DictionaryChangeType.Added:
                        e.NewValue.TriggerRunMessageReceived += TriggerRunMessageReceived;
                        LogInfo($"相机[{e.NewValue.SN}]加载触发通讯", LogInfoType.INFO);
                        e.NewValue.SN = e.NewKey;
                        break;
                    case DictionaryChangeType.Removed:
                        if (e.OldValue != null && e.OldValue is BaseCommunicator)
                            e.OldValue.CloseDevice();
                        e.OldValue.TriggerRunMessageReceived -= TriggerRunMessageReceived;
                        LogInfo($"相机[{e.OldValue.SN}]移除触发通讯", LogInfoType.INFO);
                        break;
                }
            }
            catch { }
        }
        private void VisionForm_Load(object sender, EventArgs e)
        {
            XmlConfigurator.Configure(new System.IO.FileInfo("log4net.config"));
LB_VisionProcesses/Cameras/BaseCamera.cs
@@ -23,6 +23,11 @@
        /// 相机名称
        /// </summary>
        public string CameraName { get; set; } = string.Empty;
        /// <summary>
        /// 相机硬触发获取图像触发对应的检测流程
        /// </summary>
        public Action<string, string> TriggerRunMessageReceived;
        public CameraBrand Brand { get; set; } = CameraBrand.UNSUPPORTED;
        public bool isGrabbing = false;
LB_VisionProcesses/Cameras/HRCameras/HRCamera.cs
@@ -1,4 +1,6 @@
using MVSDK_Net;
using HalconDotNet;
using LB_SmartVisionCommon;
using MVSDK_Net;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -26,6 +28,16 @@
        private Thread _callbackThread; // 回调处理线程
        private List<IMVDefine.IMV_Frame> _frameList; // 图像缓存列表
        private readonly object _frameLock = new object(); // 帧缓存锁
        private IMVDefine.IMV_EPixelType type = IMVDefine.IMV_EPixelType.gvspPixelMono8;
        private IMVDefine.IMV_PixelConvertParam stPixelConvertParam = new IMVDefine.IMV_PixelConvertParam();
        HObject Hobj = new HObject();
        IntPtr pTemp = IntPtr.Zero;
        IntPtr pConvertDstBuffer = IntPtr.Zero;
        int nConvertBufSize = 0;
        private IMVDefine.IMV_FrameCallBack frameCallBack;
        // CopyMemory API声明
        [System.Runtime.InteropServices.DllImport("kernel32.dll", EntryPoint = "RtlMoveMemory")]
@@ -92,13 +104,15 @@
                {
                    // 记录日志或抛出异常
                    //throw new Exception($"枚举设备失败,错误码:{result}");
                    Debug.WriteLine("枚举设备失败!");
                    AsyncLogHelper.Error("枚举设备失败!");
                    System.Diagnostics.Debug.WriteLine("枚举设备失败!");
                }
            }
            catch (Exception ex)
            {
                // 记录错误日志
                System.Diagnostics.Debug.WriteLine($"获取相机列表失败:{ex.Message}");
                AsyncLogHelper.Error($"获取相机列表失败:{ex.Message}");
                throw;
            }
@@ -145,6 +159,7 @@
                if (cameraIndex == -1)
                {
                    AsyncLogHelper.Error($"未找到序列号为 {SN} 的相机");
                    throw new Exception($"未找到序列号为 {SN} 的相机");
                }
@@ -152,6 +167,7 @@
                int result = _camera.IMV_CreateHandle(IMVDefine.IMV_ECreateHandleMode.modeByIndex, cameraIndex);
                if (result != IMVDefine.IMV_OK)
                {
                    AsyncLogHelper.Error($"创建设备句柄失败,错误码:{result}");
                    throw new Exception($"创建设备句柄失败,错误码:{result}");
                }
                _handleCreated = true;
@@ -160,6 +176,7 @@
                result = _camera.IMV_Open();
                if (result != IMVDefine.IMV_OK)
                {
                    AsyncLogHelper.Error($"打开相机失败,错误码:{result}");
                    throw new Exception($"打开相机失败,错误码:{result}");
                }
@@ -167,17 +184,121 @@
                this.SN = SN;
                isGrabbing = false;
                // 设置缓存个数为8
                _camera.IMV_SetBufferCount(8);
                // 注册数据帧回调函数
                // Register data frame callback function
                frameCallBack = onGetFrame;
                int res = _camera.IMV_AttachGrabbing(frameCallBack, IntPtr.Zero);
                if (res != IMVDefine.IMV_OK)
                {
                    System.Diagnostics.Debug.WriteLine("Attach grabbing failed! ErrorCode:[{0}]", res);
                    AsyncLogHelper.Error("Attach grabbing failed! ErrorCode:[{0}]" + res);
                }
                // 设置缓存个数为12
                _camera.IMV_SetBufferCount(12);
                return true;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"初始化相机失败:{ex.Message}");
                AsyncLogHelper.Error($"初始化相机失败:{ex.Message}");
                return false;
            }
        }
        // 数据帧回调函数
        // Data frame callback function
        private void onGetFrame(ref IMVDefine.IMV_Frame frame, IntPtr pUser)
        {
            if (frame.frameHandle == IntPtr.Zero)
            {
                AsyncLogHelper.Info(SN + "frame is NULL");
                return;
            }
            try
            {
                Bitmap bitmap = ConvertFrameToBitmap(frame);
                // 释放帧数据
                // release frame
                _camera.IMV_ReleaseFrame(ref frame);
                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>
        /// 图像是否为Mono格式
        /// </summary>
        /// <param name="enType"></param>
        /// <returns></returns>
        private bool IsMonoPixelFormat(IMVDefine.IMV_EPixelType enType)
        {
            switch (enType)
            {
                case IMVDefine.IMV_EPixelType.gvspPixelMono8:
                case IMVDefine.IMV_EPixelType.gvspPixelMono10:
                case IMVDefine.IMV_EPixelType.gvspPixelMono10Packed:
                case IMVDefine.IMV_EPixelType.gvspPixelMono12:
                case IMVDefine.IMV_EPixelType.gvspPixelMono12Packed:
                    return true;
                default:
                    return false;
            }
        }
        /// <summary>
        /// 图像是否为彩色
        /// </summary>
        /// <param name="enType"></param>
        /// <returns></returns>
        private bool IsColorPixelFormat(IMVDefine.IMV_EPixelType enType)
        {
            switch (enType)
            {
                case IMVDefine.IMV_EPixelType.gvspPixelRGB8:
                case IMVDefine.IMV_EPixelType.gvspPixelBGR8:
                case IMVDefine.IMV_EPixelType.gvspPixelRGBA8:
                case IMVDefine.IMV_EPixelType.gvspPixelBGRA8:
                case IMVDefine.IMV_EPixelType.gvspPixelYUV422_8:
                case IMVDefine.IMV_EPixelType.gvspPixelYUV422_8_UYVY:
                case IMVDefine.IMV_EPixelType.gvspPixelBayGR8:
                case IMVDefine.IMV_EPixelType.gvspPixelBayRG8:
                case IMVDefine.IMV_EPixelType.gvspPixelBayGB8:
                case IMVDefine.IMV_EPixelType.gvspPixelBayBG8:
                case IMVDefine.IMV_EPixelType.gvspPixelBayGB10:
                case IMVDefine.IMV_EPixelType.gvspPixelBayGB10Packed:
                case IMVDefine.IMV_EPixelType.gvspPixelBayBG10:
                case IMVDefine.IMV_EPixelType.gvspPixelBayBG10Packed:
                case IMVDefine.IMV_EPixelType.gvspPixelBayRG10:
                case IMVDefine.IMV_EPixelType.gvspPixelBayRG10Packed:
                case IMVDefine.IMV_EPixelType.gvspPixelBayGR10:
                case IMVDefine.IMV_EPixelType.gvspPixelBayGR10Packed:
                case IMVDefine.IMV_EPixelType.gvspPixelBayGB12:
                case IMVDefine.IMV_EPixelType.gvspPixelBayGB12Packed:
                case IMVDefine.IMV_EPixelType.gvspPixelBayBG12:
                case IMVDefine.IMV_EPixelType.gvspPixelBayBG12Packed:
                case IMVDefine.IMV_EPixelType.gvspPixelBayRG12:
                case IMVDefine.IMV_EPixelType.gvspPixelBayRG12Packed:
                case IMVDefine.IMV_EPixelType.gvspPixelBayGR12:
                case IMVDefine.IMV_EPixelType.gvspPixelBayGR12Packed:
                    return true;
                default:
                    return false;
            }
        }
        /// <summary>
        /// 关闭相机设备
@@ -203,6 +324,7 @@
                    if (result != IMVDefine.IMV_OK)
                    {
                        System.Diagnostics.Debug.WriteLine($"关闭相机失败,错误码:{result}");
                        AsyncLogHelper.Info(SN + $"关闭相机失败,错误码:{result}");
                    }
                }
@@ -233,6 +355,7 @@
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"关闭相机失败:{ex.Message}");
                AsyncLogHelper.Info(SN + $"关闭相机失败:{ex.Message}");
                return false;
            }
        }
@@ -251,7 +374,8 @@
            {
                if (_camera == null || !_camera.IMV_IsOpen())
                {
                    throw new Exception("相机未打开");
                    AsyncLogHelper.Error(SN + "相机未打开");
                    throw new Exception(SN + "相机未打开");
                }
                // 停止现有采集
@@ -264,7 +388,8 @@
                int result = _camera.IMV_StartGrabbing();
                if (result != IMVDefine.IMV_OK)
                {
                    throw new Exception($"启动采集失败,错误码:{result}");
                    AsyncLogHelper.Error(SN + $"启动采集失败,错误码:{result}");
                    throw new Exception(SN + $"启动采集失败,错误码:{result}");
                }
                _isGrabbing = true;
@@ -280,7 +405,8 @@
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"启动采集失败:{ex.Message}");
                System.Diagnostics.Debug.WriteLine(SN + $"启动采集失败:{ex.Message}");
                AsyncLogHelper.Error(SN + $"启动采集失败:{ex.Message}");
                _isGrabbing = false;
                isGrabbing = false;
                return false;
@@ -310,7 +436,8 @@
                int result = _camera.IMV_StopGrabbing();
                if (result != IMVDefine.IMV_OK)
                {
                    System.Diagnostics.Debug.WriteLine($"停止采集失败,错误码:{result}");
                    System.Diagnostics.Debug.WriteLine(SN + $"停止采集失败,错误码:{result}");
                    AsyncLogHelper.Info(SN + $"停止采集失败,错误码:{result}");
                }
                _isGrabbing = false;
@@ -331,7 +458,8 @@
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"停止采集失败:{ex.Message}");
                System.Diagnostics.Debug.WriteLine(SN + $"停止采集失败:{ex.Message}");
                AsyncLogHelper.Error(SN + $"停止采集失败:{ex.Message}");
                return false;
            }
        }
@@ -346,7 +474,8 @@
            {
                if (_camera == null || !_camera.IMV_IsOpen())
                {
                    throw new Exception("相机未打开");
                    AsyncLogHelper.Error(SN + "相机未打开");
                    throw new Exception(SN + "相机未打开");
                }
                int result = _camera.IMV_ExecuteCommandFeature("TriggerSoftware");
@@ -354,7 +483,8 @@
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"软触发失败:{ex.Message}");
                System.Diagnostics.Debug.WriteLine(SN + $"软触发失败:{ex.Message}");
                AsyncLogHelper.Error(SN + $"软触发失败:{ex.Message}");
                return false;
            }
        }
@@ -375,7 +505,8 @@
            {
                if (_camera == null || !_camera.IMV_IsOpen())
                {
                    throw new Exception("相机未打开");
                    AsyncLogHelper.Error(SN + "相机未打开");
                    throw new Exception(SN + "相机未打开");
                }
                // 设置触发模式
@@ -383,7 +514,8 @@
                int result = _camera.IMV_SetEnumFeatureSymbol("TriggerMode", triggerMode);
                if (result != IMVDefine.IMV_OK)
                {
                    throw new Exception($"设置触发模式失败,错误码:{result}");
                    AsyncLogHelper.Error(SN + $"设置触发模式失败,错误码:{result}");
                    throw new Exception(SN + $"设置触发模式失败,错误码:{result}");
                }
                // 设置触发源
@@ -393,7 +525,8 @@
                    result = _camera.IMV_SetEnumFeatureSymbol("TriggerSource", triggerSource);
                    if (result != IMVDefine.IMV_OK)
                    {
                        throw new Exception($"设置触发源失败,错误码:{result}");
                        AsyncLogHelper.Error(SN + $"设置触发源失败,错误码:{result}");
                        throw new Exception(SN + $"设置触发源失败,错误码:{result}");
                    }
                }
@@ -401,7 +534,8 @@
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"设置触发模式失败:{ex.Message}");
                System.Diagnostics.Debug.WriteLine(SN + $"设置触发模式失败:{ex.Message}");
                AsyncLogHelper.Error(SN + $"设置触发模式失败:{ex.Message}");
                return false;
            }
        }
@@ -421,7 +555,8 @@
            {
                if (_camera == null || !_camera.IMV_IsOpen())
                {
                    throw new Exception("相机未打开");
                    AsyncLogHelper.Error(SN + "相机未打开");
                    throw new Exception(SN + "相机未打开");
                }
                // 获取触发模式
@@ -444,7 +579,8 @@
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"获取触发模式失败:{ex.Message}");
                System.Diagnostics.Debug.WriteLine(SN + $"获取触发模式失败:{ex.Message}");
                AsyncLogHelper.Error(SN + $"获取触发模式失败:{ex.Message}");
                return false;
            }
        }
@@ -460,7 +596,8 @@
            {
                if (_camera == null || !_camera.IMV_IsOpen())
                {
                    throw new Exception("相机未打开");
                    AsyncLogHelper.Error(SN + "相机未打开");
                    throw new Exception(SN + "相机未打开");
                }
                // 验证曝光时间范围
@@ -468,32 +605,37 @@
                int result = _camera.IMV_GetDoubleFeatureMin("ExposureTime", ref minExp);
                if (result != IMVDefine.IMV_OK)
                {
                    throw new Exception($"获取曝光时间最小值失败,错误码:{result}");
                    AsyncLogHelper.Error(SN + $"获取曝光时间最小值失败,错误码:{result}");
                    throw new Exception(SN + $"获取曝光时间最小值失败,错误码:{result}");
                }
                result = _camera.IMV_GetDoubleFeatureMax("ExposureTime", ref maxExp);
                if (result != IMVDefine.IMV_OK)
                {
                    throw new Exception($"获取曝光时间最大值失败,错误码:{result}");
                    AsyncLogHelper.Error(SN + $"获取曝光时间最大值失败,错误码:{result}");
                    throw new Exception(SN + $"获取曝光时间最大值失败,错误码:{result}");
                }
                if (value < minExp || value > maxExp)
                {
                    throw new Exception($"曝光时间超出范围,有效范围:{minExp} - {maxExp}");
                    AsyncLogHelper.Error(SN + $"曝光时间超出范围,有效范围:{minExp} - {maxExp}");
                    throw new Exception(SN + $"曝光时间超出范围,有效范围:{minExp} - {maxExp}");
                }
                // 设置曝光时间
                result = _camera.IMV_SetDoubleFeatureValue("ExposureTime", value);
                if (result != IMVDefine.IMV_OK)
                {
                    throw new Exception($"设置曝光时间失败,错误码:{result}");
                    AsyncLogHelper.Error(SN + $"设置曝光时间失败,错误码:{result}");
                    throw new Exception(SN + $"设置曝光时间失败,错误码:{result}");
                }
                return true;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"设置曝光时间失败:{ex.Message}");
                AsyncLogHelper.Error(SN + $"设置曝光时间失败:{ex.Message}");
                System.Diagnostics.Debug.WriteLine(SN + $"设置曝光时间失败:{ex.Message}");
                return false;
            }
        }
@@ -511,7 +653,8 @@
            {
                if (_camera == null || !_camera.IMV_IsOpen())
                {
                    throw new Exception("相机未打开");
                    AsyncLogHelper.Error(SN + "相机未打开");
                    throw new Exception(SN + "相机未打开");
                }
                int result = _camera.IMV_GetDoubleFeatureValue("ExposureTime", ref value);
@@ -519,7 +662,8 @@
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"获取曝光时间失败:{ex.Message}");
                System.Diagnostics.Debug.WriteLine(SN + $"获取曝光时间失败:{ex.Message}");
                AsyncLogHelper.Error(SN + $"获取曝光时间失败:{ex.Message}");
                return false;
            }
        }
@@ -535,7 +679,8 @@
            {
                if (_camera == null || !_camera.IMV_IsOpen())
                {
                    throw new Exception("相机未打开");
                    AsyncLogHelper.Error(SN + "相机未打开");
                    throw new Exception(SN + "相机未打开");
                }
                string gainFeature = _camera.IMV_FeatureIsValid("Gain") ? "Gain" : "GainRaw";
@@ -545,13 +690,15 @@
                int result = _camera.IMV_GetDoubleFeatureMin(gainFeature, ref minGain);
                if (result != IMVDefine.IMV_OK)
                {
                    throw new Exception($"获取增益最小值失败,错误码:{result}");
                    AsyncLogHelper.Error(SN + $"获取增益最小值失败,错误码:{result}");
                    throw new Exception(SN + $"获取增益最小值失败,错误码:{result}");
                }
                result = _camera.IMV_GetDoubleFeatureMax(gainFeature, ref maxGain);
                if (result != IMVDefine.IMV_OK)
                {
                    throw new Exception($"获取增益最大值失败,错误码:{result}");
                    AsyncLogHelper.Error(SN + $"获取增益最大值失败,错误码:{result}");
                    throw new Exception(SN + $"获取增益最大值失败,错误码:{result}");
                }
                if (gain < minGain) gain = minGain;
@@ -561,14 +708,16 @@
                result = _camera.IMV_SetDoubleFeatureValue(gainFeature, gain);
                if (result != IMVDefine.IMV_OK)
                {
                    throw new Exception($"设置增益失败,错误码:{result}");
                    AsyncLogHelper.Error(SN + $"设置增益失败,错误码:{result}");
                    throw new Exception(SN + $"设置增益失败,错误码:{result}");
                }
                return true;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"设置增益失败:{ex.Message}");
                System.Diagnostics.Debug.WriteLine(SN + $"设置增益失败:{ex.Message}");
                AsyncLogHelper.Error(SN + $"设置增益失败:{ex.Message}");
                return false;
            }
        }
@@ -586,7 +735,8 @@
            {
                if (_camera == null || !_camera.IMV_IsOpen())
                {
                    throw new Exception("相机未打开");
                    AsyncLogHelper.Error(SN + "相机未打开");
                    throw new Exception(SN + "相机未打开");
                }
                string gainFeature = _camera.IMV_FeatureIsValid("Gain") ? "Gain" : "GainRaw";
@@ -595,7 +745,8 @@
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"获取增益失败:{ex.Message}");
                System.Diagnostics.Debug.WriteLine(SN + $"获取增益失败:{ex.Message}");
                AsyncLogHelper.Error(SN + $"获取增益失败:{ex.Message}");
                return false;
            }
        }
@@ -619,7 +770,8 @@
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"设置触发极性失败:{ex.Message}");
                System.Diagnostics.Debug.WriteLine(SN + $"设置触发极性失败:{ex.Message}");
                AsyncLogHelper.Error(SN + $"设置触发极性失败:{ex.Message}");
                return false;
            }
        }
@@ -647,7 +799,8 @@
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"获取触发极性失败:{ex.Message}");
                System.Diagnostics.Debug.WriteLine(SN + $"获取触发极性失败:{ex.Message}");
                AsyncLogHelper.Error(SN + $"获取触发极性失败:{ex.Message}");
                return false;
            }
        }
@@ -671,7 +824,8 @@
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"设置触发滤波失败:{ex.Message}");
                System.Diagnostics.Debug.WriteLine(SN + $"设置触发滤波失败:{ex.Message}");
                AsyncLogHelper.Error(SN + $"设置触发滤波失败:{ex.Message}");
                return false;
            }
        }
@@ -695,7 +849,8 @@
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"获取触发滤波失败:{ex.Message}");
                System.Diagnostics.Debug.WriteLine(SN + $"获取触发滤波失败:{ex.Message}");
                AsyncLogHelper.Error(SN + $"获取触发滤波失败:{ex.Message}");
                return false;
            }
        }
@@ -718,7 +873,8 @@
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"设置触发延时失败:{ex.Message}");
                System.Diagnostics.Debug.WriteLine(SN + $"设置触发延时失败:{ex.Message}");
                AsyncLogHelper.Error(SN + $"设置触发延时失败:{ex.Message}");
                return false;
            }
        }
@@ -742,7 +898,8 @@
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"获取触发延时失败:{ex.Message}");
                System.Diagnostics.Debug.WriteLine(SN + $"获取触发延时失败:{ex.Message}");
                AsyncLogHelper.Error(SN + $"获取触发延时失败:{ex.Message}");
                return false;
            }
        }
@@ -767,7 +924,8 @@
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"设置信号线模式失败:{ex.Message}");
                System.Diagnostics.Debug.WriteLine(SN + $"设置信号线模式失败:{ex.Message}");
                AsyncLogHelper.Error(SN + $"设置信号线模式失败:{ex.Message}");
                return false;
            }
        }
@@ -791,7 +949,8 @@
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"设置信号线状态失败:{ex.Message}");
                System.Diagnostics.Debug.WriteLine(SN + $"设置信号线状态失败:{ex.Message}");
                AsyncLogHelper.Error(SN + $"设置信号线状态失败:{ex.Message}");
                return false;
            }
        }
@@ -820,7 +979,8 @@
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"获取信号线状态失败:{ex.Message}");
                System.Diagnostics.Debug.WriteLine(SN + $"获取信号线状态失败:{ex.Message}");
                AsyncLogHelper.Error(SN + $"获取信号线状态失败:{ex.Message}");
                return false;
            }
        }
@@ -843,7 +1003,8 @@
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"自动白平衡失败:{ex.Message}");
                System.Diagnostics.Debug.WriteLine(SN + $"自动白平衡失败:{ex.Message}");
                AsyncLogHelper.Error(SN + $"自动白平衡失败:{ex.Message}");
                return false;
            }
        }
@@ -880,14 +1041,16 @@
                        if ((uint)result != 0x80000001 && result != -119 && result != -102) // 超时错误代码
                        {
                            // 非超时错误
                            System.Diagnostics.Debug.WriteLine($"获取图像帧失败,错误码:{result}");
                            System.Diagnostics.Debug.WriteLine(SN + $"获取图像帧失败,错误码:{result}");
                            AsyncLogHelper.Error(SN + $"获取图像帧失败,错误码:{result}");
                            Thread.Sleep(10); // 出错时稍作等待
                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine($"采集线程异常:{ex.Message}");
                    System.Diagnostics.Debug.WriteLine(SN + $"采集线程异常:{ex.Message}");
                    AsyncLogHelper.Error(SN + $"采集线程异常:{ex.Message}");
                    Thread.Sleep(10);
                }
@@ -918,7 +1081,8 @@
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"处理图像帧失败:{ex.Message}");
                System.Diagnostics.Debug.WriteLine(SN + $"处理图像帧失败:{ex.Message}");
                AsyncLogHelper.Error(SN + $"处理图像帧失败:{ex.Message}");
            }
            finally
            {
@@ -957,7 +1121,8 @@
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"图像格式转换失败:{ex.Message}");
                System.Diagnostics.Debug.WriteLine(SN + $"图像格式转换失败:{ex.Message}");
                AsyncLogHelper.Error(SN + $"图像格式转换失败:{ex.Message}");
                return null;
            }
        }