AgvClient_Dbline.cs
9.1 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
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using AsaPL;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public class AgvClient_Dbline
{
private static string ServerIp = ConfigAppSettings.GetValue(Setting_Init.Line_AGV);
public AsaPL.AgvClient agvClient;
private static bool isInit = false;
public static Dictionary<string, AsaPL.ClientAction> actionMap = new Dictionary<string, AsaPL.ClientAction>();
public bool A5_InProcess = false;
public bool A6_InProcess = false;
public string A6_RFID { get; set; } = "";
#region A5 Action
/// <summary>
/// 上下满
/// </summary>
public void A5_None()
{
SetStatus("A5", "", ClientAction.None,ClientLevel.Low);
}
public void A5_NeedD()
{
SetStatus("A5", "", ClientAction.NeedD,ClientLevel.Low);
}
public void A5_NeedD_High()
{
SetStatus("A5", "", ClientAction.NeedD,ClientLevel.High);
}
public void A5_NeedC()
{
SetStatus("A5", "", ClientAction.NeedC,ClientLevel.Low);
}
/// <summary>
/// 上下都未满(正常)
/// </summary>
public void A5_NeedEnter()
{
SetStatus("A5", "", ClientAction.NeedEnter,ClientLevel.Low);
}
public void A5_NeedEnter_High()
{
SetStatus("A5", "", ClientAction.NeedEnter, ClientLevel.High);
}
#endregion
#region A6 Action
/// <summary>
/// 上ON,下OFF
/// </summary>
public void A6_None()
{
SetStatus("A6", "", ClientAction.None);
}
/// <summary>
/// 上OFF,下OFF
/// </summary>
public void A6_NeedEnter()
{
SetStatus("A6", "", ClientAction.NeedEnter);
}
/// <summary>
/// 上ON,下ON
/// </summary>
public void A6_NeedLeave()
{
SetStatus("A6", A6_RFID, ClientAction.NeedLeave);
}
/// <summary>
/// 上OFF,下ON
/// </summary>
public void A6_NeedEnterLeave()
{
SetStatus("A6", A6_RFID, ClientAction.NeedEnterLeave);
}
#endregion
public void Init()
{
try
{
if (!isInit)
{
isInit = true;
agvClient = new AsaPL.AgvClient(ServerIp);
agvClient.CancelState = false;
agvClient.ReadyEnter += AgvClient_ReadyEnter;
agvClient.ReadyLeave += AgvClient_ReadyLeave;
agvClient.AGVFinishEnter += AgvClient_FinishEnter;
agvClient.AGVFinishLeave += AgvClient_FinishLeave;
}
actionMap = new Dictionary<string, AsaPL.ClientAction>();
agvClient.SetStatus("A5", "", ClientAction.None);
agvClient.SetStatus("A6", "", ClientAction.None);
agvClient.Connect();
LogUtil.info("初始化AGV服务");
}
catch (Exception ex)
{
LogUtil.error("初始化AGV服务 " + ServerIp + " 出错:", ex);
}
}
/// <summary>
/// 设置取消状态
/// </summary>
/// <param name="isCancel">true则ClientAction为None</param>
public void SetCancelState(bool isCancel)
{
agvClient.CancelState = isCancel;
}
/// <summary>
/// 小车准备进入
/// </summary>
/// <param name="name">节点名称</param>
private void AgvClient_ReadyEnter(string name)
{
if (name.Equals("A5"))
{
A5_InProcess = true;
A5_ReadyEnter = true;
}
else if (name.Equals("A6"))
{
A6_InProcess = true;
A6_ReadyEnter = true;
}
LogUtil.info("收到 AgvClient_ReadyEnter [" + name + "]");
}
/// <summary>
///料架准备离开
/// </summary>
/// <param name="name">节点名称</param>
private void AgvClient_ReadyLeave(string name)
{
//SetStatus(name, "", ClientAction.ReadyLeave);
if (name.Equals("A6"))
{
A6_InProcess = true;
A6_ReadyLeave = true;
}
LogUtil.info("收到 AgvClient_ReadyLeave [" + name + "] ");
}
/// <summary>
/// 料架离开小车完成
/// </summary>
/// <param name="name"></param>
private void AgvClient_FinishLeave(string name)
{
//if (name.Equals("A5"))
//{
// A5_InProcess = false;
//}
//else if (name.Equals("A6"))
//{
// A6_InProcess = false;
//}
LogUtil.info("收到 AgvClient_FinishLeave [" + name + "] ");
}
/// <summary>
/// 料架进入小车完成
/// </summary>
/// <param name="name"></param>
private void AgvClient_FinishEnter(string name)
{
//if (name.Equals("A5"))
//{
// A5_InProcess = false;
//}
//else if (name.Equals("A6"))
//{
// A6_InProcess = false;
//}
LogUtil.info("收到 AgvClient_FinishEnter [" + name + "] ");
}
/// <summary>
/// 左侧料架可以进入
/// </summary>
public bool A5_ReadyEnter { private set; get; }
/// <summary>
/// 右侧料架可以进入
/// </summary>
public bool A6_ReadyEnter { private set; get; }
/// <summary>
/// 右侧料架可以出去
/// </summary>
public bool A6_ReadyLeave { private set; get; }
public void MayEnter(string name)
{
SetStatus(name, "", ClientAction.MayEnter);
if (name.Equals("A5"))
{
A5_ReadyEnter = false;
}
else if (name.Equals("A6"))
{
A6_ReadyEnter = false;
}
}
public void MayLeave(string name)
{
SetStatus(name, "", ClientAction.MayLeave);
if (name.Equals("A6"))
{
A6_ReadyLeave = false;
}
}
public void FinishEnter(string name)
{
Task.Factory.StartNew(delegate {
SetStatus(name, "", ClientAction.FinishEnter);
Thread.Sleep(15000);
if (name.Equals("A5"))
{
A5_InProcess = false;
}
else if (name.Equals("A6"))
{
A6_InProcess = false;
}
});
}
public void FinishLeave(string name)
{
Task.Factory.StartNew(delegate
{
SetStatus(name, "", ClientAction.FinishLeave);
Thread.Sleep(15000);
if (name.Equals("A5"))
{
A5_InProcess = false;
}
else if (name.Equals("A6"))
{
A6_InProcess = false;
}
});
}
private bool SetStatus(string name, string shelfId = "", ClientAction action = ClientAction.None, ClientLevel level = ClientLevel.Low)
{
// if (!agvClient.IsConn)
// {
// LogUtil.error("SetStatus AGV服务未连接!");
// return false;
// }
if (actionMap.ContainsKey(name))
{
ClientAction currA = actionMap[name]; //相同状态就设置一次
if (currA.Equals(action) && shelfId == "")
{
return false;
}
// actionMap[name] = action;
// agvClient.SetStatus(name, shelfId, action, level);
//LogUtil.info("设置 " + name + " [" + shelfId + "] " + action.ToString());
return true;
}
agvClient.SetStatus(name, shelfId, action, level);
//actionMap.Add(name, action);
//LogUtil.info("设置 " + name + " ["+ shelfId + "] "+ action.ToString());
return true;
}
public bool ISConnected()
{
if (agvClient == null)
{
return false;
}
return agvClient.IsConn;
}
public void Dispose()
{
try
{
if (agvClient != null)
{
agvClient.Close();
LogUtil.info("关闭AGV服务");
}
}
catch (Exception ex)
{
LogUtil.error("关闭AGV服务 " + ServerIp + " 出错:", ex);
}
}
}
}