oyq28 6 месяцев назад
Родитель
Сommit
9d1e2ebefc
2 измененных файлов с 82 добавлено и 15 удалено
  1. 4 0
      opcua/Device/body/RequestBody.cs
  2. 78 15
      opcua/Form_Main.cs

+ 4 - 0
opcua/Device/body/RequestBody.cs

@@ -34,6 +34,10 @@ namespace IMCS.Device
         public List<string> subFileList
         { get; set; } = new List<string>();
 
+        /// 对刀仪数据集合
+        public List<string> toolFileList
+        { get; set; } = new List<string>();
+
         public string prgName
         { get; set; }
 

+ 78 - 15
opcua/Form_Main.cs

@@ -36,6 +36,7 @@ namespace IMCS
     {
         //public string UPLOAD_NC_PATH = "Sinumerik/FileSystem/Work Pieces/";
         public string UPLOAD_NC_PATH = "Sinumerik/FileSystem/NCExtend/wks.dir/nc_program/";
+        public string UPLOAD_TOOL_PATH = "Sinumerik/FileSystem/NCExtend/wks.dir/tool_device/";
         //public string UPLOAD_NC_PATH = "Sinumerik/FileSystem/Work Pieces/WORK_NC/";
         public string CHANNEL_NO = "1";
         public string TEMP_NC_NAME = "7999.MPF";
@@ -173,10 +174,10 @@ namespace IMCS
                                         // 封装需要采集字段的数据
                                         this.addAddress(opcBody);
                                     }
-                                    /*else
+                                    else
                                     {
                                         opcBody.Addresses.Add("ns=2;s=/Plc/DB2.DBX626.6");//千机质检结果
-                                    }*/
+                                    }
                                     List<string> values = opcServer.ReadValues(opcBody.Addresses);
                                     responseBody.values = values;
                                     /*RunDatasInfo runDatasInfo = new RunDatasInfo();
@@ -235,7 +236,9 @@ namespace IMCS
                                     List<ToolsInfo> toolInfoList = new List<ToolsInfo>();
                                     for (int index = 1; index <= num; index++)
                                     {
-                                        List<string> stringList = this.readVariables(opcServer, new string[10]
+                                        try
+                                        {
+                                            List<string> stringList = this.readVariables(opcServer, new string[10]
                                        {
                                           "/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()),
@@ -250,18 +253,24 @@ namespace IMCS
                                        }
                                        );
 
-                                        ToolsInfo toolInfo = new ToolsInfo(); ;
-                                        toolInfo.number = Convert.ToUInt16(stringList[0]) + "";
-                                        toolInfo.name = stringList[1];
-                                        toolInfo.length = stringList[6];
-                                        toolInfo.radius = stringList[7];
-                                        toolInfo.wearLength = stringList[8];
-                                        toolInfo.wearRadius = stringList[9];
-                                        //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);
+                                            ToolsInfo toolInfo = new ToolsInfo(); ;
+                                            toolInfo.number = Convert.ToUInt16(stringList[0]) + "";
+                                            toolInfo.name = stringList[1];
+                                            toolInfo.length = stringList[6];
+                                            toolInfo.radius = stringList[7];
+                                            toolInfo.wearLength = stringList[8];
+                                            toolInfo.wearRadius = stringList[9];
+                                            //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);
+                                        }
+                                        catch (Exception ex)
+                                        {
+                                            YG.Log.Instance.WriteLogAdd($"{ex.Message}"+":"+ index);
+                                        }
+                                        
                                     }
                                     responseBody.toolsInfo = JsonConvert.SerializeObject(toolInfoList);
                                 }
@@ -391,6 +400,7 @@ namespace IMCS
                                             YG.Log.Instance.WriteLogAdd($"493-->{ex.Message}");
                                         }
                                     }
+
                                     //设为主程序
                                     status = opcServer.MethodCallSelectProgram(UPLOAD_NC_PATH + opcBody.prgName, Convert.ToUInt32(CHANNEL_NO)).status;
                                     if (status != "Good")
@@ -398,6 +408,58 @@ namespace IMCS
                                         responseBody.msg = "选择失败";
                                         responseBody.result = false;
                                     }
+
+                                    for (int i = 0; i < opcBody.toolFileList.Count; i++)
+                                    {
+                                        string file = opcBody.toolFileList[i];
+                                        string serverPath = "";
+                                        try
+                                        {
+                                            string extension = Path.GetExtension(file);
+                                            if (string.IsNullOrWhiteSpace(extension))
+                                            {
+                                                responseBody.result = false;
+                                                responseBody.msg = file + "==文件名不合法";
+                                                break;
+                                            }
+                                            try
+                                            {
+
+                                                byte[] data = opcServer.ReadFile(file);
+
+                                                serverPath = UPLOAD_TOOL_PATH + Path.GetFileName(file);
+                                                Server.MethodCallResult methodCallResult = opcServer.MethodCallCopyFileToServer("/Methods/CopyFileToServer", serverPath, data, true);
+
+                                                if (methodCallResult.status.ToUpper().Equals("GOOD"))
+                                                {
+
+                                                    YG.Log.Instance.WriteLogAdd(file + "对刀仪上传文件成功");
+                                                }
+                                                else
+                                                {
+                                                   
+                                                    YG.Log.Instance.WriteLogAdd(file + "对刀仪上传文件失败");
+                                                    break;
+                                                }
+                                            }
+                                            catch (Exception ex)
+                                            {
+                                               
+                                                YG.Log.Instance.WriteLogAdd($"{ex.Message}");
+                                                break;
+                                            }
+
+
+                                        }
+                                        catch (Exception ex)
+                                        {
+
+                                            YG.Log.Instance.WriteLogAdd($"对刀仪493-->{ex.Message}");
+                                        }
+                                    }
+
+
+                                    
                                 }
                                 else if (opcBody.Type == ActionTypeEnum.DownLoad.ToString())
                                 {
@@ -596,6 +658,7 @@ namespace IMCS
                             responseBody.result = false;
 
                             AddList(DateTime.Now.ToString(), "POST", request.Url.ToString(), opcex.Message);
+                            YG.Log.Instance.WriteLogAdd(opcex.StackTrace);
                         }
                         finally
                         {