Просмотр исходного кода

包装码垛接口加入工号

xuwei 2 лет назад
Родитель
Сommit
a8eeabf865

+ 84 - 49
wwwroot/API/PLC/autoPacking/autoPacking6151.ashx

@@ -80,7 +80,6 @@ public class autoPacking6151 : IHttpHandler
         {
             int read = Convert.ToInt16(SiemensS7.Read<short>(PLC.dbRead));
             result.Add(new JObject(new JProperty("PLC读取(读取标识)", PLC.dbRead + " = " + read.ToString())));
-            resultFlag = true;
             return read;
         }
         catch (Exception e)
@@ -99,7 +98,6 @@ public class autoPacking6151 : IHttpHandler
         {
             int read = Convert.ToInt16(SiemensS7.Read<short>(PLC.dbGoodsId));
             result.Add(new JObject(new JProperty("PLC读取(产品ID)", PLC.dbGoodsId + " = " + read.ToString())));
-            resultFlag = true;
             return read;
         }
         catch (Exception e)
@@ -118,7 +116,6 @@ public class autoPacking6151 : IHttpHandler
         {
             int read = Convert.ToInt16(SiemensS7.Read<short>(PLC.dbGoodsNum));
             result.Add(new JObject(new JProperty("PLC读取(装板数量)", PLC.dbGoodsNum + " = " + read.ToString())));
-            resultFlag = true;
             return read;
         }
         catch (Exception e)
@@ -137,7 +134,6 @@ public class autoPacking6151 : IHttpHandler
         {
             int read = Convert.ToInt16(SiemensS7.Read<short>(PLC.dbLogoId));
             result.Add(new JObject(new JProperty("PLC读取(产品ID)", PLC.dbLogoId + " = " + read.ToString())));
-            resultFlag = true;
             return read;
         }
         catch (Exception e)
@@ -161,7 +157,6 @@ public class autoPacking6151 : IHttpHandler
                 obj.Add(new JProperty("条码" + (i + 1).ToString().PadLeft(2, '0') + "(" + PLC.dbBarcodeBlock[i] + ")", barCodes[i]));
             }
             result.Add(new JObject(new JProperty("PLC读取(产品条码)", obj)));
-            resultFlag = true;
             return barCodes;
         }
         catch (Exception e)
@@ -180,7 +175,6 @@ public class autoPacking6151 : IHttpHandler
         {
             string read = SiemensS7.Read<string>(PLC.dbBanMa, 8).ToString();
             result.Add(new JObject(new JProperty("PLC读取(板码)", PLC.dbBanMa + " = " + read.ToString())));
-            resultFlag = true;
             return read;
         }
         catch (Exception e)
@@ -199,7 +193,6 @@ public class autoPacking6151 : IHttpHandler
         {
             string read = SiemensS7.Read<string>(PLC.dbMaterialcode, 14).ToString();
             result.Add(new JObject(new JProperty("PLC读取(物料号)", PLC.dbMaterialcode + " = " + read.ToString())));
-            resultFlag = true;
             return read;
         }
         catch (Exception e)
@@ -218,7 +211,6 @@ public class autoPacking6151 : IHttpHandler
         {
             int read = Convert.ToInt32(SiemensS7.Read<short>(PLC.dbResult));
             result.Add(new JObject(new JProperty("PLC读取(结果)", PLC.dbResult + " = " + read.ToString())));
-            resultFlag = true;
             return read;
         }
         catch (Exception e)
@@ -230,21 +222,20 @@ public class autoPacking6151 : IHttpHandler
     }
 
     //读取USERCODE
-    public int PlcReadUsercode()
+    public string PlcReadUsercode()
     {
-        if (!resultFlag) return -1;
+        if (!resultFlag) return "";
         try
         {
-            int read = Convert.ToInt32(SiemensS7.Read<string>(PLC.dbUsercode,6));
+            string read = SiemensS7.Read<string>(PLC.dbUsercode,6).ToString();
             result.Add(new JObject(new JProperty("PLC读取(USECODE)", PLC.dbUsercode + " = " + read.ToString())));
-            resultFlag = true;
             return read;
         }
         catch (Exception e)
         {
             result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
             resultFlag = false;
-            return -1;
+            return "";
         }
     }
 
@@ -344,12 +335,25 @@ public class autoPacking6151 : IHttpHandler
     }
 
     //写入执行结果
+    // 1 通过 2 条码格式错误 3 产品不可到达 4 MES异常 5 条码不一致 6 绑板完成 7 工号读取错误
     public int PlcWriteResult(Int16 flag)
     {
         try
         {
+            string message = "";
+            switch(flag)
+            {
+                case 1:message = "OK:扫码通过";break;
+                case 2:message = "ERR:条码格式错误";break;
+                case 3:message = "ERR:产品不可到达";break;
+                case 4:message = "ERR:MES异常";break;
+                case 5:message = "ERR:条码不一致";break;
+                case 6:message = "ERR:绑板完成";break;
+                case 7:message = "ERR:工号读取错误";break;
+                default:message = "ERR:未定义";break;
+            }
             SiemensS7.Write<short>(PLC.dbResult, flag);
-            result.Add(new JObject(new JProperty("PLC写入(执行结果)", PLC.dbResult + " = " + flag.ToString())));
+            result.Add(new JObject(new JProperty("PLC写入("+message+")", PLC.dbResult + " = " + flag.ToString())));
             return 1;
         }
         catch (Exception e)
@@ -412,7 +416,7 @@ public class autoPacking6151 : IHttpHandler
             {
                 resultFlag = false;
                 result.Add(new JObject(
-                    new JProperty("API调用(条码状态)", "操作失败!"),
+                    new JProperty("API调用(条码状态)", json["d"]["Message"].ToString()),
                     new JProperty("接口", "/DKService/PDAModuleService/GetStatusByBarcode"),
                     new JProperty("参数(procedureID)", API.procedureID),
                     new JProperty("参数(barCode)", barCode)
@@ -478,7 +482,7 @@ public class autoPacking6151 : IHttpHandler
             {
                 resultFlag = false;
                 result.Add(new JObject(
-                    new JProperty("API调用(条码验证)", "操作失败!"),
+                    new JProperty("API调用(条码验证)", json["d"]["Message"].ToString()),
                     new JProperty("接口", "/DKService/PDAModuleService/CheckBarcode"),
                     new JProperty("参数(procedureID)", API.procedureID),
                     new JProperty("参数(barCode)", barCode)
@@ -557,7 +561,7 @@ public class autoPacking6151 : IHttpHandler
             {
                 resultFlag = false;
                 result.Add(new JObject(
-                    new JProperty("API调用(装板数量)", "操作失败!"),
+                    new JProperty("API调用(装板数量)", json["d"]["Message"].ToString()),
                     new JProperty("接口", "/DKService/PDAModuleService/DoAction"),
                     new JProperty("参数(ACTION)", "GetSetting"),
                     new JProperty("参数(MODULE)", "FinishedLoadingCar"),
@@ -637,7 +641,7 @@ public class autoPacking6151 : IHttpHandler
             {
                 resultFlag = false;
                 result.Add(new JObject(
-                    new JProperty("API调用(包装码垛)", "操作失败!"),
+                    new JProperty("API调用(包装码垛)", json["d"]["Message"].ToString()),
                     new JProperty("接口", "/DKService/PDAModuleService/AddWorkPiece"),
                     new JProperty("参数(procedureID)", API.procedureID),
                     new JProperty("参数(productionDataEntitys)", productionDataEntitys)
@@ -714,30 +718,36 @@ public class autoPacking6151 : IHttpHandler
             using (IDataAccess conn = DataAccess.Create())
             {
                 DataTable dt = conn.ExecuteDatatable(@"
-				    SELECT 
-                        * 
-                    FROM 
-                        TP_MST_USER
+                    SELECT
+	                    u.ACCOUNTCODE,
+	                    u.USERID,
+	                    u.USERCODE,
+	                    u.USERNAME,
+	                    u.PASSWORD,
+	                    l.SESSIONKEY
+                    FROM
+	                    TP_MST_USER u
+	                    LEFT JOIN TP_MST_USERLOGIN l ON u.USERID = l.USERID 
                     WHERE
-                        USERCODE = @USERCODE@ 
+                        u.USERCODE = @USERCODE@ 
 				    ",
                     new CDAParameter("USERCODE", userCode)
                 );
                 if(dt.Rows.Count >0 )
                 {
-                    API.accountCode = dt.Rows[0]["accountCode"].ToString();
-                    API.userId = dt.Rows[0]["userId"].ToString();
-                    API.userCode = dt.Rows[0]["userCode"].ToString();
-                    API.userName = dt.Rows[0]["userName"].ToString();
-                    API.userPassword = dt.Rows[0]["userPassword"].ToString();
-                    API.sessionKey = dt.Rows[0]["sessionKey"].ToString();
+                    API.accountCode = dt.Rows[0]["ACCOUNTCODE"].ToString();
+                    API.userId = dt.Rows[0]["USERID"].ToString();
+                    API.userCode = dt.Rows[0]["USERCODE"].ToString();
+                    API.userName = dt.Rows[0]["USERNAME"].ToString();
+                    API.userPassword = dt.Rows[0]["PASSWORD"].ToString();
+                    API.sessionKey = dt.Rows[0]["SESSIONKEY"].ToString();
                     JObject obj = new JObject();
-                    obj.Add(new JProperty("accountCode", dt.Rows[0]["accountCode"].ToString()));
-                    obj.Add(new JProperty("userId", dt.Rows[0]["userId"].ToString()));
-                    obj.Add(new JProperty("userCode", dt.Rows[0]["userCode"].ToString()));
-                    obj.Add(new JProperty("userName", dt.Rows[0]["userName"].ToString()));
-                    obj.Add(new JProperty("userPassword", dt.Rows[0]["userPassword"].ToString()));
-                    obj.Add(new JProperty("sessionKey", dt.Rows[0]["sessionKey"].ToString()));
+                    obj.Add(new JProperty("accountCode", dt.Rows[0]["ACCOUNTCODE"].ToString()));
+                    obj.Add(new JProperty("userId", dt.Rows[0]["USERID"].ToString()));
+                    obj.Add(new JProperty("userCode", dt.Rows[0]["USERCODE"].ToString()));
+                    obj.Add(new JProperty("userName", dt.Rows[0]["USERNAME"].ToString()));
+                    obj.Add(new JProperty("userPassword", dt.Rows[0]["PASSWORD"].ToString()));
+                    obj.Add(new JProperty("sessionKey", dt.Rows[0]["SESSIONKEY"].ToString()));
                     result.Add(new JObject(new JProperty("MES读取(用户信息)", obj)));
                     return dt.Rows[0];
                 }
@@ -795,13 +805,24 @@ public class autoPacking6151 : IHttpHandler
                     goodsId = Convert.ToInt16(dr["GOODSID"]);
                     logoId = Convert.ToInt16(dr["LOGOID"]);
 
-                    //接口验证条码状态(非必须取消这个接口)
-                    //int status = ApiGetStatusBarcode(barCode);
-
-                    //接口验证可到达
-                    int check = ApiCheckBarcode(barCode);
-                    //写验证结果
-                    if (check == -1) PlcWriteResult(3);
+                    //读取工号
+                    string userCode = PlcReadUsercode();
+                    if (userCode != "")
+                    {
+                        GetUserinfo(userCode);
+                        //接口验证条码状态(非必须取消这个接口)
+                        //int status = ApiGetStatusBarcode(barCode);
+
+                        //接口验证可到达
+                        int check = ApiCheckBarcode(barCode);
+                        //写验证结果
+                        if (check == -1) PlcWriteResult(3);
+                    }
+                    else
+                    {
+                        //工号错误
+                        PlcWriteResult(7);
+                    }
 
                 }
             }
@@ -876,13 +897,27 @@ public class autoPacking6151 : IHttpHandler
                 //绑板处理
                 if(readFlag == 2 || readFlag == 3)
                 {
-                    String[] barCodes = PlcReadBarcodes(goodsNum);
-                    string banMa = "";
-                    if (readFlag == 3) banMa = PlcReadBanma();
-                    //绑板处理
-                    ApiAddWorkPiece(barCodes, banMa, goodsNum);
-                    //写入结果
-                    PlcWriteResult(6);
+                    //读取工号
+                    string userCode = PlcReadUsercode();
+                    if (userCode != "")
+                    {
+                        //读取工号信息
+                        GetUserinfo(userCode);
+                        //读取条码
+                        String[] barCodes = PlcReadBarcodes(goodsNum);
+                        string banMa = "";
+                        if (readFlag == 3) banMa = PlcReadBanma();
+                        //绑板处理
+                        ApiAddWorkPiece(barCodes, banMa, goodsNum);
+                        //绑板完成
+                        PlcWriteResult(6);
+                    }
+                    else
+                    {
+                        //工号错误
+                        PlcWriteResult(7);
+                    }
+
                 }
 
                 //强制绑板完成

+ 5 - 1
wwwroot/API/PLC/autoPacking/autoPacking6151_db.ashx

@@ -23,6 +23,7 @@ public class autoPacking6151_db : IHttpHandler
         public static string dbRead = "151.26";
         public static string[] dbBarcodeBlock = { "150.2", "150.32", "150.62", "150.92", "150.122", "150.152", "150.182", "150.212", "150.242", "150.272", "150.302", "150.332" };
         public static string dbBanMa = "150.362";//150.360 => 150.362
+        public static string dbUsercode = "150.376"; //150.374 => 150.376
     }
 
     public void ProcessRequest(HttpContext context)
@@ -58,6 +59,7 @@ public class autoPacking6151_db : IHttpHandler
         //SiemensS7.Write<string>(PLC.dbBarcodeBlock[1], "20240102501").ToString();
 
         SiemensS7.Write<string>(PLC.dbBanMa, "00000000").ToString();
+        SiemensS7.Write<string>(PLC.dbUsercode, "DONGKE").ToString();
         SiemensS7.Close();
         context.Response.Write("INIT OK!");
     }
@@ -93,8 +95,10 @@ public class autoPacking6151_db : IHttpHandler
             context.Response.Write("条码" + (i + 1).ToString() + ":[" + PLC.dbBarcodeBlock[i] + "]:" + barcode + "\n");
         }
         string banma = SiemensS7.Read<string>(PLC.dbBanMa, 8).ToString();
-        SiemensS7.Close();
         context.Response.Write("板码:[" + PLC.dbBanMa + "]:" + banma + "\n");
+        string usercode = SiemensS7.Read<string>(PLC.dbUsercode, 6).ToString();
+        context.Response.Write("工号:[" + PLC.dbUsercode + "]:" + usercode + "\n");
+        SiemensS7.Close();
     }
 
     public bool IsReusable

+ 134 - 28
wwwroot/API/PLC/autoPacking_local/autoPacking6151.ashx

@@ -28,6 +28,7 @@ public class autoPacking6151 : IHttpHandler
         public static string dbRead = "1.26";
         public static string[] dbBarcodeBlock = { "2.2", "2.32", "2.62", "2.92", "2.122", "2.152", "2.182", "2.212", "2.242", "2.272", "2.302", "2.332" };
         public static string dbBanMa = "2.362";//2.360 => 2.362
+        public static string dbUsercode = "2.376"; //150.374 => 150.376
     }
 
     public static class API
@@ -39,7 +40,7 @@ public class autoPacking6151 : IHttpHandler
         public static string userPassword = "D63AC55256F8048265387A2B0388F1D2";
         public static string sessionKey = "C2A5AE55-8E9B-45F9-A0AF-6A5A1BF3457C";
         public static int procedureID = 107; //3#包装
-        public static bool debug = false;
+        public static bool debug = true;
     }
 
     public bool resultFlag = false;
@@ -79,7 +80,6 @@ public class autoPacking6151 : IHttpHandler
         {
             int read = Convert.ToInt16(SiemensS7.Read<short>(PLC.dbRead));
             result.Add(new JObject(new JProperty("PLC读取(读取标识)", PLC.dbRead + " = " + read.ToString())));
-            resultFlag = true;
             return read;
         }
         catch (Exception e)
@@ -98,7 +98,6 @@ public class autoPacking6151 : IHttpHandler
         {
             int read = Convert.ToInt16(SiemensS7.Read<short>(PLC.dbGoodsId));
             result.Add(new JObject(new JProperty("PLC读取(产品ID)", PLC.dbGoodsId + " = " + read.ToString())));
-            resultFlag = true;
             return read;
         }
         catch (Exception e)
@@ -117,7 +116,6 @@ public class autoPacking6151 : IHttpHandler
         {
             int read = Convert.ToInt16(SiemensS7.Read<short>(PLC.dbGoodsNum));
             result.Add(new JObject(new JProperty("PLC读取(装板数量)", PLC.dbGoodsNum + " = " + read.ToString())));
-            resultFlag = true;
             return read;
         }
         catch (Exception e)
@@ -136,7 +134,6 @@ public class autoPacking6151 : IHttpHandler
         {
             int read = Convert.ToInt16(SiemensS7.Read<short>(PLC.dbLogoId));
             result.Add(new JObject(new JProperty("PLC读取(产品ID)", PLC.dbLogoId + " = " + read.ToString())));
-            resultFlag = true;
             return read;
         }
         catch (Exception e)
@@ -160,7 +157,6 @@ public class autoPacking6151 : IHttpHandler
                 obj.Add(new JProperty("条码" + (i + 1).ToString().PadLeft(2, '0') + "(" + PLC.dbBarcodeBlock[i] + ")", barCodes[i]));
             }
             result.Add(new JObject(new JProperty("PLC读取(产品条码)", obj)));
-            resultFlag = true;
             return barCodes;
         }
         catch (Exception e)
@@ -179,7 +175,6 @@ public class autoPacking6151 : IHttpHandler
         {
             string read = SiemensS7.Read<string>(PLC.dbBanMa, 8).ToString();
             result.Add(new JObject(new JProperty("PLC读取(板码)", PLC.dbBanMa + " = " + read.ToString())));
-            resultFlag = true;
             return read;
         }
         catch (Exception e)
@@ -198,7 +193,6 @@ public class autoPacking6151 : IHttpHandler
         {
             string read = SiemensS7.Read<string>(PLC.dbMaterialcode, 14).ToString();
             result.Add(new JObject(new JProperty("PLC读取(物料号)", PLC.dbMaterialcode + " = " + read.ToString())));
-            resultFlag = true;
             return read;
         }
         catch (Exception e)
@@ -217,7 +211,6 @@ public class autoPacking6151 : IHttpHandler
         {
             int read = Convert.ToInt32(SiemensS7.Read<short>(PLC.dbResult));
             result.Add(new JObject(new JProperty("PLC读取(结果)", PLC.dbResult + " = " + read.ToString())));
-            resultFlag = true;
             return read;
         }
         catch (Exception e)
@@ -228,6 +221,24 @@ public class autoPacking6151 : IHttpHandler
         }
     }
 
+    //读取USERCODE
+    public string PlcReadUsercode()
+    {
+        if (!resultFlag) return "";
+        try
+        {
+            string read = SiemensS7.Read<string>(PLC.dbUsercode,6).ToString();
+            result.Add(new JObject(new JProperty("PLC读取(USECODE)", PLC.dbUsercode + " = " + read.ToString())));
+            return read;
+        }
+        catch (Exception e)
+        {
+            result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
+            resultFlag = false;
+            return "";
+        }
+    }
+
     //写入条码
     public int PlcWriteBarcode(string barCode)
     {
@@ -324,12 +335,25 @@ public class autoPacking6151 : IHttpHandler
     }
 
     //写入执行结果
+    // 1 通过 2 条码格式错误 3 产品不可到达 4 MES异常 5 条码不一致 6 绑板完成 7 工号读取错误
     public int PlcWriteResult(Int16 flag)
     {
         try
         {
+            string message = "";
+            switch(flag)
+            {
+                case 1:message = "OK:扫码通过";break;
+                case 2:message = "ERR:条码格式错误";break;
+                case 3:message = "ERR:产品不可到达";break;
+                case 4:message = "ERR:MES异常";break;
+                case 5:message = "ERR:条码不一致";break;
+                case 6:message = "ERR:绑板完成";break;
+                case 7:message = "ERR:工号读取错误";break;
+                default:message = "ERR:未定义";break;
+            }
             SiemensS7.Write<short>(PLC.dbResult, flag);
-            result.Add(new JObject(new JProperty("PLC写入(执行结果)", PLC.dbResult + " = " + flag.ToString())));
+            result.Add(new JObject(new JProperty("PLC写入("+message+")", PLC.dbResult + " = " + flag.ToString())));
             return 1;
         }
         catch (Exception e)
@@ -392,7 +416,7 @@ public class autoPacking6151 : IHttpHandler
             {
                 resultFlag = false;
                 result.Add(new JObject(
-                    new JProperty("API调用(条码状态)", "操作失败!"),
+                    new JProperty("API调用(条码状态)", json["d"]["Message"].ToString()),
                     new JProperty("接口", "/DKService/PDAModuleService/GetStatusByBarcode"),
                     new JProperty("参数(procedureID)", API.procedureID),
                     new JProperty("参数(barCode)", barCode)
@@ -458,7 +482,7 @@ public class autoPacking6151 : IHttpHandler
             {
                 resultFlag = false;
                 result.Add(new JObject(
-                    new JProperty("API调用(条码验证)", "操作失败!"),
+                    new JProperty("API调用(条码验证)", json["d"]["Message"].ToString()),
                     new JProperty("接口", "/DKService/PDAModuleService/CheckBarcode"),
                     new JProperty("参数(procedureID)", API.procedureID),
                     new JProperty("参数(barCode)", barCode)
@@ -537,7 +561,7 @@ public class autoPacking6151 : IHttpHandler
             {
                 resultFlag = false;
                 result.Add(new JObject(
-                    new JProperty("API调用(装板数量)", "操作失败!"),
+                    new JProperty("API调用(装板数量)", json["d"]["Message"].ToString()),
                     new JProperty("接口", "/DKService/PDAModuleService/DoAction"),
                     new JProperty("参数(ACTION)", "GetSetting"),
                     new JProperty("参数(MODULE)", "FinishedLoadingCar"),
@@ -617,7 +641,7 @@ public class autoPacking6151 : IHttpHandler
             {
                 resultFlag = false;
                 result.Add(new JObject(
-                    new JProperty("API调用(包装码垛)", "操作失败!"),
+                    new JProperty("API调用(包装码垛)", json["d"]["Message"].ToString()),
                     new JProperty("接口", "/DKService/PDAModuleService/AddWorkPiece"),
                     new JProperty("参数(procedureID)", API.procedureID),
                     new JProperty("参数(productionDataEntitys)", productionDataEntitys)
@@ -686,6 +710,63 @@ public class autoPacking6151 : IHttpHandler
         }
     }
 
+    //读取用户信息
+    public DataRow GetUserinfo(string userCode)
+    {
+        try
+        {
+            using (IDataAccess conn = DataAccess.Create())
+            {
+                DataTable dt = conn.ExecuteDatatable(@"
+                    SELECT
+	                    u.ACCOUNTCODE,
+	                    u.USERID,
+	                    u.USERCODE,
+	                    u.USERNAME,
+	                    u.PASSWORD,
+	                    l.SESSIONKEY
+                    FROM
+	                    TP_MST_USER u
+	                    LEFT JOIN TP_MST_USERLOGIN l ON u.USERID = l.USERID 
+                    WHERE
+                        u.USERCODE = @USERCODE@ 
+				    ",
+                    new CDAParameter("USERCODE", userCode)
+                );
+                if(dt.Rows.Count >0 )
+                {
+                    API.accountCode = dt.Rows[0]["ACCOUNTCODE"].ToString();
+                    API.userId = dt.Rows[0]["USERID"].ToString();
+                    API.userCode = dt.Rows[0]["USERCODE"].ToString();
+                    API.userName = dt.Rows[0]["USERNAME"].ToString();
+                    API.userPassword = dt.Rows[0]["PASSWORD"].ToString();
+                    API.sessionKey = dt.Rows[0]["SESSIONKEY"].ToString();
+                    JObject obj = new JObject();
+                    obj.Add(new JProperty("accountCode", dt.Rows[0]["ACCOUNTCODE"].ToString()));
+                    obj.Add(new JProperty("userId", dt.Rows[0]["USERID"].ToString()));
+                    obj.Add(new JProperty("userCode", dt.Rows[0]["USERCODE"].ToString()));
+                    obj.Add(new JProperty("userName", dt.Rows[0]["USERNAME"].ToString()));
+                    obj.Add(new JProperty("userPassword", dt.Rows[0]["PASSWORD"].ToString()));
+                    obj.Add(new JProperty("sessionKey", dt.Rows[0]["SESSIONKEY"].ToString()));
+                    result.Add(new JObject(new JProperty("MES读取(用户信息)", obj)));
+                    return dt.Rows[0];
+                }
+                else
+                {
+                    resultFlag = false;
+                    result.Add(new JObject(new JProperty("MES读取(用户信息)","用户未找到!")));
+                    return null;
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            resultFlag = false;
+            result.Add(new JObject(new JProperty("系统异常", e.Message)));
+            return null;
+        }
+    }
+
     //主程序入口
     public void ProcessRequest(HttpContext context)
     {
@@ -724,13 +805,24 @@ public class autoPacking6151 : IHttpHandler
                     goodsId = Convert.ToInt16(dr["GOODSID"]);
                     logoId = Convert.ToInt16(dr["LOGOID"]);
 
-                    //接口验证条码状态(非必须取消这个接口)
-                    //int status = ApiGetStatusBarcode(barCode);
-
-                    //接口验证可到达
-                    int check = ApiCheckBarcode(barCode);
-                    //写验证结果
-                    if (check == -1) PlcWriteResult(3);
+                    //读取工号
+                    string userCode = PlcReadUsercode();
+                    if (userCode != "")
+                    {
+                        GetUserinfo(userCode);
+                        //接口验证条码状态(非必须取消这个接口)
+                        //int status = ApiGetStatusBarcode(barCode);
+
+                        //接口验证可到达
+                        int check = ApiCheckBarcode(barCode);
+                        //写验证结果
+                        if (check == -1) PlcWriteResult(3);
+                    }
+                    else
+                    {
+                        //工号错误
+                        PlcWriteResult(7);
+                    }
 
                 }
             }
@@ -805,13 +897,27 @@ public class autoPacking6151 : IHttpHandler
                 //绑板处理
                 if(readFlag == 2 || readFlag == 3)
                 {
-                    String[] barCodes = PlcReadBarcodes(goodsNum);
-                    string banMa = "";
-                    if (readFlag == 3) banMa = PlcReadBanma();
-                    //绑板处理
-                    ApiAddWorkPiece(barCodes, banMa, goodsNum);
-                    //写入结果
-                    PlcWriteResult(6);
+                    //读取工号
+                    string userCode = PlcReadUsercode();
+                    if (userCode != "")
+                    {
+                        //读取工号信息
+                        GetUserinfo(userCode);
+                        //读取条码
+                        String[] barCodes = PlcReadBarcodes(goodsNum);
+                        string banMa = "";
+                        if (readFlag == 3) banMa = PlcReadBanma();
+                        //绑板处理
+                        ApiAddWorkPiece(barCodes, banMa, goodsNum);
+                        //绑板完成
+                        PlcWriteResult(6);
+                    }
+                    else
+                    {
+                        //工号错误
+                        PlcWriteResult(7);
+                    }
+
                 }
 
                 //强制绑板完成

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

@@ -23,6 +23,7 @@ public class autoPacking6151_db : IHttpHandler
         public static string dbRead = "1.26";
         public static string[] dbBarcodeBlock = { "2.2", "2.32", "2.62", "2.92", "2.122", "2.152", "2.182", "2.212", "2.242", "2.272", "2.302", "2.332" };
         public static string dbBanMa = "2.362";//2.360 => 2.362
+        public static string dbUsercode = "2.376"; //150.374 => 150.376
     }
 
     public void ProcessRequest(HttpContext context)
@@ -54,10 +55,11 @@ public class autoPacking6151_db : IHttpHandler
         }
 
         //测试条码
-        SiemensS7.Write<string>(PLC.dbBarcodeBlock[0], "20240102500").ToString();
-        SiemensS7.Write<string>(PLC.dbBarcodeBlock[1], "20240102501").ToString();
+        //SiemensS7.Write<string>(PLC.dbBarcodeBlock[0], "20240102500").ToString();
+        //SiemensS7.Write<string>(PLC.dbBarcodeBlock[1], "20240102501").ToString();
 
         SiemensS7.Write<string>(PLC.dbBanMa, "00000000").ToString();
+        SiemensS7.Write<string>(PLC.dbUsercode, "DONGKE").ToString();
         SiemensS7.Close();
         context.Response.Write("INIT OK!");
     }
@@ -93,8 +95,10 @@ public class autoPacking6151_db : IHttpHandler
             context.Response.Write("条码" + (i + 1).ToString() + ":[" + PLC.dbBarcodeBlock[i] + "]:" + barcode + "\n");
         }
         string banma = SiemensS7.Read<string>(PLC.dbBanMa, 8).ToString();
-        SiemensS7.Close();
         context.Response.Write("板码:[" + PLC.dbBanMa + "]:" + banma + "\n");
+        string usercode = SiemensS7.Read<string>(PLC.dbUsercode, 6).ToString();
+        context.Response.Write("工号:[" + PLC.dbUsercode + "]:" + usercode + "\n");
+        SiemensS7.Close();
     }
 
     public bool IsReusable