qinqi %!s(int64=2) %!d(string=hai) anos
pai
achega
1ebf3f7c0f

+ 22 - 7
wwwroot/API/PLC/gaiXi/gaixi2207.ashx

@@ -23,6 +23,7 @@ public class gaixi2207 : IHttpHandler
         public static string dbGoodsType = "200.2";//产品型号:连体:1;智能:2
         public static string dbBarcode = "200.6";  //产品条码
         public static string dbUsercode = "200.20";
+        public static string dbInfo = "200.24";//接收条码信息(int)接收不成功=0,接收成功=1
     }
 
     public static class API
@@ -118,6 +119,20 @@ public class gaixi2207 : IHttpHandler
                             bool goodstypeflag = PlcWriteRepeat<short>(PLC.dbGoodsType, Convert.ToInt16(goodsType));
                             bool barcodeflag = PlcWriteRepeat<string>(PLC.dbBarcode, barCode);
                             bool resultflag = PlcWriteRepeat<short>(PLC.dbResult, Convert.ToInt16(1));
+                            int repeat = 5;
+                            int i = 1;
+                            result.Add(new JObject(new JProperty("PLC读取接收条码数据:",PLC.dbInfo + " = " + s7.Read<short>(PLC.dbInfo) + ";")));
+
+                            while ( Convert.ToInt16(s7.Read<short>(PLC.dbInfo)) != Convert.ToInt16(1) && i<repeat )
+                            {
+                                result.Add(new JObject(new JProperty("PLC写入数据(重写第" + i.ToString() + "次):")));
+                                goodstypeflag = PlcWriteRepeat<short>(PLC.dbGoodsType, Convert.ToInt16(goodsType));
+                                barcodeflag = PlcWriteRepeat<string>(PLC.dbBarcode, barCode);
+                                resultflag = PlcWriteRepeat<short>(PLC.dbResult, Convert.ToInt16(1));
+
+                                result.Add(new JObject(new JProperty("PLC读取接收条码数据:",PLC.dbInfo + " = " + s7.Read<short>(PLC.dbInfo) + ";")));
+                                i++;
+                            }
                             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))));
                             //========================================
                         }
@@ -147,13 +162,13 @@ public class gaixi2207 : IHttpHandler
         bool isSuccess = false;
         isSuccess = s7.Write<T>(db, (T)(value));
         result.Add(new JObject(new JProperty("PLC写入数据:", db + "=" + value.ToString())));
-        int i = 0;
-        while ( !isSuccess && i<repeat )
-        {
-            isSuccess = s7.Write<T>(db, (T)(value));
-            result.Add(new JObject(new JProperty("PLC写入数据(重写第" + i.ToString() + "次):", db + "=" + value.ToString())));
-            i++;
-        }
+        //int i = 0;
+        //while ( Convert.ToInt16(s7.Read<short>(PLC.dbInfo)) != Convert.ToInt16(1) && i<repeat )
+        //{
+        //    isSuccess = s7.Write<T>(db, (T)(value));
+        //    result.Add(new JObject(new JProperty("PLC写入数据(重写第" + i.ToString() + "次):", db + "=" + value.ToString())));
+        //    i++;
+        //}
         return isSuccess;
     }
     //xuwei end =====================================================

+ 54 - 17
wwwroot/API/PLC/gaiXi/gaixiJiaoJie2206.ashx

@@ -22,6 +22,7 @@ public class gaixiJiaoJie2206 : IHttpHandler {
         public static string dbGoodsType = "100.2";//产品型号:连体:1;智能:2
         public static string dbBarcode = "100.6";  //产品条码
         public static string dbUsercode = "100.18";
+        public static string dbInfo = "100.26";//接收条码信息(int)接收不成功=0,接收成功=1
     }
 
     public static class API
@@ -85,27 +86,47 @@ public class gaixiJiaoJie2206 : IHttpHandler {
                         if (addWorkPiece == 1)
                         {
                             int goodsType = GetGoodinfo(barCode);
-                            //写PLC  
-                            bool goodstypeflag = s7.Write<short>(PLC.dbGoodsType, Convert.ToInt16(goodsType));
-                            bool barcodeflag = s7.Write<string>(PLC.dbBarcode, barCode);
-                            bool resultflag =  s7.Write<short>(PLC.dbResult, Convert.ToInt16(1));
 
-                            result.Add(new JObject(new JProperty("PLC写入返回布尔值 ",resultflag.ToString()+";"+goodstypeflag.ToString()+";"+barcodeflag.ToString())));;
-                            for (int i = 0; i < 3; i++)
+                            ////写PLC  
+                            //bool goodstypeflag = s7.Write<short>(PLC.dbGoodsType, Convert.ToInt16(goodsType));
+                            //bool barcodeflag = s7.Write<string>(PLC.dbBarcode, barCode);
+                            //bool resultflag =  s7.Write<short>(PLC.dbResult, Convert.ToInt16(1));
+
+                            //result.Add(new JObject(new JProperty("PLC写入返回布尔值 ",resultflag.ToString()+";"+goodstypeflag.ToString()+";"+barcodeflag.ToString())));;
+                            //for (int i = 0; i < 3; i++)
+                            //{
+                            //    //if (Convert.ToInt16(s7.Read<short>(PLC.dbResult)) != Convert.ToInt16(1) ||
+                            //    //    Convert.ToInt16(s7.Read<short>(PLC.dbGoodsType)) != Convert.ToInt16(goodsType) ||
+                            //    //    s7.Read<string>(PLC.dbBarcode, 11).ToString() != barCode)
+                            //    if (!resultflag || !goodstypeflag || !barcodeflag)
+                            //    {
+                            //        //写PLC  
+                            //        s7.Write<short>(PLC.dbGoodsType, Convert.ToInt16(goodsType));
+                            //        s7.Write<string>(PLC.dbBarcode, barCode);
+                            //        s7.Write<short>(PLC.dbResult, Convert.ToInt16(1));
+                            //    }
+                            //}
+
+                            bool goodstypeflag = PlcWriteRepeat<short>(PLC.dbGoodsType, Convert.ToInt16(goodsType));
+                            bool barcodeflag = PlcWriteRepeat<string>(PLC.dbBarcode, barCode);
+                            bool resultflag = PlcWriteRepeat<short>(PLC.dbResult, Convert.ToInt16(1));
+
+                            int repeat = 5;
+                            int i = 1;
+                            result.Add(new JObject(new JProperty("PLC读取接收条码数据:",PLC.dbInfo + " = " + s7.Read<short>(PLC.dbInfo) + ";")));
+
+                            while ( Convert.ToInt16(s7.Read<short>(PLC.dbInfo)) != Convert.ToInt16(1) && i<repeat )
                             {
-                                //if (Convert.ToInt16(s7.Read<short>(PLC.dbResult)) != Convert.ToInt16(1) ||
-                                //    Convert.ToInt16(s7.Read<short>(PLC.dbGoodsType)) != Convert.ToInt16(goodsType) ||
-                                //    s7.Read<string>(PLC.dbBarcode, 11).ToString() != barCode)
-                                if (!resultflag || !goodstypeflag || !barcodeflag)
-                                {
-                                    //写PLC  
-                                    s7.Write<short>(PLC.dbGoodsType, Convert.ToInt16(goodsType));
-                                    s7.Write<string>(PLC.dbBarcode, barCode);
-                                    s7.Write<short>(PLC.dbResult, Convert.ToInt16(1));
-                                }
+                                result.Add(new JObject(new JProperty("PLC写入数据(重写第" + i.ToString() + "次):")));
+                                goodstypeflag = PlcWriteRepeat<short>(PLC.dbGoodsType, Convert.ToInt16(goodsType));
+                                barcodeflag = PlcWriteRepeat<string>(PLC.dbBarcode, barCode);
+                                resultflag = PlcWriteRepeat<short>(PLC.dbResult, Convert.ToInt16(1));
+                                     
+                                result.Add(new JObject(new JProperty("PLC读取接收条码数据:",PLC.dbInfo + " = " + s7.Read<short>(PLC.dbInfo) + ";")));
+                                i++;
                             }
 
-                            result.Add(new JObject(new JProperty("PLC写入(信息:OK)",PLC.dbResult + " = " +s7.Read<short>(PLC.dbResult) + ";" + PLC.dbGoodsType+ " = " + s7.Read<short>(PLC.dbGoodsType) + ";"+ PLC.dbBarcode + " = " + s7.Read<string>(PLC.dbBarcode,11))));
+                            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))));
 
                         }
                     }
@@ -128,6 +149,22 @@ public class gaixiJiaoJie2206 : IHttpHandler {
 
     }
 
+
+    public bool PlcWriteRepeat<T>(string db,object value,int repeat = 5)
+    {
+        bool isSuccess = false;
+        isSuccess = s7.Write<T>(db, (T)(value));
+        result.Add(new JObject(new JProperty("PLC写入数据:", db + "=" + value.ToString())));
+        //int i = 0; 
+        //while ( Convert.ToInt16(s7.Read<short>(PLC.dbInfo)) != Convert.ToInt16(1) && i<repeat )
+        //{
+        //    isSuccess = s7.Write<T>(db, (T)(value));
+        //    result.Add(new JObject(new JProperty("PLC写入数据(重写第" + i.ToString() + "次):", db + "=" + value.ToString())));
+        //    i++;
+        //}
+        return isSuccess;
+    }
+
     //读取USERCODE
     public string PlcReadUsercode()
     {

+ 2 - 0
wwwroot/API/PLC/gaiXi3_plc/gaixi6381.ashx

@@ -90,7 +90,9 @@ public class gaixi6381 : IHttpHandler
     {
         bool isSuccess = false;
         isSuccess = s7.Write<T>(db, (T)(value));
+        result.Add(new JObject(new JProperty("PLC写入数据成功标识:", isSuccess)));
         result.Add(new JObject(new JProperty("PLC写入数据:", db + "=" + value.ToString())));
+        
         int i = 0;
         while ( !isSuccess && i<repeat )
         {

BIN=BIN
wwwroot/DOC/恒洁PLC及扫码头-对接设置.xlsx