ALineManager.cs
7.3 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
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 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 Dictionary<string, string> StepDesMap = new Dictionary<string, string>();
public static DischargeEquip GetDischargeEquip()
{
return (DischargeEquip)Line.AllEquipMap[102];
}
public static bool CheckEnum(Type type, bool isStep = false)
{
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);
if (isStep)
{
LineMoveStep en = (LineMoveStep)item;
string des = EnumDesHelper.GetStepDes(en);
StepDesMap.Add(en.ToString(), des);
}
}
}
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), true))
{
return false;
}
if (!CheckEnum(typeof(LineStatus)))
{
return false;
}
if (!CheckEnum(typeof(LineRunStatus)))
{
return false;
}
Dictionary<int, AGVEquip_Config> agvECMap = null;
Dictionary<int, StationEquip_Config> stationECMap = 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>();
agvECMap = new Dictionary<int, AGVEquip_Config>();
stationECMap = new Dictionary<int, StationEquip_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);
for (int i = 1; i <= 5; i++)
{
StationEquip_Config config = CSVConfigReader.LoadStationConfig(i, DeviceType.StationEquip, "");
config.SetIO(i);
stationECMap.Add(i, config);
allConfigMap.Add(i, config);
}
for (int i = 1; i <= 2; i++)
{
int subType = i + 100;
AGVEquip_Config moveConfig = CSVConfigReader.LoadMoveConfig(subType, DeviceType.AGVEquip, "");
moveConfig.SetIO(subType);
agvECMap.Add(subType, moveConfig);
allConfigMap.Add(subType, agvECMap[subType]);
}
for (int i = 1; i <= 4; i++)
{
int subType = 200 + i;
HYEquip_Config moveConfig = CSVConfigReader.LoadHYConfig(subType, DeviceType.HYEquip, "");
moveConfig.LoadParam();
moveConfig.SetIO(subType);
HYECMap.Add(subType, moveConfig);
allConfigMap.Add(subType, moveConfig);
}
Config.SetIO(1000);
Line = new LineBean(Config, agvECMap, stationECMap, 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;
}
/// <summary>
/// 箱子是否可以进入料工位
/// </summary>
/// <returns></returns>
public static bool CanBoxIntoFeeding()
{
return Line?.AllEquipMap[101]?.IsIdle() ?? false;
}
public static bool IsDisChargeIdle()
{
return Line?.AllEquipMap[102]?.IsIdle() ?? false;
}
public static void StartDisChargeMove()
{
Line?.AllEquipMap[102]?.StartMove();
}
public static void StartStationInStore(InOutParam inOutParam)
{
if(Line?.AllEquipMap.ContainsKey(inOutParam.DeviceId)??false)
{
Line?.AllEquipMap[inOutParam.DeviceId].StartInStoreMove(inOutParam);
}
}
/// <summary>
/// 是否有箱子
/// </summary>
/// <returns></returns>
public static bool IsFeedingHasBox()
{
return Line?.AllEquipMap[101]?.BoxCheck() ?? false;
}
}
}