TSAVStatus.cs
9.7 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
using PUSICANLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TSA_V.Common;
namespace TSA_V.DeviceLibrary
{
public enum WaitTypeEnum
{/// <summary>
/// 等待结果,1=节点目标位置,2=节点原点返回,,3=时间, 4=烙铁加温,5=等待XY轴运动结束,6=IO信号
/// </summary>
None = 0,
NodeMove_1 = 1,
NodeHome_2 = 2,
Time_3 = 3,
Temp_4 = 4,
XYMoveEnd_5 = 5,
IOSingle_6 = 6,
WaitCode_7=7,
}
public class WaitResultInfo
{
private WaitResultInfo()
{
IsEnd = false;
}
public static WaitResultInfo WaitIO(string ioType, IO_VALUE ioValue)
{
WaitResultInfo wait = new WaitResultInfo();
wait.CanWhileMoveCount = 0;
wait.WaitType = WaitTypeEnum.IOSingle_6;
wait.IoType = ioType;
wait.IoValue = ioValue;
return wait;
}
public static WaitResultInfo WaitNode(NodeInfo node, int targetPosition)
{
WaitResultInfo wait = new WaitResultInfo();
wait.CanWhileMoveCount = 0;
wait.WaitType = WaitTypeEnum.NodeMove_1;
wait.Node = node;
wait.IsHomeMove = false;
wait.TargetPosition = targetPosition;
return wait;
}
public static WaitResultInfo WaitNode(NodeInfo node, bool isHomeMove)
{
WaitResultInfo wait = new WaitResultInfo();
wait.CanWhileMoveCount = 0;
wait.WaitType = WaitTypeEnum.NodeHome_2;
wait.Node = node;
wait.IsHomeMove = true;
return wait;
}
public static WaitResultInfo WaitTime(int MScends)
{
WaitResultInfo wait = new WaitResultInfo();
wait.CanWhileMoveCount = 0;
wait.WaitType = WaitTypeEnum.Time_3;
wait.TimeMSeconds = MScends;
return wait;
}
public static WaitResultInfo WaitSoldering(int temp, int tempMin, int tempMax)
{
WaitResultInfo wait = new WaitResultInfo();
wait.CanWhileMoveCount = 0;
wait.WaitType = WaitTypeEnum.Temp_4;
wait.Temperature = temp;
wait.TemperatureMax = tempMax;
wait.TemperatureMin = tempMin;
return wait;
}
public static WaitResultInfo WaitCodeOk()
{
WaitResultInfo wait = new WaitResultInfo();
wait.CanWhileMoveCount = 0;
wait.WaitType = WaitTypeEnum.WaitCode_7;
return wait;
}
public string ToStr()
{
if (WaitType.Equals(WaitTypeEnum.NodeMove_1))
{
return "[" + Node.NodeName + "]目标位置[" + TargetPosition + "]";
}
else if (WaitType.Equals(WaitTypeEnum.NodeHome_2))
{
return "[" + Node.NodeName + "]原点返回";
}
else if (WaitType.Equals(WaitTypeEnum.IOSingle_6))
{
ConfigIO io = IOManager.getWaitIO(IoType);
return "IO等待[" + io.DisplayStr + "]=[" + IoValue + "]";
}
else if (WaitType.Equals(WaitTypeEnum.Time_3))
{
return "时间[" + TimeMSeconds + "]毫秒";
}
else if (WaitType.Equals(WaitTypeEnum.XYMoveEnd_5))
{
return "XY轴目标 [" + AxisValue + "] ";
//return "XY轴目标[" + MoveAxis.PortName + "][" + AxisValue + "] ";
}
else if (WaitType.Equals(WaitTypeEnum.Temp_4))
{
return "烙铁温度[" + Temperature + "] ";
}
else if (WaitType.Equals(WaitTypeEnum.WaitCode_7))
{
return "输入条码 ";
}
else
{
return "Wait位置类型:WaitType=【" + WaitType + "】";
}
}
public bool IsEnd { get; set; }
//public DACBean MoveAxis { get; set; }
public double AxisValue { get; set; }
/// <summary>
/// 当未结束时可以重复运动的次数
/// </summary>
public int CanWhileMoveCount { get; set; }
/// <summary>
/// 等待结果,1=节点目标位置,2=节点原点返回,,3=时间, 4=烙铁加温,5=等待XY轴运动结束,6=IO信号
/// </summary>
public WaitTypeEnum WaitType { get; set; }
/// <summary>
/// 轴运动时表示轴信息
/// </summary>
public NodeInfo Node { get; set; }
/// <summary>
/// IO类型
/// </summary>
public String IoType { get; set; }
/// <summary>
/// IO值
/// </summary>
public IO_VALUE IoValue { get; set; }
/// <summary>
/// 等待的毫秒
/// </summary>
public int TimeMSeconds { get; set; }
/// <summary>
/// 是否是原点返回
/// </summary>
public bool IsHomeMove = false;
/// <summary>
/// 电机目标位置
/// </summary>
public int TargetPosition { get; set; }
/// <summary>
/// 电机目标速度
/// </summary>
public int TargetSpeed { get; set; }
/// <summary>
/// 等待的温度温度
/// </summary>
public int Temperature { get; set; }
/// <summary>
/// 温度下限
/// </summary>
public int TemperatureMin { get; set; }
/// <summary>
/// 温度上限
/// </summary>
public int TemperatureMax { get; set; }
public static bool GetWaitResult(List<WaitResultInfo> waitList, TimeSpan span,bool oneOkCanEnd, out string waitMsg)
{
waitMsg = "";
try
{
if (waitList.Count <= 0)
{
return true;
}
bool isOk = true;
if (oneOkCanEnd)
{
isOk = false;
}
foreach (WaitResultInfo wait in waitList)
{
if (wait.IsEnd)
{
continue;
}
waitMsg = wait.ToStr();
if (wait.WaitType.Equals(WaitTypeEnum.NodeMove_1))
{
string msg = "";
wait.IsEnd = PUSICANControl.MoveIsEnd(wait.Node.NodeId, wait.TargetPosition,out msg);
waitMsg = waitMsg + msg;
}
else if (wait.WaitType.Equals(WaitTypeEnum.NodeHome_2))
{
wait.IsEnd = PUSICANControl.IsHomeEnd(wait.Node.NodeId);
}
else if (wait.WaitType.Equals(WaitTypeEnum.IOSingle_6))
{
wait.IsEnd = IOManager.IOValue(wait.IoType).Equals(wait.IoValue);
}
else if (wait.WaitType.Equals(WaitTypeEnum.Time_3))
{
wait.IsEnd =( span.TotalMilliseconds >= wait.TimeMSeconds);
}
else if (wait.WaitType.Equals(WaitTypeEnum.Temp_4))
{
// wait.IsEnd = SolderingManager.IsRightTemp(wait.Temperature, wait.TemperatureMin, wait.TemperatureMax);
}
else if (wait.WaitType.Equals(WaitTypeEnum.XYMoveEnd_5))
{
//wait.IsEnd = wait.MoveAxis.LastVoltage.Equals(wait.AxisValue);
wait.IsEnd = true;
}
else if (wait.WaitType.Equals(WaitTypeEnum.WaitCode_7))
{
return MesUtil.CodeISOk;
}
if (!wait.IsEnd)
{
if (oneOkCanEnd.Equals(false))
{
isOk = false;
break;
}
}else
{
if (oneOkCanEnd)
{
isOk = true;
break;
}
}
}
return isOk;
}
catch (Exception ex)
{
LogUtil.error("出错:" + ex.ToString());
return false;
}
}
}
public enum TSAVStatus
{
/// <summary>
/// 等待启动
/// </summary>
Wait=0,
/// <summary>
/// 重置中
/// </summary>
Reset=1,
/// <summary>
/// 运行中
/// </summary>
Runing=2,
}
/// <summary>
/// 重置的步骤
/// </summary>
public enum ResetStep
{
/// <summary>
/// 打开CAN协议
/// </summary>
OpenCan_0=0,
/// <summary>
/// 添加节点
/// </summary>
AddNode_1=1,
/// <summary>
/// 等待XY节点上线,并设置默认的参数
/// </summary>
XYNodeOnline_2 = 2,
/// <summary>
/// 等待XY轴回原点
/// </summary>
XYHomeMove_3=3,
/// <summary>
/// 等待所有旋转轴在线,并初始化默认参数
/// </summary>
RNodeOnline_4 = 4,
/// <summary>
/// 所有旋转轴回原点
/// </summary>
NodeGoHome_5=5,
/// <summary>
/// 所有转盘转到待机点
/// </summary>
NodeGoDefaultPosition_6=6,
}
}