Parcourir la source

增加picosmart api

zhongyongming il y a 11 mois
Parent
commit
4b9e1ebc00

+ 2 - 0
OTSIncAMeasureApp/OTSIncAMeasureApp.csproj

@@ -582,6 +582,8 @@
     <Compile Include="ServiceCenter\OxfordExtender\OxfordEDSController.cs" />
     <Compile Include="ServiceCenter\OxfordExtender\OxfordScanController.cs" />
     <Compile Include="ServiceCenter\OxfordExtender\OxfordSemController.cs" />
+    <Compile Include="ServiceCenter\PicoSmart\PicoSartScanController.cs" />
+    <Compile Include="ServiceCenter\PicoSmart\PicoSmartApi_cshape.cs" />
     <EmbeddedResource Include="1-OTSMeasure\Measure\ParamData\DIALOG_CHECK_PARAM_RESULT.resx">
       <DependentUpon>DIALOG_CHECK_PARAM_RESULT.cs</DependentUpon>
     </EmbeddedResource>

+ 13 - 0
OTSIncAMeasureApp/ServiceCenter/CPP(Bruker)API/ScanController.cs

@@ -48,6 +48,19 @@ namespace OTSModelSharp.ServiceCenter
                     
                     scanctrl = new OxfordScanController(imageSrcType);
                 }
+                else if(semtype=="PicoSmart")
+                {
+                    var srcType = FileHelper.GetOxfordInputSourceType();
+                    scanctrl = new PicoSartScanController();
+                    if (srcType == "SE")
+                    {
+
+                    }
+                    else if(srcType == "BSE")
+                    {
+
+                    }
+                }
                 else 
                 { 
                     scanctrl = new ScanController(semtype); 

+ 166 - 0
OTSIncAMeasureApp/ServiceCenter/PicoSmart/PicoSartScanController.cs

@@ -0,0 +1,166 @@
+using OTSModelSharp.ServiceCenter;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using OTSMeasureApp.ServiceCenter;
+using OTSCLRINTERFACE;
+using OxfordExtenderWrapper;
+using System.Drawing;
+using static OxfordExtenderWrapper.ExtenderIpcUI;
+using OpenCvSharp;
+using System.Runtime.InteropServices.WindowsRuntime;
+using System.Threading;
+using OpenCvSharp.Extensions;
+using System.Drawing.Imaging;
+using System.IO;
+
+namespace OTSMeasureApp.ServiceCenter
+{
+    public class PicoSartScanController : IScanController
+    {
+        public PicoSmartApi_cshape m_api;
+        private int imageWidth = 640;
+        private int imageHeight = 480;
+        double dwelltime = 10;
+        int port = 7321;
+        string ip = "127.0.0.1";
+
+        /// <summary>
+        /// //se 0;bse 1;se_bse 2;
+        /// </summary>
+        int scan_chanel = 1;
+        /// <summary>
+        /// //red 0; fast 1; slow 2; slow2 3
+        /// </summary>
+        int scan_speed = 1;
+        int get_image_type()
+        {
+            if (imageWidth == 640)
+            {
+                return 0;
+            }
+            else if (imageWidth == 1280)
+            {
+                return 1;
+            }
+            else if (imageWidth == 2560)
+            {
+                return 2;
+            }
+            return 0;
+        }
+        int get_scan_time()
+        {
+            if (imageWidth == 640)
+            {
+                return 17000;
+            }
+            else if (imageWidth == 1280)
+            {
+                return 20000;
+            }
+            else if (imageWidth == 2560)
+            {
+                return 30000;
+            }
+            return 20000;
+        }
+        ImageInputSourceType imagesourceType = new ImageInputSourceType();
+
+        public void set_scan_chanel(int scan_chanel = 1)
+        {
+            if (m_api.isStart() == 1)
+            {
+                m_api.SET_SCANMODE((uint)(scan_chanel));
+            }
+        }
+        public void set_scan_speed(int scan_speed = 1)
+        {
+            if (m_api.isStart() == 1)
+            {
+                m_api.SET_SCANSPEED((uint)(scan_speed));
+            }
+        }
+        CBSEImgClr IScanController.AcquireBSEImage()
+        {
+            try
+            {
+                Rectangle r = new Rectangle();
+                CBSEImgClr bse = new CBSEImgClr(r);
+                bse.InitImageData(imageWidth, imageHeight);
+
+                ImageAquistionParam p = new ImageAquistionParam();
+                p.width = imageWidth;
+                p.height = imageHeight;
+                p.DwellTime = dwelltime;
+                p.sourceType = imagesourceType;
+                //byte[] ImageData = new byte[imageWidth * imageHeight * 3];
+                byte[] ImageData;
+                NLog.LogManager.GetCurrentClassLogger().Info("Begin to acquire BSE image!");
+                //get image
+                Mat image = new Mat();
+                int imagtype = get_image_type();
+                m_api.GET_IMAGE((uint)scan_chanel, imagtype);
+                Thread.Sleep(50);
+                int waittime = get_scan_time();
+                if (m_api.GET_IMAGE_MSGDATA(ref image, waittime) == 1)
+                {
+                    if (!image.Empty())
+                    {
+                        Bitmap bitmap = image.ToBitmap();
+                        using (MemoryStream stream = new MemoryStream())
+                        {
+                            bitmap.Save(stream, ImageFormat.Png);  // 你可以选择其它的格式,比如Jpeg  
+                            ImageData = stream.ToArray();
+                            bse.SetImageData(ImageData, imageWidth, imageHeight);
+                            NLog.LogManager.GetCurrentClassLogger().Info("End acquiring BSE image!");
+                        }
+                    }
+                }
+                else
+                {
+                    NLog.LogManager.GetCurrentClassLogger().Info("acquiring BSE image timeout!");
+                }
+
+                //bse.SetImageData(p.ImageData, imageWidth, imageHeight);
+
+
+                return bse;
+            }
+            catch (Exception e)
+            {
+                NLog.LogManager.GetCurrentClassLogger().Warn(e.Message);
+
+            }
+            return null;
+
+        }
+
+        bool IScanController.Init()
+        {
+            m_api = new PicoSmartApi_cshape();
+            m_api.set_ip(ip);
+            m_api.set_port(port);
+            if (m_api.start() == 1)
+            {
+                return true;
+            }
+            return false;
+        }
+
+        bool IScanController.SetDwellTime(double val)
+        {
+            scan_chanel = (int)val;
+            return true;
+        }
+
+        bool IScanController.SetImageSize(int nWidth, int nHeight)
+        {
+            this.imageWidth = nWidth;
+            this.imageWidth = nHeight;
+            return true;
+        }
+    }
+}

+ 397 - 0
OTSIncAMeasureApp/ServiceCenter/PicoSmart/PicoSmartApi_cshape.cs

@@ -0,0 +1,397 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading.Tasks;
+using System.IO;
+using OpenCvSharp;
+using System.Threading;
+
+//namespace picoapi_cshape
+namespace OTSMeasureApp.ServiceCenter
+{
+   
+
+    [StructLayout(LayoutKind.Sequential, Pack = 1)]
+    public struct PACKET_HEAD_STRUCT
+    {
+        public uint dwSize;
+        public uint dwMsg;
+    }
+
+    [StructLayout(LayoutKind.Sequential, Pack = 1)]
+    public struct CHK_CERTIFICATION_CODE
+    {
+        public PACKET_HEAD_STRUCT Header;
+        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
+        public byte[] btCode;
+    }
+
+    [StructLayout(LayoutKind.Sequential, Pack = 1)]
+    public struct GET_COLUMN_PARAMETERS_COMMAND
+    {
+        public PACKET_HEAD_STRUCT Header;
+        public uint dwRequest;
+        public uint dwInterval;
+    }
+
+    [StructLayout(LayoutKind.Sequential, Pack = 1)]
+    public struct SET_COLUMN_PARAMETERS_STRUCT
+    {
+        public PACKET_HEAD_STRUCT Header;
+        public uint dwSet;
+        public uint dwGunHV;
+        public uint dwMag;
+        public uint dwSpot;
+        public uint dwWD;
+        public uint dwBrightness;
+        public uint dwContast;
+    }
+
+
+    [StructLayout(LayoutKind.Sequential, Pack = 1)]
+    public struct GET_COLUMN_PARAMETERS_STRUCT_HUIHONG
+    {
+        public PACKET_HEAD_STRUCT Header;
+        public uint dwData;
+        public uint dwState;
+        public uint dwSignal;
+        public uint dwGunHV;
+        public uint dwScanSpeed;
+        public uint dwMag;
+        public uint dwSpot;
+        public uint dwWD;
+        public uint dwBrightness;
+        public uint dwContast;
+    }
+
+    [StructLayout(LayoutKind.Sequential, Pack = 1)]
+    public struct GET_STAGE_PARAMETERS_STRUCT
+    {
+        public PACKET_HEAD_STRUCT Header;
+        public uint dwData;
+        public float dwXPos;
+        public float dwYPos;
+        public float dwZPos;
+        public float dwRPos;
+        public float dwTPos;
+        public float dwLimit;
+        public float dwXMax;
+        public float dwYMax;
+        public float dwZMax;
+        public float dwRMax;
+        public float dwTMax;
+    }
+
+    [StructLayout(LayoutKind.Sequential, Pack = 1)]
+    public struct SET_STAGE_PARAMETERS_STRUCT
+    {
+        public PACKET_HEAD_STRUCT Header;
+        public uint dwSet;
+        public uint dwXPos;
+        public uint dwYPos;
+        public uint dwZPos;
+        public uint dwRPos;
+        public uint dwTPos;
+    }
+
+    [StructLayout(LayoutKind.Sequential, Pack = 1)]
+    public struct GET_STAGE_PARAMETERS_COMMAND
+    {
+        public PACKET_HEAD_STRUCT Header;
+        public uint dwRequest;
+        public uint dwInterval;
+    }
+
+    [StructLayout(LayoutKind.Sequential, Pack = 1)]
+    public struct GET_STAGE_MOVE_COMPLETED_STRUCT
+    {
+        public PACKET_HEAD_STRUCT Header;
+        public uint dwAxis;
+        public uint dwMotion;
+    }
+
+    [StructLayout(LayoutKind.Sequential, Pack = 1)]
+    public struct GET_SCANMODE_STRUCT
+    {
+        public PACKET_HEAD_STRUCT Header;
+        public uint dwDataType;
+    }
+
+    [StructLayout(LayoutKind.Sequential, Pack = 1)]
+    public struct SET_SCANMODE_STRUCT
+    {
+        public PACKET_HEAD_STRUCT Header;
+        public uint dwDataType;
+    }
+
+    [StructLayout(LayoutKind.Sequential, Pack = 1)]
+    public struct GET_SCANSPEED_STRUCT
+    {
+        public PACKET_HEAD_STRUCT Header;
+        public uint dwDataType;
+    }
+
+    [StructLayout(LayoutKind.Sequential, Pack = 1)]
+    public struct SET_SCANSPEED_STRUCT
+    {
+        public PACKET_HEAD_STRUCT Header;
+        public uint dwDataType;
+    }
+
+    [StructLayout(LayoutKind.Sequential, Pack = 1)]
+    public struct GET_IMAGE_STRUCT
+    {
+        public PACKET_HEAD_STRUCT Header;
+        public int dwDataType;
+        public uint LIVE;
+        public uint SCANSPEED;
+        public uint width;
+        public uint height;
+        public uint chanel;
+    }
+
+    [StructLayout(LayoutKind.Sequential, Pack = 1)]
+    public struct SET_STAGE_AXIS_STOP_COMMAND
+    {
+        public PACKET_HEAD_STRUCT Header;
+        public uint dwAxisStop;
+    }
+
+    public class ModelInfo
+    {
+        string currentPath = AppDomain.CurrentDomain.BaseDirectory;
+        public const string DLL_FIlENAME = "D:\\proj\\opton\\SEM API\\SemApiTest\\bin\\Release\\SemApi.dll";
+       
+    }
+
+    public class PicoSmartApi_cshape
+    {
+        #region exten c api
+        [DllImport(ModelInfo.DLL_FIlENAME, CallingConvention = CallingConvention.Cdecl)]
+        private static extern IntPtr create();
+
+        [DllImport(ModelInfo.DLL_FIlENAME, CallingConvention = CallingConvention.Cdecl)]
+        private static extern void set_port(IntPtr m_api, int port);
+        [DllImport(ModelInfo.DLL_FIlENAME, CallingConvention = CallingConvention.Cdecl)]
+        private static extern int get_port(IntPtr m_api);
+        [DllImport(ModelInfo.DLL_FIlENAME, CallingConvention = CallingConvention.Cdecl)]
+        private static extern void set_ip(IntPtr m_api, string server_ip);
+        [DllImport(ModelInfo.DLL_FIlENAME, CallingConvention = CallingConvention.Cdecl)]
+        private static extern int start(IntPtr m_api);
+        [DllImport(ModelInfo.DLL_FIlENAME, CallingConvention = CallingConvention.Cdecl)]
+        private static extern int stop(IntPtr m_api);
+        [DllImport(ModelInfo.DLL_FIlENAME, CallingConvention = CallingConvention.Cdecl)]
+        private static extern void GET_COLUMN(IntPtr m_api, uint dwRequest, uint dwInterval);
+        [DllImport(ModelInfo.DLL_FIlENAME, CallingConvention = CallingConvention.Cdecl)]
+        private static extern int GET_COLUMN_MSGDATA(IntPtr m_api, ref GET_COLUMN_PARAMETERS_STRUCT_HUIHONG COLUMN_PARAMETERS, int iWaitMs);
+
+        [DllImport(ModelInfo.DLL_FIlENAME, CallingConvention = CallingConvention.Cdecl)]
+        private static extern void SET_COLUMN(IntPtr m_api, uint dwSet, uint dwGunHV, uint dwMag, uint dwSpot, uint dwBrightness, uint dwContast);
+        
+        [DllImport(ModelInfo.DLL_FIlENAME, CallingConvention = CallingConvention.Cdecl)]
+        private static extern void GET_STAGE(IntPtr m_api, uint dwRequest, uint dwInterval);
+        [DllImport(ModelInfo.DLL_FIlENAME, CallingConvention = CallingConvention.Cdecl)]
+        private static extern int GET_STAGE_MSGDATA(IntPtr m_api, ref GET_STAGE_PARAMETERS_STRUCT STAGE_PARAMETERS, int iWaitMs);//硬件最小发送间隔默认为1秒
+        [DllImport(ModelInfo.DLL_FIlENAME, CallingConvention = CallingConvention.Cdecl)]
+        private static extern int GET_STAGE_MOVE(IntPtr m_api, ref GET_STAGE_MOVE_COMPLETED_STRUCT STAGE_MOVE, int iWaitMs);//硬件最小发送间隔默认为1秒
+        [DllImport(ModelInfo.DLL_FIlENAME, CallingConvention = CallingConvention.Cdecl)]
+        private static extern void SET_STAGE(IntPtr m_api, uint dwSet, float dwXPos, float dwYPos, float dwZPos, float dwRPos, float dwTPos);
+
+        [DllImport(ModelInfo.DLL_FIlENAME, CallingConvention = CallingConvention.Cdecl)]
+        private static extern void STOP_STAGE(IntPtr m_api);
+
+        [DllImport(ModelInfo.DLL_FIlENAME, CallingConvention = CallingConvention.Cdecl)]
+        private static extern void GET_IMAGE(IntPtr m_api, uint dwDataType, int image_index, int chanel, int speed, int live);
+        [DllImport(ModelInfo.DLL_FIlENAME, CallingConvention = CallingConvention.Cdecl)]
+        private static extern int GET_IMAGE_MSGDATA(IntPtr m_api, IntPtr IMAGE, int iWaitMs);
+        [DllImport(ModelInfo.DLL_FIlENAME, CallingConvention = CallingConvention.Cdecl)]
+        private static extern void GET_SCANMODE(IntPtr m_api);
+        [DllImport(ModelInfo.DLL_FIlENAME, CallingConvention = CallingConvention.Cdecl)]
+     
+        private static extern int GET_SCANMODE_MSGDATA(IntPtr m_api, ref GET_SCANMODE_STRUCT SCANMODE, int iWaitMs);
+        [DllImport(ModelInfo.DLL_FIlENAME, CallingConvention = CallingConvention.Cdecl)]
+        private static extern void SET_SCANMODE(IntPtr m_api, uint dwDataType);
+        [DllImport(ModelInfo.DLL_FIlENAME, CallingConvention = CallingConvention.Cdecl)]
+
+        private static extern void GET_SCANSPEED(IntPtr m_api);
+        [DllImport(ModelInfo.DLL_FIlENAME, CallingConvention = CallingConvention.Cdecl)]
+        private static extern int GET_SCANSPEED_MSGDATA(IntPtr m_api, ref GET_SCANSPEED_STRUCT SCANSPEED, int iWaitMs);
+        [DllImport(ModelInfo.DLL_FIlENAME, CallingConvention = CallingConvention.Cdecl)]
+        private static extern void SET_SCANSPEED(IntPtr m_api, uint dwDataType);
+
+        [DllImport(ModelInfo.DLL_FIlENAME, CallingConvention = CallingConvention.Cdecl)]
+
+        private static extern int isStart(IntPtr api);
+        #endregion
+        #region c# api
+        private IntPtr m_api = IntPtr.Zero;
+        public PicoSmartApi_cshape()
+        {
+            if (File.Exists(ModelInfo.DLL_FIlENAME) == false)
+                return;
+            this.m_api = create();
+        }
+        public void set_port(int port)
+        {
+            set_port(m_api, port);
+        }
+        public int get_port()
+        {
+            return get_port(m_api);
+        }
+        public void set_ip(string ip)
+        {
+            set_ip(m_api, ip);
+        }
+        public int start()
+        {
+
+            return start(m_api);
+        }
+        public int stop()
+        {
+            return stop(m_api);
+        }
+        public void GET_COLUMN(uint dwRequest, uint dwInterval)
+        {
+            GET_COLUMN(m_api, dwRequest, dwInterval);
+        }
+        public int GET_COLUMN_MSGDATA(ref GET_COLUMN_PARAMETERS_STRUCT_HUIHONG COLUMN_PARAMETERS, int iWaitMs)
+        {
+
+            return GET_COLUMN_MSGDATA(m_api, ref COLUMN_PARAMETERS, iWaitMs);
+        }
+        public void SET_COLUMN(uint dwSet, uint dwGunHV, uint dwMag, uint dwSpot, uint dwBrightness, uint dwContast)
+        {
+            SET_COLUMN(m_api, dwSet, dwGunHV, dwMag, dwSpot, dwBrightness, dwContast);
+        }
+   
+        public void GET_STAGE(uint dwRequest, uint dwInterval)
+        {
+            GET_STAGE(m_api, dwRequest, dwInterval);
+        }
+        public int GET_STAGE_MSGDATA(ref GET_STAGE_PARAMETERS_STRUCT STAGE_PARAMETERS, int iWaitMs)//硬件最小发送间隔默认为1秒
+        {
+            return GET_STAGE_MSGDATA(m_api, ref STAGE_PARAMETERS, iWaitMs);
+        }
+        public int GET_STAGE_MOVE( ref GET_STAGE_MOVE_COMPLETED_STRUCT STAGE_MOVE, int iWaitMs)//硬件最小发送间隔默认为1秒
+        {
+        return GET_STAGE_MOVE( m_api,ref STAGE_MOVE,  iWaitMs);//硬件最小发送间隔默认为1秒
+    }
+        public void SET_STAGE( uint dwSet, float dwXPos, float dwYPos, float dwZPos, float dwRPos, float dwTPos)
+        {
+             SET_STAGE(m_api, dwSet, dwXPos, dwYPos, dwZPos, dwRPos, dwTPos);
+        }
+        public void STOP_STAGE()
+        {
+             STOP_STAGE( m_api);
+        }
+       
+        public void GET_IMAGE( uint dwDataType, int image_index, int chanel=3, int speed=0, int live=1)
+        {
+             GET_IMAGE( m_api,  dwDataType,  image_index,  chanel,  speed,  live);
+        }
+        public int GET_IMAGE_MSGDATA(ref Mat IMAGE, int iWaitMs)
+        {
+            return GET_IMAGE_MSGDATA(m_api, IMAGE.CvPtr, iWaitMs);
+        }
+        public void GET_SCANMODE()
+        {
+             GET_SCANMODE( m_api);
+        }
+
+        public int GET_SCANMODE_MSGDATA(ref GET_SCANMODE_STRUCT SCANMODE, int iWaitMs)
+        {
+            return  GET_SCANMODE_MSGDATA( m_api, ref  SCANMODE,  iWaitMs);
+        }
+     
+        public void SET_SCANMODE( uint dwDataType)
+        {
+             SET_SCANMODE( m_api,  dwDataType);
+        }
+        public void GET_SCANSPEED()
+        {
+             GET_SCANSPEED( m_api);
+        }
+        public int GET_SCANSPEED_MSGDATA( ref GET_SCANSPEED_STRUCT SCANSPEED, int iWaitMs)
+        {
+            return GET_SCANSPEED_MSGDATA( m_api, ref  SCANSPEED,  iWaitMs);
+        }
+        public void SET_SCANSPEED( uint dwDataType)
+        {
+             SET_SCANSPEED( m_api,  dwDataType);
+        }
+        public int isStart()
+        {
+            return isStart(m_api);
+        }
+
+        #endregion
+
+        #region custom thread
+
+        private Thread recThread;
+        private volatile bool rec_running; // 用于控制线程运行的布尔变量  
+  
+
+        // 定义一个事件,用于通知主线程消费产品  
+        public event Action<GET_COLUMN_PARAMETERS_STRUCT_HUIHONG> COLUMN_MSGProduced;
+        public event Action<Mat>IMAGE_MSGProduced;
+   
+
+        // 启动生产者线程  
+        public void StartProducing()
+        {
+            if (recThread == null || !recThread.IsAlive)
+            {
+                rec_running = true;
+                recThread = new Thread(Produce);
+                recThread.Start();
+            }
+        }
+
+        // 停止生产者线程  
+        public void StopProducing()
+        {
+            rec_running = false;
+            if (recThread != null && recThread.IsAlive)
+            {
+                recThread.Join(); // 等待线程终止  
+            }
+        }
+       private GET_COLUMN_PARAMETERS_STRUCT_HUIHONG COLUMN = new GET_COLUMN_PARAMETERS_STRUCT_HUIHONG();
+        // 生产方法(线程入口点)  
+        private void Produce()
+        {
+            GET_COLUMN(0, 1);
+           Mat IMAGE= new Mat();
+            while (rec_running)
+            {
+
+                if(GET_COLUMN_MSGDATA(ref COLUMN,10)==1)
+                {
+                    OnGET_COLUMN_MSG(COLUMN);
+                }
+                if(GET_IMAGE_MSGDATA(ref IMAGE,10)==1)
+                {
+                    onGET_IMAGE_MSG(IMAGE);
+                }
+                Thread.Sleep(1); 
+            }
+            IMAGE.Dispose();
+        }
+
+        // 触发产品生产事件  
+        public virtual void OnGET_COLUMN_MSG(GET_COLUMN_PARAMETERS_STRUCT_HUIHONG product)
+        {
+            COLUMN_MSGProduced?.Invoke(product);
+        }
+        public void onGET_IMAGE_MSG(Mat image)
+        {
+            IMAGE_MSGProduced?.Invoke(image);
+        }
+        #endregion
+    }
+}