TrayDisableManager.cs
7.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
using OnlineStore.Common;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public class TrayDisableManager
{
public static bool ProcessTray = false;
public static string ProWarnMsg = "拦截到禁用托盘";
/// <summary>
/// 托盘集合,key=托盘编号,value=托盘详细信息
/// </summary>
private static ConcurrentDictionary<int, TrayDisableInfo> TrayDisableMap = new ConcurrentDictionary<int, TrayDisableInfo>();
public static void ClearDisableMap()
{
List<TrayDisableInfo> tray = GetDisableList();
LogUtil.info("-------------------点击:清空禁用托盘。清空前打印托盘禁用信息:");
foreach (TrayDisableInfo t in tray)
{
LogUtil.info(t.ToStr());
}
TrayDisableMap = new ConcurrentDictionary<int, TrayDisableInfo>();
LogUtil.info("-------------------点击:清空禁用托盘。托盘禁用列表已清空");
}
public static List<TrayDisableInfo> GetDisableList()
{
List<TrayDisableInfo> dislist = new List<TrayDisableInfo>(TrayDisableMap.Values);
return dislist;
}
public static bool UseNewLogic = true;
/// <summary>
/// 添加屏蔽库位
/// </summary>
/// <param name="trayNum"></param>
/// <param name="deviceName"></param>
/// <param name="describle"></param>
/// <param name="type">0,无;1:硬件未检测到;2:硬件检测到</param>
public static void AddDisable(int trayNum, string deviceName, string describle,int type,int deviceId)
{
TrayDisableInfo t = new TrayDisableInfo(trayNum, deviceName, describle,deviceId);
if(UseNewLogic)
{
TrayInfo tray = TrayManager.GetTrayInfo(trayNum);
if(tray.InoutPar.Corrected)
{
LogUtil.info($"{deviceName} 托盘新判断逻辑,料盘已纠正,无需处理:【{tray.ToStr()}】【{describle}】");
return;
}
if (tray.IsFull && type.Equals(1))//有料,但传感器未检测到
{
LogUtil.info($"{deviceName} 托盘新判断逻辑:【{tray.ToStr()}】【{describle}】。需要二次判断");
tray.InoutPar.ManualJudgeNG = true;
TrayManager.UpdateTrayInfo(trayNum,tray.IsFull,tray.InOrOutStore,tray.InoutPar);
}
else if (!tray.IsFull && type.Equals(2) && !tray.InoutPar.InStoreNg)//无料,但传感器感应到
{
tray.InoutPar.ManualJudgeNG = true;
LogUtil.info($"{deviceName} 托盘新判断逻辑:【{tray.ToStr()}】【{describle}】。认为NG");
TrayManager.UpdateTrayInfo(trayNum, tray.IsFull, tray.InOrOutStore, tray.InoutPar);
}
else
{
tray.InoutPar.ManualJudgeNG = true;
TrayManager.UpdateTrayInfo(trayNum, tray.IsFull, tray.InOrOutStore, tray.InoutPar);
LogUtil.info($"{deviceName} 托盘新判断逻辑:【{tray.ToStr()}】【{describle}】。其他处理,需要二次判断");
}
//if (tray.InOrOutStore.Equals(1))//入库料
//{
// if (tray.IsFull && type.Equals(1))//认为无料
// {
// TrayManager.UpdateTrayInfo(trayNum) ;
// LogUtil.info($"{deviceName} 托盘新判断逻辑:【{tray.ToStr()}】【{describle}】。认为无料");
// }
// else if(!tray.IsFull && type.Equals(2) && !tray.InoutPar.InStoreNg)
// {
// tray.InoutPar.InStoreNg = true;
// TrayManager.UpdateTrayInfo(trayNum,true,tray.InOrOutStore,tray.InoutPar);
// LogUtil.info($"{deviceName} 托盘新判断逻辑:【{tray.ToStr()}】【{describle}】。认为NG");
// }
//}
//else if(tray.InOrOutStore.Equals(2))
//{
// if (tray.IsFull && type.Equals(1))//认为无料
// {
// TrayManager.UpdateTrayInfo(trayNum);
// LogUtil.info($"{deviceName} 托盘新判断逻辑:【{tray.ToStr()}】【{describle}】。认为无料");
// }
// else if (!tray.IsFull && type.Equals(2) && !tray.InoutPar.InStoreNg)
// {
// tray.InoutPar.InStoreNg = true;
// TrayManager.UpdateTrayInfo(trayNum, true, tray.InOrOutStore, tray.InoutPar);
// LogUtil.info($"{deviceName} 托盘新判断逻辑:【{tray.ToStr()}】【{describle}】。认为NG");
// }
//}
}
else
{
AddDisableTray(t);
}
}
public static void AddDisableTray(int trayNum,string deviceName,string describe,int deviceId )
{
TrayDisableInfo t = new TrayDisableInfo();
t.TrayCode = trayNum;
t.DDescribe = describe;
t.DDeviceName = deviceName;
t.DeviceId = deviceId;
if (TrayDisableMap.ContainsKey(trayNum))
{
TrayDisableMap[trayNum] = t;
}
else
{
TrayDisableMap.TryAdd(trayNum, t);
}
//如果托盘上物料是入库的,直接清理入库 任务
TrayInfo tray = TrayManager.GetTrayInfo(trayNum);
if (tray.IsFull && tray.InOrOutStore.Equals(1))
{
TrayManager.ClearInstore(tray, "禁用托盘[" + trayNum + "]");
}
LogUtil.info("增加托盘禁用:" + t.ToStr() + "");
}
public static void AddDisableTray(TrayDisableInfo t)
{
if (TrayDisableMap.ContainsKey(t.TrayCode))
{
TrayDisableMap[t.TrayCode] = t;
}
else
{
TrayDisableMap.TryAdd(t.TrayCode, t);
}
//如果托盘上物料是入库的,直接清理入库 任务
TrayInfo tray = TrayManager.GetTrayInfo(t.TrayCode);
if (tray.IsFull && tray.InOrOutStore.Equals(1))
{
TrayManager.ClearInstore(tray, "禁用托盘[" + t.TrayCode + "]");
}
LogUtil.info("增加托盘禁用:" + t.ToStr() + "");
}
public static void RemoveDisable(int trayNum)
{
TrayManager.UpdateTrayInfo(trayNum);
bool result = TrayDisableMap.TryRemove(trayNum, out TrayDisableInfo removeInfo);
if (result && removeInfo != null)
{
LogUtil.info("启用托盘:" + removeInfo.ToStr());
}
}
/// <summary>
/// 判断托盘是否被禁用
/// </summary>
/// <param name="currTrayNum"></param>
/// <returns></returns>
public static bool DisableTray(int currTrayNum)
{
return TrayDisableMap.ContainsKey(currTrayNum);
}
}
}