ALineManager.cs
14.8 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
using log4net;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace OnlineStore.DeviceLibrary
{
public class LineManager
{
public static int OutMoveId = 7;
public static bool TrayToOutLineTest = false;
public static bool DisGetWare = false;
public static bool UseBuzzer = ConfigAppSettings.GetIntValue(Setting_Init.UseBuzzer).Equals(1);
private static bool isInit = false;
public static bool IsConnectServer = !ConfigAppSettings.GetValue(Setting_Init.http_server).Equals("");
public static LineBean Line = null;
public static Line_Config Config = null;
public static Dictionary<int, DeviceConfig> allConfigMap = null;
public LineManager()
{
}
public static bool CheckEnum(Type type)
{
if (type.IsEnum)
{
List<int> valueList = new List<int>();
Array array = Enum.GetValues(type);
foreach (int item in array)
{
if (valueList.Contains(item))
{
LogUtil.error(type.Name + "枚举值:" + item + "重复存在,请检查代码!程序退出。");
Application.Exit();
return false;
}
valueList.Add(item);
}
}
return true;
}
public static bool Init()
{
try
{
if (!isInit)
{
string server = ConfigAppSettings.GetValue(Setting_Init.http_server);
if (server.Equals(""))
{
IsConnectServer = false;
}
else
{
IsConnectServer = true;
}
if (!CheckEnum(typeof(LineMoveStep)))
{
return false;
}
if (!CheckEnum(typeof(LineStatus)))
{
return false;
}
if (!CheckEnum(typeof(LineRunStatus)))
{
return false;
}
Dictionary<int, MoveEquip_Config> moveECMap = null;
Dictionary<int, FeedingEquip_Config> feedingECMap = null;
Dictionary<int, HYEquip_Config> HYECMap = null;
DeviceConfig.SubDIList = new Dictionary<int, Dictionary<string, ConfigIO>>();
DeviceConfig.SubDOList = new Dictionary<int, Dictionary<string, ConfigIO>>();
DeviceConfig.ProIOIpMap = new Dictionary<string, string>();
DeviceConfig.ProRFIpMap = new Dictionary<string, string>();
moveECMap = new Dictionary<int, MoveEquip_Config>();
feedingECMap = new Dictionary<int, FeedingEquip_Config>();
HYECMap = new Dictionary<int, HYEquip_Config>();
allConfigMap = new Dictionary<int, DeviceConfig>();
isInit = true;
string lineType = ConfigAppSettings.GetValue(Setting_Init.Line_Type);
LogUtil.info(" 类型=" + lineType + ",开始加载 配置");
if (lineType == DeviceType.Line)
{
string appPath = Application.StartupPath;
string CID = ConfigAppSettings.GetValue(Setting_Init.Line_CID);
string linefilePath = appPath + ConfigAppSettings.GetValue(Setting_Init.ConfigPath_Line);
Config = CSVConfigReader.LoadLineConfig(0, CID, DeviceType.Line, linefilePath);
allConfigMap.Add(0, Config);
int moveEquipCount = ConfigAppSettings.GetIntValue(Setting_Init.Line_moveEquip_count);
string moveEquipConfig = ConfigAppSettings.GetValue(Setting_Init.ConfigPath_MoveEquip);
for (int i = 1; i <= moveEquipCount; i++)
{
string nameStr = i.ToString().PadLeft(2, '0');
string config = appPath + moveEquipConfig.Replace(".csv", "_" + nameStr + ".csv");
if (!File.Exists(config))
{
config = appPath + moveEquipConfig;
}
MoveEquip_Config moveConfig = CSVConfigReader.LoadMoveConfig(i, DeviceType.MoveEquip, config);
moveConfig.ConfigSpeed(Config);
int subType = i;
moveECMap.Add(i, moveConfig);
}
foreach (int i in moveECMap.Keys)
{
int subType = i;
moveECMap[i].SetIO(subType);
allConfigMap.Add(subType, moveECMap[i]);
}
int feedingEquipCount = ConfigAppSettings.GetIntValue(Setting_Init.Line_feedingEquip_count);
string feedingEquipConfig = ConfigAppSettings.GetValue(Setting_Init.ConfigPath_FeedingEquip);
for (int i = 1; i <= feedingEquipCount; i++)
{
int subType = 100 + i;
string config = appPath + feedingEquipConfig.Replace(".csv", "_" + i + ".csv");
FeedingEquip_Config moveConfig = CSVConfigReader.LoadFeedingConfig(subType, DeviceType.FeedingEquip, config);
moveConfig.ConfigSpeed(Config);
moveConfig.SetIO(subType);
feedingECMap.Add(subType, moveConfig);
allConfigMap.Add(subType, moveConfig);
}
int hyEquipCount = ConfigAppSettings.GetIntValue(Setting_Init.Line_HYEquip_count);
string hyEquipConfig = ConfigAppSettings.GetValue(Setting_Init.ConfigPath_HYEquip);
for (int i = 1; i <= hyEquipCount; i++)
{
int subType = 200 + i;
string nameStr = i.ToString().PadLeft(2, '0');
string config = appPath + hyEquipConfig.Replace(".csv", "_" + nameStr + ".csv");
if (!File.Exists(config))
{
config = appPath + hyEquipConfig;
}
HYEquip_Config moveConfig = CSVConfigReader.LoadHYConfig(subType, DeviceType.HYEquip, config);
moveConfig.ConfigSpeed(Config);
moveConfig.LoadParam();
moveConfig.SetIO(subType);
HYECMap.Add(subType, moveConfig);
allConfigMap.Add(subType, moveConfig);
}
Config.SetIO(1000);
Line = new LineBean(Config, moveECMap, feedingECMap, HYECMap);
LogUtil.info("加载 完成!");
return true;
}
}
else if (Line != null)
{
return true;
}
}
catch (Exception ex)
{
LogUtil.error("出错:", ex);
MessageBox.Show(ex.ToString(), "加载配置错误(请检查配置)");
Application.Exit();
}
return false;
}
public static void SaveMoveEquipConfig(MoveEquip_Config config)
{
try
{
//位置配置到文件中
string appPath = Application.StartupPath;
string moveEquipConfig = ConfigAppSettings.GetValue(Setting_Init.ConfigPath_MoveEquip);
string configBase = appPath + moveEquipConfig;
string configStr = appPath + moveEquipConfig.Replace(".csv", "_" + config.Id.ToString().PadLeft(2, '0') + ".csv");
allConfigMap[config.Id] = config;
if (!File.Exists(configStr))
{
LogUtil.info("复制配置文件【" + configBase + "】->【" + configStr + "】");
File.Copy(configBase, configStr);
}
bool result = CSVConfigReader.SaveConfig(configStr, config, typeof(MoveEquip_Config));
if (!result)
{
LogUtil.error("保存配置文件失败:" + configStr);
}
}
catch (Exception ex)
{
LogUtil.error("出错:", ex);
}
}
public static void SaveFeedingEquipConfig(FeedingEquip_Config config)
{
try
{
//位置配置到文件中
string appPath = Application.StartupPath;
string moveEquipConfig = ConfigAppSettings.GetValue(Setting_Init.ConfigPath_FeedingEquip);
int id = config.Id - 100;
string configStr = appPath + moveEquipConfig.Replace(".csv", "_" + id + ".csv");
allConfigMap[config.Id] = config;
bool result = CSVConfigReader.SaveConfig(configStr, config, typeof(FeedingEquip_Config));
if (!result)
{
LogUtil.error("保存配置文件失败:" + configStr);
}
}
catch (Exception ex)
{
LogUtil.error("出错:", ex);
}
}
public static void SaveHYEquipConfig(HYEquip_Config config)
{
try
{
//位置配置到文件中
string appPath = Application.StartupPath;
string moveEquipConfig = ConfigAppSettings.GetValue(Setting_Init.ConfigPath_HYEquip);
int id = config.Id - 200;
string configBase = appPath + moveEquipConfig;
string configStr = appPath + moveEquipConfig.Replace(".csv", "_" + id + ".csv");
if (!File.Exists(configStr))
{
LogUtil.info("复制配置文件【" + configBase + "】->【" + configStr + "】");
File.Copy(configBase, configStr);
}
allConfigMap[config.Id] = config;
bool result = CSVConfigReader.SaveConfig(configStr, config, typeof(HYEquip_Config));
if (!result)
{
LogUtil.error("保存配置文件失败:" + configStr);
}
}
catch (Exception ex)
{
LogUtil.error("出错:", ex);
}
}
private static List<int> trayHeightList = new List<int>();
public static List<int> GetTrayList()
{
if (trayHeightList.Count <= 0)
{
string config = ConfigAppSettings.GetValue(Setting_Init.TrayHeightList);
string[] array = config.Split(';');
foreach (string s in array)
{
try
{
int v = Convert.ToInt32(s.Trim());
if (v > 0)
{
trayHeightList.Add(v);
}
}
catch (Exception ex)
{
}
}
if (trayHeightList.Count <= 0)
{
trayHeightList = new List<int>() { 8, 12, 16, 20, 24, 28, 36, 48 };
}
}
return trayHeightList;
}
private static List<string> PnList = null;
public static List<string> GetPnList()
{
if (PnList == null)
{
PnList = new List<string>();
string config = ConfigAppSettings.GetValue(Setting_Init.PNList);
string[] array = config.Split('#');
foreach (string s in array)
{
if (!String.IsNullOrEmpty(s))
{
PnList.Add(s);
}
}
}
return PnList;
}
public static void UpdatePnList()
{
if (PnList == null)
{
return;
}
string str = "";
foreach (string obj in PnList)
{
str += obj + "#";
}
ConfigAppSettings.SaveValue(Setting_Init.PNList, str);
LogUtil.info("更改脆盘料号集合:" + str);
}
public static void RemovePN(string pn)
{
if (PnList.Contains(pn))
{
PnList.Remove(pn);
UpdatePnList();
}
}
public static void AddPN(string pn)
{
if (!PnList.Contains(pn))
{
PnList.Add(pn);
UpdatePnList();
}
}
public static bool IsCrispReel(params string[] codes)
{
try
{
List<string> list = GetPnList();
foreach (string code in codes)
{
string[] array = code.Split('*');
if (array.Length >= 5)
{
string codePn = array[1];
foreach (string pn in list)
{
if (codePn.Equals(pn))
{
LogUtil.info("IsCrispReel:条码[" + code + "]料号[" + pn + "]是脆盘");
return true;
}
else if (codePn.StartsWith(pn))
{
LogUtil.info("IsCrispReel:条码[" + code + "]料号[" + pn + "]认为是脆盘");
return true;
}
}
}
}
}
catch (Exception ex)
{
LogUtil.error("IsCrispReel 出错:" + ex.ToString());
}
return false;
}
public static bool NeedWaitHassReel(params string[] codes)
{
return true;
//return !IsCrispReel(codes);
}
}
}