|
@@ -378,8 +378,8 @@ namespace IMCS.CCS.Service.Impl
|
|
|
string plcResult = plcS7.ReadInt16("DB1.16").Content.ToString();
|
|
|
if (plcResult == "5") {
|
|
|
Log.Instance.WriteLogAdd("RFID逻辑块==》任务已完成状态,放行操作,执行的任务:" + JsonConvert.SerializeObject(task), LOG_TITLE_CALLBACK);
|
|
|
+
|
|
|
|
|
|
-
|
|
|
plcS7.Write("DB2.12", Convert.ToInt16("0"));
|
|
|
plcS7.ConnectClose();
|
|
|
rfid.success = true;
|
|
@@ -406,6 +406,7 @@ namespace IMCS.CCS.Service.Impl
|
|
|
{ //下发读指令
|
|
|
|
|
|
plcS7.Write("DB2.12", Convert.ToInt16("1"));
|
|
|
+
|
|
|
Console.WriteLine("====================================RFID读命令已下发,写入DB2.12-》1");
|
|
|
Log.Instance.WriteLogAdd("RFID读命令已下发,写入DB2.12-》1:" + JsonConvert.SerializeObject(task), LOG_TITLE_CALLBACK);
|
|
|
plcS7.ConnectClose();
|
|
@@ -455,17 +456,28 @@ namespace IMCS.CCS.Service.Impl
|
|
|
string huiku = _redisService.Database.StringGetAsync(RFID + task.TaskNodeId+"_null").Result;
|
|
|
if (!huiku.IsNullOrEmpty())
|
|
|
{
|
|
|
- plcS7.Write("DB2.55", Convert.ToInt16("0"));
|
|
|
+ OperateResult op = plcS7.Write("DB2.55", (byte)0);
|
|
|
+ string readResult2 = plcS7.ReadByte("DB2.55").Content.ToString();
|
|
|
+ Console.WriteLine("写入之后重新读一边:DB2.55:" + readResult2 + ",是否写入成功:" + op.IsSuccess);
|
|
|
+ Log.Instance.WriteLogAdd("写入之后重新读一边:DB2.55:" + readResult2 + ",是否写入成功:" + op.IsSuccess, LOG_TITLE_CALLBACK);
|
|
|
plcS7.Write("DB2.56", ToolUtils.ReturnBtyesWtitString("", 39));
|
|
|
- Console.WriteLine("RFID写入DB2.55 -》 0,DB2.56写入空");
|
|
|
- Console.WriteLine("====================================RFID信息写入,空托盘入线边库");
|
|
|
+ string readResult3 = ToolUtils.ReturnStringByBytes(plcS7.Read("DB2.56", 39).Content);
|
|
|
+ Console.WriteLine("写入之后重新读一边:DB2.56:" + readResult3);
|
|
|
+ Log.Instance.WriteLogAdd("写入之后重新读一边:DB2.56:" + readResult3, LOG_TITLE_CALLBACK);
|
|
|
+
|
|
|
|
|
|
Log.Instance.WriteLogAdd(task.TaskNodeId + "RFID写入DB2.55 -》 0,DB2.56写入空,RFID信息写入,空托盘入线边库", LOG_TITLE_CALLBACK);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- plcS7.Write("DB2.55", Convert.ToInt16("1"));
|
|
|
+ OperateResult op = plcS7.Write("DB2.55", (byte)1);
|
|
|
+ string readResult2 = plcS7.ReadByte("DB2.55").Content.ToString();
|
|
|
+ Console.WriteLine("写入之后重新读一边:DB2.55:" + readResult2 + ",是否写入成功:" + op.IsSuccess);
|
|
|
+ Log.Instance.WriteLogAdd("写入之后重新读一边:DB2.55:" + readResult2 + ",是否写入成功:" + op.IsSuccess, LOG_TITLE_CALLBACK);
|
|
|
plcS7.Write("DB2.56", ToolUtils.ReturnBtyesWtitString(imcsRfid.uniqueCode, 39));
|
|
|
+ string readResult3 = ToolUtils.ReturnStringByBytes(plcS7.Read("DB2.56", 39).Content);
|
|
|
+ Console.WriteLine("写入之后重新读一边:DB2.56:" + readResult3);
|
|
|
+ Log.Instance.WriteLogAdd("写入之后重新读一边:DB2.56:" + readResult3, LOG_TITLE_CALLBACK);
|
|
|
Console.WriteLine("RFID写入DB2.55 -》 1,DB2.56写入:"+ imcsRfid.uniqueCode);
|
|
|
Console.WriteLine("====================================RFID信息写入,有工件和托盘");
|
|
|
Log.Instance.WriteLogAdd(task.TaskNodeId + "RFID写入DB2.55 -》 1,DB2.56写入:" + imcsRfid.uniqueCode+ ",RFID信息写入,有工件和托盘", LOG_TITLE_CALLBACK);
|
|
@@ -474,23 +486,41 @@ namespace IMCS.CCS.Service.Impl
|
|
|
}else if (jList.Contains(up) || up == "11")
|
|
|
{ //如果是机床,往RFID中写state(2 成品)和PID(零件编码)
|
|
|
Console.WriteLine("====================================RFID,源位置为机床或喷墨机:"+ up);
|
|
|
- plcS7.Write("DB2.55", Convert.ToInt16("2"));
|
|
|
+ OperateResult op = plcS7.Write("DB2.55", (byte)2);
|
|
|
+ string readResult2 = plcS7.ReadByte("DB2.55").Content.ToString();
|
|
|
+ Console.WriteLine("写入之后重新读一边:DB2.55:" + readResult2 + ",是否写入成功:" + op.IsSuccess);
|
|
|
+ Log.Instance.WriteLogAdd("写入之后重新读一边:DB2.55:" + readResult2 + ",是否写入成功:" + op.IsSuccess, LOG_TITLE_CALLBACK);
|
|
|
//string readResult1 = ToolUtils.ReturnStringByBytes(plcS7.Read("DB1.62", 39).Content);
|
|
|
+
|
|
|
plcS7.Write("DB2.56", ToolUtils.ReturnBtyesWtitString(imcsRfid.uniqueCode, 39));
|
|
|
+ string readResult3 = ToolUtils.ReturnStringByBytes(plcS7.Read("DB2.56", 39).Content);
|
|
|
+ Console.WriteLine("写入之后重新读一边:DB2.56:" + readResult3);
|
|
|
+ Log.Instance.WriteLogAdd("写入之后重新读一边:DB2.56:" + readResult3, LOG_TITLE_CALLBACK);
|
|
|
Console.WriteLine("RFID写入DB2.55 -》 2,DB2.56写入:" + imcsRfid.uniqueCode);
|
|
|
Log.Instance.WriteLogAdd(task.TaskNodeId + "RFID写入DB2.55 -》 2,DB2.56写入:" + imcsRfid.uniqueCode + ",源位置为机床或喷墨机:" + up, LOG_TITLE_CALLBACK);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
Console.WriteLine("====================================RFID,源位置为线边库:" + up);
|
|
|
- string readResult1 = plcS7.ReadInt16("DB1.61").Content.ToString();
|
|
|
+ string readResult1 = plcS7.ReadByte("DB1.61").Content.ToString();
|
|
|
string readResult2 = ToolUtils.ReturnStringByBytes(plcS7.Read("DB1.62", 39).Content);
|
|
|
- //plcS7.Write("DB2.55", Convert.ToInt16(readResult1));
|
|
|
- plcS7.Write("DB2.55", Convert.ToInt16("1"));
|
|
|
- plcS7.Write("DB2.56", ToolUtils.ReturnBtyesWtitString(readResult2, 39));
|
|
|
- Console.WriteLine("RFID写入DB2.55 -》 "+ readResult1 + ",DB2.56 =》"+ readResult2);
|
|
|
- Log.Instance.WriteLogAdd(task.TaskNodeId + "RFID写入DB2.55 -》 " + readResult1 + ",DB2.56 =》" + readResult2 + ",源位置为线边库:" + up, LOG_TITLE_CALLBACK);
|
|
|
- }
|
|
|
+ Log.Instance.WriteLogAdd("乱码标记:DB1.61:" + readResult1 + ",DB1.62:"+ readResult2, LOG_TITLE_CALLBACK);
|
|
|
+
|
|
|
+ OperateResult op=plcS7.Write("DB2.55", (byte)1);
|
|
|
+ string readResult4 = plcS7.ReadByte("DB2.55").Content.ToString();
|
|
|
+ Console.WriteLine("写入之后重新读一边:DB2.55:" + readResult4 + ",是否写入成功:"+ op.IsSuccess);
|
|
|
+ Log.Instance.WriteLogAdd("写入之后重新读一边:DB2.55:" + readResult4 + ",是否写入成功:" + op.IsSuccess, LOG_TITLE_CALLBACK);
|
|
|
+
|
|
|
+ plcS7.Write("DB2.56", ToolUtils.ReturnBtyesWtitString(imcsRfid.uniqueCode, 39));
|
|
|
+ string readResult3 = ToolUtils.ReturnStringByBytes(plcS7.Read("DB2.56", 39).Content);
|
|
|
+ Console.WriteLine("写入之后重新读一边:DB2.56:" + readResult3);
|
|
|
+ Log.Instance.WriteLogAdd("写入之后重新读一边:DB2.56:"+ readResult3, LOG_TITLE_CALLBACK);
|
|
|
+ Console.WriteLine("RFID写入DB2.55 -》 1" + ",DB2.56 =》"+ imcsRfid.uniqueCode);
|
|
|
+ Log.Instance.WriteLogAdd(task.TaskNodeId + "RFID写入DB2.55 -》 1" + ",DB2.56 =》" + imcsRfid.uniqueCode + ",源位置为线边库:" + up, LOG_TITLE_CALLBACK);
|
|
|
+ string readResult5 = plcS7.ReadByte("DB2.55").Content.ToString();
|
|
|
+ Console.WriteLine("在读一次,写入之后重新读一边:DB2.55:" + readResult5 );
|
|
|
+ Log.Instance.WriteLogAdd("写入之后重新读一边:DB2.55:" + readResult4 + ",是否写入成功:" + op.IsSuccess, LOG_TITLE_CALLBACK);
|
|
|
+ }
|
|
|
|
|
|
Log.Instance.WriteLogAdd("RFID逻辑块==》重新写入RFID命令已下发:" + "读取imcs_redis数据_" + JsonConvert.SerializeObject(imcsRfid) + ",读取RFID数据_" + readResult.ToString(), LOG_TITLE_CALLBACK);
|
|
|
|
|
@@ -536,8 +566,7 @@ namespace IMCS.CCS.Service.Impl
|
|
|
/// <returns></returns>
|
|
|
public async Task<string> CallbackJob2()
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
+
|
|
|
|
|
|
Console.WriteLine("取和放回调任务开始:" + DateTime.Now.ToString());
|
|
|
List<TaskCallback> taskList = new List<TaskCallback>();
|
|
@@ -566,10 +595,13 @@ namespace IMCS.CCS.Service.Impl
|
|
|
string message = "";
|
|
|
|
|
|
foreach(TaskCallback task in taskList)
|
|
|
+ {
|
|
|
+ SiemensS7Net s7 = DevicePlcS7.SiemensS7(task.IP);
|
|
|
+ HslCommunication.OperateResult ConnectionResult = s7.ConnectServer();
|
|
|
+ try
|
|
|
{
|
|
|
Console.WriteLine("进入循环:" + task.TaskNodeId);
|
|
|
- SiemensS7Net s7 = DevicePlcS7.SiemensS7(task.IP);
|
|
|
- HslCommunication.OperateResult ConnectionResult = s7.ConnectServer();
|
|
|
+
|
|
|
CcsTagValue tagValueQuery = new CcsTagValue();
|
|
|
tagValueQuery.Ip = task.IP;
|
|
|
//tagValueQuery.Address = task.Address;
|
|
@@ -620,14 +652,31 @@ namespace IMCS.CCS.Service.Impl
|
|
|
{
|
|
|
await _redisService.Database.StringSetAsync(RFID + task.TaskId + task.TaskNodeId, "3");
|
|
|
string readResult = ToolUtils.ReturnStringByBytes(s7.Read("DB1.20", 39).Content).Replace(" ", "");
|
|
|
- string readResult1 = s7.ReadInt16("DB1.61").Content.ToString();
|
|
|
+
|
|
|
+ string readResult1 = s7.ReadByte("DB1.61").Content.ToString();
|
|
|
string readResult2 = ToolUtils.ReturnStringByBytes(s7.Read("DB1.62", 39).Content).Replace(" ", "");
|
|
|
|
|
|
|
|
|
- Console.WriteLine(task.TaskNodeId+"====================================第二次读完成DB1.20:" + readResult+ ",DB1.61:"+ readResult1 + ",DB1.62:" + readResult2);
|
|
|
- Log.Instance.WriteLogAdd(task.TaskNodeId + "====================================第二次读完成DB1.20:" + readResult + ",DB1.61:" + readResult1 + ",DB1.62:" + readResult2, LOG_TITLE_CALLBACK);
|
|
|
- //下发归零任务
|
|
|
- s7.Write("DB2.12", Convert.ToInt16("0"));
|
|
|
+ string readResult3 = s7.ReadByte("DB2.55").Content.ToString();
|
|
|
+ string readResult4 = ToolUtils.ReturnStringByBytes(s7.Read("DB2.56", 39).Content);
|
|
|
+
|
|
|
+ Console.WriteLine(task.TaskNodeId+"====================================第二次读完成DB1.20:" + readResult+ ",DB1.61:"+ readResult1 + ",DB1.62:" + readResult2+ ",DB2.55:"+ readResult3+ ",DB2.56:"+ readResult4);
|
|
|
+ Log.Instance.WriteLogAdd(task.TaskNodeId + "====================================第二次读完成DB1.20:" + readResult + ",DB1.61:" + readResult1 + ",DB1.62:" + readResult2 + ",DB2.55:" + readResult3 + ",DB2.56:" + readResult4, LOG_TITLE_CALLBACK);
|
|
|
+
|
|
|
+ if(readResult1== readResult3 && readResult2== readResult4)
|
|
|
+ {
|
|
|
+ //下发归零任务
|
|
|
+ s7.Write("DB2.12", Convert.ToInt16("0"));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ await _redisService.Database.KeyDeleteAsync(RFID + task.TaskId + task.TaskNodeId);
|
|
|
+ s7.ConnectClose();
|
|
|
+ Log.Instance.WriteLogAdd(task.TaskNodeId + ",校验不通过,重新走RFID流程,DB1.61:" + readResult1 + ",DB1.62:" + readResult2 + ",DB2.55:" + readResult3 + ",DB2.56:" + readResult4, LOG_TITLE_CALLBACK);
|
|
|
+ return "校验不通过,重新走RFID流程";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
/*string readResult3 = s7.ReadInt16("DB1.2").Content.ToString();
|
|
|
if (readResult3 != "257")
|
|
@@ -791,15 +840,22 @@ namespace IMCS.CCS.Service.Impl
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ s7.ConnectClose();
|
|
|
Thread.Sleep(1000);
|
|
|
}
|
|
|
- return string.IsNullOrEmpty(message) ? "无回调任务" : message;
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- Log.Instance.WriteLogAdd("回调异常===>>" + ex.StackTrace+","+ex.Message, LOG_TITLE_CALLBACK);
|
|
|
- return "回调异常" + ex.Message;
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Log.Instance.WriteLogAdd("回调异常===>>" + ex.StackTrace + "," + ex, LOG_TITLE_CALLBACK);
|
|
|
+ return "回调异常" + ex.Message;
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ s7.ConnectClose();
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ return string.IsNullOrEmpty(message) ? "无回调任务" : message;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/// <summary>
|