FrmBatchMove.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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
using DeviceLibrary;
using log4net;
using OnlineStore.Common;
using OnlineStore.DeviceLibrary;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using UserFromControl;
namespace OnlineStore.XLRStore
{
internal partial class FrmBatchMove : FrmBase
{
private bool IsLoad = false;
private BatchMoveBean moveBean;
internal FrmBatchMove(BatchMoveBean moveEquip)
{
this.moveBean = moveEquip;
Control.CheckForIllegalCrossThreadCalls = false;
InitializeComponent();
}
private bool IsInCheck = false;
private void timer1_Tick(object sender, EventArgs e)
{
try
{
if (!this.Visible)
{
return;
}
lblWarnMsg.Text = moveBean.WarnMsg;
lblCurrInfo.Text = moveBean.GetMoveStr();
string text = "AGV " + moveBean.Config.AgvName + " :" + AgvClient.GetAction(moveBean.Config.AgvName);
if (StoreManager.XLRStore.inputEquip.runStatus > RunStatus.Wait)
{
btnReset.Enabled = true;
}
else
{
btnReset.Enabled = true;
}
text += "\r\n" + moveBean.MoveInfo.MoveType + "_" + moveBean.MoveInfo.MoveStep;
text += "\r\n" + moveBean.CurrShelf?.ToStr();
lblAgvInfo.Text = text;
}
catch (Exception ex)
{
LogUtil.error(moveBean.Name + "界面定时器出错:", ex);
}
}
private void FrmTest_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
if (this.timer1.Enabled)
{
this.timer1.Enabled = false;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.StackTrace, "Exception(异常)", MessageBoxButtons.OK, MessageBoxIcon.Error);
LogUtil.error("", ex);
}
}
private void FrmStoreIOStatus_Load(object sender, EventArgs e)
{
this.chbAutoOut.Checked = moveBean.ShelfAutoOut;
axisMoveControl1.LoadData(StoreManager.XLRStore.inputEquip, new AxisBean[] { moveBean.BatchAxis });
batchAxisP1.SetMoveData(moveBean.BatchAxis, StoreManager.XLRStore.inputEquip.Config.BatchAxis_P1Speed, moveBean.Config.BatchAxisP1);
batchAxisP2.SetMoveData(moveBean.BatchAxis, StoreManager.XLRStore.inputEquip.Config.BatchAxis_P2Speed, moveBean.Config.BatchAxisP2);
batchAxisP4.SetMoveData(moveBean.BatchAxis, StoreManager.XLRStore.inputEquip.Config.BatchAxis_P4Speed, moveBean.Config.BatchAxisP4, true);
lblWarnMsg.Text = moveBean.WarnMsg;
lblCurrInfo.Text = moveBean.GetMoveStr();
lblAgvInfo.Text = "AGV " + moveBean.Config.AgvName + " :" + AgvClient.GetAction(moveBean.Config.AgvName);
IsLoad = true;
}
private void FrmIOStatus_Shown(object sender, EventArgs e)
{
timer1.Start();
}
private void btnStart_Click(object sender, EventArgs e)
{
moveBean.Reset(true);
LogUtil.info(moveBean.Name + "点击:" + btnReset.Text);
}
private void btnSave_Click(object sender, EventArgs e)
{
int p1 = batchAxisP1.PointValue;
int p2 = batchAxisP2.PointValue;
int p4 = batchAxisP4.PointValue;
if (p4 < 0)
{
MessageBox.Show("扫码时上升高度P4不能小于0 ,请重新设置P4点位置", "保存失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
moveBean.Config.BatchAxisP1 = p1;
moveBean.Config.BatchAxisP2 = p2;
moveBean.Config.BatchAxisP4 = p4;
if (moveBean.ShelfType.Equals(1))
{
StoreManager.XLRStore.inputEquip.Config.BatchAxisP1_A = p1;
StoreManager.XLRStore.inputEquip.Config.BatchAxisP2_A = p2;
StoreManager.XLRStore.inputEquip.Config.BatchAxisP4_A = p4;
}
else
{
StoreManager.XLRStore.inputEquip.Config.BatchAxisP1_B = p1;
StoreManager.XLRStore.inputEquip.Config.BatchAxisP2_B = p2;
StoreManager.XLRStore.inputEquip.Config.BatchAxisP4_B = p4;
}
StoreManager.SaveInputEquipConfig(StoreManager.XLRStore.inputEquip.Config);
MessageBox.Show("保存成功");
}
private int TargetP2;
private bool StartTest = false;
private void btnStartTest_Click(object sender, EventArgs e)
{
ConfigMoveAxis moveAxis = moveBean.BatchAxis.Config;
bool isServoOn = AxisManager.instance.IsServeoOn(moveAxis.DeviceName, moveAxis.GetAxisValue());
if (!isServoOn)
{
MessageBox.Show(moveAxis.Explain + " 未打开,请先打开伺服 ", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
bool isStop = AxisManager.instance.GetBusyStatus(moveAxis.DeviceName, moveAxis.GetAxisValue()).Equals(0);
if (isServoOn && isStop)
{
//判断提升轴是否停止且到位
TargetP2 = moveBean.Config.BatchAxisP2;
LogUtil.info(moveBean.Name + "点击:" + btnStartTest.Text + ",目标位置:" + moveBean.Config.BatchAxisP2);
moveBean.BatchAxisToP2(true, false, true);
lblTestMsg.Text = "开始入料运动,目标位置[" + TargetP2 + "] ,开始位置[" + moveBean.StartMovePosition + "],";
StartTest = true;
}
else
{
MessageBox.Show(moveAxis.Explain + " 忙碌中,无法开始运动 ", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
private void btnTestStop_Click(object sender, EventArgs e)
{
LogUtil.info(moveBean.Name + "点击:" + btnTestStop.Text);
moveBean.BatchAxis.AxisStopCheckMove();
moveBean.BatchAxis.SuddenStop();
}
//private void BatchTimerPro()
//{
// if (moveBean.BatchAxis.IsBatchMove())
// {
// btnStartTest.Enabled = false;
// if (moveBean.LastMoveIsTest)
// {
// ConfigMoveAxis moveAxis = moveBean.BatchAxis.Config;
// bool countError = false;
// bool isStop = false;
// bool result = AxisManager.instance.AbsMoveIsEnd(moveAxis.DeviceName, moveAxis.GetAxisValue(), TargetP2, moveAxis.CanErrorCountMax, out countError);
// if (result)
// {
// isStop = true;
// LogUtil.info(moveBean.Name + "提升轴上料功能测试,发现提升轴已到达目标位置【" + TargetP2 + "】,停止上料测试 ");
// }
// else
// {
// bool axisMoveIsEnd = HuichuanLibrary.HCBoardManager.MoveIsEnd(moveBean.BatchAxis.Config.GetAxisValue());
// if (axisMoveIsEnd)
// {
// isStop = true;
// LogUtil.info(moveBean.Name + "提升轴上料功能测试,发现提升轴已停止运动,停止上料测试");
// }
// }
// if (isStop)
// {
// StartTest = false;
// moveBean.BatchAxis.AxisStopCheckMove();
// btnStartTest.Enabled = true;
// btnTestStop.Enabled = false;
// int height = moveBean.GetHeight();
// lblTestMsg.Text = "目标位置[" + TargetP2 + "] ,开始位置[" + moveBean.StartMovePosition + "],停止位置[" + moveBean.EndMovePosition + "],高度[" + height + "]mm";
// }
// else
// {
// btnTestStop.Enabled = true;
// }
// }
// else
// {
// btnTestStop.Enabled = false;
// }
// }
// else
// {
// if (StartTest)
// {
// StartTest = false;
// int height = moveBean.GetHeight();
// lblTestMsg.Text = "目标位置[" + TargetP2 + "] ,开始位置[" + moveBean.StartMovePosition + "],停止位置[" + moveBean.EndMovePosition + "],高度[" + height + "]mm";
// }
// btnStartTest.Enabled = true;
// btnTestStop.Enabled = false;
// }
//}
private void chbAutoOut_CheckedChanged(object sender, EventArgs e)
{
if (!IsLoad)
{
return;
}
moveBean.ShelfAutoOut = chbAutoOut.Checked;
LogUtil.info(moveBean.Name + "用户切换料架入库完成自动出库: " + moveBean.ShelfAutoOut);
}
private void btnShelfOut_Click(object sender, EventArgs e)
{
if (!IsLoad)
{
return;
}
moveBean.ShelfNeedLeave = true;
LogUtil.info(moveBean.Name + "用户点击:" + btnShelfOut.Text);
}
private void btnScanTest_Click(object sender, EventArgs e)
{
if (!IsLoad)
{
return;
}
string camera = moveBean.Config.CameraName;
List<string> LastCodeList = CodeManager.CameraScan(camera, moveBean.Name.Trim() + "测试");
string msg = CodeManager.ProcessCode(LastCodeList);
LogUtil.info(moveBean.Name + "[" + camera + "]扫码测试结果:\r\n" + msg);
MessageBox.Show(moveBean.Name + "[" + camera + "]扫码测试结果:" + msg);
}
private void Shelf_StopUp_A_Click(object sender, EventArgs e)
{
LogUtil.info(moveBean.Name + "点击:" + Shelf_StopUp_A.Text);
moveBean.StopUp();
}
private void Shelf_StopDown_A_Click(object sender, EventArgs e)
{
LogUtil.info(moveBean.Name + "点击:" + Shelf_StopDown_A.Text);
moveBean.StopDown();
}
private void LineStart_A_Click(object sender, EventArgs e)
{
LogUtil.info(moveBean.Name + "点击:" + LineStart_A.Text);
moveBean.LineRun();
}
private void LineBack_A_Click(object sender, EventArgs e)
{
LogUtil.info(moveBean.Name + "点击:" + LineBack_A.Text);
moveBean.LineBack();
}
private void LineStop_A_Click(object sender, EventArgs e)
{
LogUtil.info(moveBean.Name + "点击:" + LineStop_A.Text);
moveBean.LineStop();
}
private void btnResetShelf_Click(object sender, EventArgs e)
{
LogUtil.info(moveBean.Name + "点击:" + btnResetShelf.Text);
moveBean.Reset(true,true);
}
private void chbMoveStop_CheckedChanged(object sender, EventArgs e)
{
if (!IsLoad)
{
return;
}
moveBean.MoveStop = chbMoveStop.Checked;
LogUtil.info(moveBean.Name + "用户切换是否暂停: " + moveBean.MoveStop);
}
public void ShowConfig(bool state)
{
axisMoveControl1.Visible = state;
groupBox1.Visible = state;
groupBox2.Visible = state;
groupBox3.Visible = state;
chbAutoOut.Visible = state;
}
private void button1_Click(object sender, EventArgs e)
{
bool rtn = moveBean.CameraCheck("手动", out string res);
lblCameraRes.Invoke(new Action(() =>
{
lblCameraRes.Text = $"{(rtn ? "检测有料盘" : "检测无料盘")}\r\n{res}";
}));
}
private void button2_Click(object sender, EventArgs e)
{
ReelCheckCamera.ClearProject();
}
}
}