FrmBoxEquip.cs
15.1 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
using OnlineStore.Common;
using OnlineStore.DeviceLibrary;
using OnlineStore.LoadCSVLibrary;
using OnlineStore.XLRStore.inputForm.uc;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using UserFromControl;
using static System.Windows.Forms.AxHost;
namespace OnlineStore.XLRStore
{
internal partial class FrmBoxEquip : FrmBase
{
private bool IsLoad = false;
private BoxEquip boxBean;
internal FrmBoxEquip(BoxEquip moveEquip)
{
this.boxBean = moveEquip;
Control.CheckForIllegalCrossThreadCalls = false;
InitializeComponent();
}
private void FrmStoreIOStatus_Load(object sender, EventArgs e)
{
chbMoveStop.Checked = boxBean.MoveStop;
lblStoreStatus.Text = DeviceBase.GetRunStr(boxBean.runStatus);
lblThisSta.Text = boxBean.WarnMsg;
lblName.Text = boxBean.Name;
this.Text = boxBean.Name;
chbDebug.Checked = boxBean.IsDebug;
initConfigWindow(boxBean);
IsLoad = true;
}
protected Dictionary<string, IOTextControl> DIControlList = new Dictionary<string, IOTextControl>();
protected Dictionary<string, IOTextControl> DOControlList = new Dictionary<string, IOTextControl>();
protected void ReadIOList()
{
foreach (string key in DIControlList.Keys)
{
IOTextControl control = DIControlList[key];
int iov = (int)IOManager.IOValue(key, boxBean.DeviceID);
if (iov != control.IOValue)
{
control.IOValue = iov;
control.ShowData();
}
}
foreach (string key in this.DOControlList.Keys)
{
IOTextControl control = DOControlList[key];
int iov = (int)IOManager.DOValue(key, boxBean.DeviceID);
if (iov != control.IOValue)
{
control.IOValue = iov;
control.ShowData();
}
}
}
protected void StartDebug()
{
if (boxBean.runStatus.Equals(RunStatus.Wait))
{
bool result = boxBean.StartRun();
if (result)
{
FormStatus(true);
}
else
{
MessageBox.Show(boxBean.WarnMsg, "启动失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show(boxBean.Name + "已启动,不能重复启动", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private void StopRun()
{
try
{
if (boxBean.runStatus <= RunStatus.Wait)
{
MessageBox.Show(boxBean.Name + "请先启动设备", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
LogUtil.info(boxBean.Name + "点击:停止运行");
boxBean.StopRun();
FormStatus(false);
}
}
catch (Exception ex)
{
LogUtil.error("出错:", ex);
}
}
private void Reset()
{
if (boxBean.runStatus >= (RunStatus.HomeMoving))
{
LogUtil.info(boxBean.Name + "点击 :复位");
boxBean.Reset();
}
else
{
MessageBox.Show(boxBean.Name + "请先启动设备", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private void timer1_Tick(object sender, EventArgs e)
{
try
{
if (!this.Visible)
{
return;
}
//ReadBtnDO();
// clampJawControl1.UpdateSta();
if(boxBean.IsDeviceLEDOn())
{
btnDeviceLed.Text = "关闭照明";
}
else
{
btnDeviceLed.Text = "开启照明";
}
lblName.BackColor = boxBean.GetShowColor();
if (boxBean.runStatus > RunStatus.Wait)
{
if (btnStart.Enabled)
{
FormStatus(true);
}
}
else
{
if (!btnStart.Enabled)
{
FormStatus(false);
}
}
if (boxBean.MoveInfo.MoveType.Equals(MoveType.InStore) || boxBean.MoveInfo.MoveType.Equals(MoveType.OutStore))
{
// if (!boxBean.OnlyProOutTray)
{
lblInoutInfo.Text = (boxBean.MoveInfo.MoveType.Equals(MoveType.InStore) ? "入库:" : "出库:") + boxBean.MoveInfo.MoveParam.PosInfo.ToStr();
}
//else
//{
// lblInoutInfo.Text = "出料:" + boxBean.MoveInfo.MoveParam.PosInfo.ToStr();
//}
}
else
{
lblInoutInfo.Text = "";
}
lblMoveInfo.Text = boxBean.GetMoveStr();//+ "料仓类型:" + (boxBean.Config.IsBigTray.Equals(1) ? "大料盘" : "小料盘");
//string canOut = boxBean.CanOutStore(boxBean.DeviceID) ? "可出库" : "不可出库";
lblStoreStatus.Text = DeviceBase.GetRunStr(boxBean.runStatus);// + "(" + canOut + ")";
lblThisSta.Text = boxBean.WarnMsg;
string text = "";
// if (!boxBean.OnlyProOutTray)
{
//List<InOutParam> ps = new List<InOutParam>(boxBean.waitInStoreList);
//if (ps.Count > 0)
//{
// text = "等待入库列表:\r";
// foreach (InOutParam param in ps)
// {
// text += param.ToStr() + "\r";
// }
//}
//else
{
List<InOutParam> psA = new List<InOutParam>(boxBean.waitAOutStoreList);
if (psA.Count > 0)
{
text = "A面等待出库列表:\r";
foreach (InOutParam param in psA)
{
text += param.PosInfo.ToStr() + "\r";
}
}
List<InOutParam> psB = new List<InOutParam>(boxBean.waitBOutStoreList);
if (psB.Count > 0)
{
text = "B面等待出库列表:\r";
foreach (InOutParam param in psB)
{
text += param.PosInfo.ToStr() + "\r";
}
}
}
}
if (!lblInstoreList.Text.Equals(text))
{
lblInstoreList.Text = text;
}
//if (boxBean.IsNoReelAlarm() && (!boxBean.ClampEmptyMove))
//{
// btnHlhasReel.Visible = true;
//}
//else
//{
// btnHlhasReel.Visible = false;
//}
}
catch (Exception ex)
{
LogUtil.error(boxBean.Name + "界面定时器出错:", ex);
}
}
private void FrmTest_FormClosing(object sender, FormClosingEventArgs e)
{
// KNDAIManager.NeedShow = false;
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 FrmIOStatus_Shown(object sender, EventArgs e)
{
timer1.Start();
}
private void btnStart_Click(object sender, EventArgs e)
{
if (boxBean.runStatus.Equals(RunStatus.Wait))
{
LogUtil.info(boxBean.Name + "点击:启用调试");
StartDebug();
}
else
{
LogUtil.info(boxBean.Name + "点击:复位");
Reset();
}
}
internal void FormStatus(bool isStart)
{
btnStart.Enabled = true;
btnStop.Enabled = true;
btnStop.Enabled = true;
if (isStart)
{
btnStart.Text = "复位";
}
else
{
btnStart.Text = "启动";
}
//btnReset.Enabled = isStart;
}
private void btnStop_Click(object sender, EventArgs e)
{
LogUtil.info(boxBean.Name + "点击:停止");
System.Threading.Tasks.Task.Factory.StartNew(StopRun);
//StopRun();
}
private void btnReset_Click(object sender, EventArgs e)
{
LogUtil.info(boxBean.Name + "点击:复位");
Reset();
}
private void chbDebug_CheckedChanged(object sender, EventArgs e)
{
if (!IsLoad)
{
return;
}
if (chbDebug.Checked)
{
if (!boxBean.IsDebug)
{
DialogResult result = MessageBox.Show("是否切换到调试状态?", "是否确认切换", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
if (result.Equals(DialogResult.Yes))
{
boxBean.IsDebug = true;
boxBean.Config.IsDebug = 1;
StoreManager.SaveBoxConfig(boxBean.Config);
boxBean.ChangeDebug(true);
LogUtil.info(boxBean.Name + "用户切换到调试状态 ");
}
else
{
chbDebug.Checked = false;
}
}
}
else
{
if (boxBean.IsDebug)
{
DialogResult result = MessageBox.Show("是否切换到正常工作状态?", "是否确认切换", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
if (result.Equals(DialogResult.Yes))
{
boxBean.IsDebug = false;
boxBean.Config.IsDebug = 0;
StoreManager.SaveBoxConfig(boxBean.Config);
boxBean.ChangeDebug(false);
LogUtil.info(boxBean.Name + "用户切换到正常工作状态 ");
}
else
{
chbDebug.Checked = true;
}
}
}
}
protected void AddForm(TabControl tabcon, string text, Form form)
{
//text = text.PadRight(10, ' ');
TabPage lineTabPage = new TabPage(text);
// lineTabPage.AutoScroll = true;
// lineTabPage.Tag = StoreBean;
Panel linePan = new Panel();
linePan.Dock = DockStyle.Fill;
linePan.AutoScroll = true;
lineTabPage.Controls.Add(linePan);
form.FormBorderStyle = FormBorderStyle.None;
form.TopLevel = false;
linePan.Controls.Add(form);
form.Dock = DockStyle.Fill;
linePan.Anchor = ((AnchorStyles)((AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left)));
form.Anchor = ((AnchorStyles)((AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left)));
form.Show();
//tabPageList.Add(lineTabPage);
tabcon.Controls.Add(lineTabPage);
}
private void chbMoveStop_CheckedChanged(object sender, EventArgs e)
{
if (!IsLoad)
{
return;
}
boxBean.MoveStop = chbMoveStop.Checked;
LogUtil.info(boxBean.Name + "用户切换是否暂停: " + boxBean.MoveStop);
}
private void btnDebugAxis_Click(object sender, EventArgs e)
{
if(boxBean.IsDeviceLEDOn())
{
boxBean.DeviceLED(false);
}
else
{
boxBean.DeviceLED(true);
}
}
#region 调试界面展示
FrmPosDebug frmPosDebug;
Box_IO io;
FrmAxisMove axisMove;
void initConfigWindow(BoxEquip equip)
{
axisMove = new FrmAxisMove(true);
frmPosDebug = new FrmPosDebug();
io = new Box_IO(equip);
}
// AddForm(tabControl1, " 库位调试 ", frmPosDebug);
void addTablePage()
{
AddForm("IO调试", io);
AddForm("伺服调试", axisMove);
AddForm("库位调试", frmPosDebug);
}
public void Frm_ConfigModeEvent(bool state)
{
if (state)
{
addTablePage();
}
else
{
for (int i = tabControl1.TabPages.Count - 1; i > 0; i--)
{
tabControl1.TabPages[i].Parent = null;
}
}
}
private void AddForm(string text, UserControl form)
{
//text = text.PadLeft(10, ' ');
TabPage lineTabPage = new TabPage(text);
// lineTabPage.AutoScroll = true;
//lineTabPage.Tag = robot;
Panel linePan = new Panel();
linePan.Dock = DockStyle.Fill;
linePan.AutoScroll = true;
lineTabPage.Controls.Add(linePan);
//form.FormBorderStyle = FormBorderStyle.None;
//form.TopLevel = false;
linePan.Controls.Add(form);
form.Dock = DockStyle.Fill;
linePan.Anchor = ((AnchorStyles)((AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left)));
form.Anchor = ((AnchorStyles)((AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left)));
form.Show();
//tabPageList.Add(lineTabPage);
tabControl1.Controls.Add(lineTabPage);
}
private void AddForm(string text, Form form)
{
AddForm(tabControl1, text, form);
}
#endregion
}
}