Explorar el Código

RFID防止重复写入读命令

oyq28 hace 6 meses
padre
commit
dc722a45ef
Se han modificado 1 ficheros con 12 adiciones y 4 borrados
  1. 12 4
      IMCS_CCS/Service/Impl/TaskJobService.cs

+ 12 - 4
IMCS_CCS/Service/Impl/TaskJobService.cs

@@ -24,6 +24,7 @@ using Org.BouncyCastle.Ocsp;
 using System.Text;
 using IMCS.CCS.Entitys.Dto;
 using System.IO.Pipelines;
+using Microsoft.IdentityModel.Tokens;
 
 namespace IMCS.CCS.Service.Impl
 {
@@ -381,7 +382,7 @@ namespace IMCS.CCS.Service.Impl
                 return rfid;
             }
             
-            //获取任务执行结果 2表示取完成,开始下发读指令
+            
             string plcResult = plcS7.ReadInt16("DB1.16").Content.ToString();
             if (plcResult == "5") {
                 Log.Instance.WriteLogAdd("RFID逻辑块==》任务已完成状态,放行操作,执行的任务:" + JsonConvert.SerializeObject(task), LOG_TITLE_CALLBACK);
@@ -409,14 +410,19 @@ namespace IMCS.CCS.Service.Impl
             // 判断读写状态,DB1.DBB18 
             if (plcRead == "1")
             { //下发读指令
-                plcS7.Write("DB2.12", Convert.ToInt16("1"));
+                string imcsRFIDRead = _redisService.Database.StringGetAsync(RFID + task.TaskNodeId+"_1").Result;
+                if (imcsRFIDRead.IsNullOrEmpty())
+                {
+                    await _redisService.Database.StringSetAsync(RFID + task.TaskNodeId + "_1","1");
+                    plcS7.Write("DB2.12", Convert.ToInt16("1"));
+                }
                 Log.Instance.WriteLogAdd("RFID逻辑块==》rfid读命令已下发,执行的任务:" + JsonConvert.SerializeObject(task), LOG_TITLE_CALLBACK);
                 plcS7.ConnectClose();
                 rfid.success = false;
                 rfid.msg = "RFID读命令已下发";
                 return rfid;
             }
-            else if (plcRead == "3")
+            else if (plcRead == "3")//表示真正读完成了,这个时候我要去比较数据
             { // 取rfid数据,并比对数据
 
                 //  imcs缓存的托盘编码数据
@@ -429,6 +435,8 @@ namespace IMCS.CCS.Service.Impl
                 string readResult = ToolUtils.ReturnStringByBytes(plcS7.Read("DB1.20", 39).Content).Replace(" ","");
                 if (imcsRfid.trayNo != readResult)
                 {
+                    //TODO 可能要往PLC中写入一个值,表示校验错误
+
                     Log.Instance.WriteLogAdd("RFID逻辑块==》RFID校验托盘失败:" + "读取imcs_redis数据_" + JsonConvert.SerializeObject(imcsRfid) + ",读取RFID数据_" + readResult.ToString(), LOG_TITLE_CALLBACK);
 
                     plcS7.ConnectClose();
@@ -469,7 +477,7 @@ namespace IMCS.CCS.Service.Impl
                         string readResult1 = plcS7.ReadInt16("DB1.61").Content.ToString();
                         string readResult2 = ToolUtils.ReturnStringByBytes(plcS7.Read("DB1.62", 39).Content).Replace(" ","");
 
-                        plcS7.Write("DB2.55", Convert.ToInt16("2"));
+                        plcS7.Write("DB2.55", Convert.ToInt16(readResult1));
                         plcS7.Write("DB2.56", ToolUtils.ReturnBtyesWtitString(readResult2, 39));
                     }
                 }