Commit 58d1a0b3 LN

托盘号处理。

1 个父辈 1287733b
...@@ -61,11 +61,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -61,11 +61,11 @@ namespace OnlineStore.DeviceLibrary
ClampNeedCheck = config.DIList.ContainsKey(IO_Type.ClampCylinder_Check); ClampNeedCheck = config.DIList.ContainsKey(IO_Type.ClampCylinder_Check);
UpdownAxis = new AxisBean(config.UpDown_Axis, Name); UpdownAxis = new AxisBean(config.UpDown_Axis, Name);
readBuffRfidTimer = new System.Timers.Timer(); //readBuffRfidTimer = new System.Timers.Timer();
readBuffRfidTimer.Enabled = false; //readBuffRfidTimer.Enabled = false;
readBuffRfidTimer.Interval = 300; //readBuffRfidTimer.Interval = 300;
readBuffRfidTimer.Elapsed += ReadRfidBuff; //readBuffRfidTimer.Elapsed += ReadRfidBuff;
readBuffRfidTimer.AutoReset = true; //readBuffRfidTimer.AutoReset = true;
} }
public override bool StartRun(bool isDebug = false) public override bool StartRun(bool isDebug = false)
...@@ -186,7 +186,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -186,7 +186,7 @@ namespace OnlineStore.DeviceLibrary
//readBuffRfidThread = new Thread(ReadRfidBuff); //readBuffRfidThread = new Thread(ReadRfidBuff);
//readBuffRfidThread.IsBackground = true; //readBuffRfidThread.IsBackground = true;
//readBuffRfidThread.Start(); //readBuffRfidThread.Start();
readBuffRfidTimer.Enabled = true; //readBuffRfidTimer.Enabled = true;
LogInfo(MoveInfo.MoveType + " 完成!"); LogInfo(MoveInfo.MoveType + " 完成!");
runStatus = LineRunStatus.Runing; runStatus = LineRunStatus.Runing;
MoveInfo.EndMove(); MoveInfo.EndMove();
...@@ -242,7 +242,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -242,7 +242,7 @@ namespace OnlineStore.DeviceLibrary
CheckAndMove(IO_Type.ClampCylinder_Slack, IO_VALUE.LOW); CheckAndMove(IO_Type.ClampCylinder_Slack, IO_VALUE.LOW);
CheckAndMove(IO_Type.ClampCylinder_Tighten, IO_VALUE.LOW); CheckAndMove(IO_Type.ClampCylinder_Tighten, IO_VALUE.LOW);
runStatus = LineRunStatus.Wait; runStatus = LineRunStatus.Wait;
readBuffRfidTimer.Enabled = false; //readBuffRfidTimer.Enabled = false;
} }
......
...@@ -857,8 +857,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -857,8 +857,8 @@ namespace OnlineStore.DeviceLibrary
SecondMoveInfo.NewMove(LineMoveType.CheckFixture); SecondMoveInfo.NewMove(LineMoveType.CheckFixture);
SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_00_Stop1Down); SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_00_Stop1Down);
ClearTrayRFID(); ClearTrayRFID();
ClearAllBuff(); //ClearAllBuff();
StartReadRfid(); //StartReadRfid();
CheckLog(" 托盘检测:料盘检测StopCylinder_Check1 " + SecondMoveInfo.SLog + "阻挡气缸1-1下降 , 等待 StopCylinder_Check1=0,清理托盘RFID,开始记录rfid缓存"); CheckLog(" 托盘检测:料盘检测StopCylinder_Check1 " + SecondMoveInfo.SLog + "阻挡气缸1-1下降 , 等待 StopCylinder_Check1=0,清理托盘RFID,开始记录rfid缓存");
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH);//TrayManager.StopDTime IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH);//TrayManager.StopDTime
SecondMoveInfo.OneWaitCanEndStep = true; SecondMoveInfo.OneWaitCanEndStep = true;
...@@ -955,18 +955,19 @@ namespace OnlineStore.DeviceLibrary ...@@ -955,18 +955,19 @@ namespace OnlineStore.DeviceLibrary
{ {
try try
{ {
try //try
{ //{
StopReadRfid(); // //StopReadRfid();
LogUtil.debug($"【{Name}】停止记录rfid缓存"); // LogUtil.debug($"【{Name}】停止记录rfid缓存");
} //}
catch (Exception ex1) //catch (Exception ex1)
{ //{
LogUtil.error($"【{Name}】停止记录rfid缓存:", ex1); // LogUtil.error($"【{Name}】停止记录rfid缓存:", ex1);
} //}
//判断是否需要顶升 //判断是否需要顶升
bool isNeed = false; bool isNeed = false;
UpdateTrayNumFromBuff(); //UpdateTrayNumFromBuff();
UpdateTrayNum();
bool isFull = TrayManager.TrayIsFull(currTrayNum); bool isFull = TrayManager.TrayIsFull(currTrayNum);
if (TrayManager.RightTrayCode(currTrayNum, preTrayNum, false)) if (TrayManager.RightTrayCode(currTrayNum, preTrayNum, false))
{ {
......
...@@ -18,7 +18,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -18,7 +18,7 @@ namespace OnlineStore.DeviceLibrary
public static int DefaultTrayNum = ConfigAppSettings.GetIntValue(Setting_Init.DefaultTrayNum); public static int DefaultTrayNum = ConfigAppSettings.GetIntValue(Setting_Init.DefaultTrayNum);
private static ReadAll readAll = new ReadAll("TheRFID"); private static ReadAll readAll = new ReadAll("TheRFID");
private static bool IsOpen = false; private static bool IsOpen = false;
private static ConcurrentDictionary<string, string> LastRfidMap = new ConcurrentDictionary<string, string>(); private static ConcurrentDictionary<string, List<RfidCacheInfo>> LastRfidMap = new ConcurrentDictionary<string, List<RfidCacheInfo>>();
public static void Open() public static void Open()
{ {
if (IsOpen) if (IsOpen)
...@@ -33,6 +33,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -33,6 +33,7 @@ namespace OnlineStore.DeviceLibrary
port = 13000; port = 13000;
} }
LogUtil.info("RFID Server Open,port=" + port); LogUtil.info("RFID Server Open,port=" + port);
readAll.Received += ReadAll_Received;
readAll.Start(); readAll.Start();
IsOpen = true; IsOpen = true;
} }
...@@ -41,6 +42,99 @@ namespace OnlineStore.DeviceLibrary ...@@ -41,6 +42,99 @@ namespace OnlineStore.DeviceLibrary
LogUtil.error("Open 出错:" + ex.ToString()); LogUtil.error("Open 出错:" + ex.ToString());
} }
} }
private static void ReadAll_Received(string ip, string id)
{
List<RfidCacheInfo> list = LastRfidMap.GetOrAdd(ip, new List<RfidCacheInfo>());
int count = list.Count;
if (count > 0)
{
RfidCacheInfo last = list[count - 1];
if (!last.Data.StrData.Equals(id))
{
RFIDData data = new RFIDData(id);
list.Add(new RfidCacheInfo(data));
if (list.Count > 3)
{
list.RemoveAt(0);
}
LogUtil.debug("ReadAll_Received["+ip+"]["+id+"]加入缓存");
LastRfidMap.AddOrUpdate(ip, list,(key,value)=>value);
}
}
}
private static bool CheckTrayNum(string ip, int num)
{
RFIDData data = new RFIDData(ip);
List<RfidCacheInfo> list = LastRfidMap.GetOrAdd(ip, new List<RfidCacheInfo>());
if (list.Count > 0)
{
int readNumIndex = -1;
string listStr = "";
for (int i = 0; i < list.Count; i++)
{
RfidCacheInfo cacheInfo = list[i];
if (cacheInfo.Data.Num.Equals(num))
{
listStr += "【" + cacheInfo.Data.Num + "," + cacheInfo.Used + "," + cacheInfo.UpdateTime.ToLongTimeString() + "】";
readNumIndex = i;
}
}
if (readNumIndex == -1)
{
list.Add(new RfidCacheInfo(data, true));
if (list.Count > 3)
{
list.RemoveAt(0);
}
LastRfidMap.AddOrUpdate(ip, list, (key, value) => value);
LogUtil.error("CheckTrayNum托盘号验证: [" + ip + "][" + num + "],未找到此托盘缓存,增加次托盘到缓存。缓存数据:" + listStr);
return true;
}
else if (readNumIndex == (list.Count - 1))
{
//是最后一个
if (list[readNumIndex].Used)
{
LogUtil.error("CheckTrayNum托盘号验证失败: [" + ip + "][" + num + "],缓存记录当前托盘已使用。缓存数据:" + listStr);
return false;
}
else
{
//更改状态
list[readNumIndex].Used = true;
LastRfidMap.AddOrUpdate(ip, list, (key, value) => value);
//上一个已使用
if (list.Count > readNumIndex - 1)
{
if (!list[readNumIndex - 1].Used)
{
LogUtil.error("CheckTrayNum托盘号验证失败: [" + ip + "][" + num + "],缓存记录上一个托盘未使用,更新当前托盘为已用。缓存数据:" + listStr);
return false;
}
}
}
}
//不是最后一个
else
{
//更改状态
list[readNumIndex].Used = true;
LastRfidMap.AddOrUpdate(ip, list, (key, value) => value);
LogUtil.error("CheckTrayNum托盘号验证失败: [" + ip + "][" + num + "],当前托盘索引=" + readNumIndex + ",总缓存托盘数=" + list.Count + ",不是最后一个缓存托盘号,更新当前托盘为已用。缓存数据:" + listStr);
return false;
}
}
return true;
}
public static int GetTrayNum(int subType, bool isClear = false) public static int GetTrayNum(int subType, bool isClear = false)
{ {
if (DefaultTrayNum > 0) if (DefaultTrayNum > 0)
...@@ -63,8 +157,18 @@ namespace OnlineStore.DeviceLibrary ...@@ -63,8 +157,18 @@ namespace OnlineStore.DeviceLibrary
{ {
if (data.RFType.Equals('E')) if (data.RFType.Equals('E'))
{ {
bool result = CheckTrayNum(ip, data.Num);
if (!result)
{
LogUtil.error("RFID [ " + ip + " ] 读到数据 " + data.NumStr() + " 缓存验证失败,返回盘号 0");
return 0;
}
else
{
return data.Num; return data.Num;
} }
}
else if (data.RFType > 0) else if (data.RFType > 0)
{ {
LogUtil.error("RFID [ " + ip + " ] 读到数据 " + data.NumStr() + " 返回盘号 0"); LogUtil.error("RFID [ " + ip + " ] 读到数据 " + data.NumStr() + " 返回盘号 0");
...@@ -76,6 +180,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -76,6 +180,7 @@ namespace OnlineStore.DeviceLibrary
return 0; return 0;
} }
return 0; return 0;
} }
public static void ClearTrayNum(int subType) public static void ClearTrayNum(int subType)
...@@ -235,4 +340,20 @@ namespace OnlineStore.DeviceLibrary ...@@ -235,4 +340,20 @@ namespace OnlineStore.DeviceLibrary
return false; return false;
} }
} }
public class RfidCacheInfo
{
public RfidCacheInfo(RFIDData data,bool userd=false)
{
this.Data = data;
this.Used = false;
this.UpdateTime = DateTime.Now;
}
public RFIDData Data { get; set; }
public bool Used = false;
public DateTime UpdateTime = DateTime.Now;
}
} }
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!