Form1.cs
20.4 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
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
using OnlineStore;
using CodeLibrary;
using ConfigHelper;
using DeviceLibrary;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using AutoScanAndLabel.UC;
namespace AutoScanAndLabel
{
public partial class Form1 : Form
{
public Form1()
{
crc.OpenResourceLog = true;
InitializeComponent();
this.FormClosing += Form1_FormClosing;
this.Text = Config.Get(Setting_Init.App_Title);
crc.GetLanguageEvent += Crc_GetLanguageEvent;
crc.LanguageChangeEvent += Crc_LanguageChangeEvent;
crc.CurrLanguage = Crc_GetLanguageEvent();
t1.Interval = 1000;
t1.Tick += T1_Tick;
t1.Start();
GC.KeepAlive(t1);
this.Shown += Form1_Shown;
}
private void Crc_LanguageChangeEvent(object sender, EventArgs e)
{
if (tabControl1.TabCount > tabpagecount)
addTablePage();
LanguageProcess();
}
private string Crc_GetLanguageEvent()
{
return Config.Get("Default_Language","zh-CN");
}
private void Form1_Shown(object sender, EventArgs e)
{
LanguageProcess();
}
void LanguageProcess()
{
crc.LanguageProcess(this, this.GetType().Name);
crc.ProcessListItem(menuStrip1.Items, "menuStrip1");
listView1.Columns[1].Text = crc.GetString("Res0004","时间");
listView1.Columns[2].Text = crc.GetString("Res0003", "信息");
stateView.Columns[1].Text = crc.GetString("Res0005","模块");
stateView.Columns[2].Text = crc.GetString("Res0006","步骤");
stateView.Columns[3].Text = crc.GetString("Res0003","信息");
启用调试模式ToolStripMenuItem.Text = !RobotManage.IsDebug ? crc.GetString("Res0011","启用配置模式") : crc.GetString("Res0012","停用配置模式");
btn_run.Text = crc.GetString("Res0015","启动");
if (RobotManage.isRunning)
{
if (userpause)
(btn_run as Button).Text = crc.GetString("Res0014","恢复运行");
else
(btn_run as Button).Text = crc.GetString("Res0013","暂停运行");
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
e.Cancel = true;
this.WindowState = FormWindowState.Minimized;
}
}
LogControl lc = new LogControl();
IOControl ioc = new IOControl();
AxisControl ac = new AxisControl();
SettingControl sc = new SettingControl();
AgvControl agv = new AgvControl();
readonly System.Windows.Forms.Timer t1 = new System.Windows.Forms.Timer();
private void Form1_Load(object sender, EventArgs e)
{
List<CodeInfo> codeInfos = new List<CodeInfo>();
//codeInfos.Add(new CodeInfo("", 528, 406));
codeInfos.Add(new CodeInfo("", 925, 520));
//codeInfos.Add(new CodeInfo("", 564, 684));
btn_run.Enabled = false;
//btn_stop.Enabled = false;
#region 报警信息listview初始化
listView1.View = View.Details;
ColumnHeader emptycol = new ColumnHeader();
emptycol.Text = "";
emptycol.Width = 0;
ColumnHeader msgcol = new ColumnHeader();
msgcol.Text = crc.GetString("Res0003","信息");
msgcol.Width = 600;
ColumnHeader timecol = new ColumnHeader();
timecol.Text = crc.GetString("Res0004","时间");
timecol.Width = 150;
listView1.Columns.Add(emptycol);
listView1.Columns.Add(timecol);
listView1.Columns.Add(msgcol);
listView1.ColumnWidthChanging += listView_ColumnWidthChanging;
#endregion
#region 状态信息listview初始化
stateView.View = View.Details;
ColumnHeader c1 = new ColumnHeader();
c1.Text = "";
c1.Width = 0;
ColumnHeader c2 = new ColumnHeader();
c2.Text = crc.GetString("Res0005","模块");
c2.Width = 100;
ColumnHeader c3 = new ColumnHeader();
c3.Text = crc.GetString("Res0006","步骤");
c3.Width = 100;
ColumnHeader c4 = new ColumnHeader();
c4.Text = crc.GetString("Res0003","信息");
c4.Width = 400;
stateView.Columns.Add(c1);
stateView.Columns.Add(c2);
stateView.Columns.Add(c3);
stateView.Columns.Add(c4);
stateView.ColumnWidthChanging += listView_ColumnWidthChanging;
#endregion
LogUtil.info("开始初始化");
cb_EnableBuzzer.Checked = Config.Get("EnableBuzzer", true);
AlarmBuzzer.BuzzerStateChange += AlarmBuzzer_BuzzerStateChange;
RobotManage.LoadFinishEvent += RobotManage_LoadFinishEvent;
if (Config.Get("EnableLogWindow",false))
AddForm(crc.GetString("Res0007","日志"), lc);
RobotManage.Init();
}
private void AlarmBuzzer_BuzzerStateChange(object sender, bool e)
{
this.Invoke((EventHandler<bool>)delegate {
btn_PauseBuzzer.Visible = e;
}, sender, e);
}
private void listView_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
{
e.NewWidth = (sender as ListView).Columns[e.ColumnIndex].Width;
e.Cancel = true;
}
const int tabpagecount = 3;
void addTablePage() {
AddForm(crc.GetString("Res0008","IO调试"), ioc);
AddForm(crc.GetString("Res0009","伺服调试"), ac);
AddForm("Agv调试", agv);
AddForm(crc.GetString("Res0010","相关设置"), sc);
crc.LanguageProcess(this);
}
//public delegate void setstatedelegate(List<MoveInfo> moveinfoList);
private void MainMachine_ProcessMoveinfoEvent(List<MoveInfo> moveinfoList)
{
//var d = new setstatedelegate(SetState);
//this.Invoke(d, moveinfoList);
}
private void T1_Tick(object sender, EventArgs e)
{
SetState(MoveInfo.List);
}
void SetState(List<MoveInfo> moveInfoList)
{
this.SuspendLayout();
stateView.Items.Clear();
foreach (MoveInfo moveInfo in moveInfoList)
{
if (moveInfo.Name==crc.GetString("Res0016","重置") && RobotManage.mainMachine.runStatus != RunStatus.HomeReset)
{
continue;
}
ListViewItem lvi = new ListViewItem(new string[] { "", moveInfo.Name, moveInfo.MoveStep.ToString(),moveInfo.GetStateStr() });
stateView.Items.Add(lvi);
}
var printstatus = RobotManage.mainMachine.LastPrintStatus;
ListViewItem lvi1 = new ListViewItem(new string[] { "", crc.GetString("Res0216", "打印机"), (printstatus == Asa.PrintLabel.PrinterStatus.Unknown)?"Wait": printstatus.ToString(), ConfigHelper.Config.Get(Setting_Init.PrinterName) });
stateView.Items.Add(lvi1);
this.ResumeLayout(true);
}
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 启用调试模式ToolStripMenuItem_Click(object sender, EventArgs e)
{
RobotManage.IsDebug = RobotManage.IsDebug ? false : true;
(sender as ToolStripMenuItem).Text = !RobotManage.IsDebug ? crc.GetString("Res0011","启用配置模式") : crc.GetString("Res0012","停用配置模式");
//RobotManage.Init();
if (RobotManage.IsDebug)
{
RobotManage.Config = (Robot_Config)CSVConfigReader.LoadConfig(RobotManage.Config);
addTablePage();
RobotManage.LoadDebug();
}
else {
for (int i = tabControl1.TabPages.Count-1; i > 1; i--)
{
tabControl1.TabPages[i].Parent = null;
}
}
}
public delegate void setmsgdelegate(List<Msg> msgs);
private void MainMachine_ProcessMsgEvent(List<Msg> msgs)
{
var d = new setmsgdelegate(SetMsg);
this.Invoke(d, msgs);
}
private void RobotManage_LoadFinishEvent(bool state, string msg)
{
if (state)
{
btn_run.Enabled = true;
//btn_stop.Enabled = true;
RobotManage.mainMachine.ProcessMsgEvent += MainMachine_ProcessMsgEvent;
RobotManage.mainMachine.ProcessMoveinfoEvent += MainMachine_ProcessMoveinfoEvent;
}
var lm = new List<Msg>();
foreach (string ms in msg.Split(new char[] { '\n' },StringSplitOptions.RemoveEmptyEntries))
{
var m = new Msg();
m.datetime = DateTime.Now;
m.msgtxt = ms;
m.msgLevel = state ? MsgLevel.info : MsgLevel.warning;
lm.Add(m);
}
SetMsg(lm);
}
void SetMsg(List<Msg> msgs)
{
this.SuspendLayout();
listView1.Items.Clear();
foreach (Msg msg in msgs)
{
ListViewItem lvi = new ListViewItem(new string[] {"", msg.datetime.ToString(), msg.msgtxt });
if (msg.msgLevel==MsgLevel.info)
lvi.ForeColor = Color.DarkGreen;
else
lvi.ForeColor = Color.Red;
listView1.Items.Add(lvi);
}
this.ResumeLayout(true);
}
bool userpause = false;
private void btn_run_Click(object sender, EventArgs e)
{
if (!RobotManage.isRunning)
{
RobotManage.Start();
userpause = false;
if (RobotManage.isRunning)
{
btn_stop.Enabled = true;
(sender as Button).Text = crc.GetString("Res0013","暂停运行");
}
}
else if (!userpause)
{
userpause = true;
RobotManage.UserPause(userpause);
(sender as Button).Text = crc.GetString("Res0014","恢复运行");
}
else if (userpause)
{
userpause = false;
RobotManage.UserPause(userpause);
(sender as Button).Text = crc.GetString("Res0013","暂停运行");
}
}
private void btn_stop_Click(object sender, EventArgs e)
{
btn_run.Text = crc.GetString("Res0015","启动");
Task.Run(()=>{RobotManage.Stop(); });
RobotManage.UserPause(false);
userpause = false;
btn_stop.Enabled = false;
}
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (RobotManage.isRunning) {
MessageBox.Show(crc.GetString("Res0016","机器尚在运行,不能退出,请先停止运行."));
} else {
RobotManage.Stop();
RobotManage.ShutDown();
Thread.Sleep(2000);
Application.Exit();
}
}
private void cb_IgnoreSafecheck_CheckedChanged(object sender, EventArgs e)
{
RobotManage.IgnoreSafecheck((sender as CheckBox).Checked);
}
private void cb_IgnoreGratingSignal_CheckedChanged(object sender, EventArgs e)
{
RobotManage.IgnoreGratingSignal((sender as CheckBox).Checked);
}
private void 二维码识别调试ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (RobotManage.mainMachine.IsScanRunning())
{
MessageBox.Show(crc.GetString("Res0017","扫码还没完成,无法打开调试!请稍后再试."));
return;
}
IOManager.IOMove(IO_Type.Camera_Led, IO_VALUE.HIGH);
if (Camera._cam != null)
{
Camera._cam.CloseAll();
}
CodeLibrary.FrmCodeDecode frm = new CodeLibrary.FrmCodeDecode();
frm.chbZxing.Checked = false;
frm.ShowDialog();
frm.Dispose();
//IOManager.IOMove(IO_Type.Camera_Led, IO_VALUE.LOW);
}
private void btn_releaseleftshelf_Click(object sender, EventArgs e)
{
if (RobotManage.mainMachine.LeftMoveInfo.MoveStep == MoveStep.Wait)
{
MessageBox.Show(crc.GetString("Res0018","料串已是释放状态"));
return;
}
else if (RobotManage.mainMachine.SafeReleaseLeftShelf)
{
MessageBox.Show(crc.GetString("Res0019","正在执行料串释放"));
return;
}
else if (RobotManage.mainMachine.LeftMoveInfo.MoveStep < MoveStep.L04 || RobotManage.mainMachine.LeftMoveInfo.MoveStep > MoveStep.L30_LabelFinish)
{
MessageBox.Show(crc.GetString("Res0020","左侧料串正在提升或下降, 不能释放"));
return;
}
RobotManage.mainMachine.SafeReleaseLeftShelf = true;
btn_releaseleftshelf.BackColor = Color.OrangeRed;
Task.Run(()=> {
int timeout = 2 * 60;
while (RobotManage.mainMachine.SafeReleaseLeftShelf && timeout>0) {
Task.Delay(500).Wait();
timeout--;
if (timeout % 2 == 0)
{
Invoke((EventHandler)delegate
{
btn_releaseleftshelf.Text = string.Format(crc.GetString("Res0021","左侧料串等待释放中({0})"), timeout / 2);
});
}
if ((RobotManage.mainMachine.LeftMoveInfo.MoveStep== MoveStep.L20_WaitLabel || RobotManage.mainMachine.LeftMoveInfo.MoveStep== MoveStep.L10_WaitReelPut) && (RobotManage.mainMachine.RightMoveInfo.MoveStep == MoveStep.Wait || RobotManage.mainMachine.RightMoveInfo.MoveStep == MoveStep.REND))
{
RobotManage.mainMachine.LeftMoveInfo.NextMoveStep(MoveStep.L30_LabelFinish);
}
}
RobotManage.mainMachine.SafeReleaseLeftShelf = false;
Invoke((EventHandler)delegate
{
btn_releaseleftshelf.BackColor = Color.Transparent;
btn_releaseleftshelf.Text = crc.GetString("Res0022","安全释放左侧料串");
});
});
}
private void btn_releaserightshelf_Click(object sender, EventArgs e)
{
if (RobotManage.mainMachine.RightMoveInfo.MoveStep == MoveStep.Wait)
{
MessageBox.Show(crc.GetString("Res0018","料串已是释放状态"));
return;
}
else if (RobotManage.mainMachine.SafeReleaseRightShelf)
{
MessageBox.Show(crc.GetString("Res0019","正在执行料串释放"));
return;
}
else if (RobotManage.mainMachine.RightMoveInfo.MoveStep < MoveStep.R04 || RobotManage.mainMachine.RightMoveInfo.MoveStep > MoveStep.R11_NextReel)
{
MessageBox.Show(crc.GetString("Res0023","右侧料串当前没有就位, 不能释放"));
return;
}
RobotManage.mainMachine.SafeReleaseRightShelf = true;
btn_releaserightshelf.BackColor = Color.OrangeRed;
Task.Run(() => {
int timeout = 2 * 60;
while (RobotManage.mainMachine.SafeReleaseRightShelf && timeout > 0)
{
Task.Delay(500).Wait();
timeout--;
if (timeout % 2 == 0)
{
Invoke((EventHandler)delegate
{
btn_releaserightshelf.Text = string.Format(crc.GetString("Res0024","右侧料串等待释放中({0})"), timeout / 2);
});
}
}
RobotManage.mainMachine.SafeReleaseRightShelf =false;
Invoke((EventHandler)delegate
{
btn_releaserightshelf.BackColor = Color.Transparent;
btn_releaserightshelf.Text = crc.GetString("Res0025","安全释放右侧料串");
});
});
}
private void btn_maulstart_Click(object sender, EventArgs e)
{
if (RobotManage.mainMachine.RightMoveInfo.MoveStep != MoveStep.Wait) {
MessageBox.Show(crc.GetString("Res0026","右侧料串正在运行,不能手动上料"));
return;
}
if (RobotManage.mainMachine.IOValue(IO_Type.RightEnd_Check).Equals(IO_VALUE.LOW))
{
MessageBox.Show(crc.GetString("Res0027","没有检测到料串,不能手动上料"));
return;
}
RobotManage.mainMachine.RightMoveInfo.NewMove(MoveStep.R01);
LogUtil.info("手动:右侧有新料,准备上料");
}
private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)
{
AboutBox1 aboutBox1 = new AboutBox1();
crc.LanguageProcess(aboutBox1);
aboutBox1.ShowDialog();
}
private void cb_EnableBuzzer_CheckedChanged(object sender, EventArgs e)
{
Config.Set("EnableBuzzer", cb_EnableBuzzer.Checked);
AlarmBuzzer.Enable = cb_EnableBuzzer.Checked;
}
private void btn_PauseBuzzer_Click(object sender, EventArgs e)
{
AlarmBuzzer.MuteOnce();
}
private void btn_leftempty_Click(object sender, EventArgs e)
{
if (RobotManage.mainMachine.LeftMoveInfo.MoveStep != MoveStep.Wait
&& RobotManage.mainMachine.LeftMoveInfo.MoveStep != MoveStep.L10_WaitReelPut)
{
MessageBox.Show(crc.GetString("Res0028","左侧料串正在运行,不能手动上料"));
return;
}
if (RobotManage.mainMachine.IOValue(IO_Type.LeftEnd_Check).Equals(IO_VALUE.LOW))
{
MessageBox.Show(crc.GetString("Res0027","没有检测到料串,不能手动上料"));
return;
}
RobotManage.mainMachine.LeftMoveInfo.NewMove(MoveStep.L01);
LogUtil.info("手动:左侧已清空,重新上升");
}
private void 简体中文ToolStripMenuItem_Click(object sender, EventArgs e)
{
ConfigHelper.Config.Set("Default_Language", "zh-CN");
crc.LanguageChange();
}
private void 日本语ToolStripMenuItem_Click(object sender, EventArgs e)
{
ConfigHelper.Config.Set("Default_Language", "ja-JP");
crc.LanguageChange();
}
private void englishToolStripMenuItem_Click(object sender, EventArgs e)
{
ConfigHelper.Config.Set("Default_Language", "en-US");
crc.LanguageChange();
}
}
}