Common.cs
12.9 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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace AGVControl
{
public static class Common
{
public static Asa.File.Log log;
public static BLL.MiR_API mir;
public static List<ClientNode> nodeInfo;
public static List<Agv_Info> agvInfo;
public static BLL.AgvServer server;
public static BLL.Control control;
public static Dictionary<string, string> agvMission;
public static Dictionary<string, string> webService;
public static ChargeStatus chargeStatus;
public static System.Configuration.Configuration appConfig;
public static readonly string LOG_PATH = AppDomain.CurrentDomain.BaseDirectory + "Log";
public static readonly string CONFIG_PATH = AppDomain.CurrentDomain.BaseDirectory + "Config\\";
}
public static class API
{
[DllImport("user32.dll", EntryPoint = "ShowWindow", CharSet = CharSet.Auto)]
public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
[DllImport("user32.dll ", SetLastError = true)]
public static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab);
public const int SW_RESTORE = 9;
}
/// <summary>
/// 客户端的节点
/// </summary>
public class ClientNode
{
/// <summary>
/// 节点名称
/// </summary>
public string Name { set; get; }
/// <summary>
/// 标记,用于包装料仓
/// </summary>
public string Mark { set; get; }
/// <summary>
/// 当前架子的RFID
/// </summary>
public string RFID { set; get; }
/// <summary>
/// 动作
/// </summary>
public ClientAction Action { set; get; }
/// <summary>
/// 优先级
/// </summary>
public ClientLevel Level { set; get; }
/// <summary>
/// 小车名称
/// </summary>
public string AgvName { set; get; }
/// <summary>
/// 在线
/// </summary>
public bool Online { set; get; }
/// <summary>
/// 是否可用
/// </summary>
public bool IsUse { set; get; }
/// <summary>
/// 客户端的节点
/// </summary>
/// <param name="name"></param>
public ClientNode(string name)
{
Name = name;
Mark = "";
RFID = "";
Action = ClientAction.None;
Level = ClientLevel.Low;
AgvName = "";
Online = false;
IsUse = true;
}
/// <summary>
/// 客户端的节点
/// </summary>
/// <param name="name"></param>
/// <param name="isUse"></param>
public ClientNode(string name, bool isUse) : this(name)
{
IsUse = isUse;
}
public ClientNode(string name, string rfid, ClientAction action)
{
Name = name;
Mark = "";
RFID = rfid;
Action = action;
Level = ClientLevel.Low;
AgvName = "";
Online = false;
IsUse = true;
}
public string[] ToRow()
{
//节点,动作,优先级,标志,RFID,AGV名称,在线,调用,清除AGV
string[] s = new string[9];
s[0] = Name;
if (Online)
{
s[1] = Action.ToString();
s[2] = Level.ToString();
s[3] = Mark;
s[4] = RFID;
s[5] = AgvName;
}
s[6] = Online.ToString();
s[7] = IsUse.ToString();
s[8] = "Clear";
return s;
}
public string ToText()
{
string s = string.Format("Name={0}, Action={1}, Level={2}, Mark={3}, RFID={4}", Name, Action, Level, Mark, RFID);
return s;
}
/// <summary>
/// 脱机
/// </summary>
public void Offline()
{
Mark = "";
RFID = "";
Action = ClientAction.None;
Level = ClientLevel.Low;
AgvName = "";
Online = false;
}
}
/// <summary>
/// 客户端的动作
/// </summary>
public enum ClientAction : byte
{
/// <summary>
/// 没有动作
/// </summary>
None = 0,
/// <summary>
/// 关门(仅包装料仓)
/// </summary>
CloseDoor = 1,
/// <summary>
/// 可以进入料架(仅包装料仓)
/// </summary>
MayEnter = 2,
/// <summary>
/// 可以出去料架(仅包装料仓)
/// </summary>
MayLeave = 3,
/// <summary>
/// 需要进入料架
/// </summary>
NeedEnter = 4,
/// <summary>
/// 需要出去料架
/// </summary>
NeedLeave = 5,
/// <summary>
/// 完成进入料架
/// </summary>
FinishEnter = 6,
/// <summary>
/// 完成出去料架
/// </summary>
FinishLeave = 7,
/// <summary>
/// 小车到达
/// </summary>
Arrive = 8,
/// <summary>
/// 小车已准备好
/// </summary>
Ready = 9,
/// <summary>
/// 只能入料不能出料(仅包装料仓)
/// </summary>
EnterShelf = 10
}
/// <summary>
/// 客户端的优先级
/// </summary>
public enum ClientLevel : byte
{
/// <summary>
/// 低
/// </summary>
Low = 0,
/// <summary>
/// 中等
/// </summary>
Middle = 1,
/// <summary>
/// 高
/// </summary>
High = 2
}
public enum Mission_Status
{
/// <summary>
/// 没有动作
/// </summary>
None = 0,
/// <summary>
/// 小车到达
/// </summary>
Arrive = 1,
/// <summary>
/// 小车已准备好
/// </summary>
Ready = 2,
/// <summary>
/// 完成进入
/// </summary>
FinishEnter = 3,
/// <summary>
/// 完成离开
/// </summary>
FinishLeave = 4,
/// <summary>
/// 等待
/// </summary>
//Wait = 5,
/// <summary>
/// 小车到达后等待
/// </summary>
ArriveWait = 6,
/// <summary>
/// 报错
/// </summary>
Error = 10,
/// <summary>
/// 执行任务中
/// </summary>
StartMission = 11,
/// <summary>
/// 自动充电完成
/// </summary>
AutoCharge = 12
}
public class Agv_Info
{
/// <summary>
/// 小车名称
/// </summary>
public string Name { set; get; }
/// <summary>
/// 小车在FLEET中的ID号
/// </summary>
public string ID { set; get; }
/// <summary>
/// IP地址
/// </summary>
public string IP { set; get; }
/// <summary>
/// 授权码
/// </summary>
public string Authorization { set; get; }
/// <summary>
/// IO模块的ID号
/// </summary>
public string IOID { set; get; }
/// <summary>
/// 标记
/// </summary>
public string Mark { set; get; }
/// <summary>
/// 当前架子的RFID
/// </summary>
public string RFID { set; get; }
/// <summary>
/// 是否在线
/// </summary>
public bool IsCon { set; get; }
/// <summary>
/// 是否可用
/// </summary>
public bool IsUse { set; get; }
/// <summary>
/// 地点
/// </summary>
public string Place { set; get; }
/// <summary>
/// 小车的状态id
/// </summary>
public int StateID { set; get; }
/// <summary>
/// 小车的状态
/// </summary>
public string StateText { set; get; }
/// <summary>
/// 电量百分比
/// </summary>
public int Battery { set; get; }
/// <summary>
/// 任务文本
/// </summary>
public string Mission_text { set; get; }
/// <summary>
/// 任务的状态
/// </summary>
public Mission_Status MissionStatus { set; get; }
/// <summary>
/// 下一个任务
/// </summary>
public string NextMission { set; get; }
/// <summary>
/// 关门,用于执行一次
/// </summary>
public bool CloseDoor { set; get; }
/// <summary>
/// 任务发送,用于已调用API,但还没有修改状态
/// </summary>
public bool TaskSend { set; get; }
/// <summary>
/// 闲置等待时间,用于充电
/// </summary>
public int WaitTime { set; get; }
/// <summary>
/// 临时待机位,用于执行一次
/// </summary>
public bool StandbyTemp { set; get; }
/// <summary>
/// 是否清除任务缓存
/// </summary>
public bool IsClearRunInfo = false;
public struct DockingStru
{
public DateTime startTime;
public bool IsDocking;
}
/// <summary>
/// 停靠信息
/// </summary>
public DockingStru DockingInfo;
public Agv_Info(string id, string name, string ip, string authorization, string ioId, bool isUse)
{
ID = id;
Name = name;
IP = ip;
Authorization = authorization;
IOID = ioId;
Mark = "";
RFID = "";
IsCon = false;
IsUse = isUse;
Place = "";
StateText = "";
WaitTime = 0;
DockingInfo.IsDocking = false;
DockingInfo.startTime = DateTime.Now;
}
public string[] ToRow()
{
//AGV名称,IP,AGV状态,任务状态,地点,后续任务,在线,电量,调用,清除缓存
string[] s = new string[10];
s[0] = Name;
s[1] = IP;
if (IsCon)
{
s[2] = StateText;
s[3] = string.Format("{0}({1})", MissionStatus.ToString(), (int)MissionStatus);
s[4] = Place;
s[5] = NextMission;
}
s[6] = IsCon.ToString();
s[7] = Battery + "%";
s[8] = IsUse.ToString();
s[9] = "Clear";
return s;
}
public string[] ToMission()
{
//AGV名称,IP,AGV状态,任务状态,地点,后续任务,在线,电量,调用,清除缓存
string[] s = new string[2];
s[0] = Name;
s[1] = Mission_text;
return s;
}
/// <summary>
/// 脱机
/// </summary>
public void Offline()
{
IsCon = false;
//Mark = "";
//RFID = "";
//Place = "";
//StateID = -1;
//StateText = "";
//MissionStatus = Mission_Status.None;
//MissionQueue = "";
}
}
public class ChargeStatus
{
/// <summary>
/// 1号充电桩的AGV名称
/// </summary>
public string charge1 = "";
/// <summary>
/// 1号充电桩的AGV名称
/// </summary>
public string charge2 = "";
/// <summary>
/// 充电等待时间(s)
/// </summary>
public int chargeWait = 0;
/// <summary>
/// 充电最大电量,小于该值等待指定时间去充电
/// </summary>
public int chargeMax;
/// <summary>
/// 充电最小电量,小于该值直接去充电
/// </summary>
public int chargeMin;
/// <summary>
/// 两车充电间隔时间(ms)
/// </summary>
public long chargeInterval;
private bool _autoCharge;
public bool AutoCharge
{
set
{
_autoCharge = value;
Common.appConfig.AppSettings.Settings["AutoCharge"].Value = value.ToString();
Common.appConfig.Save();
}
get
{
return _autoCharge;
}
}
public ChargeStatus()
{
_autoCharge = Convert.ToBoolean(Common.appConfig.AppSettings.Settings["AutoCharge"].Value);
chargeWait = Convert.ToInt32(Common.appConfig.AppSettings.Settings["ChargeWait"].Value);
string s = Common.appConfig.AppSettings.Settings["ChargeThreshold"].Value;
string[] arr = s.Split(',');
chargeMin = Convert.ToInt32(arr[0]);
chargeMax = Convert.ToInt32(arr[1]);
chargeInterval = 0;
}
}
}