FrmEquip.cs
45.7 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
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.CompilerServices;
using System.Threading;
using System.IO;
using System.Runtime.InteropServices;
using OnlineStore.Common;
using System.Reflection;
using OnlineStore.DeviceLibrary;
using System.IO.Ports;
using OnlineStore.LoadCSVLibrary;
using UserFromControl;
using HuichuanLibrary;
using System.Diagnostics;
namespace OnlineStore.ACSingleStore
{
public partial class FrmEquip : FrmBase
{
public EquipBean equip;
private bool LoadOk = false;
private System.Timers.Timer startTimer = null;
public FrmEquip()
{
startTimer = new System.Timers.Timer();
startTimer.Interval = 1000;
startTimer.Enabled = false;
startTimer.AutoReset = false;
Control.CheckForIllegalCrossThreadCalls = false;
InitializeComponent();
}
#region "初始化界面数据"
private void FrmTest_Load(object sender, EventArgs e)
{
string version = GetVersion(true);
equip = EquipManager.InitStore();
if (equip == null)
{
this.Close();
return;
}
int autoValue = ConfigAppSettings.GetIntValue(Setting_Init.App_AutoRun);
if (autoValue.Equals(1))
{
开机自动启动ToolStripMenuItem.Text = gouStr + " 开机自动启动";
}
else
{
开机自动启动ToolStripMenuItem.Text = "开机自动启动";
}
if (EquipManager.UseBuzzer)
{
启用蜂鸣器ToolStripMenuItem.Text = gouStr + " 启用蜂鸣器";
}
else
{
启用蜂鸣器ToolStripMenuItem.Text = "启用蜂鸣器";
}
this.Text = EquipManager.Equip.Name;
this.timer1.Start();
if (equip == null)
{
LogUtil.error("找不到对应的设备");
this.Close();
return;
}
LoadPosition();
chbDebug.Checked = equip.IsDebug;
this.ShowInTaskbar = true;
tabPage2.Text = " 设备状态 ";
this.Opacity = 1;
DebugStatus(false);
AddForm(" IO调试 ", new FrmLineIO());
LogUtil.logBox = this.logBox;
HCLogUtil.logBox = this.logBox;
LoadOk = true;
}
private void AddForm(string text, Form form)
{
text = text.PadLeft(10, ' ');
TabPage lineTabPage = new TabPage(text);
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();
tabControl1.Controls.Add(lineTabPage);
}
private void LoadPosition()
{
cmbWork.SelectedIndex = 0;
ShelfPosition ktkPosition = null;
if (equip.PositionNumList.Count > 0)
{
cmbPosition.DataSource = equip.PositionNumList;
cmbPosition.SelectedIndex = 0;
ktkPosition = CSVPositionReader<ShelfPosition>.GetPositon(cmbPosition.Text);
}
txtMiddleP1.Text = equip.Config.MiddleAxis_P1.ToString();
txtUpDownP1.Text = equip.Config.UpDownAxis_DoorL_P1.ToString();
txtInOutP1.Text = equip.Config.InOutAxis_P1.ToString();
txtComP1.Text = equip.Config.CompressAxis_P1.ToString();
txtUpDownP2.Text = equip.Config.UpDownAxis_DoorH_P2.ToString();
txtUpDownP1.Text = equip.Config.UpDownAxis_DoorL_P1.ToString();
txtUpDownP5.Text = equip.Config.UpDownAxis_DoorH_P5.ToString();
txtUpDownP6.Text = equip.Config.UpDownAxis_DoorH_P6.ToString();
txtInoutP4.Text = equip.Config.InOutAxis_P4.ToString();
txtMiddleP3.Text = equip.Config.MiddleAxis_P3.ToString();
ShowPosition(ktkPosition);
timer1.Enabled = true;
}
private void ShowPosition(ShelfPosition position)
{
if (position != null)
{
lblSize.Text = "库位尺寸:" + position.BagWidth + "X" + position.BagHigh;
txtMiddleP2.Text = position.MiddleAxis_P2.ToString();
txtUpDownP4.Text = position.UpDownAxis_L_P4.ToString();
txtUpDownP3.Text = position.UpDownAxis_H_P3.ToString();
txtComP2.Text = position.CompressAxis_P2.ToString();
txtComP3.Text = position.CompressAxis_P3.ToString();
txtInOutP3.Text = position.InOutAxis_P3.ToString();
txtInOutP2.Text = position.InOutAxis_P2.ToString();
}
else
{
lblSize.Text = "库位尺寸:未知";
}
}
#endregion
private void timer1_Tick(object sender, EventArgs e)
{
if (!this.Visible)
{
return;
}
lblHeartMsg.Text = LineConnect.HeartMsg;
if (chbDebug.Checked.Equals(equip.IsDebug).Equals(false))
{
LoadOk = false;
chbDebug.Checked = equip.IsDebug;
LoadOk = true;
}
lblMoveEquipInfo.Text = "" + (equip.lineConn.CanStartOut() ? "可取料" : "不可取料") + " " + equip.lineConn.LastUpdateTime.ToLongTimeString() + "";
lblThisSta.Text = equip.GetRunStr();
lblMoveStr.Text = equip.GetMoveStr();
//ReadPosistion();
if (equip.storeRunStatus > StoreRunStatus.Wait)
{
string wmsg = "";
//lblWarnMsg.Text = equip.WarnMsg;
if (!String.IsNullOrEmpty(equip.WarnMsg))
{
wmsg += equip.WarnMsg+"\r\n";
}
foreach (WorkStation s in equip.StationMap.Values)
{
if (!string.IsNullOrEmpty(s.WarnMsg))
{
wmsg += s.WarnMsg + "\r\n";
}
}
//如果不在出料中,且叉子上有信号,需要提示检查叉子
if (equip.storeRunStatus.Equals(StoreRunStatus.Runing) && equip.IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH))
{
wmsg += "叉子料盘检测有料,请检查" + "\r\n";
}
lblWarnMsg.Text = wmsg;
//if (lblWarnMsg.Text.Equals(""))
//{
// if (LineConnect.DoorPosInfo != null)
// {
// string msg = "出料口物料:" + LineConnect.DoorPosInfo?.ToStr()+"\r\n"+"料架信息:"+equip.CurrTray?.ToStr();
// lblWarnMsg.Text = msg;
// }
//}
if (equip.autoNext)
{
string msg = equip.autoMsg;
lblAutoMsg.Text = msg;
try
{
msg = msg.Replace("自动出库:", "");
msg = msg.Replace("自动出料:", "");
msg = msg.Replace("自动盘点:", "");
int index = equip.PositionNumList.IndexOf(msg);
if (index >= 0 && (!msg.Equals("")))
{
cmbPosition.SelectedIndex = index;
}
}
catch (Exception ex) { }
}
else
{
// lblMsg.Text = "没有开启自动出料";
if (btnStartAuTo.Text.Equals("停止自动出料"))
{
btnStartAuTo.Text = "开始自动出料";
}
}
}
else
{
lblThisSta.Text = "等待启动";
lblWarnMsg.Text = "";
btnStartAuTo.Text = "开始自动出料";
}
}
private void FrmTest_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)//当用户点击窗体右上角X按钮或(Alt + F4)时 发生
{
e.Cancel = true;
//HideForm();
}
}
private void btnInStore_Click(object sender, EventArgs e)
{
if (equip.storeRunStatus >= StoreRunStatus.HomeMoving)
{
LogUtil.info(equip.Name + "点击:出料测试");
string selectPositionNum = cmbPosition.Text;
LineMoveP ktk = LoadPostion();
equip.StartOutMove(new InOutParam(new InOutPosInfo( "", selectPositionNum), ktk));
}
else
{
int v = equip.Config.GetCompP2(8);
MessageBox.Show("请先启动设备!");
}
}
private LineMoveP LoadPostion()
{
LineMoveP ktk = new LineMoveP();
ktk.ComPress_P1 = FormUtil.GetIntValue(txtComP1);
ktk.ComPress_P2 = FormUtil.GetIntValue(txtComP2);
ktk.ComPress_P3 = FormUtil.GetIntValue(txtComP3);
ktk.InOut_P1 = FormUtil.GetIntValue(txtInOutP1);
ktk.InOut_P2 = FormUtil.GetIntValue(txtInOutP2);
ktk.InOut_P3 = FormUtil.GetIntValue(txtInOutP3);
ktk.InOut_P4 = FormUtil.GetIntValue(txtInoutP4);
ktk.Middle_P1 = FormUtil.GetIntValue(txtMiddleP1);
ktk.Middle_P2 = FormUtil.GetIntValue(txtMiddleP2);
ktk.Middle_P3 = FormUtil.GetIntValue(txtMiddleP3);
ktk.UpDown_P1 = FormUtil.GetIntValue(txtUpDownP1);
ktk.UpDown_P2 = FormUtil.GetIntValue(txtUpDownP2);
ktk.UpDown_P3 = FormUtil.GetIntValue(txtUpDownP3);
ktk.UpDown_P4 = FormUtil.GetIntValue(txtUpDownP4);
ktk.UpDown_P5 = FormUtil.GetIntValue(txtUpDownP5);
ktk.UpDown_P6 = FormUtil.GetIntValue(txtUpDownP6);
return ktk;
}
private void cmbPosition_SelectedIndexChanged(object sender, EventArgs e)
{
if (cmbPosition.SelectedIndex >= 0)
{
string selectPositionNum = cmbPosition.Text;
ShelfPosition ktkPosition = CSVPositionReader<ShelfPosition>.GetPositon(selectPositionNum);
ShowPosition(ktkPosition);
}
}
private void btnSavePosition_Click(object sender, EventArgs e)
{
LogUtil.info(equip.Name + "点击:保存位置");
//设备格子位置保存
string pNum = cmbPosition.Text;
ShelfPosition position = CSVPositionReader<ShelfPosition>.GetPositon(pNum);
if (position != null)
{
position.MiddleAxis_P2 = FormUtil.GetIntValue(txtMiddleP2);
position.UpDownAxis_L_P4 = FormUtil.GetIntValue(txtUpDownP4);
position.UpDownAxis_H_P3 = FormUtil.GetIntValue(txtUpDownP3);
position.InOutAxis_P3 = FormUtil.GetIntValue(txtInOutP3);
position.CompressAxis_P3 = FormUtil.GetIntValue(txtComP3);
position.CompressAxis_P2 = FormUtil.GetIntValue(txtComP2);
position.InOutAxis_P2 = FormUtil.GetIntValue(txtInOutP2);
}
//位置配置
string appPath = Application.StartupPath;
//如果总配置文件存在,保存到总的配置文件
string positionConfigFile = appPath + ConfigAppSettings.GetValue(Setting_Init.Store_Position_Config);
bool result = CSVPositionReader<ShelfPosition>.SavePostion(positionConfigFile, position);
if (!result)
{
MessageBox.Show("保存位置失败!");
}
//设备固定位置保存
bool needUpdate = false;
equip.Config.MiddleAxis_P1 = GetV(equip.Config.MiddleAxis_P1, txtMiddleP1, ref needUpdate);
equip.Config.UpDownAxis_DoorL_P1 = GetV(equip.Config.UpDownAxis_DoorL_P1, txtUpDownP1, ref needUpdate);
equip.Config.InOutAxis_P1 = GetV(equip.Config.InOutAxis_P1, txtInOutP1, ref needUpdate);
equip.Config.CompressAxis_P1 = GetV(equip.Config.CompressAxis_P1, txtComP1, ref needUpdate);
equip.Config.UpDownAxis_DoorH_P2 = GetV(equip.Config.UpDownAxis_DoorH_P2, txtUpDownP2 , ref needUpdate);
equip.Config.UpDownAxis_DoorH_P5 = GetV(equip.Config.UpDownAxis_DoorH_P5, txtUpDownP5, ref needUpdate);
equip.Config.UpDownAxis_DoorH_P6 = GetV(equip.Config.UpDownAxis_DoorH_P6, txtUpDownP6, ref needUpdate);
equip.Config.MiddleAxis_P3 = GetV(equip.Config.MiddleAxis_P3, txtMiddleP3, ref needUpdate);
equip.Config.InOutAxis_P4 = GetV(equip.Config.InOutAxis_P4, txtInoutP4, ref needUpdate);
if (needUpdate)
{
//更新缓存
EquipManager.UpdateStoreConfig(equip.Config);
}
MessageBox.Show("保存位置成功!");
}
private int GetV(int currV, TextBox text, ref bool needUpdate)
{
int targetV = FormUtil.GetIntValue(text);
if (currV != targetV)
{
needUpdate = true;
return targetV;
}
return currV;
}
private bool InoutInP1()
{
int InOutDefaultPosition = ConfigAppSettings.GetIntValue(Setting_Init.InOutDefaultPosition);
int currValue = AxisManager.instance.GetActualtPosition(equip.Config.InOut_Axis.DeviceName, equip.Config.InOut_Axis.GetAxisValue());
if (currValue <= InOutDefaultPosition)
{
return true;
}
MessageBox.Show("叉子不在待机位,请先将叉子退回待机位("+InOutDefaultPosition+")", "警告(叉子在待机位时,才能移动升降轴和旋转轴) ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return false;
}
private void AxisABSMove(ConfigMoveAxis moveAxis, int targetPosition, int targetSpeed)
{
LogUtil.info(equip.Name + " 点击点位运动:" + moveAxis.DisplayStr + " [" + targetPosition + "] [" + targetSpeed + "] ");
moveAxis.TargetPosition = targetPosition;
AxisManager.instance.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition, targetSpeed, moveAxis.AddSpeed, moveAxis.DelSpeed);
}
private void btnUpDownP1_Click(object sender, EventArgs e)
{
if (InoutInP1())
{
int value = FormUtil.GetIntValue(txtUpDownP1);
AxisABSMove(equip.Config.UpDown_Axis, value, equip.Config.UpDownAxis_P1_Speed);
}
}
private void btnUpDownP2_Click(object sender, EventArgs e)
{
if (InoutInP1())
{
int value = FormUtil.GetIntValue(txtUpDownP2);
AxisABSMove(equip.Config.UpDown_Axis, value, equip.Config.UpDownAxis_P2_Speed);
}
}
private void btnUpDownP3_Click(object sender, EventArgs e)
{
if (InoutInP1())
{
int value = FormUtil.GetIntValue(txtUpDownP3);
AxisABSMove(equip.Config.UpDown_Axis, value, equip.Config.UpDownAxis_P3_Speed);
}
}
private void btnUpDownP4_Click(object sender, EventArgs e)
{
if (InoutInP1())
{
int value = FormUtil.GetIntValue(txtUpDownP4);
AxisABSMove(equip.Config.UpDown_Axis, value, equip.Config.UpDownAxis_P4_Speed);
}
}
private void btnUpDownP5_Click(object sender, EventArgs e)
{
if (InoutInP1())
{
int value = FormUtil.GetIntValue(txtUpDownP5);
AxisABSMove(equip.Config.UpDown_Axis, value, equip.Config.UpDownAxis_P5_Speed);
}
}
private void btnUpDownP6_Click(object sender, EventArgs e)
{
if (InoutInP1())
{
int value = FormUtil.GetIntValue(txtUpDownP6);
AxisABSMove(equip.Config.UpDown_Axis, value, equip.Config.UpDownAxis_P6_Speed);
}
}
private void btnMiddleP1_Click(object sender, EventArgs e)
{
if (InoutInP1())
{
int value = FormUtil.GetIntValue(txtMiddleP1);
AxisABSMove(equip.Config.Middle_Axis, value, equip.Config.MiddleAxis_P1_Speed);
}
}
private void btnMiddleP2_Click(object sender, EventArgs e)
{
if (InoutInP1())
{
int value = FormUtil.GetIntValue(txtMiddleP2);
AxisABSMove(equip.Config.Middle_Axis, value, equip.Config.MiddleAxis_P2_Speed);
}
}
private void btnInOutP1_Click(object sender, EventArgs e)
{
int value = FormUtil.GetIntValue(txtInOutP1);
AxisABSMove(equip.Config.InOut_Axis, value, equip.Config.InOutAxis_P1_Speed);
}
private void btnInOutP3_Click(object sender, EventArgs e)
{
int value = FormUtil.GetIntValue(txtInOutP3);
AxisABSMove(equip.Config.InOut_Axis, value, equip.Config.InOutAxis_P3_Speed);
}
private void btnInOutP2_Click(object sender, EventArgs e)
{
int value = FormUtil.GetIntValue(txtInOutP2);
AxisABSMove(equip.Config.InOut_Axis, value, equip.Config.InOutAxis_P2_Speed);
}
private void btnComP2_Click(object sender, EventArgs e)
{
int value = FormUtil.GetIntValue(txtComP2);
AxisABSMove(equip.Config.Comp_Axis, value, equip.Config.CompAxis_P2_Speed);
}
private void btnComP1_Click(object sender, EventArgs e)
{
int value = FormUtil.GetIntValue(txtComP1);
AxisABSMove(equip.Config.Comp_Axis, value, equip.Config.CompAxis_P1_Speed);
}
private void btnComP3_Click(object sender, EventArgs e)
{
int value = FormUtil.GetIntValue(txtComP3);
AxisABSMove(equip.Config.Comp_Axis, value, equip.Config.CompAxis_P3_Speed);
}
private void button1_Click(object sender, EventArgs e)
{
FrmAxisDebug frm = new FrmAxisDebug(equip);
frm.ShowDialog();
}
private void btnStartAuTo_Click(object sender, EventArgs e)
{
if (equip.storeRunStatus >= StoreRunStatus.HomeMoving)
{
if (equip.autoNext)
{
equip.autoNext = false;
btnStartAuTo.Text = "开始自动出料";
}
else
{
DialogResult res = MessageBox.Show("确定开始自动出料?", "提示", MessageBoxButtons.YesNo);
if (res.Equals(DialogResult.Yes))
{
equip.autoNext = true;
int jiange = FormUtil.GetIntValue(txtJiange);
equip.autoJiange = jiange;
if (cmbPosition.SelectedIndex >= 0)
{
int currIndex = cmbPosition.SelectedIndex;
equip.autoPositionIndex = currIndex;
equip.AutoStartIndex = currIndex;
string poText = cmbPosition.Text;
equip.autoMsg = "自动出库:" + poText;
LogUtil.info( equip.Name + "开启自动出料模式,开始位置【" + poText + "】(索引=" + currIndex + "),间隔=" + jiange + ",出料开始!");
//store.StartOutStoreMove(new InOutStoreParam("", poText));
equip.StartOutMove(new InOutParam(new InOutPosInfo("AUTOINOUT", poText)));
}
btnStartAuTo.Text = "停止自动出料";
}
}
}
else
{
MessageBox.Show("请先启动设备!");
}
}
private void 轴卡点动ToolStripMenuItem_Click(object sender, EventArgs e)
{
button1_Click(null, null);
}
private void 设备运转ONToolStripMenuItem_Click(object sender, EventArgs e)
{
LogUtil.info(equip.Name + "打开所有伺服");
this.Enabled = false;
equip.OpenAllAxis(false );
this.Enabled = true;
LogUtil.info(equip.Name + "打开所有伺服 完成");
}
private void 设备运转OFFToolStripMenuItem_Click(object sender, EventArgs e)
{
LogUtil.info(equip.Name + "关闭所有伺服");
equip.CloseAllAxis();
LogUtil.info(equip.Name + "关闭所有伺服 完成");
}
private void FrmStoreBox_Shown(object sender, EventArgs e)
{
this.btnUpDownP1.ForeColor = System.Drawing.Color.Red;
this.btnUpDownP2.ForeColor = System.Drawing.Color.Red;
this.btnUpDownP3.ForeColor = System.Drawing.Color.Red;
this.btnUpDownP4.ForeColor = System.Drawing.Color.Red;
this.btnUpDownP5.ForeColor = System.Drawing.Color.Red;
this.btnUpDownP6.ForeColor = System.Drawing.Color.Red;
this.btnComP1.ForeColor = System.Drawing.Color.Purple;
this.btnComP3.ForeColor = System.Drawing.Color.Purple;
this.btnComP2.ForeColor = System.Drawing.Color.Purple;
this.btnInOutP2.ForeColor = System.Drawing.Color.Green;
this.btnInOutP1.ForeColor = System.Drawing.Color.Green;
this.btnInOutP3.ForeColor = System.Drawing.Color.Green;
this.btnMiddleP1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))));
this.btnMiddleP2.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))));
axisMoveControl1.LoadData(equip);
}
private void ExitApp()
{
DialogResult result = MessageBox.Show("是否确定退出设备客户端?", "提示", MessageBoxButtons.YesNo);
if (result.Equals(DialogResult.Yes))
{
//如果设备还在运行状态,先关闭设备
if (!equip.storeRunStatus.Equals(StoreRunStatus.Wait))
{
LogUtil.info("ExitApp 停止" + equip.Name + "运行 ");
equip.StopRun();
}
try
{
IOManager.instance.CloseAllDO();
IOManager.instance.CloseAllConnection();
AxisManager.instance.CloseAllPort();
AxisManager.instance.CloseCard();
RFIDManager.Close();
AgvClient.Dispose();
}catch(Exception ex)
{
LogUtil.error("ExitApp出错:" + ex.ToString());
}
System.Environment.Exit(System.Environment.ExitCode);
}
}
private void FrmStoreBox_FormClosed(object sender, FormClosedEventArgs e)
{
ExitApp();
}
private void button3_Click(object sender, EventArgs e)
{
equip.lineConn.StartConnect();
}
private void button5_Click(object sender, EventArgs e)
{
equip.lineConn.StopConnect();
}
private void button6_Click(object sender, EventArgs e)
{
if (equip.lineConn.IsConnect())
{
int hasTray = (int)equip.IOValue(IO_Type.TrayCheck_Door);
StoreStatus ss = StoreStatus.StoreOnline;
if (equip.IsDebug)
{
ss = StoreStatus.Debugging;
}
string posid = "";
if (equip.MoveInfo.MoveType.Equals(StoreMoveType.None))
{
if (equip.MoveInfo.MoveParam.PosInfo.IsNg)
{
posid = "";
}
else
{
}
posid = equip.MoveInfo.MoveParam?.PosInfo.BoxPosId;
}
StoreSendBean bean = equip.lineConn.GetBean((int)ss, (int)StoreRunStatus.Runing, hasTray, (int)StoreAlarmType.None,posid,equip.GetShelfRfids());
equip.lineConn.SendHeart(bean);
}
}
private void chbDebug_CheckedChanged(object sender, EventArgs e)
{
if (!LoadOk)
{
return;
}
if (chbDebug.Checked)
{
if (!equip.IsDebug)
{
DialogResult result = MessageBox.Show("是否切换到调试状态?", "是否确认切换", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
if (result.Equals(DialogResult.Yes))
{
equip.IsDebug = true;
equip.Config.ISDebug = 1;
EquipManager.UpdateStoreConfig(equip.Config);
LogUtil.info(equip.Name+"用户切换到调试状态 ");
}
}
}
else
{
if (equip.IsDebug)
{
DialogResult result = MessageBox.Show("是否切换到正常工作状态?", "是否确认切换", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
if (result.Equals(DialogResult.Yes))
{
equip.IsDebug = false;
equip.Config.ISDebug = 0;
EquipManager.UpdateStoreConfig(equip.Config);
LogUtil.info(equip.Name + "用户切换到正常工作状态 ");
}
}
}
}
private FrmTool frmTool = null;
private void btnUpdown_Click(object sender, EventArgs e)
{
foreach (ConfigMoveAxis axis in equip.moveAxisList)
{
if (equip.Config.Comp_Axis.IsSameAxis(axis.DeviceName, axis.GetAxisValue()))
{
continue;
}
//判断伺服是否已经打开
bool inoutOn = AxisManager.instance.IsServeoOn(axis.DeviceName, axis.GetAxisValue());
if (!inoutOn)
{
MessageBox.Show(axis.DisplayStr + "伺服未打开,清先打开伺服");
return;
}
}
if (equip.Config.DIList.ContainsKey(IO_Type.Check_Pos))
{
string ioIP = equip.Config.DIList[IO_Type.Check_Pos].IO_IP;
int ioIndex = equip.Config.DIList[IO_Type.Check_Pos].GetIOAddr();
if (frmTool == null)
{
frmTool = new FrmTool(equip, ioIP, ioIndex, equip.Name);
}
frmTool.Show();
frmTool.FormClosed += FrmTool_FormClosed;
frmTool.Focus();
}
else
{
MessageBox.Show("未配置激光检测信号");
}
}
private void FrmTool_FormClosed(object sender, FormClosedEventArgs e)
{
frmTool = null;
}
public void DebugStatus(bool status)
{
axisMoveControl1.Enabled = status;
//groupComAxis.Enabled = status;
groupInout.Enabled = status;
axisMoveControl1.Enabled = status;
}
private void logBox_VisibleChanged(object sender, EventArgs e)
{
if (logBox.Visible)
{
if (LogUtil.logBox == null)
{
LogUtil.logBox = logBox;
LogUtil.UpdateLogbox();
}
}
}
private void frmInOutStore_FormClosed(object sender, FormClosedEventArgs e)
{
//frmInOutStore = null;
}
private void cmbWork_SelectedIndexChanged(object sender, EventArgs e)
{
if (cmbWork.SelectedIndex < 0)
{
return;
}
if (LoadOk)
{
int index = cmbWork.SelectedIndex;
List<string> pos = new List<string>();
foreach(string str in equip.PositionNumList)
{
ShelfPosition position = CSVPositionReader<ShelfPosition>.GetPositon(str);
if(position.ShelfID.Equals(index)||index.Equals(0))
{
pos.Add(str);
}
}
cmbPosition.DataSource = null;
cmbPosition.Items.Clear();
cmbPosition.DataSource = pos;
cmbPosition.SelectedIndex = 0;
}
}
private void btnMiddleP3_Click(object sender, EventArgs e)
{
if (InoutInP1())
{
int value = FormUtil.GetIntValue(txtMiddleP3 );
AxisABSMove(equip.Config.Middle_Axis, value, equip.Config.MiddleAxis_P3_Speed);
}
}
private void btnInoutP4_Click(object sender, EventArgs e)
{
int value = FormUtil.GetIntValue(txtInoutP4);
AxisABSMove(equip.Config.InOut_Axis, value, equip.Config.InOutAxis_P4_Speed);
}
private void btnNGMove_Click(object sender, EventArgs e)
{
if (equip.storeRunStatus >= StoreRunStatus.HomeMoving)
{
LogUtil.info(equip.Name + "点击:"+btnNGMove.Text);
string selectPositionNum = cmbPosition.Text;
LineMoveP ktk = LoadPostion();
InOutPosInfo inOutPos = new InOutPosInfo("", selectPositionNum);
inOutPos.IsNg = true;
equip.StartOutMove(new InOutParam(inOutPos, ktk));
}
else
{
MessageBox.Show("请先启动设备!");
}
}
private void HideForm()
{
this.Opacity = 0;
this.ShowInTaskbar = false;
this.notifyIcon1.Visible = true;
this.Hide();
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
this.contextMenuStrip1.Show();
}
if (e.Button == MouseButtons.Left)
{
this.Visible = true;
this.WindowState = FormWindowState.Maximized;
this.ShowInTaskbar = true;
}
}
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)//当用户点击窗体右上角X按钮或(Alt + F4)时 发生
{
e.Cancel = true;
HideForm();
}
}
private void 显示ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
FrmPwd fw = new FrmPwd(10);
DialogResult result = fw.ShowDialog();
if (!result.Equals(DialogResult.OK))
{
LogUtil.info("切换界面显示时,没有正确输入密码");
return;
}
this.Opacity = 100;
this.Visible = true;
this.WindowState = FormWindowState.Maximized;
this.notifyIcon1.Visible = false;
this.ShowInTaskbar = true;
}
catch (Exception ex)
{
LogUtil.error("显示界面出错:" + ex.ToString());
}
}
private void 启动所有设备AToolStripMenuItem_Click(object sender, EventArgs e)
{
if (equip.storeRunStatus != StoreRunStatus.Wait)
{
MessageBox.Show(equip.Name + "当前状态:" + equip.storeRunStatus + ",不能启动!");
return;
}
LogUtil.info(equip.Name + "点击:启动");
startTimer.Interval = 300;
startTimer.Elapsed += timer_Elapsed;
startTimer.AutoReset = false;
startTimer.Enabled = true;
}
private delegate void ShowFormDelegate();
void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
startTimer.Enabled = false;
if (equip.storeRunStatus > StoreRunStatus.Wait)
{
return;
}
if (equip.StartRun())
{
BeginInvoke(new ShowFormDelegate(ShowStatus));
}
LogM();
}
private void ShowStatus()
{
formLineStatus(true);
}
private void formLineStatus(bool isStart)
{
//frmBox.StoreOpenStatus(isStart);
启动AToolStripMenuItem.Enabled = !isStart;
停止TToolStripMenuItem.Enabled = isStart;
}
private void 停止所有设备TToolStripMenuItem_Click(object sender, EventArgs e)
{
LogUtil.info(equip.Name + "点击:停止");
if (equip != null)
{
if (equip.storeRunStatus.Equals(StoreRunStatus.Wait))
{
MessageBox.Show(equip.Name + "设备未启动,不需要停止");
return;
}
if (equip != null)
{
equip.StopRun();
}
formLineStatus(false);
}
}
private void 复位RToolStripMenuItem_Click(object sender, EventArgs e)
{
LogUtil.info(equip.Name + "点击:复位");
if (equip.storeRunStatus.Equals(StoreRunStatus.Wait))
{
MessageBox.Show(equip.Name + "设备未启动,无法复位");
return;
}
equip.Reset();
}
private void FrmLineStore_FormClosed(object sender, FormClosedEventArgs e)
{
if (停止TToolStripMenuItem.Enabled)
{
停止所有设备TToolStripMenuItem_Click(null, null);
}
}
private void btnClearLog_Click(object sender, EventArgs e)
{
LogUtil.ClearLog();
}
private void btnCopyLog_Click(object sender, EventArgs e)
{
Clipboard.SetDataObject(logBox.Text);
MessageBox.Show("已复制日志到粘贴板!");
}
private DateTime lastLogTime = DateTime.Now;
private void LogM()
{
try
{
TimeSpan sp = DateTime.Now - lastLogTime;
if (sp.TotalMinutes > 10)
{
lastLogTime = DateTime.Now;
Process[] processes = Process.GetProcesses();
long totalMemery = 0;
StringBuilder sbResult = new StringBuilder();
int interval = 1000;
var prevCpuTime = TimeSpan.Zero;
foreach (Process process in processes)
{
if (process.ProcessName.EndsWith("OutletEquip"))
{
sbResult.AppendFormat(DateTime.Now.ToLongTimeString() + ", 名称:{0} 内存大小:{1}M ", process.ProcessName, process.PrivateMemorySize64 / 1024 / 1024F);
totalMemery += process.PrivateMemorySize64 / 1024;
double value = (process.TotalProcessorTime - prevCpuTime).TotalMilliseconds / interval / Environment.ProcessorCount;
sbResult.AppendFormat(" CPU : " + Math.Round(value, 2) + "%");
// string result = string.Format("进程总数 {0} 个,共占内存:{1}MB \n", processes.Length, totalMemery / 1024) + sbResult.ToString();
LogUtil.info(sbResult.ToString());
}
}
}
}
catch (Exception ex)
{
LogUtil.error("LogM Error: " + ex.ToString());
}
}
private void 版本号ToolStripMenuItem_Click(object sender, EventArgs e)
{
FrmAbout about = new FrmAbout();
about.ShowDialog();
}
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
LogUtil.info(equip.Name + "点击:退出");
ExitApp();
}
private void toolStripMenuItem2_Click(object sender, EventArgs e)
{
if (toolStripMenuItem2.Text.Equals("启用调试"))
{
LogUtil.info(equip.Name + "点击:启用调试");
DebugOpen(true);
}
else
{
LogUtil.info(equip.Name + "点击:禁用调试");
DebugOpen(false);
}
}
private void DebugOpen(bool isopen)
{
DebugStatus(isopen);
if (isopen)
{
toolStripMenuItem2.Text = "禁用调试";
}
else
{
toolStripMenuItem2.Text = "启用调试";
}
}
private void toolStripMenuItem3_Click(object sender, EventArgs e)
{
try
{
FrmPwd fw = new FrmPwd(10);
DialogResult result = fw.ShowDialog();
if (!result.Equals(DialogResult.OK))
{
LogUtil.info("切换界面显示时,没有正确输入密码");
return;
}
FrmIdConfig frm = new FrmIdConfig();
frm.ShowDialog();
}
catch (Exception ex)
{
LogUtil.error("显示界面出错:" + ex.ToString());
}
}
private string gouStr = "✔";
private void 开机自动启动ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!LoadOk)
{
return;
}
if (开机自动启动ToolStripMenuItem.Text.Contains(gouStr))
{
ConfigAppSettings.SaveValue(Setting_Init.App_AutoRun, 0);
ManagerUtil.AutoRun(Application.ExecutablePath, false);
开机自动启动ToolStripMenuItem.Text = "开机自动启动";
}
else
{
ConfigAppSettings.SaveValue(Setting_Init.App_AutoRun, 1);
ManagerUtil.AutoRun(Application.ExecutablePath, true);
开机自动启动ToolStripMenuItem.Text = gouStr + "开机自动启动";
}
LogUtil.info(Name + " 点击:" + 开机自动启动ToolStripMenuItem.Text);
}
private void 启用蜂鸣器ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!LoadOk)
{
return;
}
bool result = !启用蜂鸣器ToolStripMenuItem.Text.Contains(gouStr);
if (result.Equals(EquipManager.UseBuzzer))
{
return;
}
EquipManager.UseBuzzer = result;
ConfigAppSettings.SaveValue(Setting_Init.UseBuzzer, (EquipManager.UseBuzzer ? 1 : 0));
if (result)
{
启用蜂鸣器ToolStripMenuItem.Text = gouStr + " 启用蜂鸣器";
}
else
{
启用蜂鸣器ToolStripMenuItem.Text = "启用蜂鸣器";
}
LogUtil.info(Name + " 点击:" + 启用蜂鸣器ToolStripMenuItem.Text);
}
private void 开启DEBUG日志ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!LoadOk)
{
return;
}
bool result = !开启DEBUG日志ToolStripMenuItem.Text.Contains(gouStr);
if (result.Equals(LogUtil.debug_opened))
{
return;
}
LogUtil.debug_opened = result;
if (result)
{
开启DEBUG日志ToolStripMenuItem.Text = gouStr + " 开启DEBUG日志";
}
else
{
开启DEBUG日志ToolStripMenuItem.Text = "开启DEBUG日志";
}
LogUtil.info(Name + " 点击:" + 开启DEBUG日志ToolStripMenuItem.Text);
}
private void 板卡调试ToolStripMenuItem_Click(object sender, EventArgs e)
{
DialogResult resul = MessageBox.Show("将关闭板卡,请确认设备未在运行中", "提示", MessageBoxButtons.OKCancel);
if (resul.Equals(DialogResult.OK))
{
ACServerManager.instance.CloseCard();
LogUtil.info("打开板卡测试界面前,先CloseCard");
FrmHuiChuanTest frm = new FrmHuiChuanTest();
frm.ShowDialog();
HCLogUtil.logBox = this.logBox;
LogUtil.info("板卡测试界面关闭后,调用OpenCard");
ACServerManager.instance.OpenCard();
}
}
private void 复制日志ToolStripMenuItem_Click(object sender, EventArgs e)
{
Clipboard.SetDataObject(logBox.Text);
MessageBox.Show("已复制日志到粘贴板!");
}
private void 清空日志ToolStripMenuItem_Click(object sender, EventArgs e)
{
LogUtil.ClearLog();
}
private void 打开设备照明ToolStripMenuItem_Click(object sender, EventArgs e)
{
equip.IOMove(IO_Type.Device_Led, IO_VALUE.HIGH);
}
private void 关闭设备照明ToolStripMenuItem_Click(object sender, EventArgs e)
{
equip.IOMove(IO_Type.Device_Led, IO_VALUE.LOW);
}
private void btnMoni_Click(object sender, EventArgs e)
{
string text = txtMoni.Text.Trim();
LogUtil.info("点击模拟按钮:" + text);
equip.lineConn.HandlerMsg(text);
}
private void btnClearDoor_Click(object sender, EventArgs e)
{
DialogResult resul = MessageBox.Show("确定清除:" + LineConnect.DoorPosInfo?.ToStr() + "", "提示", MessageBoxButtons.OKCancel);
if (resul.Equals(DialogResult.OK))
{
LogUtil.info(equip.Name + "点击:清理门口料盘:" + LineConnect.DoorPosInfo?.ToStr());
LineConnect.DoorPosInfo = null;
}
}
private void SReset(int num)
{
LogUtil.info(equip.Name + "点击:S"+ num + "复位");
if (equip.storeRunStatus.Equals(StoreRunStatus.Wait))
{
MessageBox.Show(equip.Name + "设备未启动,无法复位");
return;
}
equip.StationMap[num].Reset();
}
private void btnS1Reset_Click(object sender, EventArgs e)
{
SReset(1);
}
private void btnS2Reset_Click(object sender, EventArgs e)
{
SReset(2);
}
private void btnS3Reset_Click(object sender, EventArgs e)
{
SReset(3);
}
private void DisS(int num,CheckBox chebox)
{
if (!LoadOk)
{
return;
}
if (chebox.Checked)
{
if (!EquipManager.DisStationList.Contains(num))
{
EquipManager.DisStationList.Add(num);
LogUtil.info(equip.Name + "用户勾选禁用工位S" + num);
}
}
else
{
if (EquipManager.DisStationList.Contains(num))
{
EquipManager.DisStationList.Remove(num);
LogUtil.info(equip.Name + "用户取消禁用工位S" + num);
}
}
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
int num = 1;
DisS(num, checkBox1);
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
int num = 2;
DisS(num, checkBox2);
}
private void checkBox3_CheckedChanged(object sender, EventArgs e)
{
int num = 3;
DisS(num, checkBox3);
}
private void chbMoveStop_CheckedChanged(object sender, EventArgs e)
{
if (!LoadOk)
{
return;
}
equip.MoveStop = chbMoveStop.Checked;
LogUtil.info(equip.Name + "用户切换是否暂停: " + equip.MoveStop);
}
}
}