Kaynağa Gözat

add ipc support for Measure app.

gsp 3 yıl önce
ebeveyn
işleme
f407b90a1f

+ 45 - 30
OTSCPP/OTSClrInterface/ControlClr/OTSControlFunExport.h

@@ -40,13 +40,21 @@ namespace OTSCLRINTERFACE
 	public ref class COTSControlFunExport
 	{
 	public:
-		static COTSControlFunExport^ GetControllerInstance()
+		/*static COTSControlFunExport^ GetControllerInstance()
 		{
 			if (theInstance == nullptr)
 			{
 				theInstance = gcnew COTSControlFunExport();
 			}
 			return theInstance;
+		}*/
+		COTSControlFunExport()
+		{
+
+			m_pHardWareMgr = new COTSHardwareMgr();
+			
+
+
 		}
 
 		~COTSControlFunExport()
@@ -71,7 +79,22 @@ namespace OTSCLRINTERFACE
 
 
 		}
-	
+		//get the hardware object according to the configure file.
+		bool Init()
+		{
+			m_pSem = (m_pHardWareMgr->GetSemControllerMgrPtr()).get();
+			m_pScan = (m_pHardWareMgr->GetScanControllerPtr()).get();
+			m_pEDS = (m_pHardWareMgr->GetEDSControllerPtr()).get();
+			if (m_pSem == nullptr || m_pScan == nullptr || m_pEDS == nullptr)
+			{
+				return false;
+			}
+			else
+			{
+				return true;
+			}
+		
+		}
 
 		//和电镜建立通讯连接
 		bool ConncetSem()
@@ -92,7 +115,26 @@ namespace OTSCLRINTERFACE
 			BOOL bRev = m_pSem->IsConnected();
 			return bRev;
 		}
-		
+
+		// 初始化
+		bool ScanInit()
+		{
+			bool bRet = m_pScan->Init();
+			return bRet;
+		}
+
+		//EDS初始化
+		//函数名称:bool EDSInit()
+		//输入参数:无
+		//输出参数:类型:bool,true,设备申请成功
+		//						false,设备申请失败
+		bool EDSInit()
+		{
+
+			bool bRet = m_pEDS->Init();
+			return bRet;
+		}
+
 
 		//获取当前电镜的ID号
 		int GetSemType()
@@ -393,17 +435,6 @@ namespace OTSCLRINTERFACE
 		}
 
 	
-		//EDS初始化
-		//函数名称:bool EDSInit()
-		//输入参数:无
-		//输出参数:类型:bool,true,设备申请成功
-		//						false,设备申请失败
-		bool EDSInit()
-		{
-
-			bool bRet = m_pEDS->Init();
-			return bRet;
-		}
 
 
 		//是否支持Xray采集
@@ -504,13 +535,6 @@ namespace OTSCLRINTERFACE
 
 
 
-		// 初始化
-		bool ScanInit()
-		{
-			bool bRet = m_pScan->Init();
-			return bRet;
-		}
-
 
 
 		int GetScanType()
@@ -702,16 +726,7 @@ namespace OTSCLRINTERFACE
 			return bRet;
 		}
 	private:
-		COTSControlFunExport()
-		{
-
-			m_pHardWareMgr = new COTSHardwareMgr();
-			m_pSem = (m_pHardWareMgr->GetSemControllerMgrPtr()).get();
-			m_pScan = (m_pHardWareMgr->GetScanControllerPtr()).get();
-			m_pEDS = (m_pHardWareMgr->GetEDSControllerPtr()).get();
 		
-
-		}
 	
 		 COTSSemBase* m_pSem;
 		

+ 0 - 2
OTSCPP/OTSClrInterface/OTSClrInterface.vcxproj

@@ -219,7 +219,6 @@
     <ClCompile Include="CommonClr\SEMDataMsrClr.cpp" />
     <ClCompile Include="CommonClr\SEMStageDataClr.cpp" />
     <ClCompile Include="CommonClr\StageClr.cpp" />
-    <ClCompile Include="ControlClr\COTSSimuControlClr.cpp" />
     <ClCompile Include="ControlClr\OTSControlFunExport.cpp" />
     <ClCompile Include="ImageProClr\FieldMgrClr.cpp" />
     <ClCompile Include="ImageProClr\ImageProForClr.cpp" />
@@ -258,7 +257,6 @@
     <ClInclude Include="CommonClr\SEMDataMsrClr.h" />
     <ClInclude Include="CommonClr\SEMStageDataClr.h" />
     <ClInclude Include="CommonClr\StageClr.h" />
-    <ClInclude Include="ControlClr\COTSSimuControlClr.h" />
     <ClInclude Include="ControlClr\OTSControlFunExport.h" />
     <ClInclude Include="ImageProClr\FieldMgrClr.h" />
     <ClInclude Include="ImageProClr\ImageProForClr.h" />

+ 0 - 6
OTSCPP/OTSClrInterface/OTSClrInterface.vcxproj.filters

@@ -138,9 +138,6 @@
     <ClCompile Include="ReportCalculateClr\SmplMsrResultFileMgrClr.cpp">
       <Filter>OTSREPORTCLR</Filter>
     </ClCompile>
-    <ClCompile Include="ControlClr\COTSSimuControlClr.cpp">
-      <Filter>ControlClr</Filter>
-    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="CommonClr\BSEImgClr.h">
@@ -251,8 +248,5 @@
     <ClInclude Include="ReportCalculateClr\SmplMsrResultFileMgrClr.h">
       <Filter>OTSREPORTCLR</Filter>
     </ClInclude>
-    <ClInclude Include="ControlClr\COTSSimuControlClr.h">
-      <Filter>ControlClr</Filter>
-    </ClInclude>
   </ItemGroup>
 </Project>

+ 5 - 6
OTSCPP/OTSControl/COTSHardwareMgr.cpp

@@ -59,7 +59,7 @@ namespace OTSController {
 
 	}
 
-	CSemBasePtr COTSHardwareMgr::GetSemControllerMgrPtr()
+	CSemBasePtr COTSHardwareMgr::GetSemControllerMgrPtr()// this is the same as the constructor of singleton.So we cann't put expensive operation in it,such as the "connect" operation
 	{	
 		if (nullptr == m_SemBasePtr)
 		{
@@ -102,8 +102,8 @@ namespace OTSController {
 
 					break;
 			}
-			//connect the hardware when the singleton instanced ,make it an enforcement.
-			m_SemBasePtr->Connect();
+			
+			
 		}
 		
 		return m_SemBasePtr;
@@ -157,7 +157,7 @@ namespace OTSController {
 
 					break;
 			}
-			m_EDSPtr->Init();
+			
 			
 		}
 		
@@ -210,8 +210,7 @@ namespace OTSController {
 
 					break;
 			}
-			//connect the hardware when the singleton instanced ,make it an enforcement.
-			m_SCanPtr->Init();
+		
 
 		}
 		

+ 9 - 1
OTSIncAMeasureApp/1-OTSMeasure/CMeasureThreadWrapper.cs

@@ -383,11 +383,19 @@ namespace OTSMeasureApp
 
 
         #endregion
+    
+        public bool ConnectSEM()
+        {
+           return m_MsrThread.GetSEMController().Connect();
+        }
         public void DisconnectSEM()
         {
             m_MsrThread.GetSEMController().DisConnect();
         }
-
+        public bool IsSEMConnected()
+        {
+            return m_MsrThread.GetSEMController().IsConnected();
+        }
         public bool GetMsrRetData(ref SMSR_COMPLETE_DATA MsrCompleteData)
         {
             try

+ 1 - 1
OTSIncAMeasureApp/5-OTSMeasureStatuImageFun/OTSBSEImageFun.cs

@@ -33,7 +33,7 @@ namespace OTSMeasureApp
         public int GetScanImage(int iWidth, int iHeigh, ref byte[] bImageData)
         {
             //电镜设置对象
-            COTSControlFunExport cfun = COTSControlFunExport.GetControllerInstance();
+            COTSControlFunExport cfun = new COTSControlFunExport();
             int GetImgCount = 0;
             try
             {

+ 1 - 1
OTSIncAMeasureApp/5-OTSMeasureStatuImageFun/OTSImageData.cs

@@ -147,7 +147,7 @@ namespace OTSMeasureApp
                 //设置获取图像的Byte数组
                 bData = new byte[iWidth * iHeight];
                 ImageValue = GetImageData(iWidth, iHeight, ref bData, true);
-                
+
                 if (resultCount == ImageValue)
                 {
                     return true;

+ 1 - 1
OTSIncAMeasureApp/5-OTSMeasureStatuImageFun/OTSMeasureStatusWindow.cs

@@ -1488,7 +1488,7 @@ namespace OTSMeasureApp
             MenuItemLineScam.Checked = false;
             //电镜设置对象
             //控制类对象初始化
-            COTSControlFunExport cfun = COTSControlFunExport.GetControllerInstance();
+            COTSControlFunExport cfun =new  COTSControlFunExport();
             //1.连接电镜
             if (cfun.ConncetSem())
             {

+ 3 - 0
OTSIncAMeasureApp/OTSIncAMeasureApp.csproj

@@ -161,6 +161,7 @@
     </Reference>
     <Reference Include="System.Design" />
     <Reference Include="System.Management" />
+    <Reference Include="System.Runtime.Remoting" />
     <Reference Include="System.Security" />
     <Reference Include="System.Windows.Forms.DataVisualization" />
     <Reference Include="System.Windows.Forms.Ribbon, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
@@ -270,6 +271,7 @@
       <DependentUpon>DlgStageRename.cs</DependentUpon>
     </Compile>
     <Compile Include="7-OTSProgMgrInfo\Stage\StageDisplayHelp.cs" />
+    <Compile Include="CRegistration.cs" />
     <Compile Include="ResourceManage\ResourceData.cs" />
     <Compile Include="ResourceManage\ResourceID.cs" />
     <Compile Include="ServiceCenter\CClassifyEngine.cs" />
@@ -296,6 +298,7 @@
     <Compile Include="ServiceCenter\IClassifyEngine.cs" />
     <Compile Include="ServiceCenter\IImageProcess.cs" />
     <Compile Include="ServiceCenter\IMeasureHardware.cs" />
+    <Compile Include="ServiceCenter\IpcSEMController.cs" />
     <Compile Include="ServiceCenter\ScanController.cs" />
     <Compile Include="ServiceCenter\SemController.cs" />
     <Compile Include="3-OTSDisplaySourceGridData\OTSPropertyWindow1.Designer.cs">

+ 30 - 119
OTSIncAMeasureApp/OTSIncAMeasureAppForm.cs

@@ -20,6 +20,10 @@ using System.Management;
 using System.Xml;
 using System.Linq;
 using System.Text;
+using System.Runtime.Remoting.Channels.Ipc;
+using System.Runtime.Remoting.Channels;
+using System.Runtime.Remoting;
+using OTSMeasureApp.ServiceCenter;
 
 namespace OTSMeasureApp 
 {
@@ -157,13 +161,7 @@ namespace OTSMeasureApp
           
             try
             {
-                //判断是否有授权
-                if(!RegistrationVerification())
-                {
-                    MessageBox.Show("Error: missing authorization");
-                    System.Environment.Exit(0);
-                    return;
-                }
+  
 
                 ArrangWorkspaceWindow();
 
@@ -191,17 +189,29 @@ namespace OTSMeasureApp
                     }
                     else
                     {
-                        log.Error("(OTSIncAMeasureAppForm.OTSIncAMeasureAppForm_Load)  this.CheckMeasureSysFileExist() = false");
+                        log.Error("(OTSIncAMeasureAppForm.OTSIncAMeasureAppForm_Load)  InitResultData() failed");
                     }
                 }
                 else
                 {
-                    log.Error("(OTSIncAMeasureAppForm.OTSIncAMeasureAppForm_Load)  (m_DataMgrFun.CheckParamFile() && m_DataMgrFun.CheckStageFile()) = false");
+                    log.Error("(OTSIncAMeasureAppForm.OTSIncAMeasureAppForm_Load)  (LoadParamFile() && LoadStageParamFile()) failed");
+                }
+               
+                if (!m_MsrThreadWrapper.ConnectSEM())
+                {
+                    MessageBox.Show("Connect SEM failed!Please goto the SysMgrApp.exe to setup the proper parameter and check other parameter of the EDS software");
+                    System.Diagnostics.ProcessStartInfo process = new System.Diagnostics.ProcessStartInfo();
+                    process.FileName = "OTSSysMgrApp.exe";//打开app的路径
+                    //string FilePath = string.Join(" ",m_ProjData.GetPathName());
+                    //process.Arguments = FilePath;//多个参数用空格隔开
+                    process.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
+                    System.Diagnostics.Process.Start(process);
                 }
+                PrepareIpcServer();
             }
             catch (Exception ex)
             {
-                log.Error("(OTSIncAMeasureAppForm.OTSIncAMeasureAppForm_Load) OTSIncAMeasureAppForm_Load:" + ex.ToString());
+                log.Error(" OTSIncAMeasureAppForm_Load:" + ex.ToString());
             }
            
 
@@ -1316,117 +1326,18 @@ namespace OTSMeasureApp
             return csName;
         }
 
-
-        // 获得CPU的序列号
-        static string getCpu()
-        {
-            string strCpu = null;
-            ManagementClass myCpu = new ManagementClass("win32_Processor");
-            ManagementObjectCollection myCpuConnection = myCpu.GetInstances();
-            foreach (ManagementObject myObject in myCpuConnection)
-            {
-                strCpu = myObject.Properties["Processorid"].Value.ToString();
-                break;
-            }
-            return strCpu;
-        }
-
-        // 取得设备硬盘的卷标号
-        static string GetDiskVolumeSerialNumber()
-        {
-            ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
-            ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\"");
-            disk.Get();
-            return disk.GetPropertyValue("VolumeSerialNumber").ToString();
-        }
-
-        public static IDictionary<String, List<String>> ReadXML(string address)
-        {
-            IDictionary<String, List<String>> infos = new Dictionary<String, List<String>>();
-
-            if (File.Exists(address))
-            {
-                XmlDocument xmlDoc = new XmlDocument();
-
-                xmlDoc.Load(address);
-
-                XmlNode xn = xmlDoc.SelectSingleNode("infos");
-
-                XmlNodeList xnl = xn.ChildNodes;
-
-                foreach (XmlNode xnf in xnl)
-                {
-                    XmlElement xe = (XmlElement)xnf;
-
-                    XmlNode nameNode = xe.SelectSingleNode("ID");
-
-                    string name = nameNode.InnerText;
-                    Console.WriteLine(name);
-                    XmlNode filelist = xe.SelectSingleNode("filelist");
-
-                    List<String> list = new List<string>();
-
-                    foreach (XmlNode item in filelist.ChildNodes)
-                    {
-                        list.Add(item.InnerText);
-                    }
-
-                    infos.Add(name, list);
-                }
-            }
-            return infos;
-        }
-        private string ConvertString(string str)
-        {
-            string str_out;
-            string[] arr = str.Split(',');
-            byte[] be = new byte[arr.Count()];
-
-            for (int i = 0; i < arr.Count(); i++)
-            {
-                be[i] = Convert.ToByte(arr[i]);
-            }
-            str_out = Encoding.Unicode.GetString(be);
-            return str_out;
-        }
-        private bool RegistrationVerification()
+        private void PrepareIpcServer()
         {
-            string CPUID, DiskID;
-            try
-            {
-                SenseShield.DogDecrypting.decrypting(101);//参数为许可号
-            }
-            catch (Exception ex)
-            {
-                CPUID = getCpu();
-                DiskID = GetDiskVolumeSerialNumber();
-                var ID = ReadXML("./Config/SysData/RegistrationProofreading.txt");
-                List<string> list_str = new List<string>();
-                List<string> list_time = new List<string>();
-                ID.TryGetValue("ID", out list_str);
-                ID.TryGetValue("Time", out list_time);
-                string setCPU = ConvertString(list_str[0]);
-                string setDisk = ConvertString(list_str[1]);
-                string setYear = ConvertString(list_time[0]);
-                string setMonth = ConvertString(list_time[1]);
-                string setDay = ConvertString(list_time[2]);
-                if (CPUID != setCPU || DiskID != setDisk)
-                {
-                    return false;
+            //Instantiate our server channel.
+            IpcServerChannel channel = new IpcServerChannel("ServerChannel");
+            //Register the server channel.
+            ChannelServices.RegisterChannel(channel, false);
+            //Register this service type.
+            RemotingConfiguration.RegisterWellKnownServiceType(typeof(IpcSEMController), "RemoteObject", WellKnownObjectMode.Singleton);
+            //RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject2), "RemoteObject2", WellKnownObjectMode.Singleton);
+            //Console.WriteLine("press return to exit");
+            //Console.ReadLine();
 
-                }
-              
-                DateTime dt = DateTime.ParseExact(setYear + setMonth + setDay+ "235959", "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
-
-                if (DateTime.Now > dt)
-                {
-                    
-                    return false;
-                }
-                
-
-            }
-            return true;
         }
     }
 }

+ 9 - 0
OTSIncAMeasureApp/Program.cs

@@ -12,6 +12,14 @@ namespace OTSMeasureApp
         [STAThread]
         static void Main()
         {
+            //判断是否有授权
+            var reg = new CRegistration();
+            if (!reg.RegistrationVerification())
+            {
+                MessageBox.Show("Error: missing authorization");
+                System.Environment.Exit(0);
+                return;
+            }
             //--------------------------只运行一个测量程序--------------------------------
 
             bool flag = false;
@@ -29,5 +37,6 @@ namespace OTSMeasureApp
             Application.SetCompatibleTextRenderingDefault(false);
             Application.Run(new OTSIncAMeasureAppForm());
         }
+      
     }
 }

+ 28 - 14
OTSIncAMeasureApp/ServiceCenter/EDSController.cs

@@ -19,34 +19,47 @@ namespace OTSModelSharp.ServiceInterface
     {
 
       private  COTSControlFunExport eds;
-
+        private bool m_init=false;
         public EDSController()
         {
-         
-           
-           
+
+            eds = SemController.hw;
+
         }
 
 
 
-        public void GetXRayByFeatures(List<COTSParticleClr> a_listParticles,  double a_nXRayAQTime, bool a_bElementInfo)
+        public bool GetXRayByFeatures(List<COTSParticleClr> a_listParticles,  double a_nXRayAQTime, bool a_bElementInfo)
         {
 
-            Init();
-
+            if (!eds.IsConnected())
+            {
+                return false;
+            }
+            if (!m_init)
+            {
+                return false;
+            }
             COTSParticleClr[] parts = a_listParticles.ToArray();
            
             
-            eds.GetXRayByFeatures((uint)a_nXRayAQTime, parts,  a_bElementInfo);
+          return  eds.GetXRayByFeatures((uint)a_nXRayAQTime, parts,  a_bElementInfo);
 
 
 
             
         }
 
-        public void GetXRayByPoints(List<COTSParticleClr> a_listParticles, uint a_nXRayAQTime, bool a_bElementInfo)
+        public bool GetXRayByPoints(List<COTSParticleClr> a_listParticles, uint a_nXRayAQTime, bool a_bElementInfo)
         {
-            Init();
+            if (!eds.IsConnected())
+            {
+                return false;
+            }
+            if (!m_init)
+            {
+                return false;
+            }
             int xrayNum = a_listParticles.Count;
             Point[] Ps = new Point[xrayNum];
 
@@ -60,15 +73,16 @@ namespace OTSModelSharp.ServiceInterface
             COTSParticleClr[] parts = a_listParticles.ToArray();
 
             string[] a_strEleResult = new string[xrayNum];
-            eds.GetXRayByPoints(a_nXRayAQTime, Ps,parts, a_bElementInfo);
+           return eds.GetXRayByPoints(a_nXRayAQTime, Ps,parts, a_bElementInfo);
 
-            return ;
+            
         }
 
         public bool Init()
         {
-            eds = SemController.hw;
-            return eds.EDSInit();
+            
+            m_init= eds.EDSInit();
+            return m_init;
         }
     }
 }

+ 2 - 2
OTSIncAMeasureApp/ServiceCenter/IMeasureHardware.cs

@@ -42,7 +42,7 @@ namespace OTSModelSharp.ServiceInterface
     public interface IEDSController
     {
         bool Init();
-        void GetXRayByFeatures(List<COTSParticleClr> a_listParticles,  double a_nXRayAQTime, bool a_bElementInfo /*= FALSE*/);//这里将DWORD转成了Double类型,因为在后续调用时还有DWORD强制转换
-        void GetXRayByPoints(List<COTSParticleClr> a_listParticles, uint a_nXRayAQTime, bool a_bElementInfo /*= FALSE*/);
+        bool GetXRayByFeatures(List<COTSParticleClr> a_listParticles,  double a_nXRayAQTime, bool a_bElementInfo /*= FALSE*/);//这里将DWORD转成了Double类型,因为在后续调用时还有DWORD强制转换
+        bool GetXRayByPoints(List<COTSParticleClr> a_listParticles, uint a_nXRayAQTime, bool a_bElementInfo /*= FALSE*/);
     }
 }

+ 31 - 8
OTSIncAMeasureApp/ServiceCenter/ScanController.cs

@@ -13,16 +13,23 @@ namespace OTSModelSharp.ServiceInterface
     public class ScanController : IScanController
     {
        private OTSCLRINTERFACE.COTSControlFunExport scan;
-
+        private bool m_init=false;
         public ScanController()
         {
-          
-           
+
+            this.scan = SemController.hw;
         }
 
         public CBSEImgClr AcquireBSEImage(int matrixIndex, int reads, int dwell)
         {
-            Init();
+            if (!scan.IsConnected())
+            {
+                return null;
+            }
+            if (!m_init)
+            {
+                return null;
+            }
             Rectangle r = new Rectangle();
             CBSEImgClr bse = new CBSEImgClr(r);
            if (!scan.AcquireBSEImage(matrixIndex, reads, dwell, ref bse))
@@ -35,21 +42,37 @@ namespace OTSModelSharp.ServiceInterface
 
         public bool Init()
         {
-            this.scan = SemController.hw;
-            return  scan.ScanInit();
+
+            m_init= scan.ScanInit();
+            return m_init;
+
         }
 
    
 
         public bool SetDwellTime(long val)
         {
-            Init();
+            if (!scan.IsConnected())
+            {
+                return false;
+            }
+            if (!m_init)
+            {
+                return false;
+            }
             return scan.SetDwellTime((int)val);
         }
 
         public bool SetImageSize(int width,int height)
         {
-            Init();
+            if (!scan.IsConnected())
+            {
+                return false;
+            }
+            if (!m_init)
+            {
+                return false;
+            }
             return scan.SetImageSize(width,height);
         }
     }

+ 56 - 26
OTSIncAMeasureApp/ServiceCenter/SemController.cs

@@ -14,37 +14,44 @@ namespace OTSModelSharp.ServiceInterface
 
         public SemController()
         {
-            
-            
-        }
 
+            hw =new  OTSCLRINTERFACE.COTSControlFunExport();
+        }
+       
         public bool Connect()
         {
-            if (hw == null)
+            if (!hw.Init())
             {
-                hw = OTSCLRINTERFACE.COTSControlFunExport.GetControllerInstance();
+                return false;
             }
             if (hw.IsConnected())
             {
                 return true;
             }
-            else
-            { //和电镜建立通讯连接
-                return hw.ConncetSem();
-            }
+           
+            return hw.ConncetSem();
+            
+        }
+        public bool IsConnected()
+        {
+            //return true;
+            return hw.IsConnected();
         }
-
         public bool DisConnect()
         {
-            if (hw != null)
+            if (hw.IsConnected())
             {
                 return hw.DisconnectSem();
             }
+            
             return true;
         }
         public bool GetSEMDataGnrFromHw(ref CSEMDataGnr SemDataGnr)
         {
-            Connect();
+            if (!hw.IsConnected())
+            {
+                return false;
+            }
             double kv=0, brightness=0, contrast=0;
             hw.GetSemHighTension(ref kv);
             hw.GetSemBrightness(ref brightness);
@@ -55,20 +62,29 @@ namespace OTSModelSharp.ServiceInterface
         }
         public bool GetMagnification(ref double a_dMagnification)
         {
-            Connect();
+            if (!hw.IsConnected())
+            {
+                return false;
+            }
             return hw.GetSemMagnification(ref a_dMagnification);
              
         }
 
         public bool GetScanFieldSize(ref double dScanFieldSizeX, ref double dScanFieldSizeY)
         {
-            Connect();
+            if (!hw.IsConnected())
+            {
+                return false;
+            }
             return  hw.GetSemScanFieldSize(ref dScanFieldSizeX, ref dScanFieldSizeY);
         }
 
         public bool GetSemPositionXY(ref double a_dPositionX, ref double a_dPositionY, ref double a_dPositionR)
         {
-            Connect();
+            if (!hw.IsConnected())
+            {
+                return false;
+            }
             return hw.GetSemPositionXY(ref a_dPositionX, ref a_dPositionY, ref a_dPositionR);
         }
 
@@ -76,25 +92,30 @@ namespace OTSModelSharp.ServiceInterface
 
         public bool GetWorkingDistance(ref double a_distance)
         {
-            Connect();
+            if (!hw.IsConnected())
+            {
+                return false;
+            }
             return hw.GetSemWorkingDistance(ref a_distance);
         }
 
-        public bool IsConnected()
-        {
-            //return true;
-            return hw.IsConnected();
-        }
+      
 
         public bool MoveSEMToPoint(Point poi, double rotation)
         {
-            Connect();
+            if (!hw.IsConnected())
+            {
+                return false;
+            }
             return hw.MoveSEMToPoint(poi.X, poi.Y, rotation);
         }
 
         public bool SetMagnification(double a_dMagnification)
         {
-            Connect();
+            if (!hw.IsConnected())
+            {
+                return false;
+            }
             //hw.SetMagnification(a_dMagnification);
             hw.SetSemMagnification(a_dMagnification);
             return true;
@@ -102,20 +123,29 @@ namespace OTSModelSharp.ServiceInterface
 
         public bool SetScanExternal(bool b)
         {
-            Connect();
+            if (!hw.IsConnected())
+            {
+                return false;
+            }
             //int seValue = b ? 1 : 0;
             return hw.SetSemScanExternal(b);
         }
 
         public bool SetWorkingDistance(double a_distance)
         {
-            Connect();
+            if (!hw.IsConnected())
+            {
+                return false;
+            }
             return hw.SetSemWorkingDistance(a_distance);
         }
 
         public OTSCLRINTERFACE.COTSControlFunExport GetHardwareInterface()
         {
-            Connect();
+            if (!hw.IsConnected())
+            {
+                return null;
+            }
             return hw;
         }
     }

+ 12 - 11
OTSIncAReportApp/1-UI/Control_Grids/OTSIncAReportGridsFuncation/OTSReportGridsFun.cs

@@ -2,6 +2,7 @@
 using OTSCLRINTERFACE;
 using OTSIncAReportApp.DataOperation.Model;
 using OTSIncAReportApp.SysMgrTools;
+using ServiceInterface;
 using System;
 using System.Collections;
 using System.Collections.Generic;
@@ -19,7 +20,7 @@ namespace OTSIncAReportGrids.OTSIncAReportGridsFuncation
 
         #region 定义变量
         //电镜设置对象
-        public OTSCLRINTERFACE.COTSControlFunExport m_cfun = null;
+       
 
         //为了加快颗粒列表抠图的速度,这里保存一个全局变量
         public List<Field> m_list_COTSFieldMgrClr = null;
@@ -32,7 +33,7 @@ namespace OTSIncAReportGrids.OTSIncAReportGridsFuncation
         Hashtable table;
 
         OTSIncAReportApp.frmReportApp m_frmReportApp = null;
-       //public COTSControlFunExport m_cfun = null;
+        public SemController m_cfun = null;
 
         #endregion
 
@@ -51,7 +52,7 @@ namespace OTSIncAReportGrids.OTSIncAReportGridsFuncation
 
             m_frmReportApp = in_frmReportApp;
 
-            m_cfun = OTSCLRINTERFACE.COTSControlFunExport.GetControllerInstance();//重新new一下试试呢,不new不好使   It's better to reinitialize, but it's not good to uninitialize
+            m_cfun = new SemController();//  It's better to reinitialize, but it's not good to uninitialize
 
         }
 
@@ -152,15 +153,15 @@ namespace OTSIncAReportGrids.OTSIncAReportGridsFuncation
         /// </summary>
         public void Connection_ForParticlesGrid()
         {
-            if (m_cfun == null)
-            {
-                m_cfun =  COTSControlFunExport.GetControllerInstance();
-            }
+            //if (m_cfun == null)
+            //{
+            //    m_cfun =  new SemController();
+            //}
            
             if (!m_SEMConnectionState)
             {
-               
-                m_SEMConnectionState = m_cfun.ConncetSem();
+
+                m_SEMConnectionState = m_cfun.Connect();
                 
             }
            
@@ -187,7 +188,7 @@ namespace OTSIncAReportGrids.OTSIncAReportGridsFuncation
 
             if (m_SEMConnectionState)
             {
-                m_cfun.MoveSEMToPoint(in_PositionX, in_PositionY, ls_PositionR);
+                m_cfun.MoveSEMToPoint(new Point((int)in_PositionX, (int)in_PositionY), ls_PositionR);
             }
            
         }
@@ -197,7 +198,7 @@ namespace OTSIncAReportGrids.OTSIncAReportGridsFuncation
         /// </summary>
         public void DisConnectSEM_ForParticlesGrid()
         {
-            m_cfun.DisconnectSem();
+            m_cfun.DisConnect();
             //if (m_cfun.DisConnectSem() == true)
 
             m_SEMConnectionState = false;

+ 2 - 2
OTSIncAReportApp/1-UI/frmReportApp.cs

@@ -1058,8 +1058,8 @@ namespace OTSIncAReportApp
 
         private void frmReportApp_FormClosing(object sender, FormClosingEventArgs e)
         {
-            ServiceInterface.SemController sem = new ServiceInterface.SemController();
-            sem.DisConnect();
+            //ServiceInterface.SemController sem = new ServiceInterface.SemController();
+            //sem.DisConnect();
         }
 
         private void ribbonOrbMenuItem_Extremum_Click(object sender, EventArgs e)

+ 36 - 75
OTSIncAReportApp/3-ServiceCenter/SemController.cs

@@ -5,112 +5,73 @@ using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Runtime.InteropServices;
+using System.Runtime.Remoting.Channels;
+using OTSModelSharp.ServiceInterface;
+using System.Runtime.Remoting.Channels.Ipc;
+using OTSMeasureApp.ServiceCenter;
 
 namespace ServiceInterface
 {
     public class SemController 
     {
-     public static OTSCLRINTERFACE.COTSControlFunExport hw=null;
-
+       
+        //[DllImport("user32.dll", EntryPoint = "SendMessage")]
+        //private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
+        private IpcSEMController remoteObj;
         public SemController()
         {
-           
-           
+            IpcClientChannel channel = new IpcClientChannel();
+            //Register the channel with ChannelServices.
+            ChannelServices.RegisterChannel(channel, false);
+         
+
         }
 
         public bool Connect()
         {
-            if (hw == null)
+             remoteObj = (IpcSEMController)Activator.GetObject(typeof(IpcSEMController), "ipc://ServerChannel/RemoteObject");
+   
+            if (remoteObj == null)
             {
-                hw = OTSCLRINTERFACE.COTSControlFunExport.GetControllerInstance();
-            }
-            if (hw.IsConnected())
-            {
-                return true;
-            }
-            else
-            { //和电镜建立通讯连接
-                return hw.ConncetSem();
+                return false;
+            
             }
+            return true;
         }
 
         public bool DisConnect()
         {
-            if (hw != null)
-            {
+            remoteObj = null;
 
-                if (hw.IsConnected())
-                {
-                    return hw.DisconnectSem();
-                }
-            }
-           
             return true;
         }
 
-        public bool GetMagnification(ref double a_dMagnification)
-        {
-            Connect();
-            return hw.GetSemMagnification(ref a_dMagnification);
-             
-        }
-
-        public bool GetScanFieldSize(ref double dScanFieldSizeX, ref double dScanFieldSizeY)
-        {
-            Connect();
-            return  hw.GetSemScanFieldSize(ref dScanFieldSizeX, ref dScanFieldSizeY);
-        }
-
-        public bool GetSemPositionXY(ref double a_dPositionX, ref double a_dPositionY, ref double a_dPositionR)
-        {
-            Connect();
-            return hw.GetSemPositionXY(ref a_dPositionX, ref a_dPositionY, ref a_dPositionR);
-        }
-
-      
 
-        public bool GetWorkingDistance(ref double a_distance)
-        {
-            Connect();
-            return hw.GetSemWorkingDistance(ref a_distance);
-        }
 
-        public bool IsConnected()
-        {
-            //return true;
-            return hw.IsConnected();
-        }
 
         public bool MoveSEMToPoint(Point poi, double rotation)
         {
-            Connect();
-            return hw.MoveSEMToPoint(poi.X, poi.Y, rotation);
-        }
+            //Connect();
+            if (remoteObj == null)
+            {
+                return false;
 
-        public bool SetMagnification(double a_dMagnification)
-        {
-            Connect();
-            //hw.SetMagnification(a_dMagnification);
-            hw.SetSemMagnification(a_dMagnification);
-            return true;
-        }
+            }
 
-        public bool SetScanExternal(bool b)
-        {
-            Connect();
-            //int seValue = b ? 1 : 0;
-            return hw.SetSemScanExternal(b);
+            return remoteObj.MoveSEMToPoint(poi , rotation);
         }
-
-        public bool SetWorkingDistance(double a_distance)
+        public bool GetSemPositionXY(ref double ls_PositionX, ref double ls_PositionY, ref double ls_PositionR)
         {
-            Connect();
-            return hw.SetSemWorkingDistance(a_distance);
-        }
+            //Connect();
+            if (remoteObj == null)
+            {
+                return false;
 
-        public OTSCLRINTERFACE.COTSControlFunExport GetHardwareInterface()
-        {
-            return hw;
+            }
+
+            return remoteObj.GetSemPositionXY(ref ls_PositionX,ref ls_PositionY, ref ls_PositionR);
         }
+      
     }
 }

+ 6 - 1
OTSIncAReportApp/OTSIncAReportApp.csproj

@@ -230,6 +230,7 @@
     <Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
       <HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
     </Reference>
+    <Reference Include="System.Runtime.Remoting" />
     <Reference Include="System.Runtime.Serialization" />
     <Reference Include="System.ServiceModel" />
     <Reference Include="System.ServiceModel.Web" />
@@ -527,6 +528,7 @@
     <Compile Include="1-UI\OutputNlog.Designer.cs">
       <DependentUpon>OutputNlog.cs</DependentUpon>
     </Compile>
+    <Compile Include="3-ServiceCenter\SemController.cs" />
     <Compile Include="Help.cs">
       <SubType>Form</SubType>
     </Compile>
@@ -541,7 +543,6 @@
     <Compile Include="1-UI\OTSMgrInfo\frmReportSysConfig.Designer.cs">
       <DependentUpon>frmReportSysConfig.cs</DependentUpon>
     </Compile>
-    <Compile Include="3-ServiceCenter\SemController.cs" />
     <EmbeddedResource Include="1-UI\Control_Grids\ParticlesGridDevidePage.resx">
       <DependentUpon>ParticlesGridDevidePage.cs</DependentUpon>
     </EmbeddedResource>
@@ -1351,6 +1352,10 @@
       <Project>{490a8592-7b13-4536-b475-028e73007fae}</Project>
       <Name>OTSClrInterface</Name>
     </ProjectReference>
+    <ProjectReference Include="..\OTSIncAMeasureApp\OTSIncAMeasureApp.csproj">
+      <Project>{474772dc-334a-4e87-bb46-3abd913aa44a}</Project>
+      <Name>OTSIncAMeasureApp</Name>
+    </ProjectReference>
     <ProjectReference Include="..\OTSSysMgrTools\OTSSysMgrTools.csproj">
       <Project>{3b7695aa-8231-45ac-b493-84390a945d02}</Project>
       <Name>OTSSysMgrTools</Name>

+ 1 - 1
OTSSysMgrApp/ControllerSettingForm.cs

@@ -55,7 +55,7 @@ namespace OTSSysMgrApp
             //控制类对象初始化
             if (cfun == null)
             {
-                cfun =  COTSControlFunExport.GetControllerInstance();
+                cfun =new COTSControlFunExport();
             }
             lan = new OTSSysMgrTools.Language(this);
             table = lan.GetNameTable(this.Name);

+ 2 - 2
OTSSysMgrApp/SemTestForms.cs

@@ -43,9 +43,9 @@ namespace OTSSysMgrApp
             //控制类对象初始化
             if (cfun == null)
             {
-                cfun =  COTSControlFunExport.GetControllerInstance();
+                cfun =new COTSControlFunExport();
             }
-         
+
             //国际化
             lan = new OTSSysMgrTools.Language(this);
             table = lan.GetNameTable(this.Name);

+ 4 - 184
OTSSysMgrTools/Imagepro.cs

@@ -76,200 +76,20 @@ namespace OTSSysMgrTools
             }
             bmp.Palette = tempPalette;
 
-            //// 算法到此结束,返回结果    
+          
             return bmp;
         }
         #endregion
 
 
-        #region 将文件转换成byte[] 数组
-        /// <summary>
-        /// 将文件转换成byte[] 数组
-        /// </summary>
-        /// <param name="fileUrl">文件路径文件名称</param>
-        /// <returns>byte[]</returns>
-        //public static byte[] GetFileData(string fileUrl)
-        //{
-        //    FileStream pFileStream = null;
-        //    byte[] pReadByte = new byte[0];
-        //    try
-        //    {
-        //        //读取文本文件
-        //        pFileStream = new FileStream(fileUrl, FileMode.Open, FileAccess.Read);
-        //        //实例读取字节流对象
-        //        StreamReader sr = new StreamReader(pFileStream, System.Text.Encoding.Default);
-        //        string temp = sr.ReadToEnd();
-        //        //转换byte数组
-        //        byte[] byteArray = System.Text.Encoding.Default.GetBytes(temp);
-        //        //生成字符数组
-        //        string[] tempGroup = temp.Split(',');
-        //        //关闭读取对象
-        //        sr.Close();
-        //        string AppendStr = string.Empty;
-        //        for (int i = 0; i < tempGroup.Length; i++)
-        //        {
-        //            //十进制转十六进制
-        //            AppendStr += Convert.ToString(Convert.ToInt32(tempGroup[i]), 16) + " ";
-        //        }
-        //        //替换字符符号
-        //        AppendStr = AppendStr.Replace(" ", "");
-        //        if ((AppendStr.Length % 2) != 0)
-        //        {
-        //            AppendStr += " ";
-        //        }
-        //        byte[] returnBytes = new byte[AppendStr.Length / 2];
-        //        //转换为byte[]数组
-        //        for (int i = 0; i < returnBytes.Length; i++)
-        //        {
-        //            returnBytes[i] = Convert.ToByte(AppendStr.Substring(i * 2, 2), 16);
-        //        }
-        //        return returnBytes;
-        //    }
-        //    catch
-        //    {
-        //        return pReadByte;
-        //    }
-        //    finally
-        //    {
-        //        if (pFileStream != null)
-        //            pFileStream.Close();
-        //    }
-        //}
-        #endregion
-
-        #region 根据分辨率获取图像
-        //public static bool GetScanImage(string ImgWidth, string ImgHeight, string DwellTime, COTSControlFunExport cfun, ref byte[] ImageByte)
-        //{
-        //    try
-        //    {
-
-        //        //设置图像分辨率
-        //        int width = 0;
-        //        int height = 0;
-        //        //获取宽度
-        //        width = Convert.ToInt32(ImgWidth);
-        //        height = Convert.ToInt32(ImgHeight);
-                
-        //        int a_ExternalMode = 0;
-        //        //获取终止模式
-        //        a_ExternalMode = cfun.GetSemExternalMode();
-                
-        //        //保存初始模式变量
-        //        int a_oldMode = 0;
-        //        //获取初始模式
-        //        if (!cfun.GetSemScanMode(ref a_oldMode))
-        //        {
-        //            return false;
-        //        }
-        //        //设置当前模式
-        //        if (!cfun.SetSemScanMode(a_ExternalMode))
-        //        {
-        //            return false;
-        //        }
-                
-        //        #region BeamBlank
-        //        int a_nBeamBlank = 0;
-        //        //获取参数
-        //        if (!cfun.GetSemBeamBlank(ref a_nBeamBlank))
-        //        {
-        //            cfun.SetSemScanMode(a_oldMode);
-        //            return false;
-        //        }
-        //        //设置参数
-        //        if (!cfun.SetSemBeamBlank(0))
-        //        {
-        //            cfun.SetSemScanMode(a_oldMode);
-        //            return false;
-        //        }
-        //        #endregion
-               
-        //        #region 获得放大倍数
-        //        //获得放大倍数
-        //        double a_dMagnification = 0;
-        //        //获取参数
-        //        if (!cfun.GetSemMagnification(ref a_dMagnification))
-        //        {
-        //            cfun.SetSemScanMode(a_oldMode);
-        //            return false;
-        //        }
-        //        #endregion
-
-
-                
-
-        //        #region 获取 电镜 X、Y轴 与角度
-        //        //获取 电镜 X、Y轴 与角度
-        //        double PositionX = 0;
-        //        double PositionY = 0;
-        //        double PositionR = 0;
-        //        //获取参数
-        //        if (!cfun.GetSemPositionXY(ref PositionX, ref PositionY, ref PositionR))
-        //        {
-        //            cfun.SetSemScanMode(a_oldMode);
-        //            return false;
-        //        }
-        //        #endregion
-
-        //        #region 设置图像分辨率
-        //        //设置宽度
-        //        if (!cfun.SetImageSize(width, height))
-        //        {
-        //            cfun.SetSemScanMode(a_oldMode);
-        //            return false;
-        //        }
-        //        #endregion
-
-        //        #region 采集时间
-        //        //采集时间
-        //        int nDwellTime = 16;
-        //        nDwellTime = Convert.ToInt32(DwellTime);
-        //        //nDwellTime = Convert.ToInt32(tbCollectionTime.Text);
-        //        //设置采集时间
-        //        if (!cfun.SetDwellTime(nDwellTime))
-        //        {
-        //            cfun.SetSemScanMode(a_oldMode);
-        //            return false;
-        //        }
-        //        #endregion
-
-        //        #region MatrixSize
-        //        //获得放大倍数
-        //        int a_MatrixSize = 0;
-        //        Size size = new Size();
-        //        //获取参数
-        //        size = cfun.GetMatrixSize(a_MatrixSize);
-        //        #endregion
-                
-        //        //获取图像数据
-        //        int resultCount = width * height;
-        //        int GetImgCount = cfun.AcquireBSEImage(0, 0, 0, ref ImageByte);
-
-        //        if (resultCount == GetImgCount)
-        //        {
-        //            //设置为原始 扫描模式
-        //            cfun.SetSemScanMode(a_oldMode);
-        //        }
-        //        else
-        //        {
-        //            cfun.SetSemScanMode(a_oldMode);
-        //        }
-        //        return true;
+       
 
-        //    }
-        //    catch (Exception ex)
-        //    {
-        //        //记录日志
-        //         //NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
-        //         // log.Error(ex.Message.ToString());
-        //        return false;
-        //    }
-        //}
-        #endregion
+       
 
         public static int GetScanImage(int iWidth, int iHeigh, string DwellTime, ref byte[] bImageData)
         {
             //电镜设置对象
-            COTSControlFunExport cfun = COTSControlFunExport.GetControllerInstance();
+            COTSControlFunExport cfun =new COTSControlFunExport();
             int GetImgCount = 0;
             try
             {