Node.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
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
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Windows.Forms;
using DeviceLibrary.manager;
namespace DeviceLibrary
{
public class Node
{
/// <summary>
/// 节点ID
/// </summary>
public int Id { get; set; }
/// <summary>
/// 节点名称
/// </summary>
public string Name { get; set; }
public NodeType Type { get; set; }
/// <summary>
/// 所属区域
/// </summary>
public Area Area { get; set; }
/// <summary>
/// 节点IP
/// </summary>
public string IP { get; set; }
/// <summary>
/// 在线状态
/// </summary>
public bool Online { get; set; }
/// <summary>
/// 是否可调用
/// </summary>
public bool IsUse
{
set
{
if (!isuse.Equals(value))
{
isuse = value;
XmlConfigOpManager.SetNodeIsUse(this);
}
}
get { return isuse; }
}
private bool isuse;
/// <summary>
/// 节点状态
/// </summary>
public NodeStatus nodeStatus { get; set; }
protected string rfid = "00";
/// <summary>
/// RFID
/// </summary>
public string RFID
{
set
{
if (value.Length < 2)
rfid = value.PadLeft(2, '0');
else
rfid = value;
}
get
{
return rfid;
}
}
public ClientLevel ClientLevel { get; set; } = ClientLevel.Low;
/// <summary>
/// 别名
/// </summary>
public string AliceName { get; set; }
/// <summary>
/// 警告信息
/// </summary>
public string WarnMsg { get; set; } = "";
public Node() { }
public Node(int id, string name, string ip, NodeType nodeType, Area area, bool isUse = false)
{
Id = id;
Name = name;
IP = ip;
Online = false;
IsUse = isUse;
Type = nodeType;
Area = area;
nodeStatus = NodeStatus.None;
}
public Node(string name)
{
Name = name;
}
/// <summary>
/// 状态比较
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public bool StateEquals(NodeStatus obj)
{
return nodeStatus.Equals(obj);
}
/// <summary>
/// 获取当前状态
/// </summary>
/// <returns></returns>
public NodeStatus GetState()
{
return nodeStatus;
}
/// <summary>
/// 更新节点状态
/// </summary>
/// <param name="status"></param>
public void UpdateNodeStatus(NodeStatus status)
{
nodeStatus = status;
}
/// <summary>
/// 客户端节点
/// </summary>
/// <param name="name"></param>
/// <param name="ip"></param>
/// <param name="isUse"></param>
public Node(int id, string name, string ip, string aliceName, NodeType nodeType, Area area, bool isUse)
{
Id = id;
Name = name;
IP = ip;
Type = nodeType;
Area = area;
IsUse = isUse;
AliceName = aliceName;
Online = false;
}
/// <summary>
/// 客户端节点
/// </summary>
/// <param name="name"></param>
/// <param name="rfid"></param>
/// <param name="action"></param>
/// <param name="level"></param>
public Node(string name, string rfid = "", NodeStatus status = NodeStatus.None)
{
Name = name;
RFID = rfid;
nodeStatus = status;
}
/// <summary>
/// 节点状态的文本形式
/// </summary>
/// <returns></returns>
public string StatetText()
{
string s = string.Format("[Name={0}, NodeStatus={1}, RFID={2},ClientLevel ={3}]", Name, nodeStatus.ToString(), RFID, ClientLevel.ToString());
return s;
}
public string[] ToRow()
{
//节点,IP,动作,RFID,AGV名称,在线,调用,清除AGV
List<string> vs = new List<string>();
vs.Add(AliceName);
vs.Add(IP);
vs.Add(nodeStatus.ToString());
vs.Add(ClientLevel.ToString());
vs.Add(RFID);
vs.Add(Online ? "在线" : "离线");
vs.Add(IsUse ? "是" : "否");
return vs.ToArray();
}
/// <summary>
/// 脱机
/// </summary>
public void Offline()
{
RFID = "00";
nodeStatus = NodeStatus.None;
Online = false;
}
public Node ToCopy()
{
PropertyInfo[] infos = this.GetType().GetProperties();
Node node = new Node();
PropertyInfo[] infos2 = node.GetType().GetProperties();
for (int i = 0; i < infos2.Length; i++)
{
infos2[i].SetValue(node, Convert.ChangeType(infos[i].GetValue(this), infos[i].PropertyType));
}
return node;
}
public override string ToString()
{
return $" {AliceName}[{Area}] ";
}
}
/// <summary>
/// 节点状态
/// </summary>
public enum NodeStatus : byte
{
/// <summary>
/// 没有动作
/// </summary>
None = 0,
/// <summary>
/// 需要7寸D料架
/// </summary>
NeedD = 1,
/// <summary>
/// 需要大尺寸C料架
/// </summary>
NeedC = 2,
/// <summary>
/// 需要进入料架
/// </summary>
NeedEnter = 3,
/// <summary>
/// 需要出去料架
/// </summary>
NeedLeave = 4,
/// <summary>
/// 需要进入离开料架
/// </summary>
NeedEnterLeave = 5,
/// <summary>
/// 准备进入料架,服务器发送
/// </summary>
ReadyEnter = 6,
/// <summary>
/// 可以进入料架
/// </summary>
MayEnter = 7,
/// <summary>
/// 完成进入料架
/// </summary>
FinishEnter = 8,
/// <summary>
/// 准备离开料架,服务器发送
/// </summary>
ReadyLeave = 9,
/// <summary>
/// 可以出去料架
/// </summary>
MayLeave = 10,
/// <summary>
/// 完成出去料架
/// </summary>
FinishLeave = 11,
}
/// <summary>
/// 客户端的优先级
/// </summary>
public enum ClientLevel : byte
{
/// <summary>
/// 低
/// </summary>
Low = 0,
/// <summary>
/// 中等
/// </summary>
Middle = 1,
/// <summary>
/// 高
/// </summary>
High = 2
}
public enum Area
{
D,
C,
Air_C,
}
public enum NodeType
{
AutoCharge,
Standby,
Node
}
}