AssemblyLineManager.cs
9.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
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
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 readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public static int CurrInOutType = 0;
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, MoveEquip_Config> moveECMap = null;
public static Dictionary<int, FeedingEquip_Config> feedingECMap = null;
public static Dictionary<int, ProvidingEquip_Config> providingECMap = null;
public LineManager()
{
}
public static void CheckEnum(Type type)
{
if (type.IsEnum)
{
List<int> valueList = new List<int>();
foreach (int item in Enum.GetValues(type))
{
if (valueList.Contains(item))
{
LogUtil.error(LOGGER, type.Name + "枚举值:" + item + "重复存在,请检查代码!");
Application.Exit();
break;
}
valueList.Add(item);
}
}
}
public static LineBean Init()
{
try
{
if (!isInit)
{
moveECMap = new Dictionary<int, MoveEquip_Config>();
feedingECMap = new Dictionary<int, FeedingEquip_Config>();
providingECMap = new Dictionary<int, ProvidingEquip_Config>();
string server = ConfigAppSettings.GetValue(Setting_Init.http_server);
if (server.Equals(""))
{
IsConnectServer = false;
}
else
{
IsConnectServer = true;
}
CheckEnum(typeof(LineMoveStep));
CheckEnum(typeof(LineStatus));
CheckEnum(typeof(LineRunStatus));
isInit = true;
string lineType = ConfigAppSettings.GetValue(Setting_Init.Line_Type);
LogUtil.info(LOGGER, " 类型=" + lineType + ",开始加载 配置");
if (lineType == StoreType.RC_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(1, CID, StoreType.RC_LINE, linefilePath);
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");
MoveEquip_Config moveConfig = CSVConfigReader.LoadMoveConfig(i, config);
int subType = i;
moveConfig.SetIO(Config, subType);
moveECMap.Add(i, moveConfig);
}
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, config);
moveConfig.SetIO(Config, subType);
feedingECMap.Add(i, moveConfig);
}
int providingEquipCount = ConfigAppSettings.GetIntValue(Setting_Init.Line_providingEquip_count);
string providingEquipConfig = ConfigAppSettings.GetValue(Setting_Init.ConfigPath_ProvidingEquip);
for (int i = 1; i <= providingEquipCount; i++)
{
int subType = 200 + i;
string config = appPath + providingEquipConfig.Replace(".csv", "_" + i + ".csv");
ProvidingEquip_Config moveConfig = CSVConfigReader.LoadProvidingConfig(subType, config);
moveConfig.SetIO(Config, subType);
providingECMap.Add(i, moveConfig);
}
Line = new LineBean(Config, moveECMap,feedingECMap,providingECMap);
LogUtil.info(LOGGER, "加载 完成!");
return Line;
}
}
}
catch (Exception ex)
{
LOGGER.Error("出错:", ex);
MessageBox.Show(ex.ToString(), "加载配置错误(请检查配置)");
Application.Exit();
}
return null;
}
/// <summary>
/// 获取阻挡气缸检测类型
/// </summary>
/// <returns></returns>
public static string GetStopIoType(int stopCylinderIOType)
{
string type = IO_Type.Fixture_Check_1;
switch (stopCylinderIOType)
{
case 1:
type = IO_Type.Fixture_Check_1;
break;
case 2:
type = IO_Type.Fixture_Check_2;
break;
case 3:
type = IO_Type.Fixture_Check_3;
break;
case 4:
type = IO_Type.Fixture_Check_4;
break;
}
return type;
}
public static void SaveMoveEquipConfig(MoveEquip_Config config)
{
try
{
//位置配置到文件中
string appPath = Application.StartupPath;
string moveEquipConfig = ConfigAppSettings.GetValue(Setting_Init.ConfigPath_MoveEquip);
string configStr = appPath + moveEquipConfig.Replace(".csv", "_" + config.Id.ToString().PadLeft(2,'0') + ".csv");
moveECMap[config.Id] = config;
bool result = CSVConfigReader.SaveConfig(configStr, config,typeof(MoveEquip_Config));
if (!result)
{
LOGGER.Error("保存配置文件失败:" + configStr);
}
}
catch (Exception ex)
{
LOGGER.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");
feedingECMap[config.Id] = config;
bool result = CSVConfigReader.SaveConfig(configStr, config,typeof(FeedingEquip_Config));
if (!result)
{
LOGGER.Error("保存配置文件失败:" + configStr);
}
}
catch (Exception ex)
{
LOGGER.Error("出错:", ex);
}
}
public static void SaveProvidingEquipConfig(ProvidingEquip_Config config)
{
try
{
//位置配置到文件中
string appPath = Application.StartupPath;
string moveEquipConfig = ConfigAppSettings.GetValue(Setting_Init.ConfigPath_ProvidingEquip);
int id = config.Id - 200;
string configStr = appPath + moveEquipConfig.Replace(".csv", "_" + id + ".csv");
providingECMap[config.Id] = config;
bool result = CSVConfigReader.SaveConfig(configStr, config,typeof(ProvidingEquip_Config));
if (!result)
{
LOGGER.Error("保存配置文件失败:" + configStr);
}
}
catch (Exception ex)
{
LOGGER.Error("出错:", ex);
}
}
}
}