FrmMain.cs
38.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
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AssemblyLine
{
public partial class FrmMain : Form
{
private string debug = "";
private NotifyIcon notify;
private ContextMenuStrip notifyMenu;
private List<string> _log;
public FrmMain(string[] args)
{
if (args.Length == 1)
debug = args[0];
Common.frmMain = this;
InitializeComponent();
}
private void FrmMain_Load(object sender, EventArgs e)
{
Common.config = new Dictionary<string, string>();
//string path = AppDomain.CurrentDomain.BaseDirectory + "Config\\Config.csv";
//string[] text = System.IO.File.ReadAllLines(path);
//for (int i = 0; i < text.Length; i++)
//{
// if (text[i].StartsWith("//")) continue;
// string[] temp = text[i].Split(',');
// if (temp.Length != 2) continue;
// Common.config.Add(temp[0], temp[1]);
//}
//Common.LOCAL_IP = Common.config["Local"];
string path = AppDomain.CurrentDomain.BaseDirectory + "Config\\Config.xml";
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
System.Xml.XmlNode root;
System.Xml.XmlNode node;
doc.Load(path);
root = doc.LastChild;
int count = root.ChildNodes.Count;
for (int i = 0; i < count; i++)
{
node = root.ChildNodes[i];
if (node.NodeType == System.Xml.XmlNodeType.Element)
Common.config.Add(node.Name, node.InnerText);
}
//Common.LOCAL_IP = Common.config["Local"];
_log = new List<string>();
//RFID
Common.RFID101_Dev = new RFIDInfo("192.168.103.101", "RFID31", "双层线左侧提升机");
Common.RFID102_Dev = new RFIDInfo("192.168.103.102", "RFID32", "双层线中间提升机");
Common.RFID103_Dev = new RFIDInfo("192.168.103.103", "RFID33", "双层线上料工位1");
Common.RFID104_Dev = new RFIDInfo("192.168.103.104", "RFID34", "双层线上料工位2");
Common.RFID105_Dev = new RFIDInfo("192.168.103.105", "RFID35", "双层线右侧提升机");
Common.RFID106_Dev = new RFIDInfo("192.168.103.106", "RFID36", "带包装料线体");
Common.RFID107_Dev = new RFIDInfo("192.168.103.107", "RFID37", "VMI进料线体");
Common.RFID108_Dev = new RFIDInfo("192.168.103.108", "RFID38", "VMI出料线体");
Common.RFID109_Dev = new RFIDInfo("192.168.103.109", "RFID41", "双层线右侧上层");
Common.RFID110_Dev = new RFIDInfo("192.168.103.110", "RFID42", "分盘线体出料");
Common.ReaderAll = new Asa.RFID.ReaderAll();
Common.ReaderAll.LogPath = Common.LOG_PATH;
Common.ReaderAll.ConnectStatus += ReaderAll_ConnectStatus;
Common.ReaderAll.ScanStatus += ReaderAll_ScanStatus;
//ABB
Common.ABB_Dev = new ABBInfo[3];
Common.ABB_Dev[0] = new ABBInfo("192.168.103.51", "ABB1(右)", "", "关闭");
Common.ABB_Dev[1] = new ABBInfo("192.168.103.52", "ABB2(左)", "", "关闭");
Common.ABB_Dev[2] = new ABBInfo("192.168.103.53", "ABB3(下)", "", "关闭");
for (int i = 0; i < Common.ABB_Dev.Length; i++)
DgvABBInfo.Rows.Add(Common.ABB_Dev[i].Name, Common.ABB_Dev[i].IP, Common.ABB_Dev[i].State, Common.ABB_Dev[i].Server);
CboAbbAction.Items.Add(Common.ABB_MOVEGET);
CboAbbAction.Items.Add(Common.ABB_MOVEPUT);
CboAbbAction.Items.Add(Common.ABB_MOVEHOME);
CboAbbAction.Items.Add(Common.ABB_MOVEP);
CboAbbAction.SelectedIndex = 0;
CboAbbType.Items.Add("C:双层线其他规格料格");
CboAbbType.Items.Add("D:双层线7寸料格");
CboAbbType.SelectedIndex = 0;
//MiR小车
Common.Agv = new AgvInfo[4];
Common.Agv[0] = new AgvInfo("MiR_R1467", "10.85.199.67", "Basic ZGlzdHJpYnV0b3I6NjJmMmYwZjFlZmYxMGQzMTUyYzk1ZjZmMDU5NjU3NmU0ODJiYjhlNDQ4MDY0MzNmNGNmOTI5NzkyODM0YjAxNA==");
Common.Agv[1] = new AgvInfo("MiR_R1468", "10.85.199.68", "Basic ZGlzdHJpYnV0b3I6NjJmMmYwZjFlZmYxMGQzMTUyYzk1ZjZmMDU5NjU3NmU0ODJiYjhlNDQ4MDY0MzNmNGNmOTI5NzkyODM0YjAxNA==");
Common.Agv[2] = new AgvInfo("MiR_R1469", "10.85.199.69", "Basic ZGlzdHJpYnV0b3I6NjJmMmYwZjFlZmYxMGQzMTUyYzk1ZjZmMDU5NjU3NmU0ODJiYjhlNDQ4MDY0MzNmNGNmOTI5NzkyODM0YjAxNA==");
Common.Agv[3] = new AgvInfo("MiR_R1470", "10.85.199.70", "Basic ZGlzdHJpYnV0b3I6NjJmMmYwZjFlZmYxMGQzMTUyYzk1ZjZmMDU5NjU3NmU0ODJiYjhlNDQ4MDY0MzNmNGNmOTI5NzkyODM0YjAxNA==");
dataGridView1.Rows.Clear();
for (int i = 0; i < Common.Agv.Length; i++)
dataGridView1.Rows.Add(Common.Agv[i].Name, Common.Agv[i].IP, "脱机", "", "自动");
//托盘菜单
notifyMenu = new ContextMenuStrip();
ToolStripMenuItem item1 = new ToolStripMenuItem("显示(&S)");
item1.Click += Item1_Click;
ToolStripMenuItem item2 = new ToolStripMenuItem("退出(&X)");
item2.Click += Item2_Click;
notifyMenu.Items.Add(item1);
notifyMenu.Items.Add(item2);
//托盘控件
notify = new NotifyIcon { Icon = Icon, Visible = true, ContextMenuStrip = notifyMenu, Text = Text };
notify.MouseDoubleClick += Notify_MouseDoubleClick;
//用于显示完界面后在打开
System.Threading.Thread tTemp = new System.Threading.Thread(new System.Threading.ThreadStart(Dev_Open));
tTemp.Start();
}
private void FrmMain_SizeChanged(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
Hide();
}
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
{
if (debug == "debug")
{
if (Common.line_Double != null)
Common.line_Double.Exit();
if (Common.line_Packing != null)
Common.line_Packing.Exit();
if (Common.ABB_Robot != null)
Common.ABB_Robot.Exit();
if (Common.MiR_AGV != null)
Common.MiR_AGV.Exit();
if (Common.ReaderAll != null)
Common.ReaderAll.Close();
if (Common.controlCenter != null)
Common.controlCenter.Exit();
Dispose();
notify.Dispose();
//Environment.Exit(0);
}
else
{
e.Cancel = true;
Hide();
}
}
private void Dev_Open()
{
System.Threading.Thread.Sleep(50);
Application.DoEvents();
//RFID
Common.ReaderAll.ScanMode = true;
Common.ReaderAll.Open("192.168.103.101", "192.168.103.102", "192.168.103.103",
"192.168.103.104", "192.168.103.105", "192.168.103.106", "192.168.103.109");
//控制中心
Common.controlCenter = new BLL.ControlCenter();
Common.controlCenter.IOStatus += ControlCenter_IOStatus;
Common.controlCenter.AGVText += ControlCenter_AGVText;
Common.controlCenter.Start();
//双层线
Common.line_Double = new BLL.Doubleline();
Common.line_Double.IO_Status += Line_Double_IOStatus;
Common.line_Double.BenQ_Agv_Status += Line_Double_AgvStatus;
Common.line_Double.Start();
//包装线
Common.line_Packing = new BLL.PackingLine();
Common.line_Packing.IOStatus += Line_Packing_IOStatus;
Common.line_Packing.Start();
//ABB机器人
Common.ABB_Robot = new BLL.ABB();
Common.ABB_Robot.StatusChanged += Robot_StatusChanged;
Common.ABB_Robot.ServerChanged += Robot_ServerChanged;
Common.ABB_Robot.Start();
//MiR小车
Common.MiR_AGV = new BLL.MiR();
Common.MiR_AGV.StatusChanged += MiR_AGV_StatusChanged;
string[] s = Common.MiR_AGV.MissionName();
Invoke(new Action(() =>
{
LstAgvPlace.Items.Clear();
LstAgvPlace.Items.AddRange(s);
}));
Common.MiR_AGV.Start();
}
private void ControlCenter_AGVText(string s)
{
//Invoke(new Action(() =>
//{
// string[] tt = s.Split(',');
// if (tt.Length == 4)
// {
// int idx = Convert.ToInt32(tt[0]);
// if (idx < dataGridView2.Rows.Count)
// {
// dataGridView2.Rows[idx].Cells[0].Value = tt[1];
// dataGridView2.Rows[idx].Cells[1].Value = tt[2];
// dataGridView2.Rows[idx].Cells[2].Value = tt[3];
// }
// else
// {
// dataGridView2.Rows.Add(tt[1], tt[2], tt[3]);
// }
// }
// else
// {
// textBox1.AppendText(s + "\r\n");
// }
//}));
}
private void ReaderAll_ScanStatus(int idx, string ip, bool status)
{
Invoke(new Action(() => {
Label lbl = (Label)groupBox11.Controls["LblRFIDScan" + idx];
if (status)
lbl.BackColor = Color.Lime;
else
lbl.BackColor = Color.Red;
}));
}
private void ReaderAll_ConnectStatus(int idx, string ip, bool status)
{
Invoke(new Action(() => {
Label lbl = (Label)groupBox11.Controls["LblRFIDSta" + idx];
if (status)
lbl.BackColor = Color.Lime;
else
lbl.BackColor = Color.Red;
}));
}
internal void Log_Show(string s)
{
int count = Convert.ToInt32(Common.config["Log_Count"]);
s = string.Format("[{0:HH:mm:ss.fff}] ", DateTime.Now) + s;
if (_log.Count > count)
_log.RemoveAt(0);
_log.Add(s);
Invoke(new Action(() =>
{
TxtLog.Text = string.Join("\r\n", _log);
TxtLog.SelectionStart = TxtLog.Text.Length;
TxtLog.ScrollToCaret();
}));
}
#region 系统托盘
private void Item2_Click(object sender, EventArgs e)
{
if (Common.line_Double != null)
Common.line_Double.Exit();
if (Common.line_Packing != null)
Common.line_Packing.Exit();
if (Common.ABB_Robot != null)
Common.ABB_Robot.Exit();
if (Common.MiR_AGV != null)
Common.MiR_AGV.Exit();
if (Common.ReaderAll != null)
Common.ReaderAll.Close();
if (Common.controlCenter != null)
Common.controlCenter.Exit();
Dispose();
notify.Dispose();
Environment.Exit(0);
}
private void Item1_Click(object sender, EventArgs e)
{
Show();
if (WindowState == FormWindowState.Minimized)
WindowState = FormWindowState.Normal;
}
private void Notify_MouseDoubleClick(object sender, MouseEventArgs e)
{
Show();
if (WindowState == FormWindowState.Minimized)
WindowState = FormWindowState.Normal;
}
#endregion
#region 双层线
internal void DI1_Changed(Asa.IOModule.AIOBOX box, Asa.IOModule.Box_Sta[] sta)
{
Control ctl = this;
for (int i = 0; i < sta.Length; i++)
{
if (Common.IO21_Dev.DI[i].Sta == sta[i]) continue;
if (i < 4)
ctl = tabPage1;
else if (i < 8)
ctl = groupBox1;
else if (i < 14)
ctl = groupBox6;
else if (i < 16)
ctl = groupBox2;
if (sta[i] == Asa.IOModule.Box_Sta.On)
ctl.Controls["DI1_" + i].BackColor = Color.Lime;
else
ctl.Controls["DI1_" + i].BackColor = Color.LightGray;
Common.IO21_Dev.DI[i].Sta = sta[i];
}
}
internal void DI2_Changed(Asa.IOModule.AIOBOX box, Asa.IOModule.Box_Sta[] sta)
{
Control ctl = this;
for (int i = 0; i < sta.Length; i++)
{
if (Common.IO22_Dev.DI[i].Sta == sta[i]) continue;
switch (i)
{
case 0:
case 1:
ctl = groupBox2;
break;
case 2:
case 3:
case 5:
case 8:
case 9:
ctl = groupBox4;
break;
case 4:
case 6:
case 7:
case 10:
case 11:
ctl = groupBox5;
break;
case 12:
case 13:
ctl = groupBox3;
break;
case 14:
case 15:
ctl = groupBox7;
break;
}
if (sta[i] == Asa.IOModule.Box_Sta.On)
ctl.Controls["DI2_" + i].BackColor = Color.Lime;
else
ctl.Controls["DI2_" + i].BackColor = Color.LightGray;
Common.IO22_Dev.DI[i].Sta = sta[i];
}
}
internal void DI3_Changed(Asa.IOModule.AIOBOX box, Asa.IOModule.Box_Sta[] sta)
{
Control ctl = this;
for (int i = 0; i < sta.Length; i++)
{
if (Common.IO23_Dev.DI[i].Sta == sta[i]) continue;
switch (i)
{
case 0:
case 1:
ctl = groupBox3;
break;
case 2:
case 3:
ctl = groupBox7;
break;
}
if (sta[i] == Asa.IOModule.Box_Sta.On)
ctl.Controls["DI3_" + i].BackColor = Color.Lime;
else
ctl.Controls["DI3_" + i].BackColor = Color.LightGray;
Common.IO23_Dev.DI[i].Sta = sta[i];
}
}
internal void DO1_Changed(Asa.IOModule.AIOBOX box, Asa.IOModule.Box_Sta[] sta)
{
Control ctl = this;
for (int i = 0; i < sta.Length; i++)
{
if (Common.IO21_Dev.DO[i].Sta == sta[i]) continue;
switch (i)
{
case 0:
case 1:
case 2:
case 3:
ctl = tabPage1;
break;
case 4:
case 5:
case 6:
case 13:
case 14:
ctl = groupBox1;
break;
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
ctl = groupBox6;
break;
}
if (sta[i] == Asa.IOModule.Box_Sta.On)
ctl.Controls["DO1_" + i].BackColor = Color.Lime;
else
ctl.Controls["DO1_" + i].BackColor = Color.Transparent;
Common.IO21_Dev.DO[i].Sta = sta[i];
}
}
internal void DO2_Changed(Asa.IOModule.AIOBOX box, Asa.IOModule.Box_Sta[] sta)
{
Control ctl = this;
for (int i = 0; i < sta.Length; i++)
{
if (Common.IO22_Dev.DO[i].Sta == sta[i]) continue;
switch (i)
{
case 0:
case 1:
ctl = groupBox6;
break;
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
ctl = groupBox2;
break;
case 8:
case 9:
case 10:
case 11:
ctl = groupBox4;
break;
case 12:
case 13:
ctl = groupBox5;
break;
}
if (sta[i] == Asa.IOModule.Box_Sta.On)
ctl.Controls["DO2_" + i].BackColor = Color.Lime;
else
ctl.Controls["DO2_" + i].BackColor = Color.Transparent;
Common.IO22_Dev.DO[i].Sta = sta[i];
}
}
internal void DO3_Changed(Asa.IOModule.AIOBOX box, Asa.IOModule.Box_Sta[] sta)
{
Control ctl = this;
for (int i = 0; i < sta.Length; i++)
{
if (Common.IO23_Dev.DO[i].Sta == sta[i]) continue;
switch (i)
{
case 0:
case 1:
case 4:
case 5:
ctl = groupBox4;
break;
case 2:
case 3:
case 6:
case 7:
ctl = groupBox5;
break;
case 8:
case 9:
ctl = groupBox3;
break;
case 10:
case 11:
case 12:
case 13:
case 18:
case 19:
ctl = groupBox7;
break;
case 14:
case 15:
case 16:
case 17:
ctl = groupBox3;
break;
}
if (sta[i] == Asa.IOModule.Box_Sta.On)
ctl.Controls["DO3_" + i].BackColor = Color.Lime;
else
ctl.Controls["DO3_" + i].BackColor = Color.Transparent;
Common.IO23_Dev.DO[i].Sta = sta[i];
}
}
private void DO1_Click(object sender, EventArgs e)
{
if (!Common.IO21_Dev.Box.IsConn) return;
int add = Convert.ToInt32((sender as Control).Name.Substring(4));
if (add == 4)
Common.IO21_Dev.Box.WriteDO(5, Asa.IOModule.Box_Sta.Off);
else if (add == 5)
Common.IO21_Dev.Box.WriteDO(4, Asa.IOModule.Box_Sta.Off);
else if (add == 13)
Common.IO21_Dev.Box.WriteDO(14, Asa.IOModule.Box_Sta.Off);
else if (add == 14)
Common.IO21_Dev.Box.WriteDO(13, Asa.IOModule.Box_Sta.Off);
Asa.IOModule.Box_Sta sta = Common.IO21_Dev.Box.ReadDO(add);
sta = Common.IO21_Dev.Box.ReverseStatus(sta);
Common.IO21_Dev.Box.WriteDO(add, sta);
}
private void DO2_Click(object sender, EventArgs e)
{
if (!Common.IO22_Dev.Box.IsConn) return;
int add = Convert.ToInt32((sender as Control).Name.Substring(4));
if (add == 2)
Common.IO22_Dev.Box.WriteDO(3, Asa.IOModule.Box_Sta.Off);
else if (add == 3)
Common.IO22_Dev.Box.WriteDO(2, Asa.IOModule.Box_Sta.Off);
else if (add == 4)
Common.IO22_Dev.Box.WriteDO(5, Asa.IOModule.Box_Sta.Off);
else if (add == 5)
Common.IO22_Dev.Box.WriteDO(4, Asa.IOModule.Box_Sta.Off);
Asa.IOModule.Box_Sta sta = Common.IO22_Dev.Box.ReadDO(add);
sta = Common.IO22_Dev.Box.ReverseStatus(sta);
Common.IO22_Dev.Box.WriteDO(add, sta);
}
private void DO3_Click(object sender, EventArgs e)
{
if (!Common.IO23_Dev.Box.IsConn) return;
int add = Convert.ToInt32((sender as Control).Name.Substring(4));
if (add == 0)
Common.IO23_Dev.Box.WriteDO(1, Asa.IOModule.Box_Sta.Off);
else if (add == 1)
Common.IO23_Dev.Box.WriteDO(0, Asa.IOModule.Box_Sta.Off);
else if (add == 2)
Common.IO23_Dev.Box.WriteDO(3, Asa.IOModule.Box_Sta.Off);
else if (add == 3)
Common.IO23_Dev.Box.WriteDO(2, Asa.IOModule.Box_Sta.Off);
else if (add == 4)
Common.IO23_Dev.Box.WriteDO(5, Asa.IOModule.Box_Sta.Off);
else if (add == 5)
Common.IO23_Dev.Box.WriteDO(4, Asa.IOModule.Box_Sta.Off);
else if (add == 6)
Common.IO23_Dev.Box.WriteDO(7, Asa.IOModule.Box_Sta.Off);
else if (add == 7)
Common.IO23_Dev.Box.WriteDO(6, Asa.IOModule.Box_Sta.Off);
else if (add == 8)
Common.IO23_Dev.Box.WriteDO(9, Asa.IOModule.Box_Sta.Off);
else if (add == 9)
Common.IO23_Dev.Box.WriteDO(8, Asa.IOModule.Box_Sta.Off);
else if (add == 14)
Common.IO23_Dev.Box.WriteDO(15, Asa.IOModule.Box_Sta.Off);
else if (add == 15)
Common.IO23_Dev.Box.WriteDO(14, Asa.IOModule.Box_Sta.Off);
Asa.IOModule.Box_Sta sta = Common.IO23_Dev.Box.ReadDO(add);
sta = Common.IO23_Dev.Box.ReverseStatus(sta);
Common.IO23_Dev.Box.WriteDO(add, sta);
}
private void BtnRFID_Click(object sender, EventArgs e)
{
Control ctl = sender as Control;
string s = ctl.Name.Substring(3);
string val = "";
switch (s)
{
case "101":
val = Common.ReaderAll.ReadStr(Common.RFID101_Dev.IP);
break;
case "102":
val = Common.ReaderAll.ReadStr(Common.RFID102_Dev.IP);
break;
case "103":
val = Common.ReaderAll.ReadStr(Common.RFID103_Dev.IP);
break;
case "104":
val = Common.ReaderAll.ReadStr(Common.RFID104_Dev.IP);
break;
case "105":
val = Common.ReaderAll.ReadStr(Common.RFID105_Dev.IP);
break;
case "106":
val = Common.ReaderAll.ReadStr(Common.RFID106_Dev.IP);
break;
case "107":
val = Common.ReaderAll.ReadStr(Common.RFID107_Dev.IP);
break;
case "108":
val = Common.ReaderAll.ReadStr(Common.RFID108_Dev.IP);
break;
case "109":
val = Common.ReaderAll.ReadStr(Common.RFID109_Dev.IP);
break;
case "110":
val = Common.ReaderAll.ReadStr(Common.RFID110_Dev.IP);
break;
default:
return;
}
ctl.Text = "RFID:" + val;
}
private void Line_Double_IOStatus(int idx, string ip, bool status)
{
Invoke(new Action(() => {
Label lbl = (Label)groupBox12.Controls["LblIOSta" + idx];
if (status)
lbl.BackColor = Color.Lime;
else
lbl.BackColor = Color.Red;
}));
}
private void Line_Double_AgvStatus(int idx, string ip, bool status)
{
if (status)
label19.BackColor = Color.Lime;
else
label19.BackColor = Color.Red;
}
private void ChkAGVServer_CheckedChanged(object sender, EventArgs e)
{
Common.line_Double.AgvTest(ChkAGVServer.Checked);
BtnAgvEnter.Enabled = ChkAGVServer.Checked;
BtnAgvLeave.Enabled = ChkAGVServer.Checked;
}
private void BtnAgvLeave_Click(object sender, EventArgs e)
{
Common.line_Double.AgvLeave();
}
private void BtnAgvEnter_Click(object sender, EventArgs e)
{
Common.line_Double.AgvEnter();
}
#endregion
#region 包装线
internal void DI4_Changed(Asa.IOModule.AIOBOX box, Asa.IOModule.Box_Sta[] sta)
{
for (int i = 0; i < sta.Length; i++)
{
if (Common.IO24_Dev.DI[i].Sta == sta[i]) continue;
if (sta[i] == Asa.IOModule.Box_Sta.On)
tabPage2.Controls["DI4_" + i].BackColor = Color.Lime;
else
tabPage2.Controls["DI4_" + i].BackColor = Color.LightGray;
Common.IO24_Dev.DI[i].Sta = sta[i];
}
}
internal void DO4_Changed(Asa.IOModule.AIOBOX box, Asa.IOModule.Box_Sta[] sta)
{
for (int i = 0; i < sta.Length; i++)
{
if (Common.IO24_Dev.DO[i].Sta == sta[i]) continue;
if (sta[i] == Asa.IOModule.Box_Sta.On)
tabPage2.Controls["DO4_" + i].BackColor = Color.Lime;
else
tabPage2.Controls["DO4_" + i].BackColor = Color.Transparent;
Common.IO24_Dev.DO[i].Sta = sta[i];
}
}
private void DO4_Click(object sender, EventArgs e)
{
if (!Common.IO24_Dev.Box.IsConn) return;
int add = Convert.ToInt32((sender as Control).Name.Substring(4));
if (add == 7)
Common.IO24_Dev.Box.WriteDO(8, Asa.IOModule.Box_Sta.Off);
else if (add == 8)
Common.IO24_Dev.Box.WriteDO(7, Asa.IOModule.Box_Sta.Off);
if (add == 10)
Common.IO24_Dev.Box.WriteDO(11, Asa.IOModule.Box_Sta.Off);
else if (add == 11)
Common.IO24_Dev.Box.WriteDO(10, Asa.IOModule.Box_Sta.Off);
if (add == 12)
Common.IO24_Dev.Box.WriteDO(13, Asa.IOModule.Box_Sta.Off);
else if (add == 13)
Common.IO24_Dev.Box.WriteDO(12, Asa.IOModule.Box_Sta.Off);
Asa.IOModule.Box_Sta sta = Common.IO24_Dev.Box.ReadDO(add);
sta = Common.IO24_Dev.Box.ReverseStatus(sta);
Common.IO24_Dev.Box.WriteDO(add, sta);
}
private void Line_Packing_IOStatus(int idx, string ip, bool status)
{
Invoke(new Action(() => {
Label lbl = (Label)groupBox12.Controls["LblIOSta" + (idx + 3).ToString()];
if (status)
lbl.BackColor = Color.Lime;
else
lbl.BackColor = Color.Red;
}));
}
#endregion
#region 其他
private void ChkServerPause_CheckedChanged(object sender, EventArgs e)
{
Common.line_Double.ServerPause = ChkServerPause.Checked;
}
private void BtnPlaceLeft_Click(object sender, EventArgs e)
{
Common.line_Double.PlaceLeft = 1;
}
private void BtnPlaceRight_Click(object sender, EventArgs e)
{
Common.line_Double.PlaceRight = 1;
}
private void BtnNeedTypeD_Click(object sender, EventArgs e)
{
Common.line_Double.NeedTypeD = 1;
}
private void BtnNeedTypeC_Click(object sender, EventArgs e)
{
Common.line_Double.NeedTypeC = 1;
}
private void BtnGoPlace1_Click(object sender, EventArgs e)
{
Common.line_Double.GoPlace1 = 1;
}
private void BtnGoPlace2_Click(object sender, EventArgs e)
{
Common.line_Double.GoPlace2 = 1;
}
private void BtnPlace1Leave_Click(object sender, EventArgs e)
{
Common.line_Double.Place1Leave = 1;
}
private void BtnPlace2Leave_Click(object sender, EventArgs e)
{
Common.line_Double.Place2Leave = 1;
}
#endregion
#region ABB
private void BtnAbbMove_Click(object sender, EventArgs e)
{
if (DgvABBInfo.SelectedCells.Count == 0) return;
int idx = DgvABBInfo.SelectedCells[0].RowIndex;
string command = CboAbbAction.Text;
string point = "p" + numericUpDown1.Value;
if (command == Common.ABB_MOVEPUT)
{
if (CboAbbType.SelectedIndex == 0)
point = "cp" + numericUpDown1.Value;
else
point = "dp" + numericUpDown1.Value;
}
string movement = RdoAbbMove1.Checked ? "L" : "J";
int speed = Convert.ToInt32(NudAbbSpeed.Value);
string s = string.Format("{0},{1},{2},{3}", command, point, movement, speed);
Common.ABB_Robot.SendCommand(idx, s);
}
private void BtnAbbMove2_Click(object sender, EventArgs e)
{
if (DgvABBInfo.SelectedCells.Count == 0) return;
int idx = DgvABBInfo.SelectedCells[0].RowIndex;
string command = CboAbbAction.Text;
string point = "p{0}";
if (command == Common.ABB_MOVEPUT)
{
if (CboAbbType.SelectedIndex == 0)
point = "cp{0}";
else
point = "dp{0}";
}
int p1 = Convert.ToInt32(numericUpDown1.Value);
int p2 = Convert.ToInt32(numericUpDown2.Value);
string movement = RdoAbbMove1.Checked ? "L" : "J";
int speed = Convert.ToInt32(NudAbbSpeed.Value);
string s = string.Format("{0},{1},{2},{3}", command, point, movement, speed);
Common.ABB_Robot.Multitask(idx, s, p1, p2);
}
private void Robot_StatusChanged(int idx, string sta)
{
Invoke(new Action(() =>
{
DgvABBInfo.Rows[idx].Cells[2].Value = sta;
Common.ABB_Dev[idx].State = sta;
groupBox13.Controls["LblABBSta" + idx].BackColor = Color.Lime;
}));
}
private void Robot_ServerChanged(int idx, string sta)
{
Invoke(new Action(() =>
{
DgvABBInfo.Rows[idx].Cells[3].Value = sta;
Common.ABB_Dev[idx].Server = sta;
}));
}
#endregion
#region 出料皮带线
internal void DI6_Changed(Asa.IOModule.AIOBOX box, Asa.IOModule.Box_Sta[] sta)
{
for (int i = 0; i < sta.Length; i++)
{
if (Common.IO26_Dev.DI[i].Sta == sta[i]) continue;
if (sta[i] == Asa.IOModule.Box_Sta.On)
tabPage7.Controls["DI6_" + i].BackColor = Color.Lime;
else
tabPage7.Controls["DI6_" + i].BackColor = Color.LightGray;
Common.IO26_Dev.DI[i].Sta = sta[i];
}
}
internal void DI7_Changed(Asa.IOModule.AIOBOX box, Asa.IOModule.Box_Sta[] sta)
{
for (int i = 0; i < sta.Length; i++)
{
if (Common.IO27_Dev.DI[i].Sta == sta[i]) continue;
if (sta[i] == Asa.IOModule.Box_Sta.On)
tabPage7.Controls["DI7_" + i].BackColor = Color.Lime;
else
tabPage7.Controls["DI7_" + i].BackColor = Color.LightGray;
Common.IO27_Dev.DI[i].Sta = sta[i];
}
}
internal void DO6_Changed(Asa.IOModule.AIOBOX box, Asa.IOModule.Box_Sta[] sta)
{
for (int i = 0; i < sta.Length; i++)
{
if (Common.IO26_Dev.DO[i].Sta == sta[i]) continue;
if (sta[i] == Asa.IOModule.Box_Sta.On)
tabPage7.Controls["DO6_" + i].BackColor = Color.Lime;
else
tabPage7.Controls["DO6_" + i].BackColor = Color.Transparent;
Common.IO26_Dev.DO[i].Sta = sta[i];
}
}
internal void DO7_Changed(Asa.IOModule.AIOBOX box, Asa.IOModule.Box_Sta[] sta)
{
for (int i = 0; i < sta.Length; i++)
{
if (Common.IO27_Dev.DO[i].Sta == sta[i]) continue;
if (sta[i] == Asa.IOModule.Box_Sta.On)
tabPage7.Controls["DO7_" + i].BackColor = Color.Lime;
else
tabPage7.Controls["DO7_" + i].BackColor = Color.Transparent;
Common.IO27_Dev.DO[i].Sta = sta[i];
}
}
private void DO6_Click(object sender, EventArgs e)
{
if (!Common.IO26_Dev.Box.IsConn) return;
int add = Convert.ToInt32((sender as Control).Name.Substring(4));
if (add == 1)
Common.IO26_Dev.Box.WriteDO(2, Asa.IOModule.Box_Sta.Off);
else if (add == 2)
Common.IO26_Dev.Box.WriteDO(1, Asa.IOModule.Box_Sta.Off);
Asa.IOModule.Box_Sta sta = Common.IO26_Dev.Box.ReadDO(add);
sta = Common.IO26_Dev.Box.ReverseStatus(sta);
Common.IO26_Dev.Box.WriteDO(add, sta);
}
private void DO7_Click(object sender, EventArgs e)
{
if (!Common.IO27_Dev.Box.IsConn) return;
int add = Convert.ToInt32((sender as Control).Name.Substring(4));
if (add == 1)
Common.IO27_Dev.Box.WriteDO(2, Asa.IOModule.Box_Sta.Off);
else if (add == 2)
Common.IO27_Dev.Box.WriteDO(1, Asa.IOModule.Box_Sta.Off);
Asa.IOModule.Box_Sta sta = Common.IO27_Dev.Box.ReadDO(add);
sta = Common.IO27_Dev.Box.ReverseStatus(sta);
Common.IO27_Dev.Box.WriteDO(add, sta);
}
#endregion
private void ControlCenter_IOStatus(int idx, string ip, bool status)
{
Invoke(new Action(() => {
Label lbl = (Label)groupBox12.Controls["LblIOSta" + (idx + 5)];
if (status)
lbl.BackColor = Color.Lime;
else
lbl.BackColor = Color.Red;
}));
}
private void MiR_AGV_StatusChanged(int idx, string sta)
{
Invoke(new Action(() =>
{
dataGridView1.Rows[idx].Cells[2].Value = sta;
}));
}
private void button13_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedCells.Count == 0) return;
int idx = dataGridView1.SelectedCells[0].RowIndex;
if (!Common.Agv[idx].IsCancel)
Common.MiR_AGV.Mission(idx, LstAgvPlace.Text);
}
private void button27_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedCells.Count == 0) return;
int idx = dataGridView1.SelectedCells[0].RowIndex;
if (!Common.Agv[idx].IsCancel)
Common.MiR_AGV.RunMission(idx);
}
private void button28_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedCells.Count == 0) return;
int idx = dataGridView1.SelectedCells[0].RowIndex;
if (!Common.Agv[idx].IsCancel)
Common.MiR_AGV.PauseMission(idx);
}
private void button30_Click(object sender, EventArgs e)
{
Common.ABB_Robot.StopMultitask = true;
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
Common.ABB_Robot.LoadController();
}
private void BtnPackingGoPlace_Click(object sender, EventArgs e)
{
Common.line_Packing.GoPlace = 1;
}
private void BtnPackingPlaceLeave_Click(object sender, EventArgs e)
{
Common.line_Packing.PlaceLeave = 1;
}
private void CboAbbType_SelectedIndexChanged(object sender, EventArgs e)
{
if (CboAbbType.SelectedIndex == 0)
{
numericUpDown1.Maximum = 12;
numericUpDown2.Maximum = 12;
}
else if(CboAbbType.SelectedIndex == 1)
{
numericUpDown1.Maximum = 92;
numericUpDown2.Maximum = 92;
}
}
private void button1_Click(object sender, EventArgs e)
{
Common.line_Packing.Leave = true;
}
private void button2_Click(object sender, EventArgs e)
{
Common.line_Double.Place1ToPlace2 = 1;
}
private void button3_Click(object sender, EventArgs e)
{
Common.controlCenter.ClearNodeBuff();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
//if (e.ColumnIndex == 4)
//{
// DataGridViewCell cell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
// Common.Agv[e.RowIndex].IsCancel = Convert.ToBoolean(cell.Value);
//}
}
private void button5_Click(object sender, EventArgs e)
{
button5.Text = "Place: " + Common.line_Double.Place1RFID;
}
private void button6_Click(object sender, EventArgs e)
{
button6.Text = "Place: " + Common.line_Double.Place2RFID;
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 4 && e.RowIndex > -1)
{
DataGridViewCell cell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
Common.Agv[e.RowIndex].IsCancel = !Common.Agv[e.RowIndex].IsCancel;
cell.Value = Common.Agv[e.RowIndex].IsCancel ? "手动" : "自动";
}
}
private void BtnPlaceBackflow_Click(object sender, EventArgs e)
{
Common.line_Packing.PlaceBefore = 1;
}
}
}