فهرست منبع

Merge branch 'master' of http://49.235.130.76/LN/LampInspectionMachine

刘彬 1 هفته پیش
والد
کامیت
872b8ec69b

+ 1 - 2
App.xaml.cs

@@ -2,7 +2,6 @@
 using LampInspectionMachine.Log4xml;
 using LampInspectionMachine.Model;
 using LampInspectionMachine.Views;
-using log4net.Config;
 using Prism.Ioc;
 using Prism.Unity;
 using System.ComponentModel;
@@ -20,7 +19,7 @@ namespace LampInspectionMachine
         {
 
 
-            XmlConfigurator.Configure(new FileInfo("Log4xml/log4net.config"));
+            //XmlConfigurator.Configure(new FileInfo("Log4xml/log4net.config"));
             LogHelper.Info("程序启动");
             return Container.Resolve<MainWindow>();
         }

+ 3 - 34
Cameralibs/CameraService.cs

@@ -1,4 +1,5 @@
 using LampInspectionMachine.Cameralibs.HKCamera;
+using LampInspectionMachine.Interfaces;
 using LampInspectionMachine.Model;
 using MvCamCtrl.NET;
 using System;
@@ -19,41 +20,9 @@ namespace LampInspectionMachine.Cameralibs
             _CameraCollection = new Dictionary<Guid, ICamera>();
         }
 
-        public List<string> GetDeviceEnum() 
-        {
-            GC.Collect();
-            List<CCameraInfo> m_ltDeviceList = new List<CCameraInfo>();
-            int nRet = CSystem.EnumDevices(CSystem.MV_GIGE_DEVICE | CSystem.MV_USB_DEVICE, ref m_ltDeviceList);
-            if ( 0 != nRet )
-            {
-                throw new Exception("Enumerate devices fail!");
-            }
-            List<string> listsn = new List<string>();
-            MyCamera.MV_CC_DEVICE_INFO device = default(MyCamera.MV_CC_DEVICE_INFO);
-            for ( int i = 0; i < m_ltDeviceList.Count; i++ )
-            {
-                if ( m_ltDeviceList[ i ].nTLayerType == CSystem.MV_GIGE_DEVICE )
-                {
-                    CGigECameraInfo gigeInfo = (CGigECameraInfo)m_ltDeviceList[i];
-                    listsn.Add(gigeInfo.chSerialNumber);
-                }
-                else if ( m_ltDeviceList[ i ].nTLayerType == CSystem.MV_USB_DEVICE )
-                {
-                    CGigECameraInfo usbInfo = (CGigECameraInfo)m_ltDeviceList[i];
-                    listsn.Add(usbInfo.chSerialNumber);
-                }
-
-            
-
-            }
-
-            return listsn;
-
-
-        }
         public bool CreateCamera(Guid id ,CameraInfo cameraInfo)
         {
-            ICamera  camera = new MvCamera(id, cameraInfo.SerialNumber);
+            ICamera  camera = new MvCamera(id, cameraInfo.CameraName, cameraInfo.SerialNumber);
             
 
             if ( _CameraCollection.ContainsKey(id) )
@@ -70,7 +39,7 @@ namespace LampInspectionMachine.Cameralibs
 
         public Task<bool> CreateCameraAsync(Guid id, CameraInfo cameraInfo)
         {
-            ICamera camera= new MvCamera(id, cameraInfo.SerialNumber);
+            ICamera camera= new MvCamera(id, cameraInfo.CameraName, cameraInfo.SerialNumber);
             if ( _CameraCollection.ContainsKey(id) )
             {
                 var currenCamera = _CameraCollection[id];

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 721 - 133
Cameralibs/HKCamera/MvCamera.cs


+ 0 - 138
Cameralibs/ICamera.cs

@@ -1,138 +0,0 @@
-using Cognex.VisionPro;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace LampInspectionMachine.Cameralibs
-{
-    public interface ICamera
-    {
-        string Name { get; }
-
-        Guid ID { get; }
-
-        /// <summary>
-        /// 相机品牌
-        /// </summary>
-        CameraBrand CameraBrand { get; }
-
-        /// <summary>
-        /// 厂商名
-        /// </summary>
-        string ManufacturerName { get; }
-
-        /// <summary>
-        /// 相机型号
-        /// </summary>
-        string ModelName { get; }
-
-        /// <summary>
-        /// 相机序列号
-        /// </summary>
-        string SerialNumber { get; }
-
-        /// <summary>
-        /// 相机类型
-        /// </summary>
-        CameraType CameraType { get; }
-
-        /// <summary>
-        /// 正在采集图像
-        /// </summary>
-        bool IsGrabbing { get; }
-
-        /// <summary>
-        /// 相机图像
-        /// </summary>
-        ICogImage Image { get; }
-
-        bool IsConnected { get; }
-
-        /// <summary>
-        /// 采集用时
-        /// </summary>
-        TimeSpan TotalTime { get; }
-
-        /// <summary>
-        /// 错误信息
-        /// </summary>
-        string ErrorMessage { get; }
-
-        List<string> GetListEnum();
-
-        /// <summary>
-        /// 打开相机
-        /// </summary>
-        /// <returns></returns>
-        bool OpenDevice();
-
-        /// <summary>
-        /// 关闭相机
-        /// </summary>
-        void CloseDevice();
-
-        void SetTriggerModeOn();
-        
-            
-        
-       void SetTriggerModeOff();
-
-      void  SetTriggerSoftware(int value = 7);
-
-
-        /// <summary>
-        /// 采集单张图片
-        /// </summary>
-        /// <returns></returns>
-        ICogImage Grab();
-
-    /// <summary>
-    /// 开始实时采集图像
-    /// </summary>
-    void StartGrabbing();
-
-    /// <summary>
-    /// 停止实时采集图像
-    /// </summary>
-    void StopGrabbing();
-
-    /// <summary>
-    /// 设置曝光时间
-    /// </summary>
-    /// <param name="ExposureTime"></param>
-    /// <returns></returns>
-    bool SetExposureTime(float ExposureTime);
-
-    /// <summary>
-    /// 获取曝光时间
-    /// </summary>
-    /// <returns></returns>
-    float GetExposureTime();
-
-    /// <summary>
-    /// 设置增益
-    /// </summary>
-    /// <param name="Gain"></param>
-    /// <returns></returns>
-    bool SetGain(float Gain);
-
-    /// <summary>
-    /// 获取增益
-    /// </summary>
-    /// <returns></returns>
-    float GetGain();
-
-    /// <summary>
-    /// 图像回调
-    /// </summary>
-    event Action<ICogImage,TimeSpan,string> ImageCallbackEvent;
-    /// <summary>
-    /// 相机连接状态变更时
-    /// </summary>
-    event Action<Guid, bool> CameraConnectChangedEvent;
-
-     bool CheckImageCallbackEvent(Action<ICogImage, TimeSpan, string> action);
-    }
-}

+ 76 - 87
Core/Management.cs

@@ -10,7 +10,6 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using Prism.Mvvm;
-using static Cognex.VisionPro.QuickBuild.CogJobManager;
 using LampInspectionMachine.Log4xml;
 using Cognex.VisionPro.ImageFile;
 using System.Drawing;
@@ -40,6 +39,7 @@ using System.Diagnostics;
 using LampInspectionMachine.Cameralibs.HKCamera;
 using Newtonsoft.Json.Linq;
 using OpenCvSharp.Dnn;
+using LampInspectionMachine.Interfaces;
 
 namespace LampInspectionMachine.Core
 {
@@ -73,9 +73,6 @@ namespace LampInspectionMachine.Core
         public delegate void ChangeEventHandler(ICogImage e);
         public event ChangeEventHandler OnChange;
 
-
-
-
         public CameraService CameraService { get; set; }
 
         public CogJobManager MyJobManager { get => myJobManager; set => myJobManager = value; }
@@ -101,36 +98,30 @@ namespace LampInspectionMachine.Core
         /// </summary>
         public ObservableCollection<CameraInfo> CamConfigs { get => _CamConfigs; set { SetProperty(ref _CamConfigs, value); } }
 
-
-
-
-
         public bool IsTriggerModel { get => _isTriggerModel; set { SetProperty(ref _isTriggerModel, value); } }
 
         public ICamera MyCamera { get => myCamera; set { SetProperty(ref myCamera, value); } }
 
-
         /// <summary>
         /// 相机对应模板工具
         /// </summary>
         public List<CogToolBlock> CamTemplateS { get => _CamTemplateS; set => _CamTemplateS = value; }
 
-
         public event Action<int> ToolBlockSwitched;
         /// <summary>
         /// 当前选中相机的SN
         /// </summary>
         public string CurrCameraSn { get => _CurrCameraSn; set { SetProperty(ref _CurrCameraSn, value); } }
 
-        private  ObservableCollection<CameraInfo> _CamConfigs=new ObservableCollection<CameraInfo>();
+        private ObservableCollection<CameraInfo> _CamConfigs = new ObservableCollection<CameraInfo>();
 
-        private List<CogToolBlock> _CamTemplateS=new  List<CogToolBlock>();
+        private List<CogToolBlock> _CamTemplateS = new List<CogToolBlock>();
 
         private CogToolBlock cogToolBlock1;
 
-        private CameraInfo _CurrCamConfig=null;
+        private CameraInfo _CurrCamConfig = null;
         private ICamera myCamera;
-        private  bool _isTriggerModel=false;
+        private bool _isTriggerModel = false;
 
 
         /// <summary>
@@ -138,11 +129,11 @@ namespace LampInspectionMachine.Core
         /// </summary>
         private CogJobManagerEdit myJobManagerEdit;
 
-        private ObservableCollection<string>  _CameraList=new ObservableCollection<string>();
+        private ObservableCollection<string> _CameraList = new ObservableCollection<string>();
 
-        private string _CurrCameraSn="";
+        private string _CurrCameraSn = "";
 
-        public Stopwatch stopwatch=new Stopwatch();
+        public Stopwatch stopwatch = new Stopwatch();
 
         public Management()
         {
@@ -159,7 +150,7 @@ namespace LampInspectionMachine.Core
         {
             CameraService = new CameraService();
             CameraList = FindLoadCamera();
-            if ( CamConfigs.Count == 0 )
+            if (CamConfigs.Count == 0)
             {
 
                 CamConfigs.Add(new CameraInfo() { VppFileName = "Cam1.vpp" });
@@ -168,8 +159,6 @@ namespace LampInspectionMachine.Core
                 CamConfigs.Add(new CameraInfo() { VppFileName = "Cam4.vpp" });
                 CamConfigs.Add(new CameraInfo() { VppFileName = "Cam5.vpp" });
                 CamConfigs.Add(new CameraInfo() { VppFileName = "Cam6.vpp" });
-
-
             }
         }
 
@@ -187,7 +176,7 @@ namespace LampInspectionMachine.Core
 
 
             tipService.ShowMsg("相机模板加载2%");
-            CogToolBlock cogToolBlock = ( CogToolBlock ) CogSerializer.LoadObjectFromFile(Environment.CurrentDirectory + "\\Vpp\\Cam1.vpp");
+            CogToolBlock cogToolBlock = (CogToolBlock)CogSerializer.LoadObjectFromFile(Environment.CurrentDirectory + "\\Vpp\\Cam1.vpp");
             CamTemplateS.Add(cogToolBlock);
             //tipService.ShowMsg("相机模板加载10%");
             //cogToolBlock = ( CogToolBlock ) CogSerializer.LoadObjectFromFile(Environment.CurrentDirectory + "\\Vpp\\Cam2.vpp");
@@ -219,17 +208,17 @@ namespace LampInspectionMachine.Core
         /// </summary>
         public void SoftTrigger()
         {
-            if ( isConnected )
+            if (isConnected)
             {
                 MyCamera.StopGrabbing();
                 LogHelper.Info($"软触发配置写入");
-                MyCamera.SetTriggerModeOff();
-                CurrCamConfig.TriggerMode = false;
-                MyCamera.SetTriggerSoftware();
-                if ( !MyCamera.CheckImageCallbackEvent(CamCallBack) )
-                    MyCamera.ImageCallbackEvent -= CamCallBack;
-                if ( MyCamera.CheckImageCallbackEvent(CamVisionProCallBack) )
-                    MyCamera.ImageCallbackEvent += CamVisionProCallBack;
+                //MyCamera.SetTriggerModeOff();
+                //CurrCamConfig.TriggerMode = false;
+                //MyCamera.SetTriggerSoftware();
+                //if (!MyCamera.CheckImageCallbackEvent(CamCallBack))
+                //    MyCamera.ImageCallbackEvent -= CamCallBack;
+                //if (MyCamera.CheckImageCallbackEvent(CamVisionProCallBack))
+                //    MyCamera.ImageCallbackEvent += CamVisionProCallBack;
                 LogHelper.Info($"软触发取图");
 
                 MyCamera.Grab();
@@ -242,13 +231,13 @@ namespace LampInspectionMachine.Core
         /// </summary>
         public void SoftTrigger__Continue()
         {
-            MyCamera.SetTriggerModeOff();
-            CurrCamConfig.TriggerMode = false;
-            MyCamera.SetTriggerSoftware();
-            if ( MyCamera.CheckImageCallbackEvent(CamCallBack) )
-                MyCamera.ImageCallbackEvent += CamCallBack;
-            if ( !MyCamera.CheckImageCallbackEvent(CamVisionProCallBack) )
-                MyCamera.ImageCallbackEvent -= CamVisionProCallBack;
+            //MyCamera.SetTriggerModeOff();
+            //CurrCamConfig.TriggerMode = false;
+            //MyCamera.SetTriggerSoftware();
+            //if (MyCamera.CheckImageCallbackEvent(CamCallBack))
+            //    MyCamera.ImageCallbackEvent += CamCallBack;
+            //if (!MyCamera.CheckImageCallbackEvent(CamVisionProCallBack))
+            //    MyCamera.ImageCallbackEvent -= CamVisionProCallBack;
             LogHelper.Info($"连续采集启动");
             MyCamera.StartGrabbing();
         }
@@ -257,13 +246,13 @@ namespace LampInspectionMachine.Core
         public void SetHardTrigger_CallBack()
         {
             LogHelper.Info($"硬触发模式 启动");
-            MyCamera.SetTriggerModeOn();
-            CurrCamConfig.TriggerMode = true;
-            MyCamera.SetTriggerSoftware(0);
-            if ( !MyCamera.CheckImageCallbackEvent(CamCallBack) )
-                MyCamera.ImageCallbackEvent -= CamCallBack;
-            if ( MyCamera.CheckImageCallbackEvent(CamVisionProCallBack) )
-                MyCamera.ImageCallbackEvent += CamVisionProCallBack;
+            //MyCamera.SetTriggerModeOn();
+            //CurrCamConfig.TriggerMode = true;
+            //MyCamera.SetTriggerSoftware(0);
+            //if (!MyCamera.CheckImageCallbackEvent(CamCallBack))
+            //    MyCamera.ImageCallbackEvent -= CamCallBack;
+            //if (MyCamera.CheckImageCallbackEvent(CamVisionProCallBack))
+            //    MyCamera.ImageCallbackEvent += CamVisionProCallBack;
             MyCamera.StartGrabbing();
         }
         /// <summary>
@@ -271,13 +260,13 @@ namespace LampInspectionMachine.Core
         /// </summary>
         public ObservableCollection<string> FindLoadCamera()
         {
-            List<string> listsn = CameraService.GetDeviceEnum();
-            if ( listsn.Count > 0 )
+            var listsn = MvCamera.GetDevices();
+            if (listsn.Length > 0)
             {
-                ObservableCollection<string> strings=new ObservableCollection<string>();
-                for ( int i = 0; i < listsn.Count; i++ )
+                ObservableCollection<string> strings = new ObservableCollection<string>();
+                for (int i = 0; i < listsn.Length; i++)
                 {
-                    strings.Add(listsn[ i ]);
+                    //strings.Add(listsn[i].);
                 }
                 return strings;
             }
@@ -292,17 +281,17 @@ namespace LampInspectionMachine.Core
         public void InitCamera(string name)
         {
             // 初始化相机
-            if ( isConnected && myCamera != null )
+            if (isConnected && myCamera != null)
             {
                 myCamera.CloseDevice();
                 myCamera = null;
             }
-            Guid guid= new Guid();
+            Guid guid = new Guid();
             CameraService.CreateCamera(guid, new CameraInfo() { SerialNumber = name });
             myCamera = CameraService.GetCamera(guid);
             bool res = myCamera.OpenDevice();
 
-            if ( !res )
+            if (!res)
             {
                 myCamera.CloseDevice();
                 myCamera = null;
@@ -317,13 +306,13 @@ namespace LampInspectionMachine.Core
         public void InitCameras()
         {
             CameraService = new CameraService();
-            foreach ( var item in CamConfigs )
+            foreach (var item in CamConfigs)
             {
                 try
                 {
                     CameraService.CreateCamera(item.Id, item);
                     CameraService.GetCamera(item.Id).CameraConnectChangedEvent += Management_CameraConnectChangedEvent;
-                    if ( CameraService.GetCamera(item.Id).OpenDevice() )
+                    if (CameraService.GetCamera(item.Id).OpenDevice())
                     {
 
 
@@ -333,7 +322,7 @@ namespace LampInspectionMachine.Core
 
                     }
                 }
-                catch ( Exception ex )
+                catch (Exception ex)
                 {
 
                 }
@@ -363,9 +352,9 @@ namespace LampInspectionMachine.Core
         {
             try
             {
-               
+
                 Image = image;
-              
+
             }
             finally
             {
@@ -382,9 +371,9 @@ namespace LampInspectionMachine.Core
         {
             try
             {
-                
+
                 Image = image;
-               
+
             }
             finally
             {
@@ -398,8 +387,8 @@ namespace LampInspectionMachine.Core
         {
 
             // 验证像素格式(支持MONO8/RGB8转灰度)
-            if ( pFrameInfo.enPixelType != MvCamCtrl.NET.MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8 &&
-                pFrameInfo.enPixelType != MvCamCtrl.NET.MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed )
+            if (pFrameInfo.enPixelType != MvCamCtrl.NET.MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8 &&
+                pFrameInfo.enPixelType != MvCamCtrl.NET.MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed)
             {
                 throw new ArgumentException("Unsupported pixel format");
             }
@@ -421,10 +410,10 @@ namespace LampInspectionMachine.Core
 
             // IntPtr destPtr = cogImage.GetPixelData(CogImageDataModeConstants.ReadWrite);
 
-            if ( pFrameInfo.enPixelType == MvCamCtrl.NET.MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8 )
+            if (pFrameInfo.enPixelType == MvCamCtrl.NET.MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8)
             {
                 // 直接拷贝MONO8数据
-                SafeMemoryCopy(destPtr, pData,  width * height );
+                SafeMemoryCopy(destPtr, pData, width * height);
             }
             else // RGB转灰度
             {
@@ -434,12 +423,12 @@ namespace LampInspectionMachine.Core
                 unsafe
                 {
                     byte* pDest = (byte*)destPtr.ToPointer();
-                    for ( int i = 0; i < rgbBuffer.Length; i += 3 )
+                    for (int i = 0; i < rgbBuffer.Length; i += 3)
                     {
                         // RGB转灰度公式:0.299*R + 0.587*G + 0.114*B
-                        *pDest++ = ( byte ) ( 0.299 * rgbBuffer[ i ] +
-                                         0.587 * rgbBuffer[ i + 1 ] +
-                                         0.114 * rgbBuffer[ i + 2 ] );
+                        *pDest++ = (byte)(0.299 * rgbBuffer[i] +
+                                         0.587 * rgbBuffer[i + 1] +
+                                         0.114 * rgbBuffer[i + 2]);
                     }
                 }
             }
@@ -449,7 +438,7 @@ namespace LampInspectionMachine.Core
         // 将海康相机帧数据转换为CogImage24PlanarColor彩色图像
         public static ICogImage ConvertToColorCogImage(IntPtr pData, ref MyCamera.MV_FRAME_OUT_INFO_EX pFrameInfo)
         {
-            if ( pFrameInfo.enPixelType != MvCamCtrl.NET.MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed )
+            if (pFrameInfo.enPixelType != MvCamCtrl.NET.MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed)
             {
                 throw new ArgumentException("Only RGB8 format supported for color conversion");
             }
@@ -463,9 +452,9 @@ namespace LampInspectionMachine.Core
 
             // 获取三个颜色平面指针
 
-            CogImage8Grey red= cogColorImage.GetPlane(CogImagePlaneConstants.Red);
-            CogImage8Grey green= cogColorImage.GetPlane(CogImagePlaneConstants.Green);
-            CogImage8Grey blue= cogColorImage.GetPlane(CogImagePlaneConstants.Blue);
+            CogImage8Grey red = cogColorImage.GetPlane(CogImagePlaneConstants.Red);
+            CogImage8Grey green = cogColorImage.GetPlane(CogImagePlaneConstants.Green);
+            CogImage8Grey blue = cogColorImage.GetPlane(CogImagePlaneConstants.Blue);
 
 
 
@@ -473,11 +462,11 @@ namespace LampInspectionMachine.Core
     CogImageDataModeConstants.ReadWrite,
     0, 0,
     red.Width, red.Height).Scan0;  // 获取像素数据指针
-            IntPtr greenPtr =cogColorImage.GetPlane(CogImagePlaneConstants.Green).Get8GreyPixelMemory(
+            IntPtr greenPtr = cogColorImage.GetPlane(CogImagePlaneConstants.Green).Get8GreyPixelMemory(
     CogImageDataModeConstants.ReadWrite,
     0, 0,
     red.Width, red.Height).Scan0; ;
-            IntPtr bluePtr =cogColorImage.GetPlane(CogImagePlaneConstants.Blue).Get8GreyPixelMemory(
+            IntPtr bluePtr = cogColorImage.GetPlane(CogImagePlaneConstants.Blue).Get8GreyPixelMemory(
     CogImageDataModeConstants.ReadWrite,
     0, 0,
     red.Width, red.Height).Scan0; ;
@@ -492,11 +481,11 @@ namespace LampInspectionMachine.Core
                 byte* pGreen = (byte*)greenPtr.ToPointer();
                 byte* pBlue = (byte*)bluePtr.ToPointer();
 
-                for ( int i = 0; i < rgbBuffer.Length; i += 3 )
+                for (int i = 0; i < rgbBuffer.Length; i += 3)
                 {
-                    *pRed++ = rgbBuffer[ i ];     // R
-                    *pGreen++ = rgbBuffer[ i + 1 ]; // G
-                    *pBlue++ = rgbBuffer[ i + 2 ];  // B
+                    *pRed++ = rgbBuffer[i];     // R
+                    *pGreen++ = rgbBuffer[i + 1]; // G
+                    *pBlue++ = rgbBuffer[i + 2];  // B
                 }
             }
             return cogColorImage;
@@ -506,7 +495,7 @@ namespace LampInspectionMachine.Core
         private void ImageCallback(IntPtr pData, ref MyCamera.MV_FRAME_OUT_INFO_EX pFrameInfo, IntPtr pUser)
         {
             ICogImage resultImage;
-            if ( pFrameInfo.enPixelType == MvCamCtrl.NET.MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8 )
+            if (pFrameInfo.enPixelType == MvCamCtrl.NET.MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8)
             {
                 resultImage = ConvertToCogImage(pData, ref pFrameInfo);
             }
@@ -515,7 +504,7 @@ namespace LampInspectionMachine.Core
                 resultImage = ConvertToColorCogImage(pData, ref pFrameInfo);
             }
 
-           
+
             Image = resultImage;
         }
 
@@ -530,9 +519,9 @@ namespace LampInspectionMachine.Core
             try
             {
 
-                cogToolBlock1.Inputs[ 0 ].Value = image;
+                cogToolBlock1.Inputs[0].Value = image;
                 cogToolBlock1.Run();
-                Image = ( ICogImage ) cogToolBlock1.Outputs[ 6 ].Value;
+                Image = (ICogImage)cogToolBlock1.Outputs[6].Value;
             }
             finally
             {
@@ -549,12 +538,12 @@ namespace LampInspectionMachine.Core
         public static Bitmap SafeConvert(WriteableBitmap wb)
         {
             Bitmap bmp = new Bitmap(wb.PixelWidth, wb.PixelHeight);
-            using ( var ms = new System.IO.MemoryStream() )
+            using (var ms = new System.IO.MemoryStream())
             {
                 var encoder = new PngBitmapEncoder();
                 encoder.Frames.Add(BitmapFrame.Create(wb));
                 encoder.Save(ms);
-                bmp = ( Bitmap ) System.Drawing.Image.FromStream(ms);
+                bmp = (Bitmap)System.Drawing.Image.FromStream(ms);
             }
             return bmp;
         }
@@ -566,21 +555,21 @@ namespace LampInspectionMachine.Core
         // 安全封装方法(带参数校验)
         public static void SafeMemoryCopy(IntPtr dest, IntPtr src, int byteCount)
         {
-            if ( dest == IntPtr.Zero || src == IntPtr.Zero )
+            if (dest == IntPtr.Zero || src == IntPtr.Zero)
                 throw new ArgumentNullException("指针参数不能为null");
 
-            if ( byteCount <= 0 )
+            if (byteCount <= 0)
                 throw new ArgumentOutOfRangeException("字节数必须大于0");
 
-            RtlMoveMemory(dest, src, ( uint ) byteCount);
+            RtlMoveMemory(dest, src, (uint)byteCount);
         }
         /// <summary>
         /// 将WriteableBitmap转换为CogImage8Grey(自动处理彩色转灰度)
         /// </summary>
-        
+
         public void OnSwitchToolBlock(int index)
         {
-            cogToolBlock1 = CamTemplateS[ index ];
+            cogToolBlock1 = CamTemplateS[index];
             ToolBlockSwitched?.Invoke(index); // 触发事件,传递索引参数。
         }
 

+ 168 - 0
Interfaces/ICamera.cs

@@ -0,0 +1,168 @@
+using Cognex.VisionPro;
+using LampInspectionMachine.Cameralibs;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace LampInspectionMachine.Interfaces
+{
+    public interface ICamera
+    {
+        string Name { get; }
+
+        Guid ID { get; }
+
+        /// <summary>
+        /// 相机品牌
+        /// </summary>
+        CameraBrand CameraBrand { get; }
+
+        /// <summary>
+        /// 厂商名
+        /// </summary>
+        string ManufacturerName { get; }
+
+        /// <summary>
+        /// 相机型号
+        /// </summary>
+        string ModelName { get; }
+
+        /// <summary>
+        /// 相机序列号
+        /// </summary>
+        string SerialNumber { get; }
+
+        /// <summary>
+        /// 相机类型
+        /// </summary>
+        CameraType CameraType { get; }
+
+        /// <summary>
+        /// 正在采集图像
+        /// </summary>
+        bool IsGrabbing { get; }
+
+        /// <summary>
+        /// 相机图像
+        /// </summary>
+        ICogImage Image { get; }
+
+        bool IsConnected { get; }
+
+        /// <summary>
+        /// 采集用时
+        /// </summary>
+        TimeSpan TotalTime { get; }
+
+        /// <summary>
+        /// 错误信息
+        /// </summary>
+        string ErrorMessage { get; }
+
+        UInt32 ImageWidth { get; }
+
+        UInt32 ImageHeight { get; }
+
+        /// <summary>
+        /// 打开相机
+        /// </summary>
+        /// <returns></returns>
+        bool OpenDevice();
+
+        /// <summary>
+        /// 关闭相机
+        /// </summary>
+        void CloseDevice();
+
+        /// <summary>
+        /// 采集单张图片
+        /// </summary>
+        /// <returns></returns>
+        ICogImage Grab();
+
+        /// <summary>
+        /// 开始实时采集图像
+        /// </summary>
+        void StartGrabbing();
+
+        /// <summary>
+        /// 停止实时采集图像
+        /// </summary>
+        void StopGrabbing();
+
+        /// <summary>
+        /// 设置曝光时间
+        /// </summary>
+        /// <param name="ExposureTime"></param>
+        /// <returns></returns>
+        bool SetExposureTime(float ExposureTime);
+
+        /// <summary>
+        /// 获取曝光时间
+        /// </summary>
+        /// <returns></returns>
+        float GetExposureTime();
+
+        /// <summary>
+        /// 设置增益
+        /// </summary>
+        /// <param name="Gain"></param>
+        /// <returns></returns>
+        bool SetGain(float Gain);
+
+        /// <summary>
+        /// 获取增益
+        /// </summary>
+        /// <returns></returns>
+        float GetGain();
+
+        /// <summary>
+        /// 获取触发模式
+        /// </summary>
+        /// <returns></returns>
+        bool GetTriggerMode();
+
+        /// <summary>
+        /// 设置触发模式
+        /// </summary>
+        /// <param name="mode"></param>
+        /// <param name="triggerSource"></param>
+        /// <returns></returns>
+        bool SetTriggerMode(bool mode, int triggerSource);
+
+        /// <summary>
+        /// 设置触发源
+        /// </summary>
+        /// <param name="source"></param>
+        /// <returns></returns>
+        bool SetTriggerSource(int source);
+
+        /// <summary>
+        /// 获取触发源
+        /// </summary>
+        /// <returns></returns>
+        int GetTriggerSource();
+
+        /// <summary>
+        /// 软触发
+        /// </summary>
+        void TriggerSoftware();
+
+        /// <summary>
+        /// 图像回调
+        /// </summary>
+        event Action<ICogImage, TimeSpan, string> ImageCallbackEvent;
+
+        /// <summary>
+        /// 触发取图回调事件
+        /// </summary>
+        event Action<ICogImage> GrabImageCallbackEvent;
+
+        /// <summary>
+        /// 相机连接状态变更时
+        /// </summary>
+        event Action<Guid, bool> CameraConnectChangedEvent;
+    }
+}

+ 8 - 10
LampInspectionMachine.csproj

@@ -105,8 +105,8 @@
     <Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
       <HintPath>packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll</HintPath>
     </Reference>
-    <Reference Include="log4net, Version=3.0.4.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
-      <HintPath>packages\log4net.3.0.4\lib\net462\log4net.dll</HintPath>
+    <Reference Include="log4net, Version=3.1.0.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
+      <HintPath>packages\log4net.3.1.0\lib\net462\log4net.dll</HintPath>
     </Reference>
     <Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
       <HintPath>packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
@@ -117,13 +117,9 @@
     <Reference Include="Microsoft.Xaml.Behaviors, Version=1.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
       <HintPath>packages\Microsoft.Xaml.Behaviors.Wpf.1.1.31\lib\net45\Microsoft.Xaml.Behaviors.dll</HintPath>
     </Reference>
-    <Reference Include="MvCamCtrl.Net, Version=0.0.0.0, Culture=neutral, PublicKeyToken=01e3fc1d84d12cbf, processorArchitecture=MSIL">
+    <Reference Include="MvCameraControl.Net, Version=4.5.0.2, Culture=neutral, PublicKeyToken=a3c7c5e3a730cd12, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
-      <HintPath>bin\Debug\MvCamCtrl.Net.dll</HintPath>
-    </Reference>
-    <Reference Include="MvCameraAcqTool, Version=1.0.1.0, Culture=neutral, processorArchitecture=AMD64">
-      <SpecificVersion>False</SpecificVersion>
-      <HintPath>bin\Debug\MvCameraAcqTool.dll</HintPath>
+      <HintPath>Resources\MvCameraControl.Net.dll</HintPath>
     </Reference>
     <Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
       <HintPath>packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
@@ -200,7 +196,6 @@
     <Reference Include="Unity.Container, Version=5.11.11.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0, processorArchitecture=MSIL">
       <HintPath>packages\Unity.Container.5.11.11\lib\net48\Unity.Container.dll</HintPath>
     </Reference>
-    <Reference Include="Cognex.VisionPro.QuickBuild" />
     <Reference Include="Cognex.VisionPro.QuickBuild.Controls" />
     <Reference Include="WindowsBase" />
     <Reference Include="PresentationCore" />
@@ -220,7 +215,7 @@
     <Compile Include="Cameralibs\CameraService.cs" />
     <Compile Include="Cameralibs\CameraType.cs" />
     <Compile Include="Cameralibs\HKCamera\MvCamera.cs" />
-    <Compile Include="Cameralibs\ICamera.cs" />
+    <Compile Include="Interfaces\ICamera.cs" />
     <Compile Include="Core\Management.cs" />
     <Compile Include="Core\TipService.cs" />
     <Compile Include="Core\VisionProManager.cs" />
@@ -340,6 +335,9 @@
       <SubType>Designer</SubType>
     </Page>
   </ItemGroup>
+  <ItemGroup>
+    <Content Include="Resources\MvCameraControl.Net.dll" />
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
     <PropertyGroup>

+ 0 - 6
Log4xml/LogHelper.cs

@@ -5,12 +5,6 @@ namespace LampInspectionMachine.Log4xml
 {
     public class LogHelper
     {
-
-
-
-
-
-
         public delegate void LogChangHandler(Log log);
 
         public static LogChangHandler logChangHandler;

+ 64 - 5
Model/CameraInfo.cs

@@ -43,8 +43,6 @@ namespace LampInspectionMachine.Model
 
         private float gain;
 
-        private string _Sn;
-
         private string _VppFileName;
 
 
@@ -57,9 +55,65 @@ namespace LampInspectionMachine.Model
 
         public float Gain { get => gain; set { SetProperty(ref gain, value); } }
 
-        public string Sn { get => _Sn; set { SetProperty(ref _Sn, value); } }
         public string VppFileName { get => _VppFileName; set { SetProperty(ref _VppFileName, value); } }
 
+        private string _CameraName;
+        /// <summary>
+        /// 相机名称
+        /// </summary>
+        public string CameraName
+        {
+            get { return _CameraName; }
+            set { SetProperty(ref _CameraName, value); }
+        }
+
+        private string _Model;
+        /// <summary>
+        /// 相机型号
+        /// </summary>
+        public string Model
+        {
+            get { return _Model; }
+            set { SetProperty(ref _Model, value); }
+        }
+
+        private string _ManufacturerName;
+        /// <summary>
+        /// 厂商名
+        /// </summary>
+        public string ManufacturerName
+        {
+            get { return _ManufacturerName; }
+            set { SetProperty(ref _ManufacturerName, value); }
+        }
+
+        private CameraType _CameraType;
+        /// <summary>
+        /// 相机类型
+        /// </summary>
+        public CameraType CameraType
+        {
+            get { return _CameraType; }
+            set { SetProperty(ref _CameraType, value); }
+        }
+
+        private CameraBrand _CameraBrand;
+        /// <summary>
+        /// 相机品牌
+        /// </summary>
+        public CameraBrand CameraBrand
+        {
+            get { return _CameraBrand; }
+            set { SetProperty(ref _CameraBrand, value); }
+        }
+
+        private string _CameraIp;
+        public string CameraIp
+        {
+            get { return _CameraIp; }
+            set { SetProperty(ref _CameraIp, value); }
+        }
+
         public CameraInfo Copy()
         {
 
@@ -68,14 +122,19 @@ namespace LampInspectionMachine.Model
             {
                 ExpouseTime = ExpouseTime,
                 Gain = Gain,
-                Sn = Sn,
                 TriggerDelay = TriggerDelay,
                 TriggerFilter = TriggerFilter,
                 TriggerPolarity = TriggerPolarity,
                 TriggeSource = TriggeSource,
                 VppFileName = VppFileName,
                 TriggerMode = TriggerMode,
-
+                CameraName = this.CameraName,
+                Model = this.Model,
+                SerialNumber = this.SerialNumber,
+                ManufacturerName = this.ManufacturerName,
+                CameraType = this.CameraType,
+                CameraBrand = this.CameraBrand,
+                CameraIp = this.CameraIp
             };
         }
 

BIN
Resources/MvCameraControl.Net.dll


+ 2 - 1
Views/CameraView.xaml

@@ -13,7 +13,8 @@
              FontFamily="微软雅黑"
              FontSize="10"
              d:DesignHeight="800"
-             d:DesignWidth="800">
+             d:DesignWidth="800"
+             d:Background="White">
     <UserControl.Resources>
         <Style x:Key="buttonborder"
                TargetType="Border">

+ 2 - 1
Views/MenuView.xaml

@@ -8,7 +8,8 @@
              prism:ViewModelLocator.AutoWireViewModel="True"
              mc:Ignorable="d"
              d:DesignHeight="450"
-             d:DesignWidth="800">
+             d:DesignWidth="800"
+             d:Background="White">
     <UserControl.Resources>
         <Style x:Key="buttonborder"
                TargetType="Border">

+ 2 - 1
Views/ProductView.xaml

@@ -7,7 +7,8 @@
              xmlns:prism="http://prismlibrary.com/"
              prism:ViewModelLocator.AutoWireViewModel="True"
              mc:Ignorable="d"
-             d:DesignHeight="450" d:DesignWidth="800">
+             d:DesignHeight="450" d:DesignWidth="800"
+             d:Background="White">
     <UserControl.Resources>
         <Style  TargetType="{x:Type GridViewColumnHeader}">
             <Setter Property="OverridesDefaultStyle"

+ 42 - 22
Views/RoleLoginView.xaml

@@ -10,7 +10,10 @@
         mc:Ignorable="d"
         FontFamily="微软雅黑"
         WindowStyle="None"
-        Title="RoleLoginView" Height="360" Width="650">
+        Title="RoleLoginView"
+        Height="360"
+        Width="650"
+        d:Background="White">
     <WindowChrome.WindowChrome>
         <WindowChrome GlassFrameThickness="50"
                       CaptionHeight="30"
@@ -225,7 +228,10 @@
         </Style>
     </Window.Resources>
     <Grid Background="Transparent">
-        <Border BorderBrush="AliceBlue" BorderThickness="2" Margin="10" CornerRadius="10">
+        <Border BorderBrush="AliceBlue"
+                BorderThickness="2"
+                Margin="10"
+                CornerRadius="10">
             <Border.Background>
                 <LinearGradientBrush>
                     <GradientStop Color="#95DDFD"
@@ -236,11 +242,12 @@
                                   Offset="0.9" />
                 </LinearGradientBrush>
             </Border.Background>
-            <Grid Background="White" Opacity="0.8">
+            <Grid Background="White"
+                  Opacity="0.8">
                 <Grid.RowDefinitions>
-                    <RowDefinition Height="60"/>
-                    <RowDefinition Height="Auto"/>
-                    <RowDefinition Height="Auto"/>
+                    <RowDefinition Height="60" />
+                    <RowDefinition Height="Auto" />
+                    <RowDefinition Height="Auto" />
                     <RowDefinition />
                 </Grid.RowDefinitions>
                 <Grid Grid.Row="0">
@@ -248,7 +255,8 @@
                         <ColumnDefinition />
                         <ColumnDefinition />
                     </Grid.ColumnDefinitions>
-                    <StackPanel Orientation="Horizontal" Grid.Column="0">
+                    <StackPanel Orientation="Horizontal"
+                                Grid.Column="0">
                         <Ellipse Fill="#8A2BE1"
                                  Width="50"
                                  Height="50"
@@ -260,12 +268,14 @@
                                    Margin="10"
                                    FontWeight="Bold" />
                     </StackPanel>
-                    <TextBlock Text="Login" Grid.Column="0"
+                    <TextBlock Text="Login"
+                               Grid.Column="0"
                                HorizontalAlignment="Left"
                                Margin="5"
                                VerticalAlignment="Center"
                                FontSize="14" />
-                    <StackPanel Grid.Column="1" HorizontalAlignment="Right">
+                    <StackPanel Grid.Column="1"
+                                HorizontalAlignment="Right">
                         <Border Style="{StaticResource buttonborder}">
 
                             <Button Content="关闭"
@@ -281,7 +291,9 @@
                         </Border>
                     </StackPanel>
                 </Grid>
-                <Grid Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center">
+                <Grid Grid.Row="1"
+                      VerticalAlignment="Center"
+                      HorizontalAlignment="Center">
                     <StackPanel>
                         <TextBlock Text="登录"
                                    Foreground="Black"
@@ -296,17 +308,16 @@
                                   Width="180"
                                   Height="30"
                                   SelectedItem="{Binding CurrRole}"
-                                  ItemsSource="{Binding RolesList}"/>
+                                  ItemsSource="{Binding RolesList}" />
                     </StackPanel>
                 </Grid>
                 <Grid Grid.Row="2">
                     <StackPanel VerticalAlignment="Bottom"
-                                HorizontalAlignment="Center"
-                               >
-           
+                                HorizontalAlignment="Center">
+
                         <PasswordBox x:Name="PasswordBox"
-                                         Margin="5,20,5,5"
-                                         Width="180"
+                                     Margin="5,20,5,5"
+                                     Width="180"
                                      Height="30"
                                      VerticalContentAlignment="Bottom"
                                      FontSize="20"
@@ -318,16 +329,25 @@
                                 </i:EventTrigger>
                             </i:Interaction.Triggers>
                         </PasswordBox>
-                       
+
                     </StackPanel>
                 </Grid>
                 <Grid Grid.Row="3">
-                    
-                    <StackPanel HorizontalAlignment="Stretch"  VerticalAlignment="Center" Width="180">
+
+                    <StackPanel HorizontalAlignment="Stretch"
+                                VerticalAlignment="Center"
+                                Width="180">
                         <TextBlock  TextAlignment="Center"
                                     Background="{ Binding L_Brush}"
-                                    Text="{Binding Loginstr}" FontSize="12" FontWeight="Bold" FontFamily="微软雅黑" Margin="50,0,50,10"/>
-                        <Border Background="#0A85D9"  BorderBrush="Black" BorderThickness="1" CornerRadius="8">
+                                    Text="{Binding Loginstr}"
+                                    FontSize="12"
+                                    FontWeight="Bold"
+                                    FontFamily="微软雅黑"
+                                    Margin="50,0,50,10" />
+                        <Border Background="#0A85D9"
+                                BorderBrush="Black"
+                                BorderThickness="1"
+                                CornerRadius="8">
                             <Button Content="登录"
                                     Name="loginbtu"
                                     Background="Transparent"
@@ -336,7 +356,7 @@
                                     Margin="5"
                                     BorderThickness="0"
                                     Command="{Binding LogoutCommand}"
-                                    CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}"/>
+                                    CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}" />
                         </Border>
                     </StackPanel>
                 </Grid>

+ 2 - 1
Views/SettingView.xaml

@@ -8,7 +8,8 @@
              prism:ViewModelLocator.AutoWireViewModel="True"
              mc:Ignorable="d"
              d:DesignHeight="700"
-             d:DesignWidth="1000">
+             d:DesignWidth="1000"
+             d:Background="White">
     <UserControl.Resources>
         <Style x:Key="textborder"
                TargetType="Border">

+ 14 - 12
Views/WorkRunView.xaml

@@ -1,24 +1,26 @@
 <UserControl x:Class="LampInspectionMachine.Views.WorkRunView"
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
              xmlns:local="clr-namespace:LampInspectionMachine.Views"
              xmlns:prism="http://prismlibrary.com/"
              prism:ViewModelLocator.AutoWireViewModel="True"
-             mc:Ignorable="d" 
-             d:DesignHeight="450" d:DesignWidth="1200">
+             mc:Ignorable="d"
+             d:DesignHeight="450"
+             d:DesignWidth="1200"
+             d:Background="White">
     <Grid>
         <Grid.RowDefinitions>
-            <RowDefinition Height="Auto"/>
-            <RowDefinition Height="*"/>
-            <RowDefinition Height="Auto"/>
+            <RowDefinition Height="Auto" />
+            <RowDefinition Height="*" />
+            <RowDefinition Height="Auto" />
         </Grid.RowDefinitions>
         <Grid.ColumnDefinitions>
             <ColumnDefinition />
-            <ColumnDefinition Width="Auto"/>
+            <ColumnDefinition Width="Auto" />
         </Grid.ColumnDefinitions>
-        
+
         <Border  Grid.Row="1"
                  Grid.Column="0"
                  Margin="5"
@@ -26,7 +28,7 @@
                  BorderThickness="2"
                  CornerRadius="5"
                  Padding="1">
-         
+
         </Border>
         <Border  Grid.Row="1"
                  Grid.Column="1"
@@ -34,15 +36,15 @@
                  Padding="1">
             <Grid>
                 <Grid.RowDefinitions>
-                    <RowDefinition Height="Auto"/>
+                    <RowDefinition Height="Auto" />
                     <RowDefinition />
                 </Grid.RowDefinitions>
-            
+
                 <Border Grid.Row="1"
                         Margin="30"
                         BorderBrush="#7AB0F0"
                         BorderThickness="2">
-                    
+
                 </Border>
 
             </Grid>

+ 1 - 0
packages.config

@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
   <package id="EntityFramework" version="6.4.4" targetFramework="net48" />
+  <package id="log4net" version="3.1.0" targetFramework="net48" />
   <package id="Microsoft.Xaml.Behaviors.Wpf" version="1.1.31" targetFramework="net48" />
   <package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
   <package id="OpenCvSharp4" version="4.10.0.20241108" targetFramework="net48" />

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است