From 45a1c9f2540754e7cea2b58cd736bc677b2d4fdc Mon Sep 17 00:00:00 2001
From: patrick.xu <patrick.xu@broconcentric.com>
Date: 星期四, 28 七月 2022 17:45:28 +0800
Subject: [PATCH] 海康相机测试修改

---
 Lib/HikCamera/MvCameraControl.Net.dll                           |    0 
 LLMF/LLMF.csproj                                                |   21 +
 LLMF/Toolkit/ConfigStruct.cs                                    |    2 
 PointGreyAndHalcon/PointGreyAndHalcon/PointGreyAndHalcon.csproj |    7 
 PointGreyAndHalcon/PointGreyAndHalcon/PointGreyAndHalcon.cs     |  506 ++++++++++++++++++++++++++++++++------------------
 LLMF/frmMain.cs                                                 |    9 
 README.md                                                       |    6 
 7 files changed, 348 insertions(+), 203 deletions(-)

diff --git a/LLMF/LLMF.csproj b/LLMF/LLMF.csproj
index b0663ff..9898c40 100644
--- a/LLMF/LLMF.csproj
+++ b/LLMF/LLMF.csproj
@@ -29,7 +29,7 @@
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
     <PlatformTarget>AnyCPU</PlatformTarget>
-    <Prefer32Bit>true</Prefer32Bit>
+    <Prefer32Bit>false</Prefer32Bit>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <DebugType>pdbonly</DebugType>
@@ -44,19 +44,11 @@
     <Reference Include="dog_net_windows">
       <HintPath>..\Lib\SuperDog\dog_net_windows.dll</HintPath>
     </Reference>
-    <Reference Include="FlyCapture2Managed_v100, Version=2.8.3.1, Culture=neutral, PublicKeyToken=76c6583b4a4585f4, processorArchitecture=x86">
-      <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\Lib\FlyCapture\FlyCapture2Managed_v100.dll</HintPath>
-    </Reference>
     <Reference Include="halcondotnet">
       <HintPath>..\Lib\halcon\halcondotnet.dll</HintPath>
     </Reference>
     <Reference Include="hdevenginedotnet">
       <HintPath>..\Lib\halcon\hdevenginedotnet.dll</HintPath>
-    </Reference>
-    <Reference Include="Interop.OPCAutomation">
-      <HintPath>..\Lib\Interop.OPCAutomation.dll</HintPath>
-      <EmbedInteropTypes>True</EmbedInteropTypes>
     </Reference>
     <Reference Include="PresentationCore">
       <RequiredTargetFramework>3.0</RequiredTargetFramework>
@@ -181,6 +173,17 @@
       <Name>PointGreyAndHalcon</Name>
     </ProjectReference>
   </ItemGroup>
+  <ItemGroup>
+    <COMReference Include="OPCAutomation">
+      <Guid>{28E68F91-8D75-11D1-8DC3-3C302A000000}</Guid>
+      <VersionMajor>1</VersionMajor>
+      <VersionMinor>0</VersionMinor>
+      <Lcid>0</Lcid>
+      <WrapperTool>tlbimp</WrapperTool>
+      <Isolated>False</Isolated>
+      <EmbedInteropTypes>True</EmbedInteropTypes>
+    </COMReference>
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.
diff --git a/LLMF/Toolkit/ConfigStruct.cs b/LLMF/Toolkit/ConfigStruct.cs
index 2861497..507a498 100644
--- a/LLMF/Toolkit/ConfigStruct.cs
+++ b/LLMF/Toolkit/ConfigStruct.cs
@@ -61,7 +61,7 @@
 
     public struct CamerasConfig
     {
-        public uint[] SerialNumber;
+        public string[] SerialNumber;
     }
 
     [Serializable]
diff --git a/LLMF/frmMain.cs b/LLMF/frmMain.cs
index a96d35b..cf7ec0b 100644
--- a/LLMF/frmMain.cs
+++ b/LLMF/frmMain.cs
@@ -57,6 +57,8 @@
         public frmMain()
         {
             InitializeComponent();
+
+            //this.Load += frmMain_Load;
         }
 
         private void frmMain_Load(object sender, EventArgs e)
@@ -175,8 +177,8 @@
                 config.opcConfig.groupProperty.updateRate = 300;
                 config.title = "LLMF V1.1";
                 config.cams = new CamerasConfig();
-                config.cams.SerialNumber = new uint[1];
-                config.cams.SerialNumber[0] = 11111111;
+                config.cams.SerialNumber = new string[1];
+                config.cams.SerialNumber[0] = "192.168.0.10";
                 config.password = "1";
                 config.minAngle = 119;
                 config.maxAngle = 121;
@@ -2092,7 +2094,8 @@
             Log.WriteLog("initCam_Left Enter");
 
             cam_left = new PointGreyAndHalcon.PointGreyAndHalcon();
-            isLeftCameraOpen = cam_left.OpenCamera(config.cams.SerialNumber[0]);
+            string ipAddress = config?.cams.SerialNumber[0] ?? "";
+            isLeftCameraOpen = cam_left.OpenCamera(ipAddress);
             cam_left.GrabImageDone += new GrabImageDoneDelegate(cam_left_GrabImageDone);
 
             Log.WriteLog("initCam_Left Leave");
diff --git a/Lib/HikCamera/MvCameraControl.Net.dll b/Lib/HikCamera/MvCameraControl.Net.dll
new file mode 100644
index 0000000..635662b
--- /dev/null
+++ b/Lib/HikCamera/MvCameraControl.Net.dll
Binary files differ
diff --git a/PointGreyAndHalcon/PointGreyAndHalcon/PointGreyAndHalcon.cs b/PointGreyAndHalcon/PointGreyAndHalcon/PointGreyAndHalcon.cs
index 2fc2fd9..7611ec4 100644
--- a/PointGreyAndHalcon/PointGreyAndHalcon/PointGreyAndHalcon.cs
+++ b/PointGreyAndHalcon/PointGreyAndHalcon/PointGreyAndHalcon.cs
@@ -6,7 +6,10 @@
 using System.Drawing;
 using System.Drawing.Imaging;
 using HalconDotNet;
-using FlyCapture2Managed;
+using System.Net;
+using MvCamCtrl.NET;
+using System.Runtime.InteropServices;
+//using FlyCapture2Managed;
 
 namespace PointGreyAndHalcon
 {
@@ -15,11 +18,7 @@
     public class PointGreyAndHalcon
     {
         #region 瀹氫箟
-        ManagedBusManager busMgr = new ManagedBusManager();
-        //CameraInfo[] camInfos = ManagedBusManager.DiscoverGigECameras();
         int camNum;
-        ManagedPGRGuid guid;
-        ManagedGigECamera cam;
 
         public HImage image = new HImage();
         public event GrabImageDoneDelegate GrabImageDone;
@@ -27,57 +26,162 @@
 
         HImage tmpImage = new HImage();
         bool isCameraOpen = false;
-        //bool isRightCameraOpen = false;
+
+        static MyCamera.MV_CC_DEVICE_INFO_LIST m_pDeviceList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
+        readonly MyCamera device = new MyCamera();
+        MyCamera.MV_CC_DEVICE_INFO stDevInfo = new MyCamera.MV_CC_DEVICE_INFO();
+        int nRet = MyCamera.MV_OK;
         #endregion
 
         public PointGreyAndHalcon()
         {
-            //camNum = camInfos.Length;
         }
+
+        ///// <summary>
+        ///// 鎵撳紑鐩告満
+        ///// </summary>
+        ///// <param name="index">缂栧彿</param>
+        //public void OpenCamera(int index)
+        //{
+        //    try
+        //    {
+        //        guid = busMgr.GetCameraFromIndex((uint)index);
+        //        cam = new ManagedGigECamera();
+        //        cam.Connect(guid);
+        //        cam.StartCapture();
+        //        isCameraOpen = true;
+        //    }
+        //    catch (Exception ex)
+        //    {
+        //        MessageBox.Show("鐩告満" + index.ToString() + "鎵撳紑澶辫触");
+
+        //    }
+        //}
 
         /// <summary>
         /// 鎵撳紑鐩告満
         /// </summary>
-        /// <param name="index">缂栧彿</param>
-        public void OpenCamera(int index)
+        /// <param name="serialnumber">IP鍦板潃</param>
+        public bool OpenCamera(string ipAddress)
         {
             try
             {
-                guid = busMgr.GetCameraFromIndex((uint)index);
-                cam = new ManagedGigECamera();
-                cam.Connect(guid);
-                cam.StartCapture();
-                isCameraOpen = true;
-            }
-            catch (Exception ex)
-            {
-                MessageBox.Show("鐩告満" + index.ToString() + "鎵撳紑澶辫触");
+                //灏咺P鍦板潃杞崲涓哄瓧鑺傛暟缁� 
+                uint intAddress = 0;
+                if (!string.IsNullOrWhiteSpace(ipAddress))
+                {
+                    byte[] IPArr = IPAddress.Parse(ipAddress).GetAddressBytes();
+                    for (int i = 0; i < IPArr.Length; i++)
+                    {
+                        intAddress += (uint)(IPArr[i] << (IPArr.Length - 1 - i) * 8);
+                    }
+                }
 
-            }
-        }
+                if (m_pDeviceList.pDeviceInfo == null)
+                {
+                    int nRet = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE, ref m_pDeviceList);
+                    if (0 != nRet)
+                    {
+                        throw new Exception($"Enumerate devices fail!");
+                    }
+                }
 
-        /// <summary>
-        /// 鎵撳紑鐩告満
-        /// </summary>
-        /// <param name="serialnumber">搴忓垪鍙�</param>
-        public bool OpenCamera(uint serialnumber)
-        {
-            try
-            {
-                guid = busMgr.GetCameraFromSerialNumber(serialnumber);
-                cam = new ManagedGigECamera();
-                cam.Connect(guid);
+                bool isCameraFound = false;
+                for (int i = 0; i < m_pDeviceList.nDeviceNum; i++)
+                {
+                    MyCamera.MV_CC_DEVICE_INFO device = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(m_pDeviceList.pDeviceInfo[i], typeof(MyCamera.MV_CC_DEVICE_INFO));
+                    IntPtr buffer = IntPtr.Zero;
 
-                cam.WriteRegister(0x610, 0x00000000);//鎺у埗鐩告満涓婄數
-                System.Threading.Thread.Sleep(100);
-                cam.WriteRegister(0x610, 0x80000000);//鎺у埗鐩告満涓嬬數
+                    buffer = Marshal.UnsafeAddrOfPinnedArrayElement(device.SpecialInfo.stGigEInfo, 0);
+                    MyCamera.MV_GIGE_DEVICE_INFO stGigEDev = (MyCamera.MV_GIGE_DEVICE_INFO)Marshal.PtrToStructure(buffer, typeof(MyCamera.MV_GIGE_DEVICE_INFO));
 
-                cam.StartCapture();
+                    if (stGigEDev.nCurrentIp == intAddress)
+                    {
+                        stDevInfo = device;
+                        isCameraFound = true;
+                    }
+                    if (isCameraFound)
+                        break;
+                }
+
+                if (!isCameraFound)
+                {
+                    throw new Exception($"鐩告満{ipAddress}鏈兘鎵惧埌");
+                }
+
+                // ch:鍒涘缓璁惧 | en: Create device
+                nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
+
+                if (MyCamera.MV_OK != nRet)
+                {
+                    throw new Exception($"Create device failed:{nRet:x8}");
+                }
+
+                // ch:鎵撳紑璁惧 | en:Open device
+                nRet = device.MV_CC_OpenDevice_NET();
+                if (MyCamera.MV_OK != nRet)
+                {
+                    throw new Exception($"Open device failed:{nRet:x8}");
+                }
+
+                // ch:鎺㈡祴缃戠粶鏈�浣冲寘澶у皬(鍙GigE鐩告満鏈夋晥) | en:Detection network optimal package size(It only works for the GigE camera)
+                int nPacketSize = device.MV_CC_GetOptimalPacketSize_NET();
+                if (nPacketSize > 0)
+                {
+                    nRet = device.MV_CC_SetIntValue_NET("GevSCPSPacketSize", (uint)nPacketSize);
+                    if (nRet != MyCamera.MV_OK)
+                    {
+                        Console.WriteLine("Warning: Set Packet Size failed {0:x8}", nRet);
+                    }
+                }
+                else
+                {
+                    Console.WriteLine("Warning: Get Packet Size failed {0:x8}", nPacketSize);
+                }
+
+                //// ch:娉ㄥ唽鍥炶皟鍑芥暟 | en:Register image callback
+                //ImageCallback = new MyCamera.cbOutputExdelegate(ImageCallbackFunc);
+                //nRet = device.MV_CC_RegisterImageCallBackEx_NET(ImageCallback, IntPtr.Zero);
+                //if (MyCamera.MV_OK != nRet)
+                //{
+                //    throw new Exception("Register image callback failed!");
+                //}
+
+                // ch:璁剧疆閲囬泦杩炵画妯″紡 | en:Set Continues Aquisition Mode
+                device.MV_CC_SetEnumValue_NET("AcquisitionMode", 2);// ch:宸ヤ綔鍦ㄨ繛缁ā寮� | en:Acquisition On Continuous Mode
+
+                // ch:璁剧疆瑙﹀彂妯″紡涓篛n || en:set trigger mode as on
+                nRet = device.MV_CC_SetEnumValue_NET("TriggerMode", 1);
+                if (MyCamera.MV_OK != nRet)
+                {
+                    throw new Exception("Set TriggerMode failed!");
+                }
+
+                //7 璁剧疆杞欢瑙﹀彂
+                nRet = device.MV_CC_SetEnumValue_NET("TriggerSource", (uint)7);
+                if (MyCamera.MV_OK != nRet)
+                {
+                    throw new Exception($"Set Software Trigger failed!");
+                }
+
+                ////璁剧疆鍙栧浘缂撳瓨鑺傜偣
+                //device.MV_CC_SetImageNodeNum_NET((uint)IIConfig.ImageNodeNum);
+
+                // ch:寮�鍚姄鍥� || en: start grab image
+                nRet = device.MV_CC_StartGrabbing_NET();
+                if (MyCamera.MV_OK != nRet)
+                {
+                    throw new Exception($"Start grabbing failed:{nRet:x8}");
+                }
+
+                //鍙栨秷鑷姩鏇濆厜
+                device.MV_CC_SetEnumValue_NET("ExposureAuto", 0);
+
                 return true;
             }
             catch (Exception ex)
             {
-                MessageBox.Show("鐩告満" + serialnumber.ToString() + "鎵撳紑澶辫触");
+                MessageBox.Show($"鐩告満{ipAddress}鎵撳紑澶辫触\r\n{ex.Message}");
                 return false;
             }
         }
@@ -101,57 +205,76 @@
         //    }
         //}
 
-        private void Test(ManagedImage image)
-        {
-            lock (GetMutexLock())
-            {
-                SerialNo = "";
-                try
-                {
-                    //ManagedImage rawImage = new ManagedImage();
+        //private void Test(ManagedImage image)
+        //{
+        //    lock (GetMutexLock())
+        //    {
+        //        SerialNo = "";
+        //        try
+        //        {
+        //            //ManagedImage rawImage = new ManagedImage();
 
-                    // Retrieve an image
-                    //cam.RetrieveBuffer(rawImage);
+        //            // Retrieve an image
+        //            //cam.RetrieveBuffer(rawImage);
 
-                    // Create a converted image
-                    ManagedImage convertedImage = new ManagedImage();
+        //            // Create a converted image
+        //            ManagedImage convertedImage = new ManagedImage();
 
-                    // Convert the raw image
-                    image.Convert(FlyCapture2Managed.PixelFormat.PixelFormatMono8, convertedImage);
+        //            // Convert the raw image
+        //            image.Convert(FlyCapture2Managed.PixelFormat.PixelFormatMono8, convertedImage);
 
-                    //converterImage to HImage
-                    Bitmap tmpBmp = convertedImage.bitmap;
-                    BitmapData tmpBitmapData = tmpBmp.LockBits(new Rectangle(0, 0, tmpBmp.Width, tmpBmp.Height), ImageLockMode.ReadOnly,
-                        System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
+        //            //converterImage to HImage
+        //            Bitmap tmpBmp = convertedImage.bitmap;
+        //            BitmapData tmpBitmapData = tmpBmp.LockBits(new Rectangle(0, 0, tmpBmp.Width, tmpBmp.Height), ImageLockMode.ReadOnly,
+        //                System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
 
-                    tmpImage.GenImage1("byte", tmpBmp.Width, tmpBmp.Height, tmpBitmapData.Scan0);
+        //            tmpImage.GenImage1("byte", tmpBmp.Width, tmpBmp.Height, tmpBitmapData.Scan0);
 
-                    if (GrabImageDone != null)
-                    {
-                        GrabImageDone("GrabSuccess", tmpImage);
-                    }
+        //            if (GrabImageDone != null)
+        //            {
+        //                GrabImageDone("GrabSuccess", tmpImage);
+        //            }
 
-                    tmpBmp.UnlockBits(tmpBitmapData);
-                    image.Dispose();
-                    convertedImage.Dispose();
-                    tmpBmp.Dispose();
-                }
-                catch (Exception ex)
-                {
-                    if (GrabImageDone != null)
-                    {
-                        GrabImageDone("GrabFail", tmpImage);
-                    }
-                }
-            }
-        }
+        //            tmpBmp.UnlockBits(tmpBitmapData);
+        //            image.Dispose();
+        //            convertedImage.Dispose();
+        //            tmpBmp.Dispose();
+        //        }
+        //        catch (Exception ex)
+        //        {
+        //            if (GrabImageDone != null)
+        //            {
+        //                GrabImageDone("GrabFail", tmpImage);
+        //            }
+        //        }
+        //    }
+        //}
 
         /// <summary>
         /// 鍏抽棴鐩告満
         /// </summary>
         public void CloseCamera()
         {
-            cam.StopCapture();
+            // ch:鍋滄鎶撳浘 | en:Stop grab image
+            nRet = device.MV_CC_StopGrabbing_NET();
+            if (MyCamera.MV_OK != nRet)
+            {
+                throw new Exception($"Stop grabbing failed{nRet:x8}");
+            }
+
+            // ch:鍏抽棴璁惧 | en:Close device
+            nRet = device.MV_CC_CloseDevice_NET();
+            if (MyCamera.MV_OK != nRet)
+            {
+                throw new Exception($"Close device failed{nRet:x8}");
+            }
+
+            // ch:閿�姣佽澶� | en:Destroy device
+            nRet = device.MV_CC_DestroyDevice_NET();
+            if (MyCamera.MV_OK != nRet)
+            {
+                throw new Exception($"Destroy device failed:{nRet:x8}");
+            }
         }
 
         /// <summary>
@@ -164,34 +287,43 @@
                 SerialNo = sn;
                 try
                 {
-                    ManagedImage rawImage = new ManagedImage();
-
-                    // Retrieve an image
-                    cam.RetrieveBuffer(rawImage);
-
-                    // Create a converted image
-                    ManagedImage convertedImage = new ManagedImage();
-
-                    // Convert the raw image
-                    rawImage.Convert(FlyCapture2Managed.PixelFormat.PixelFormatMono8, convertedImage);
-
-                    //converterImage to HImage
-                    Bitmap tmpBmp = convertedImage.bitmap;
-                    BitmapData tmpBitmapData = tmpBmp.LockBits(new Rectangle(0, 0, tmpBmp.Width, tmpBmp.Height), ImageLockMode.ReadOnly,
-                        System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
-
-                    tmpImage.GenImage1("byte", tmpBmp.Width, tmpBmp.Height, tmpBitmapData.Scan0);
-                    image.Dispose();
-                    image = tmpImage.CopyImage();
-                    if (GrabImageDone != null)
+                    nRet = device.MV_CC_SetCommandValue_NET("TriggerSoftware");
+                    if (MyCamera.MV_OK != nRet)
                     {
-                        GrabImageDone("GrabSuccess", tmpImage);
+                        throw new Exception($"鐩告満鎷嶇収瑙﹀彂澶辫触:{nRet}");
                     }
 
-                    tmpBmp.UnlockBits(tmpBitmapData);
-                    rawImage.Dispose();
-                    convertedImage.Dispose();
-                    tmpBmp.Dispose();
+                    MyCamera.MV_FRAME_OUT frameInfo = new MyCamera.MV_FRAME_OUT();
+                    nRet = device.MV_CC_GetImageBuffer_NET(ref frameInfo, 1000);
+
+                    // ch:鑾峰彇涓�甯у浘鍍� | en:Get one image
+                    if (MyCamera.MV_OK == nRet)
+                    {
+                        int width = frameInfo.stFrameInfo.nWidth;
+                        int height = frameInfo.stFrameInfo.nHeight;
+                        if (frameInfo.pBufAddr != IntPtr.Zero)
+                        {
+                            HImage temp = new HImage();
+                            temp.GenImage1("byte", width, height, frameInfo.pBufAddr);
+
+                            tmpImage.Dispose();
+                            tmpImage = null;
+
+                            tmpImage = temp.CopyImage();
+                            image.Dispose();
+                            image = tmpImage.CopyImage();
+                            if (GrabImageDone != null)
+                            {
+                                GrabImageDone("GrabSuccess", tmpImage);
+                            }
+
+                            nRet = device.MV_CC_FreeImageBuffer_NET(ref frameInfo);
+                            if (nRet != MyCamera.MV_OK)
+                            {
+                                Console.WriteLine("Free Image Buffer fail:{0:x8}", nRet);
+                            }
+                        }
+                    }
                 }
                 catch (Exception ex)
                 {
@@ -203,100 +335,100 @@
             }
         }
 
-        /// <summary>
-        /// 閲囧僵鑹插浘
-        /// </summary>
-        public void GrabColorImage(string sn)
-        {
-            SerialNo = sn;
-            try
-            {
-                ManagedImage rawImage = new ManagedImage();
+        ///// <summary>
+        ///// 閲囧僵鑹插浘
+        ///// </summary>
+        //public void GrabColorImage(string sn)
+        //{
+        //    SerialNo = sn;
+        //    try
+        //    {
+        //        ManagedImage rawImage = new ManagedImage();
 
-                // Retrieve an image
-                cam.RetrieveBuffer(rawImage);
+        //        // Retrieve an image
+        //        cam.RetrieveBuffer(rawImage);
 
-                // Create a converted image
-                ManagedImage convertedImage = new ManagedImage();
+        //        // Create a converted image
+        //        ManagedImage convertedImage = new ManagedImage();
 
-                // Convert the raw image
-                rawImage.Convert(FlyCapture2Managed.PixelFormat.PixelFormatBgr, convertedImage);
+        //        // Convert the raw image
+        //        rawImage.Convert(FlyCapture2Managed.PixelFormat.PixelFormatBgr, convertedImage);
 
-                //converterImage to HImage
-                Bitmap tmpBmp = convertedImage.bitmap;
-                Rectangle rect = new Rectangle(0, 0, tmpBmp.Width, tmpBmp.Height);
-                BitmapData tmpBitmapData = tmpBmp.LockBits(rect, ImageLockMode.ReadOnly,
-                    System.Drawing.Imaging.PixelFormat.Format24bppRgb);
+        //        //converterImage to HImage
+        //        Bitmap tmpBmp = convertedImage.bitmap;
+        //        Rectangle rect = new Rectangle(0, 0, tmpBmp.Width, tmpBmp.Height);
+        //        BitmapData tmpBitmapData = tmpBmp.LockBits(rect, ImageLockMode.ReadOnly,
+        //            System.Drawing.Imaging.PixelFormat.Format24bppRgb);
 
-                #region 灏哛GB鍒嗙寮�鏉�
-                //鍒涘缓鏂扮殑褰╄壊鐨刡itmap
-                Bitmap redBitmap = new Bitmap(tmpBmp.Width, tmpBmp.Height);
-                Bitmap greenBitmap = new Bitmap(tmpBmp.Width, tmpBmp.Height);
-                Bitmap blueBitmap = new Bitmap(tmpBmp.Width, tmpBmp.Height);
-                //鍒涘缓鏂扮殑褰╄壊鐨勬暟鎹鍣�
-                BitmapData redBmData = redBitmap.LockBits(rect, ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
-                BitmapData greenBmData = greenBitmap.LockBits(rect, ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
-                BitmapData blueBmData = blueBitmap.LockBits(rect, ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
-                //灏咮itmap瀵硅薄鐨勪俊鎭瓨鏀惧埌byte鏁扮粍涓�
-                int tmp_bytes = tmpBitmapData.Stride * tmpBmp.Height;
-                int red_bytes = redBmData.Stride * tmpBmp.Height;
-                int green_bytes = greenBmData.Stride * tmpBmp.Height;
-                int blue_bytes = blueBmData.Stride * tmpBmp.Height;
-                byte[] tmpValues = new byte[tmp_bytes];
-                byte[] redValues = new byte[red_bytes];
-                byte[] greenValues = new byte[green_bytes];
-                byte[] blueValues = new byte[blue_bytes];
-                //澶嶅埗GRB淇℃伅鍒癰yte鏁扮粍
-                System.Runtime.InteropServices.Marshal.Copy(tmpBitmapData.Scan0, tmpValues, 0, tmp_bytes);
-                System.Runtime.InteropServices.Marshal.Copy(redBmData.Scan0, redValues, 0, red_bytes);
-                System.Runtime.InteropServices.Marshal.Copy(greenBmData.Scan0, greenValues, 0, green_bytes);
-                System.Runtime.InteropServices.Marshal.Copy(blueBmData.Scan0, blueValues, 0, blue_bytes);
+        //        #region 灏哛GB鍒嗙寮�鏉�
+        //        //鍒涘缓鏂扮殑褰╄壊鐨刡itmap
+        //        Bitmap redBitmap = new Bitmap(tmpBmp.Width, tmpBmp.Height);
+        //        Bitmap greenBitmap = new Bitmap(tmpBmp.Width, tmpBmp.Height);
+        //        Bitmap blueBitmap = new Bitmap(tmpBmp.Width, tmpBmp.Height);
+        //        //鍒涘缓鏂扮殑褰╄壊鐨勬暟鎹鍣�
+        //        BitmapData redBmData = redBitmap.LockBits(rect, ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
+        //        BitmapData greenBmData = greenBitmap.LockBits(rect, ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
+        //        BitmapData blueBmData = blueBitmap.LockBits(rect, ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
+        //        //灏咮itmap瀵硅薄鐨勪俊鎭瓨鏀惧埌byte鏁扮粍涓�
+        //        int tmp_bytes = tmpBitmapData.Stride * tmpBmp.Height;
+        //        int red_bytes = redBmData.Stride * tmpBmp.Height;
+        //        int green_bytes = greenBmData.Stride * tmpBmp.Height;
+        //        int blue_bytes = blueBmData.Stride * tmpBmp.Height;
+        //        byte[] tmpValues = new byte[tmp_bytes];
+        //        byte[] redValues = new byte[red_bytes];
+        //        byte[] greenValues = new byte[green_bytes];
+        //        byte[] blueValues = new byte[blue_bytes];
+        //        //澶嶅埗GRB淇℃伅鍒癰yte鏁扮粍
+        //        System.Runtime.InteropServices.Marshal.Copy(tmpBitmapData.Scan0, tmpValues, 0, tmp_bytes);
+        //        System.Runtime.InteropServices.Marshal.Copy(redBmData.Scan0, redValues, 0, red_bytes);
+        //        System.Runtime.InteropServices.Marshal.Copy(greenBmData.Scan0, greenValues, 0, green_bytes);
+        //        System.Runtime.InteropServices.Marshal.Copy(blueBmData.Scan0, blueValues, 0, blue_bytes);
 
-                //灏嗗僵鑹蹭俊鎭垎鍒瓨鍌ㄥ埌RGB鏁扮粍涓�
-                for (int i = 0; i < tmpBmp.Height; i++)
-                {
-                    for (int j = 0; j < tmpBmp.Width; j++)
-                    {
-                        int k = 3 * j;
-                        redValues[i * redBmData.Stride + j] = tmpValues[i * tmpBitmapData.Stride + k + 2];
-                        greenValues[i * blueBmData.Stride + j] = tmpValues[i * tmpBitmapData.Stride + k + 1];
-                        blueValues[i * greenBmData.Stride + j] = tmpValues[i * tmpBitmapData.Stride + k];
-                    }
-                }
+        //        //灏嗗僵鑹蹭俊鎭垎鍒瓨鍌ㄥ埌RGB鏁扮粍涓�
+        //        for (int i = 0; i < tmpBmp.Height; i++)
+        //        {
+        //            for (int j = 0; j < tmpBmp.Width; j++)
+        //            {
+        //                int k = 3 * j;
+        //                redValues[i * redBmData.Stride + j] = tmpValues[i * tmpBitmapData.Stride + k + 2];
+        //                greenValues[i * blueBmData.Stride + j] = tmpValues[i * tmpBitmapData.Stride + k + 1];
+        //                blueValues[i * greenBmData.Stride + j] = tmpValues[i * tmpBitmapData.Stride + k];
+        //            }
+        //        }
 
-                //鍐嶅皢鏁扮粍淇℃伅澶嶅埗鍒癛GB
-                System.Runtime.InteropServices.Marshal.Copy(redValues, 0, redBmData.Scan0, red_bytes);
-                System.Runtime.InteropServices.Marshal.Copy(greenValues, 0, greenBmData.Scan0, green_bytes);
-                System.Runtime.InteropServices.Marshal.Copy(blueValues, 0, blueBmData.Scan0, blue_bytes);
+        //        //鍐嶅皢鏁扮粍淇℃伅澶嶅埗鍒癛GB
+        //        System.Runtime.InteropServices.Marshal.Copy(redValues, 0, redBmData.Scan0, red_bytes);
+        //        System.Runtime.InteropServices.Marshal.Copy(greenValues, 0, greenBmData.Scan0, green_bytes);
+        //        System.Runtime.InteropServices.Marshal.Copy(blueValues, 0, blueBmData.Scan0, blue_bytes);
 
-                #endregion
+        //        #endregion
 
-                tmpImage.GenImage3("byte", tmpBmp.Width, tmpBmp.Height, redBmData.Scan0, greenBmData.Scan0, blueBmData.Scan0);
+        //        tmpImage.GenImage3("byte", tmpBmp.Width, tmpBmp.Height, redBmData.Scan0, greenBmData.Scan0, blueBmData.Scan0);
 
-                if (GrabImageDone != null)
-                {
-                    GrabImageDone("GrabSuccess", tmpImage);
-                }
+        //        if (GrabImageDone != null)
+        //        {
+        //            GrabImageDone("GrabSuccess", tmpImage);
+        //        }
 
-                tmpBmp.UnlockBits(tmpBitmapData);
-                redBitmap.UnlockBits(redBmData);
-                greenBitmap.UnlockBits(greenBmData);
-                blueBitmap.UnlockBits(blueBmData);
-                rawImage.Dispose();
-                convertedImage.Dispose();
-                tmpBmp.Dispose();
-                redBitmap.Dispose();
-                greenBitmap.Dispose();
-                blueBitmap.Dispose();
-            }
-            catch (Exception ex)
-            {
-                if (GrabImageDone != null)
-                {
-                    GrabImageDone("GrabFail", tmpImage);
-                }
-            }
-        }
+        //        tmpBmp.UnlockBits(tmpBitmapData);
+        //        redBitmap.UnlockBits(redBmData);
+        //        greenBitmap.UnlockBits(greenBmData);
+        //        blueBitmap.UnlockBits(blueBmData);
+        //        rawImage.Dispose();
+        //        convertedImage.Dispose();
+        //        tmpBmp.Dispose();
+        //        redBitmap.Dispose();
+        //        greenBitmap.Dispose();
+        //        blueBitmap.Dispose();
+        //    }
+        //    catch (Exception ex)
+        //    {
+        //        if (GrabImageDone != null)
+        //        {
+        //            GrabImageDone("GrabFail", tmpImage);
+        //        }
+        //    }
+        //}
 
         /// <summary>
         /// 灏嗗浘鐗囨樉绀哄埌鍥剧浉妗嗕腑
@@ -326,10 +458,12 @@
 
         public void SetExposure(float exposure)
         {
-            CameraProperty cp = cam.GetProperty(PropertyType.Shutter);
-            cp.absValue = exposure;
-            cp.autoManualMode = false;
-            cam.SetProperty(cp);
+            device.MV_CC_SetEnumValue_NET("ExposureAuto", 0);
+            nRet = device.MV_CC_SetFloatValue_NET("ExposureTime", exposure);
+            if (nRet != MyCamera.MV_OK)
+            {
+                throw new Exception($"Exposure set failed:{nRet}");
+            }
         }
 
         private static System.Threading.Mutex _mutex;
diff --git a/PointGreyAndHalcon/PointGreyAndHalcon/PointGreyAndHalcon.csproj b/PointGreyAndHalcon/PointGreyAndHalcon/PointGreyAndHalcon.csproj
index 0eb3fd0..6a24408 100644
--- a/PointGreyAndHalcon/PointGreyAndHalcon/PointGreyAndHalcon.csproj
+++ b/PointGreyAndHalcon/PointGreyAndHalcon/PointGreyAndHalcon.csproj
@@ -39,14 +39,13 @@
     <Prefer32Bit>false</Prefer32Bit>
   </PropertyGroup>
   <ItemGroup>
-    <Reference Include="FlyCapture2Managed_v100, Version=2.8.3.1, Culture=neutral, PublicKeyToken=76c6583b4a4585f4, processorArchitecture=x86">
-      <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\..\Lib\FlyCapture\FlyCapture2Managed_v100.dll</HintPath>
-    </Reference>
     <Reference Include="halcondotnet, Version=11.0.1.0, Culture=neutral, PublicKeyToken=4973bed59ddbf2b8, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
       <HintPath>..\..\Lib\halcon\halcondotnet.dll</HintPath>
     </Reference>
+    <Reference Include="MvCameraControl.Net">
+      <HintPath>..\..\Lib\HikCamera\MvCameraControl.Net.dll</HintPath>
+    </Reference>
     <Reference Include="System" />
     <Reference Include="System.Core">
       <RequiredTargetFramework>3.5</RequiredTargetFramework>
diff --git a/README.md b/README.md
index 3749e36..8109f9d 100644
--- a/README.md
+++ b/README.md
@@ -5,3 +5,9 @@
 
 鐏扮偣鐩告満椹卞姩鍜宧alcon閮藉畨瑁�32bit绯荤粺
 
+
+20220728
+鐩告満椹卞姩鏇存崲涓篐ik鐩告満
+鍥犱负kepware鍘熷洜锛屾墍鏈夌郴缁熷彧鑳戒娇鐢�32浣峝ll銆�
+halcon瀹夎32浣嶇幆澧�
+hik鐨刣ll娉ㄦ剰浣跨敤win32鐨�

--
Gitblit v1.8.0