lxb 1 jaar geleden
bovenliggende
commit
bd12aff4ed

+ 41 - 1
deviceHttpServer/DeviceHttpServer.csproj

@@ -13,6 +13,22 @@
     <FileAlignment>512</FileAlignment>
     <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
     <TargetFrameworkProfile />
+    <IsWebBootstrapper>false</IsWebBootstrapper>
+    <PublishUrl>D:\publish\</PublishUrl>
+    <Install>true</Install>
+    <InstallFrom>Disk</InstallFrom>
+    <UpdateEnabled>false</UpdateEnabled>
+    <UpdateMode>Foreground</UpdateMode>
+    <UpdateInterval>7</UpdateInterval>
+    <UpdateIntervalUnits>Days</UpdateIntervalUnits>
+    <UpdatePeriodically>false</UpdatePeriodically>
+    <UpdateRequired>false</UpdateRequired>
+    <MapFileExtensions>true</MapFileExtensions>
+    <ApplicationRevision>1</ApplicationRevision>
+    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
+    <UseApplicationTrust>false</UseApplicationTrust>
+    <PublishWizardCompleted>true</PublishWizardCompleted>
+    <BootstrapperEnabled>true</BootstrapperEnabled>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <PlatformTarget>AnyCPU</PlatformTarget>
@@ -33,6 +49,18 @@
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
+  <PropertyGroup>
+    <ManifestCertificateThumbprint>FE2B6A7C949DDF03613609EACEF46FCA861E5B59</ManifestCertificateThumbprint>
+  </PropertyGroup>
+  <PropertyGroup>
+    <ManifestKeyFile>DeviceHttpServer_TemporaryKey.pfx</ManifestKeyFile>
+  </PropertyGroup>
+  <PropertyGroup>
+    <GenerateManifests>true</GenerateManifests>
+  </PropertyGroup>
+  <PropertyGroup>
+    <SignManifests>true</SignManifests>
+  </PropertyGroup>
   <ItemGroup>
     <Reference Include="Interop.EZNCAUTLib, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
@@ -141,6 +169,7 @@
       <DependentUpon>Resources.resx</DependentUpon>
       <DesignTime>True</DesignTime>
     </Compile>
+    <None Include="DeviceHttpServer_TemporaryKey.pfx" />
     <None Include="packages.config" />
     <None Include="Properties\Settings.settings">
       <Generator>SettingsSingleFileGenerator</Generator>
@@ -177,7 +206,18 @@
     <Content Include="dll\SinumerikOpcUaAPI.dll" />
     <Content Include="dll\UAClientHelperAPI.dll" />
   </ItemGroup>
-  <ItemGroup />
+  <ItemGroup>
+    <BootstrapperPackage Include=".NETFramework,Version=v4.7.2">
+      <Visible>False</Visible>
+      <ProductName>Microsoft .NET Framework 4.7.2 %28x86 和 x64%29</ProductName>
+      <Install>true</Install>
+    </BootstrapperPackage>
+    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
+      <Visible>False</Visible>
+      <ProductName>.NET Framework 3.5 SP1</ProductName>
+      <Install>false</Install>
+    </BootstrapperPackage>
+  </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.

+ 59 - 15
deviceHttpServer/Form1.cs

@@ -45,12 +45,20 @@ namespace HttpServer
 
         private void Form1_Load(object sender, EventArgs e)
         {
-            this.RecvAndSend += new RecvAndSendHandler(HttpListen_RecvAndSend);
-            #region 添加监听的信息线程添加到线程池
-            WaitCallback wc = new WaitCallback(http_Listen);
-            ThreadPool.QueueUserWorkItem(wc);
-            label1.Text = "HttpServer已开启:" + FanucHttp_Request_Url;
-            #endregion 
+            try
+            {
+                this.RecvAndSend += new RecvAndSendHandler(HttpListen_RecvAndSend);
+                #region 添加监听的信息线程添加到线程池
+                WaitCallback wc = new WaitCallback(http_Listen);
+                ThreadPool.QueueUserWorkItem(wc);
+                label1.Text = "HttpServer已开启:" + FanucHttp_Request_Url;
+                #endregion
+            }catch(Exception e2)
+            {
+                YG.Log.Instance.WriteLogAdd(">>>===HttpServer服务异常 : >>>>===" + e2.Message);
+            }
+
+
         }
 
         /// <summary>
@@ -133,25 +141,61 @@ namespace HttpServer
                         RequestBody reqBody = JsonConvert.DeserializeObject<RequestBody>(body);
                         if (reqBody.deviceType == DeviceTypeEnum.Fanuc.ToString())
                         {
-                            responseBody = FanucServer.requestHttpServer(reqBody);
-                            AddList(DateTime.Now.ToString(), "POST", request.Url.ToString(), responseBody.msg);
+                            try
+                            {
+                                responseBody = FanucServer.requestHttpServer(reqBody);
+                                AddList(DateTime.Now.ToString(), "POST", request.Url.ToString(), responseBody.msg);
+                                
+                            }
+                            catch(Exception eFunc)
+                            {
+                                YG.Log.Instance.WriteLogAdd($"法拉科异常--->>" + eFunc.Message);
+                                AddList(DateTime.Now.ToString(), "POST", request.Url.ToString(), "func:"+eFunc.Message);
+                            }
+                           
                         }
                         else if (reqBody.deviceType == DeviceTypeEnum.Opcua.ToString())
                         {
                             reqBody.userName = "OpcUaClient";
                             reqBody.password = "OPCUA123";
-                            responseBody = new OpcUaServer().requestHttpServer(reqBody);
-                            AddList(DateTime.Now.ToString(), "POST", request.Url.ToString(), responseBody.msg);
+                            try
+                            {
+                                responseBody = new OpcUaServer().requestHttpServer(reqBody);
+                                AddList(DateTime.Now.ToString(), "POST", request.Url.ToString(), responseBody.msg);
+                            }
+                            catch (Exception eOpcua)
+                            {
+                                YG.Log.Instance.WriteLogAdd($"西门子异常--->>" + eOpcua.Message);
+                                AddList(DateTime.Now.ToString(), "POST", request.Url.ToString(), "opcua:"+eOpcua.Message);
+                            }
+                            
                         }
                         else if (reqBody.deviceType == DeviceTypeEnum.Heidenhain.ToString())
                         {
-                            responseBody = new HeidenhainServer().requestHttpServer(reqBody);
-                            AddList(DateTime.Now.ToString(), "POST", request.Url.ToString(), responseBody.msg);
+                            try
+                            {
+                                responseBody = new HeidenhainServer().requestHttpServer(reqBody);
+                                AddList(DateTime.Now.ToString(), "POST", request.Url.ToString(), responseBody.msg);
+                            }
+                            catch (Exception eHeidenhain)
+                            {
+                                YG.Log.Instance.WriteLogAdd($"海德汉异常--->>" + eHeidenhain.Message);
+                                AddList(DateTime.Now.ToString(), "POST", request.Url.ToString(), "Heidenhain:" + eHeidenhain.Message);
+                            }
+                           
                         }
                         else if (reqBody.deviceType == DeviceTypeEnum.Mitsubishi.ToString())
-                        {
-                            responseBody =  MitsubishiServer.requestHttpServer(reqBody);
-                            AddList(DateTime.Now.ToString(), "POST", request.Url.ToString(), responseBody.msg);
+                        {                            
+                            try
+                            {
+                                responseBody = MitsubishiServer.requestHttpServer(reqBody);
+                                AddList(DateTime.Now.ToString(), "POST", request.Url.ToString(), responseBody.msg);
+                            }
+                            catch (Exception eMitsubishi)
+                            {
+                                YG.Log.Instance.WriteLogAdd($"三菱异常--->>" + eMitsubishi.Message);
+                                AddList(DateTime.Now.ToString(), "POST", request.Url.ToString(), "Mitsubishi:" + eMitsubishi.Message);
+                            }
                         }
                         else if (reqBody.deviceType == DeviceTypeEnum.Mazaka.ToString())
                         {

+ 32 - 0
deviceHttpServer/Program.cs

@@ -14,9 +14,41 @@ namespace HttpServer
         [STAThread]
         static void Main()
         {
+            // 设置未处理异常的处理程序
+            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
+            TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
+
+            // 设置应用程序捕获未处理的异常
+            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
+
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);
             Application.Run(new Form1());
         }
+
+        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
+        {
+            LogException(e.ExceptionObject as Exception);
+        }
+
+        private static void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
+        {
+           // LogException(e.Exception);
+            // 在生产环境中,可以选择立即抛出异常以终止程序,或者在调试时使用以下代码
+             e.SetObserved(); 
+        }
+
+        private static void LogException(Exception ex)
+        {
+            string errorLog = $"Unhandled Exception occurred: {ex.Message}, Stack Trace: {ex.StackTrace}";
+            try
+            {
+                //File.AppendAllText("error.log", errorLog);
+            }
+            catch
+            {
+                // 如果写入日志失败,可以考虑其他的错误处理方式
+            }
+        }
     }
 }

BIN
deviceHttpServer/bin/Debug/HttpServer.exe


BIN
deviceHttpServer/bin/Debug/HttpServer.pdb


+ 1 - 1
deviceHttpServer/mitsubishi/EZSockets/MitCom.cs

@@ -118,7 +118,7 @@ namespace EZSockets
                     {
                         lResultOpen = EZNcCom.Open2(lSystemType, lMachine, lTimeOut, "EZNC_LOCALHOST");//EZNC_LOCALHOST
                         lResult = lResultOpen;
-                        deviceList.Add(ipAdress, EZNcCom);
+                       // deviceList.Add(ipAdress, EZNcCom);
                         ErrorCheck("Open");
                     }
                 }

+ 1 - 1
deviceHttpServer/mitsubishi/MitsubishiServer.cs

@@ -34,7 +34,7 @@ namespace HttpServer.mitsubishi
             else
             { 
                     try
-                    {
+                    {   
                         MitCom mitCom = new MitCom(requestBody.serverUrl);
                         mitCom.GetSimConnect("M700M", "1", "10", ip);
                         responseBody.deviceState = ON_LINE_STATE;

BIN
deviceHttpServer/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache


+ 4 - 0
deviceHttpServer/obj/Debug/DeviceHttpServer.csproj.FileListAbsolute.txt

@@ -140,3 +140,7 @@ D:\项目\哈飞\xs_httpserver\deviceHttpServer\bin\Debug\System.Security.Access
 D:\项目\哈飞\xs_httpserver\deviceHttpServer\bin\Debug\System.Security.Permissions.xml
 D:\项目\哈飞\xs_httpserver\deviceHttpServer\bin\Debug\System.Security.Principal.Windows.xml
 D:\项目\哈飞\xs_httpserver\deviceHttpServer\obj\Debug\DeviceHttpServer.csproj.CopyComplete
+D:\项目\哈飞\xs_httpserver\deviceHttpServer\bin\Debug\HttpServer.exe.manifest
+D:\项目\哈飞\xs_httpserver\deviceHttpServer\bin\Debug\HttpServer.application
+D:\项目\哈飞\xs_httpserver\deviceHttpServer\obj\Debug\HttpServer.exe.manifest
+D:\项目\哈飞\xs_httpserver\deviceHttpServer\obj\Debug\HttpServer.application

BIN
deviceHttpServer/obj/Debug/HttpServer.exe


BIN
deviceHttpServer/obj/Debug/HttpServer.pdb


+ 157 - 141
deviceHttpServer/opcua/OpcUaServer.cs

@@ -30,7 +30,10 @@ namespace Fanuc_HttpServer.opcuaserver
             string fun = requestBody.type;
 
             ResponseBody responseBody = new ResponseBody();
-            if (fun == ActionTypeEnum.Connect.ToString())
+
+
+
+            if (fun == ActionTypeEnum.Collect.ToString())
             {
                 Ping pingSender = new Ping();
                 PingReply reply = pingSender.Send(requestBody.serverUrl);
@@ -39,178 +42,191 @@ namespace Fanuc_HttpServer.opcuaserver
                     //responseBody.result = false;
                     responseBody.msg = "调用失败";
                 }
-            }
-            else
-            {
-                if (deviceList == null || (deviceList.Where(m => m.Key.Equals(requestBody.serverUrl)).Count() == 0))
-                {
-                    opcServer = DeviceOPCUat.OpcUa_Connection1(requestBody.serverUrl, requestBody.userName, requestBody.password);
-                    if (opcServer.Session != null)
-                    {
-                        deviceList.Add(requestBody.serverUrl, opcServer);
-                    }
-                }
                 else
                 {
-                    opcServer = deviceList.Where(m => m.Key.Equals(requestBody.serverUrl)).FirstOrDefault().Value;
-                }
-                if (opcServer == null || !opcServer.Session.Connected)
-                {
-                    opcServer = DeviceOPCUat.OpcUa_Connection1(requestBody.serverUrl, requestBody.userName, requestBody.password);
-                }
-                //else
-                //{
-                //    opcServer.Session.Reconnect();
-                //}
-
-                if (opcServer.Session.Connected)
-                {
-                    responseBody.deviceState = ON_LINE_STATE;
-                    if (fun == ActionTypeEnum.Connect.ToString()) //连接状态
+                    requestBody.serverUrl = "opc.tcp://" + requestBody.serverUrl + ":4840";
+                    YG.Log.Instance.WriteLogAdd(">>>===come in >>>>===");
+                    if (deviceList == null || (deviceList.Where(m => m.Key.Equals(requestBody.serverUrl)).Count() == 0))
                     {
-                        responseBody.result = true;
-                    }
-                    else if (fun == ActionTypeEnum.Collect.ToString()) //采集
-                    {
-                        
-                        List<string> addresses = new List<string>();
-                        addresses.Add("ns=2;s=/Channel/GeometricAxis/feedRateOvr"); //进给倍率
-                        addresses.Add("ns=2;s=/Channel/State/acFZ"); //进给速度
-                        addresses.Add("ns=2;s=/Channel/Spindle/speedOvr");//主轴倍率
-                        addresses.Add("ns=2;s=/Channel/Spindle/actSpeed");//主轴实际速度
-                        //addresses.Add("ns=2;s=/Channel/Spindle/driveLoad");//主轴负载
-                        addresses.Add("ns=2;s=/Channel/ProgramInfo/selectedWorkPProg");//主程序
-                        addresses.Add("ns=2;s=/Nck/ChannelDiagnose/poweronTime");
-                        List<string> values = opcServer.ReadValues(addresses);
-                        RunDatasInfo runDatasInfo = new RunDatasInfo();
-                        for (int i = 0; i < values.Count; i++)
+                        YG.Log.Instance.WriteLogAdd(">>>===come in deviceList>>>>===");
+                        try
                         {
-                            if (i == 0)
-                            { 
-                                responseBody.feedRateOvr = values[i];
-                                responseBody.actFeed = values[i];
-                            }
-                            else if (i == 1)
-                            {
-                                responseBody.actFeed = values[i];
-                                
-                            }
-                            else if (i == 2)
-                            { 
-                                responseBody.spindleMagnification = values[i]; 
-                                
-                            }
-                            else if (i == 3)
-                            {
-                                responseBody.actSpindle = values[i];
-                                
-
-                            }
-                            else if (i == 4)
-                            { 
-                                responseBody.mainProg = values[i];
-
-                            }
-                            else if (i == 5)
-                            {
-                                responseBody.powerOnTime = values[i];
-
-                            }
+                            opcServer = DeviceOPCUat.OpcUa_Connection1(requestBody.serverUrl, requestBody.userName, requestBody.password);
+                        }
+                        catch (Exception e)
+                        {
+                            YG.Log.Instance.WriteLogAdd(">>>===come in deviceList1>>>>===" + e.Message);
                         }
-                        // responseBody.runDatasInfo = JsonConvert.SerializeObject(runDatasInfo);
 
+                        YG.Log.Instance.WriteLogAdd(">>>===come in deviceList2>>>>===");
+                        if (opcServer.Session != null)
+                        {
+                            deviceList.Add(requestBody.serverUrl, opcServer);
+                        }
                     }
-                    else if (fun == ActionTypeEnum.ToolList.ToString())
-                    {
-                        //List<ToolsInfo> toolInfoList = new List<ToolsInfo>();
-                        //int index = 1;
-                        //List<string> stringList = this.readVariables(opcServer, new string[6]
-                        //   {
-                        //                      "/Tool/Catalogue/toolNo[u<Area index>, <Row index>]".Replace("<Area index>", this.currentToolArea.ToString()).Replace("<Row index>", index.ToString()),
-                        //                      "/Tool/Catalogue/toolIdent[u<Area index>, <Row index>]".Replace("<Area index>", this.currentToolArea.ToString()).Replace("<Row index>", index.ToString()),
-                        //                      "/Tool/Catalogue/toolInMag[u<Area index>, <Row index>]".Replace("<Area index>", this.currentToolArea.ToString()).Replace("<Row index>", index.ToString()),
-                        //                      "/Tool/Catalogue/toolInPlace[u<Area index>, <Row index>]".Replace("<Area index>", this.currentToolArea.ToString()).Replace("<Row index>", index.ToString()),
-                        //                      "/Tool/Catalogue/nrDuplo[u<Area index>, <Row index>]".Replace("<Area index>", this.currentToolArea.ToString()).Replace("<Row index>", index.ToString()),
-                        //                      "/Tool/Catalogue/numCuttEdges[u<Area index>, <Row index>]".Replace("<Area index>", this.currentToolArea.ToString()).Replace("<Row index>", index.ToString())
-                        //   }
-                        //   );
-                        //ToolsInfo toolInfo = new ToolsInfo(); ;
-                        //toolInfo.number = Convert.ToUInt16(stringList[0]) + "";
-                        ////toolInfo.toolIdent = stringList[1];
-                        ////toolInfo.toolInMag = Convert.ToUInt16(stringList[2]);
-                        ////toolInfo.toolInPlace = Convert.ToUInt16(stringList[3]);
-                        ////toolInfo.nrDuplo = Convert.ToUInt16(stringList[4]);
-                        ////toolInfo.numCuttEdges = Convert.ToUInt16(stringList[5]);
-                        //toolInfoList.Add(toolInfo);
-                        //    responseBody.toolsInfo = toolInfoList;
-                    }
-                    else if (fun == ActionTypeEnum.Read.ToString())
+                    else
                     {
-
+                        opcServer = deviceList.Where(m => m.Key.Equals(requestBody.serverUrl)).FirstOrDefault().Value;
                     }
-                    else if (fun == ActionTypeEnum.Write.ToString())
+                    if (opcServer == null || !opcServer.Session.Connected)
                     {
-
+                        opcServer = DeviceOPCUat.OpcUa_Connection1(requestBody.serverUrl, requestBody.userName, requestBody.password);
                     }
+                    //else
+                    //{
+                    //    opcServer.Session.Reconnect();
+                    //}
 
-                    else if (fun == ActionTypeEnum.Upload.ToString())
+                    if (opcServer.Session.Connected)
                     {
-                        string file = requestBody.path;
-                        string serverPath = "";
-                        //选择临时文件
-                        string status = opcServer.MethodCallSelectProgram(UPLOAD_NC_PATH + TEMP_NC_NAME, Convert.ToUInt32(CHANNEL_NO)).status;
-                        try
+                        responseBody.deviceState = ON_LINE_STATE;
+                        if (fun == ActionTypeEnum.Connect.ToString()) //连接状态
                         {
-                            string extension = Path.GetExtension(file);
-                            if (string.IsNullOrWhiteSpace(extension))
+                            responseBody.result = true;
+                        }
+                        else if (fun == ActionTypeEnum.Collect.ToString()) //采集
+                        {
+
+                            List<string> addresses = new List<string>();
+                            addresses.Add("ns=2;s=/Channel/GeometricAxis/feedRateOvr"); //进给倍率
+                            addresses.Add("ns=2;s=/Channel/State/actFeedRateIpo"); //进给速度
+                            addresses.Add("ns=2;s=/Channel/Spindle/speedOvr");//主轴倍率
+                            addresses.Add("ns=2;s=/Channel/Spindle/actSpeed");//主轴实际速度
+                                                                              //addresses.Add("ns=2;s=/Channel/Spindle/driveLoad");//主轴负载
+                            addresses.Add("ns=2;s=/Channel/ProgramInfo/selectedWorkPProg");//主程序
+                            addresses.Add("ns=2;s=/Nck/ChannelDiagnose/poweronTime");
+                            List<string> values = opcServer.ReadValues(addresses);
+                            RunDatasInfo runDatasInfo = new RunDatasInfo();
+                            for (int i = 0; i < values.Count; i++)
                             {
-                                responseBody.msg = "文件名不合法";
+                                if (i == 0)
+                                {
+                                    responseBody.feedRateOvr = values[i];
+                                    responseBody.actFeed = values[i];
+                                }
+                                else if (i == 1)
+                                {
+                                    responseBody.actFeed = values[i];
+
+                                }
+                                else if (i == 2)
+                                {
+                                    responseBody.spindleMagnification = values[i];
+
+                                }
+                                else if (i == 3)
+                                {
+                                    responseBody.actSpindle = values[i];
+
+
+                                }
+                                else if (i == 4)
+                                {
+                                    responseBody.mainProg = values[i];
+
+                                }
+                                else if (i == 5)
+                                {
+                                    responseBody.powerOnTime = values[i];
+
+                                }
                             }
-                            try
-                            {
+                            // responseBody.runDatasInfo = JsonConvert.SerializeObject(runDatasInfo);
+
+                        }
+                        else if (fun == ActionTypeEnum.ToolList.ToString())
+                        {
+                            //List<ToolsInfo> toolInfoList = new List<ToolsInfo>();
+                            //int index = 1;
+                            //List<string> stringList = this.readVariables(opcServer, new string[6]
+                            //   {
+                            //                      "/Tool/Catalogue/toolNo[u<Area index>, <Row index>]".Replace("<Area index>", this.currentToolArea.ToString()).Replace("<Row index>", index.ToString()),
+                            //                      "/Tool/Catalogue/toolIdent[u<Area index>, <Row index>]".Replace("<Area index>", this.currentToolArea.ToString()).Replace("<Row index>", index.ToString()),
+                            //                      "/Tool/Catalogue/toolInMag[u<Area index>, <Row index>]".Replace("<Area index>", this.currentToolArea.ToString()).Replace("<Row index>", index.ToString()),
+                            //                      "/Tool/Catalogue/toolInPlace[u<Area index>, <Row index>]".Replace("<Area index>", this.currentToolArea.ToString()).Replace("<Row index>", index.ToString()),
+                            //                      "/Tool/Catalogue/nrDuplo[u<Area index>, <Row index>]".Replace("<Area index>", this.currentToolArea.ToString()).Replace("<Row index>", index.ToString()),
+                            //                      "/Tool/Catalogue/numCuttEdges[u<Area index>, <Row index>]".Replace("<Area index>", this.currentToolArea.ToString()).Replace("<Row index>", index.ToString())
+                            //   }
+                            //   );
+                            //ToolsInfo toolInfo = new ToolsInfo(); ;
+                            //toolInfo.number = Convert.ToUInt16(stringList[0]) + "";
+                            ////toolInfo.toolIdent = stringList[1];
+                            ////toolInfo.toolInMag = Convert.ToUInt16(stringList[2]);
+                            ////toolInfo.toolInPlace = Convert.ToUInt16(stringList[3]);
+                            ////toolInfo.nrDuplo = Convert.ToUInt16(stringList[4]);
+                            ////toolInfo.numCuttEdges = Convert.ToUInt16(stringList[5]);
+                            //toolInfoList.Add(toolInfo);
+                            //    responseBody.toolsInfo = toolInfoList;
+                        }
+                        else if (fun == ActionTypeEnum.Read.ToString())
+                        {
 
-                                byte[] data = opcServer.ReadFile(file);
+                        }
+                        else if (fun == ActionTypeEnum.Write.ToString())
+                        {
 
-                                serverPath = UPLOAD_NC_PATH + Path.GetFileName(file);
-                                Server.MethodCallResult methodCallResult = opcServer.MethodCallCopyFileToServer("/Methods/CopyFileToServer", serverPath, data, true);
+                        }
 
-                                if (methodCallResult.status.ToUpper().Equals("GOOD"))
+                        else if (fun == ActionTypeEnum.Upload.ToString())
+                        {
+                            string file = requestBody.path;
+                            string serverPath = "";
+                            //选择临时文件
+                            string status = opcServer.MethodCallSelectProgram(UPLOAD_NC_PATH + TEMP_NC_NAME, Convert.ToUInt32(CHANNEL_NO)).status;
+                            try
+                            {
+                                string extension = Path.GetExtension(file);
+                                if (string.IsNullOrWhiteSpace(extension))
                                 {
-                                    responseBody.msg = "上传文件成功";
-                                    YG.Log.Instance.WriteLogAdd(file + "上传文件成功");
+                                    responseBody.msg = "文件名不合法";
                                 }
-                                else
+                                try
                                 {
-                                    responseBody.msg = "上传文件失败";
-                                    YG.Log.Instance.WriteLogAdd(file + "上传文件失败");
+
+                                    byte[] data = opcServer.ReadFile(file);
+
+                                    serverPath = UPLOAD_NC_PATH + Path.GetFileName(file);
+                                    Server.MethodCallResult methodCallResult = opcServer.MethodCallCopyFileToServer("/Methods/CopyFileToServer", serverPath, data, true);
+
+                                    if (methodCallResult.status.ToUpper().Equals("GOOD"))
+                                    {
+                                        responseBody.msg = "上传文件成功";
+                                        YG.Log.Instance.WriteLogAdd(file + "上传文件成功");
+                                    }
+                                    else
+                                    {
+                                        responseBody.msg = "上传文件失败";
+                                        YG.Log.Instance.WriteLogAdd(file + "上传文件失败");
+                                    }
+                                    // } 
+                                }
+                                catch (Exception ex)
+                                {
+                                    responseBody.msg = "上传文件失败===>" + ex.Message;
+                                    YG.Log.Instance.WriteLogAdd($"{ex.Message}");
                                 }
-                                // } 
+
+
                             }
                             catch (Exception ex)
                             {
                                 responseBody.msg = "上传文件失败===>" + ex.Message;
-                                YG.Log.Instance.WriteLogAdd($"{ex.Message}");
+                                YG.Log.Instance.WriteLogAdd($"493-->{ex.Message}");
                             }
-
-
-                        }
-                        catch (Exception ex)
-                        {
-                            responseBody.msg = "上传文件失败===>" + ex.Message;
-                            YG.Log.Instance.WriteLogAdd($"493-->{ex.Message}");
+                            //设位主程序
+                            status = opcServer.MethodCallSelectProgram(serverPath, Convert.ToUInt32(CHANNEL_NO)).status;
                         }
-                        //设位主程序
-                        status = opcServer.MethodCallSelectProgram(serverPath, Convert.ToUInt32(CHANNEL_NO)).status;
-                    }
 
-                }
-                else
-                {
-                    responseBody.code = 0;
-                    responseBody.msg = "服务器离线,连不上opcUa";
-                    responseBody.result = false;
+                    }
+                    else
+                    {
+                        responseBody.code = 0;
+                        responseBody.msg = "服务器离线,连不上opcUa";
+                        responseBody.result = false;
+                    }
                 }
             }
+            
             return responseBody;
         }
     }