WorkInfo.cs
12.6 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
using PUSICANLibrary;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using TSA_V.Common;
using TSA_V.LoadCSVLibrary;
namespace TSA_V.DeviceLibrary
{
public class WorkInfo
{
public static bool IsCycleDebug = false;
public static int LastDBId = 0;
/// <summary>
/// 是否在工作中,在插件中,会接受信号移动位置
/// </summary>
public bool IsWorking = false;
public BoardInfo currBoard = null;
public int currIndex = -1;
public SMTPointInfo currPoint = null;
public TSAVPosition currPosition = null;
/// <summary>
/// 工作类型0=未在工作界面,1=插件,2=焊接,3=检测,默认不设置是1
/// </summary>
public int WorkType = 0;
public bool IsWaitMove = false;
public List<WaitResultInfo> waitList = new List<WaitResultInfo>();
public DateTime endWorkTime = DateTime.Now;
public DateTime LastSetpTime = DateTime.Now;
public uint PreNodeId = 0;
public List<SMTPointInfo> needWorkSmtList = new List<SMTPointInfo>();
//开始工作后共工作了几块电路板
public int BoardCount = 0;
public DateTime beginWorkTime = DateTime.Now;
public bool IsShowAOI = false;
private List<ComponetInfo> useComponets = new List<ComponetInfo>();
public void StartWork(BoardInfo boardInfo)
{
//StatusClient.instance.SendNew(Color.Green, "扫码成功:" + BoardManager.CurrBoard.boardCode);
beginWorkTime = DateTime.Now;
//开始工作
LogUtil.info("开始程序【" + boardInfo.boardName + "】的插件");
currBoard = boardInfo;
needWorkSmtList = currBoard.GetSmtList();
currIndex = -1;
IsShowAOI = false;
currPoint = null;
IsWorking = true;
endWorkTime = DateTime.Now;
IsWaitMove = false;
BoardCount = 0;
}
public List<SMTPointInfo> GetSmtList()
{
if (currBoard == null)
{
return new List<SMTPointInfo>();
}
//if (WorkType.Equals(1))
//{
// return currBoard.smtList;
//}
//else if (WorkType.Equals(2))
//{
// return needSoldSmtList;
//}
//else if (WorkType.Equals(3))
//{
// return needCheckSmtList;
//}
//return new List<SMTPointInfo>();
return needWorkSmtList;
}
public void StopWork()
{
try
{
if (IsWorking)
{
EndWait();
if (currIndex > 0 && currBoard != null)
{
//如果是下一个并且当前是最后一个,其实是切换了新程序,需要减去刚刚的数量
CSVBomManager.DelUseCount(currBoard, useComponets);
useComponets = new List<ComponetInfo>();
}
DeviceStatus deviceStatus = MesUtil.GetCurrStatus();
if (MesUtil.CodeISOk)
{
MesUtil.SendStatus(deviceStatus);
}
deviceStatus.workInfo.ID = LastDBId;
DB.db.AddHistory(deviceStatus.workInfo, out int id);
if (LastDBId < 0)
{
LastDBId = id;
LogUtil.info("保存LastDBId=" + LastDBId);
}
if (currBoard != null)
{
LogUtil.info("停止程序【" + currBoard.boardName + "】工作");
}
//把上次的旋转轴转回待机点
if (this.WorkType.Equals(1) && PreNodeId > 0)
{
PUSICANControl.StopMove(PreNodeId);
Thread.Sleep(10);
//上一个节点返回原点
PUSICANControl.AbsMove(PreNodeId, TSAVBean.RotateNode_DefaultPosition);
Thread.Sleep(10);
}
//Thread.Sleep(100);
endWorkTime = DateTime.Now;
IsShowAOI = false;
IsWorking = false;
IsWaitMove = false;
}
}catch(Exception ex)
{
LogUtil.error("StopWork出错:"+ex.ToString());
}
}
public void EndWait()
{
endWorkTime = DateTime.Now;
IsWaitMove = false;
waitList = new List<WaitResultInfo>();
}
public bool MoveToNextPoint(bool isNext)
{
return MoveToNextPoint(isNext, false);
}
public bool MoveToNextPoint(bool isNext, bool isReset)
{
waitList = new List<WaitResultInfo>();
IsWaitMove = true;
LastSetpTime = DateTime.Now;
if (isNext)
{
currIndex++;
}
else
{
currIndex--;
}
if (currIndex > GetSmtList().Count)
{
if (isReset)
{
if (IsCycleDebug)
{
LogUtil.info("程序【" + currBoard.boardName + "】已到达最后一个焊点,重新开始工作");
StartWork(BoardManager.CurrBoard);
return true;
}
else
{
LogUtil.info("程序【" + currBoard.boardName + "】已到达最后一个焊点,停止工作");
StopWork();
return true;
}
}
else
{
return false;
}
}
if (currIndex < 0)
{
currIndex = GetSmtList().Count - 1;
}
if (currIndex == GetSmtList().Count)
{
if (WorkType.Equals(1))
{
LogUtil.info(" 程序【" + currBoard.boardName + "】所有位置已走完 ");
if (PreNodeId > 0)
{
//上一个节点返回原点
PUSICANControl.AbsMove(PreNodeId, TSAVBean.RotateNode_DefaultPosition);
}
//if (TSAVBean.IsNeedSoldering)
//{
// LogUtil.info(" 程序【" + currBoard.boardName + "】需要焊接,打开烙铁灯 ");
// LedManager.LedOFFALL();
// LedManager.OpenSoldering();
// waitList.Add(WaitResultInfo.WaitTime(5000));
//}
}
}
else
{
currPoint = GetSmtList()[currIndex];
//LogUtil.info(" 程序【" + currBoard.boardName + "】插件【" + currPoint.pointName + "】");
ComponetInfo com = CSVBomManager.GetCom(currBoard.bomName, currPoint);
TSAVPosition position = null;
if (com != null)
{
position = CSVPositionReader<TSAVPosition>.GetPositonByNum(com.PositionNum);
useComponets.Add(com);
}
else
{
position = CSVPositionReader<TSAVPosition>.GetPositonByNum(currPoint.PositionNum);
}
if (position == null)
{
LogUtil.info(" 程序【" + currBoard.boardName + "】插件【" + currPoint.PN + "】未找到对应的元器件");
}
else
{
this.currPosition = position;
XYMove();
//插件机工作
if (WorkType.Equals(1))
{
LogUtil.info(" 程序【" + currBoard.boardName + "】插件【" + currPoint.PN + "】 库位【" + position.PositionName + "】X轴【" + currPoint.NodePositionX + "】,Y轴【" + currPoint.NodePositionY + "】");
MoveToBag(position);
//如果是下一个并且当前是最后一个,其实是切换了新程序,需要减去刚刚的数量
if (isNext && (currIndex == 0))
{
BoardCount++;
CSVBomManager.DelUseCount(currBoard, useComponets);
useComponets = new List<ComponetInfo>();
}
}
//焊接工作
else if (WorkType.Equals(2))
{
if (isNext && (currIndex == 0))
{
BoardCount++;
}
int temp = currPoint.WeldTemp;
LogUtil.info(" 程序【" + currBoard.boardName + "】焊接【" + currPoint.PN + "】,温度【" + temp + "】");
}
else if (WorkType.Equals(3))
{
if (isNext && (currIndex == 0))
{
BoardCount++;
}
int temp = currPoint.WeldTemp;
LogUtil.info(" 程序【" + currBoard.boardName + "】检测【" + currPoint.PN + "】");
}
}
}
return true;
}
public void XYMove()
{
//xy轴运动到固定点
if (TSAVBean.IsValidPosition(currPoint.NodePositionX, currPoint.NodePositionY))
{
//LogUtil.info(" 程序【" + currBoard.boardName + "】插件【" + currPoint.pointName + "】,X轴【" + currPoint.NodePositionX + "】,Y轴【" + currPoint.NodePositionY + "】");
TSAVBean.ShowPoint(currPoint.NodePositionX, currPoint.NodePositionY,currPoint.PointType,currPoint.PointSizeX,currPoint.PointSizeY,currPoint.PenWidth,currPoint.ShowText);
waitList.Add(WaitResultInfo.WaitTime(1000));
}
else
{
LogUtil.info(" 程序【" + currBoard.boardName + "】插件【" + currPoint.PN + "】,X轴【" + currPoint.NodePositionX + "】,Y轴【" + currPoint.NodePositionY + "】坐标无效,不移动光标");
}
}
public void MoveToBag(TSAVPosition position)
{
//LedManager.LedOFFALL();
if (position.PositionType.Equals(1))
{
//转盘转动
NodeInfo moveNode = position.GetNode(TSAVBean.RotateMap);
if (moveNode != null)
{
if (PreNodeId > 0 && !(moveNode.NodeId.Equals(PreNodeId)))
{
//上一个节点返回原点
PUSICANControl.AbsMove(PreNodeId, TSAVBean.RotateNode_DefaultPosition);
Thread.Sleep(50);
}
PUSICANControl.AbsMove(moveNode.NodeId, position.RotatePosition);
waitList.Add(WaitResultInfo.WaitNode(moveNode, position.RotatePosition));
PreNodeId = moveNode.NodeId;
}
else
{
LogUtil.error("positionNum=" + position.PositionNum + ",未找到对应的运动轴!");
}
}
else
{
if (PreNodeId > 0)
{
PUSICANControl.AbsMove(PreNodeId, TSAVBean.RotateNode_DefaultPosition);
}
PreNodeId = 0;
LEDModule module = LedManager.GetLEDModule(position.DeviceIP);
LedManager.LightOn(position.DeviceIP, position.getLedList());
waitList.Add(WaitResultInfo.WaitTime(500));
}
}
public bool IsLastP()
{
if (IsWorking)
{
if (currIndex >= GetSmtList().Count)
{
return true;
}
}
return false;
}
}
}