ztl 2 лет назад
Родитель
Сommit
103b7fde1f

+ 3 - 3
wwwroot/API/PLC/autoPacking/autoPacking6151.ashx

@@ -46,7 +46,7 @@ public class autoPacking6151 : IHttpHandler
     public bool resultFlag = false;
     public JArray result = new JArray();
 
-    public S7 s7 = new S7();
+    public static S7 s7 = new S7();
 
     //打开PLC
     public int PlcOpen()
@@ -883,7 +883,7 @@ public class autoPacking6151 : IHttpHandler
                     PlcWriteResult(4);
                 }
             }
-            PlcClose();
+            //PlcClose();
         }
         context.Response.Write(new JsonResult(resultFlag ? JsonStatus.success : JsonStatus.error) { rows = result }.ToJson());
     }
@@ -939,7 +939,7 @@ public class autoPacking6151 : IHttpHandler
                     PlcWriteResult(6);
                 }
             }
-            PlcClose();
+            //PlcClose();
         }
         context.Response.Write(new JsonResult(resultFlag ? JsonStatus.success : JsonStatus.error) { rows = result }.ToJson());
     }

+ 3 - 3
wwwroot/API/PLC/autoPacking/autoPacking6151_db.ashx

@@ -26,7 +26,7 @@ public class autoPacking6151_db : IHttpHandler
         public static string dbUsercode = "150.376"; //150.374 => 150.376
     }
 
-    public S7 s7 = new S7();
+    public static S7 s7 = new S7();
 
     public void ProcessRequest(HttpContext context)
     {
@@ -62,7 +62,7 @@ public class autoPacking6151_db : IHttpHandler
 
         s7.Write<string>(PLC.dbBanMa, "00000000").ToString();
         s7.Write<string>(PLC.dbUsercode, "DONGKE").ToString();
-        s7.Close();
+        //s7.Close();
         context.Response.Write("INIT OK!");
     }
 
@@ -100,7 +100,7 @@ public class autoPacking6151_db : IHttpHandler
         context.Response.Write("板码:[" + PLC.dbBanMa + "]:" + banma + "\n");
         string usercode = s7.Read<string>(PLC.dbUsercode, 6).ToString();
         context.Response.Write("工号:[" + PLC.dbUsercode + "]:" + usercode + "\n");
-        s7.Close();
+        //s7.Close();
     }
 
     public bool IsReusable

+ 3 - 3
wwwroot/API/PLC/autoPacking_local/autoPacking6151.ashx

@@ -46,7 +46,7 @@ public class autoPacking6151 : IHttpHandler
     public bool resultFlag = false;
     public JArray result = new JArray();
 
-    public S7 s7 = new S7();
+    public static S7 s7 = new S7();
 
     //打开PLC
     public int PlcOpen()
@@ -882,7 +882,7 @@ public class autoPacking6151 : IHttpHandler
                     PlcWriteResult(4);
                 }
             }
-            PlcClose();
+            //PlcClose();
         }
         context.Response.Write(new JsonResult(resultFlag ? JsonStatus.success : JsonStatus.error) { rows = result }.ToJson());
     }
@@ -930,7 +930,7 @@ public class autoPacking6151 : IHttpHandler
                     PlcWriteResult(6);
                 }
             }
-            PlcClose();
+            //PlcClose();
         }
         context.Response.Write(new JsonResult(resultFlag ? JsonStatus.success : JsonStatus.error) { rows = result }.ToJson());
     }

+ 3 - 3
wwwroot/API/PLC/autoPacking_local/autoPacking6151_db.ashx

@@ -26,7 +26,7 @@ public class autoPacking6151_db : IHttpHandler
         public static string dbUsercode = "2.376"; //150.374 => 150.376
     }
 
-    S7 s7 = new S7();
+    public static S7 s7 = new S7();
 
     public void ProcessRequest(HttpContext context)
     {
@@ -62,7 +62,7 @@ public class autoPacking6151_db : IHttpHandler
 
         s7.Write<string>(PLC.dbBanMa, "00000000").ToString();
         s7.Write<string>(PLC.dbUsercode, "DONGKE").ToString();
-        s7.Close();
+        //s7.Close();
         context.Response.Write("INIT OK!");
     }
 
@@ -100,7 +100,7 @@ public class autoPacking6151_db : IHttpHandler
         context.Response.Write("板码:[" + PLC.dbBanMa + "]:" + banma + "\n");
         string usercode = s7.Read<string>(PLC.dbUsercode, 6).ToString();
         context.Response.Write("工号:[" + PLC.dbUsercode + "]:" + usercode + "\n");
-        s7.Close();
+        //s7.Close();
     }
 
     public bool IsReusable

+ 2 - 2
wwwroot/API/PLC/gaiXi/gaixi2207.ashx

@@ -37,7 +37,7 @@ public class gaixi2207 : IHttpHandler
     }
 
     public JArray result = new JArray();
-    public S7 s7 = new S7();
+    public static  S7 s7 = new S7();
 
     //打开PLC
     public int PlcOpen()
@@ -128,7 +128,7 @@ public class gaixi2207 : IHttpHandler
                     }
 
                 }
-                PlcClose();
+                //PlcClose();
 
             }
             context.Response.Write(new JsonResult(JsonStatus.success) { rows = result }.ToJson());

+ 2 - 2
wwwroot/API/PLC/gaiXi/gaixiJiaoJie2206.ashx

@@ -36,7 +36,7 @@ public class gaixiJiaoJie2206 : IHttpHandler {
     }
 
     public JArray result = new JArray();
-    public S7 s7 = new S7();
+    public static  S7 s7 = new S7();
 
     //打开PLC
     public int PlcOpen()
@@ -115,7 +115,7 @@ public class gaixiJiaoJie2206 : IHttpHandler {
                     }
 
                 }
-                PlcClose();
+                //PlcClose();
 
             }
             context.Response.Write(new JsonResult(JsonStatus.success) { rows = result }.ToJson());

+ 1 - 30
wwwroot/API/PLC/gaiXi3_plc/gaixi6381.ashx

@@ -17,8 +17,6 @@ public class gaixi6381 : IHttpHandler
 
     public static class PLC
     {
-        public static string plcIp = "172.18.37.141";
-        public static int plcPort = 102;
         public static string dbResult = "100.0";   //产品型号(int)产品的标识码(盖板标识码)
         public static string dbGoodsType = "100.2";//产品型号:连体:1;智能:2
         public static string dbBarcode = "100.8";  //产品条码 
@@ -35,32 +33,9 @@ public class gaixi6381 : IHttpHandler
     //    public static int procedureID = 2; //改洗 
     //}
 
+    public static S7 s7=new S7("172.18.37.141");
     public JArray result = new JArray();
-    public S7 s7 = new S7();
 
-    //打开PLC
-    public int PlcOpen()
-    {
-        try
-        {
-            s7.Open(PLC.plcIp, PLC.plcPort);
-            result.Add(new JObject(new JProperty("PLC连接", PLC.plcIp + ":" + PLC.plcPort + " 连接成功!")));
-        }
-        catch (Exception e)
-        {
-            result.Add(new JObject(new JProperty("PLC连接", PLC.plcIp + ":" + PLC.plcPort + " 连接失败!")));
-            result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
-        }
-        return 1;
-    }
-
-    //关闭PLC
-    public int PlcClose()
-    {
-        s7.Close();
-        result.Add(new JObject(new JProperty("PLC关闭", PLC.plcIp + ":" + PLC.plcPort + " 关闭成功!")));
-        return 1;
-    }
 
     //主程序入口
     public void ProcessRequest(HttpContext context)
@@ -69,8 +44,6 @@ public class gaixi6381 : IHttpHandler
         if (context.Request["barcode"] is object)
         {
             string barCode = context.Request["barcode"].ToString();
-            if (PlcOpen() == 1)
-            {
                 DataTable goodsType = GetGoodinfo(barCode);
                 /*
                 //写PLC  
@@ -103,8 +76,6 @@ public class gaixi6381 : IHttpHandler
                 bool resultflag = PlcWriteRepeat<short>(PLC.dbResult, goodsType.Rows[0]["SEATCOVERCODE"].ToString());
                 result.Add(new JObject(new JProperty("PLC读出(核对)", PLC.dbResult + " = " + s7.Read<short>(PLC.dbResult) + ";" + PLC.dbGoodsType + " = " + s7.Read<short>(PLC.dbGoodsType) + ";" + PLC.dbBarcode + " = " + s7.Read<string>(PLC.dbBarcode, 11))));
                 //========================================
-                PlcClose();
-            }
             context.Response.Write(new JsonResult(JsonStatus.success) { rows = result }.ToJson());
         }
         else

BIN
wwwroot/Bin/DK.XuWei.WebMes.dll