C3204
2025-12-25 32e832a898a6466369669717e7b11f7c957371bb
LB_VisionProcesses/Cameras/CameraConfig.cs
@@ -206,12 +206,24 @@
                        return Result;
                    }
                    if (Camera == null || Camera.SN != SN)
                    // 始终检查缓存的Camera对象是否与全局字典中的一致
                    // 防止相机被删除并重建后(SN相同), 仍然引用旧的已销毁对象
                    if (dicCameras.ContainsKey(SN))
                    {
                        if (dicCameras.ContainsKey(SN))
                            Camera = dicCameras[SN];
                        else
                            Camera = null;
                        var currentCam = dicCameras[SN];
                        if (Camera != currentCam)
                        {
                            Camera = currentCam;
                            // 如果切换了相机实例,且未开始采集,尝试开启采集
                            if (Camera != null && !Camera.isGrabbing)
                            {
                                try { Camera.StartGrabbing(); } catch { }
                            }
                        }
                    }
                    else
                    {
                        Camera = null;
                    }
                    if (Camera == null)
@@ -244,12 +256,17 @@
                    {
                        times--;
                        if (TriggerSource == TriggerSource.Software)
                        {
                            Camera.GetImageWithSoftTrigger(out bitmap, timeout);
                        }
                        else
                        {
                            Camera.GetImage(out bitmap, timeout);
                        }
                        if (bitmap != null)
                        {
                            break;
                        }
                        else if (isRegrab)
                        {
                            Debug.WriteLine($"取图失败,重新取图,剩余次数:{times}");
@@ -257,8 +274,9 @@
                    } while (times > 0 && isRegrab);
                    if (isUpParams)
                    {
                        Camera.SetCamConfig(oriConfig);
                    }
                    OutputImage = bitmap;
                }
@@ -281,14 +299,23 @@
        {
            Result = true;
            Msg = "";
            OutputImage = null;
            if (OutputImage != null)
            {
                if (OutputImage is Bitmap)
                {
                    ((Bitmap)OutputImage).Dispose();
                }
                OutputImage = null;
            }
            if (Record != null)
            {
                Record.Dispose();
            }
        }
        public override void Dispose()
        {
            return;
        }
@@ -302,7 +329,9 @@
                if (OutputImage != null)
                {
                    if (OutputImage is Bitmap)
                    {
                        obj.OutputImage = ((Bitmap)OutputImage).Clone();
                    }
                }
                return obj;