bklLiudl
2024-07-23 277bbae216debe7e6c04e8cc6ee6e1ba9763e14b
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
using BLL.DAL;
using Commom.DotNetDevices;
using Model.WcsModel;
using NLog;
using System;
using System.Data;
using System.IO;
using System.Threading;
using Common;
using wms.Controllers;
using Model.MessageModel;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
 
namespace wms.Task
{
    //Parallel.For
    public static class TaskAction
    {
        // JC09WCS
        private static bool IsRunTast = true;                                                               // 测试方法控制
        private static bool IsRunConveyor = true;                                                           // 托盘运输线方法控制
        private static bool IsRunBoxConveyor = true;                                                        // 件箱运输线方法控制
        private static bool IsRunStacker = true;                                                            // 跺机方法控制   
        private static bool IsRunStackerAddre = true;                                                       // 跺机地址方法控制   
        private static DataTable PlcInfoDt;                                                                 // 获取所有设备
        private static DataTable PlcIpDt;                                                                   // 获取所有IP地址
 
        private static string plcConveyVal = "";                                                                  // 托盘输送线连接状态
        private static PlcIO plcConvey;                                                                           // 托盘输送线IP地址
 
        private static string plcBoxConveyVal = "";                                                                  // 件箱输送线连接状态
        private static PlcIO plcBoxConvey;                                                                           // 件箱输送线IP地址
 
        #region 垛机地址与链接状态
        private static string plcStackVal1 = "";                                                                  // 跺机1连接状态
        private static PlcIO plcStack1;                                                                           // 跺机1IP地址
 
        private static string plcStackVal2 = "";                                                                  // 跺机2连接状态
        private static PlcIO plcStack2;                                                                           // 跺机2IP地址
 
        private static string plcStackVal3 = "";                                                                  // 跺机1连接状态
        private static PlcIO plcStack3;                                                                           // 跺机1IP地址
 
        private static string plcStackVal4 = "";                                                                  // 跺机2连接状态
        private static PlcIO plcStack4;                                                                           // 跺机2IP地址
 
        private static string plcStackVal5 = "";                                                                  // 跺机1连接状态
        private static PlcIO plcStack5;                                                                           // 跺机1IP地址
 
        private static string plcStackVal6 = "";                                                                  // 跺机2连接状态
        private static PlcIO plcStack6;                                                                           // 跺机2IP地址
 
        private static string plcStackVal7 = "";                                                                  // 跺机1连接状态
        private static PlcIO plcStack7;                                                                           // 跺机1IP地址
 
        #endregion
 
        public static bool fuwu = false;                                                                           // 服务开启关闭
        public static bool refresh = false;                                                                           // 自刷新开启关闭
        public static bool tuoji = false;                                                                           // 脱机开启关闭
        public static bool Demo = false;                                                                            //演示模式开启关闭
 
        /// <summary>
        /// 服务初始化
        /// </summary>
        [Obsolete]
        static TaskAction()
        {
            // WCS标准版本代码  执行一次
            DALWcsMessage wcsSql = new DALWcsMessage();
            PlcIpDt = wcsSql.GetPlcIps();
            PlcInfoDt = wcsSql.GetPlcInfos();
 
            // 开启服务
            fuwu = true;
            //自刷新
            refresh = true;
 
            // 打开设备连接(输送线 跺机 码垛...)
            plcConvey = new PlcIO("192.168.21.2", 1, ref plcConveyVal);
            plcStack1 = new PlcIO("192.168.21.30", 1, ref plcStackVal1);
            plcStack2 = new PlcIO("192.168.21.40", 1, ref plcStackVal2);
        }
 
 
 
        /// <summary>
        /// PLC读写测试
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        public static async void TestPlc(object source, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                if (IsRunTast)
                {
                    IsRunTast = false;
                    //WebStocket发送消息
                    WSChatController wSChat = new WSChatController();
 
                    //通知设备--任务
                    //一号巷道
                    DeviceMessage message = new DeviceMessage();
                    message.Message = "任务更新";
                    message.Status = "1";
                    message.RoadwayNo = "R01";
                    message.StartLocat = 10;
                    message.EndLocat = 15;
                    var a = JsonConvert.SerializeObject(message);
                    wSChat.AlarmInformation(a);
 
                    //二号巷道 没问题
                    message.Message = "任务更新";
                    message.Status = "1";
                    message.RoadwayNo = "R02";
                    message.StartLocat = 53;
                    message.EndLocat = 15;
                    var b = JsonConvert.SerializeObject(message);
                    wSChat.AlarmInformation(b);
 
                    //三号巷道
                    message.Message = "任务更新";
                    message.Status = "1";
                    message.RoadwayNo = "R03";
                    message.StartLocat = 14;
                    message.EndLocat = 53;
                    var c = JsonConvert.SerializeObject(message);
                    wSChat.AlarmInformation(c);
 
                    //四号巷道
                    message.Message = "任务更新";
                    message.Status = "1";
                    message.RoadwayNo = "R04";
                    message.StartLocat = 15;
                    message.EndLocat = 10;
                    var d = JsonConvert.SerializeObject(message);
                    wSChat.AlarmInformation(d);
 
                    //一号巷道
                    message.Message = "垛机实时";
                    message.RoadwayNo = "R01";
                    message.Position = 15;
                    var f = JsonConvert.SerializeObject(message);
                    wSChat.AlarmInformation(f);
 
                    message.Message = "垛机实时";
                    message.RoadwayNo = "R01";
                    message.Position = 33;
                     f = JsonConvert.SerializeObject(message);
                    wSChat.AlarmInformation(f);
 
                    message.Message = "垛机实时";
                    message.RoadwayNo = "R01";
                    message.Position = 36;
                     f = JsonConvert.SerializeObject(message);
                    wSChat.AlarmInformation(f);
 
                    message.Message = "垛机实时";
                    message.RoadwayNo = "R01";
                    message.Position = 45;
                     f = JsonConvert.SerializeObject(message);
                    wSChat.AlarmInformation(f);
 
                    message.Message = "垛机实时";
                    message.RoadwayNo = "R01";
                    message.Position = 48;
                     f = JsonConvert.SerializeObject(message);
                    wSChat.AlarmInformation(f);
 
                    //wSChat.AlarmInformation(d);
                    //var s = fuwu;
                    //WSChatController wSChat = new WSChatController();
                    //wSChat.AlarmInformation(s.ToString());
                    //DALWcsMessage wcsMySql = new DALWcsMessage();
                    //string EndLocat = string.Empty;
 
                    // LED显示屏连接测试
                    //LedDll Led = new LedDll();
                    //Led.LEDstr("192.168.21.150", "最上方", "中间多文本区域!", "最下方区域    ");
                    //Led.LEDstr("192.168.21.150", "测试LED");
                    //TaskReques taskReques = new TaskReques();
                    //taskReques.taskNo = "TK2023092000001";
                    //taskReques.TaskType = "0";
                    //taskReques.TaskStatus = "2";
                    //bool bl = wcsMySql.RequestTasks(taskReques);
 
 
 
                    //string strMsg = wcsMySql.GetLocations("T2300021", "1", ref EndLocat);
                    //WSChatController wSChat = new WSChatController();
                    // wSChat.AlarmInformation("连接设备失败:");
 
 
                    //Logger logger = LogManager.GetCurrentClassLogger();
                    //logger.Error("在运行" + "执行该方法:", "iis自动回收机制");
 
                    //string plcStatus = "";
                    //PlcIO plc = new PlcIO("192.168.21.2", 1, ref plcStatus);
                    //if (plcStatus.Length > 0)
                    //{
                    //    // 连接失败
                    //}
                    //bool bl = plc.SetPlcDBValue(107, "String", "CS2024010100002", "40.0");
                    //bool bl1 = plc.SetPlcDBValue(107, "String", "T2300063", "60.0");
 
 
                    //连接测试
                    //string plcStatus = "";
                    //PlcIO plc = new PlcIO("192.168.21.2", 1, ref plcStatus);
                    //if (plcStatus.Length > 0)
                    //{
                    //    // 连接失败
                    //}
                    //plc = new PlcIO("192.168.21.30", 1, ref plcStatus);
                    //if (plcStatus.Length > 0)
                    //{
                    //    // 连接失败
                    //}
                    //PlcIO plc2 = new PlcIO("192.168.21.40", 1, ref plcStatus);
                    //if (plcStatus.Length > 0)
                    //{
                    //    // 连接失败
                    //}
                    //string plcValue = "";
                    //plcValue = plc.GetPlcDBValue(107, "Int", "84.0");
                    //if (plcValue!= "30")
                    //{
                    //    var vl = plc.SetPlcDBValue(107, "Int", "30","84.0");
                    //}
                    //plcValue = plc.GetPlcDBValue(107, "String", "0.0");
                    //plcValue = plc.GetPlcDBValue(107, "String", "20.0");
                    //plcValue = plc.GetPlcDBValue(107, "String", "40.0");
                    //plcValue = plc.GetPlcDBValue(107, "String", "60.0");
                    //plcValue = plc.GetPlcDBValue(107, "Int", "80.0");
                    //plcValue = plc.GetPlcDBValue(107, "Int", "82.0");
                    //plcValue = plc.GetPlcDBValue(107, "Int", "84.0");
                    //plcValue = plc.GetPlcDBValue(107, "Int", "86.0");
 
                    //plcStatus = "";
                    //PlcIO plc2 = new PlcIO("192.168.21.30", 1, ref plcStatus);
                    //if (plcStatus.Length > 0)
                    //{
                    //    // 连接失败
                    //} 
                    //plcValue = plc2.GetPlcDBValue(100, "String", "0.0");
                    //plcValue = plc2.GetPlcDBValue(100, "String", "20.0");
                    //plcValue = plc2.GetPlcDBValue(100, "Int", "40.0");
                    //plcValue = plc2.GetPlcDBValue(100, "String", "42.0");
                    //plcValue = plc2.GetPlcDBValue(100, "String", "62.0");
                    //plcValue = plc2.GetPlcDBValue(100, "Int", "82.0");
                    //plcValue = plc2.GetPlcDBValue(100, "Int", "84.0");
                    //plcValue = plc2.GetPlcDBValue(100, "Int", "86.0");
                    //plcValue = plc2.GetPlcDBValue(100, "Int", "88.0");
                    //plcValue = plc2.GetPlcDBValue(100, "Int", "90.0");
                    //plcValue = plc2.GetPlcDBValue(100, "Int", "92.0");
                    //plcValue = plc2.GetPlcDBValue(100, "Int", "94.0");
 
                    //led灯相应位置显示
                    // 提示LED选择执行批次
                    // LedDisplay(row["LedIP"].ToString(), "38工位", "入库前,请操作执行批次信息!", "停止入库\t");
                    //LedDisplay("192.168.8.55", "38工位 C1口", "空闲中D", "整托空桶/重桶入库分拣交互工位38"); //D口
                    //LedDisplay("192.168.8.51", "28工位 C口", "空闲中C1", "人工处理/整托袋子入库交互工位28"); //C1口
                    //LedDisplay("192.168.8.52", "24工位 B口", "空闲中C", "托袋子入库交互工位24"); //C口
                    //LedDisplay("192.168.8.54", "18工位 A口", "空闲中B", "吨袋入库B口 交互工位18"); //B口
                    //LedDisplay("192.168.8.53", "13工位 D口", "空闲中A", "桶类出入库A口 交互工位13"); //A口
 
                    //LedDisplay("192.168.8.51", "28工位 C1口", "空闲中", "人工处理/整托袋子入库交互工位28"); //C1口
                    //LedDisplay("192.168.8.52", "24工位 C口", "空闲中", "托袋子入库交互工位24"); //C口
                    //LedDisplay("192.168.8.54", "18工位 B口", "空闲中", "吨袋入库B口 交互工位18"); //B口
                    //LedDisplay("192.168.8.53", "13工位 A口", "空闲中", "桶类出入库A口 交互工位13"); //A口
                    //LedDisplay("192.168.8.55", "38工位 D口", "空闲中", "整托空桶/重桶入库分拣交互工位38"); //D口
                    //return;
 
                    //// 手动设置各工位状态
                    //plc.SetPlcDBValue(1101, "Int", "100", "420.0");                                              // PLC控制流程字
                    //var aa = plc.SetPlcDBValue(1101, "String", "T2300001", "400.0");                                      // 托盘号
                    //plc.SetPlcDBValue(1101, "Int", "70", "424.0");                                               // 任务类型  70满桶子母托入 80满桶母托入
                    //plc.SetPlcDBValue(1101, "Int", "60", "426.0");                                               // 物料类型  60:满桶字母托盘 70:满桶母托盘
                    //plc.SetPlcDBValue(1101, "Byte", "1", "428.0");                                                // 目标工位号
                    //plc.SetPlcDBValue(1101, "Byte", "1", "429.0");                                               // 字母托盘状态 0无 1有
                    //plc.SetPlcDBValue(1101, "Byte", "1", "430.0");                                                // 物料数量
                    //plc.SetPlcDBValue(1101, "Real", "200", "432.0");                                             // 物料重量
                    //plc.SetPlcDBValue(1101, "Byte", "0", "431.0");                                                // 拆跺数量
 
                    // 读取
                    //string plcValue = "";
                    //plcValue = plc.GetPlcDBValue(101, "String", "20.0");
 
 
                    //bool inBl = plc.SetPlcDBValue(101, "String", "T2300001", "20.0");
                    //plcValue = plc.GetPlcDBValue(101, "String", "20.0");
 
                    //plcValue = plc.GetPlcDBValue(101, "Int", "82.0");
 
                    ////bool inBl = plc.SetPlcDBValue(101, "Int", "1", "82.0");
                    ////plc.SetPlcDBValue(1101, "String", "T2300001", "10.0");
                    //plcValue = "";
                    //plcValue = plc.GetPlcDBValue(1101, "Int", "20.0");
                    ////plc.SetPlcDBValue(1101, "Int", "99", "22.0");
                    //plcValue = plc.GetPlcDBValue(1101, "Int", "424.0");
                    ////plc.SetPlcDBValue(1101, "Int", "99", "24.0");
                    //plcValue = plc.GetPlcDBValue(1101, "Int", "426.0");
                    ////plc.SetPlcDBValue(1101, "Int", "99", "26.0");
                    //plcValue = plc.GetPlcDBValue(1101, "Byte", "428.0");
                    ////plc.SetPlcDBValue(1101, "Byte", "99", "28.0");
                    //plcValue = plc.GetPlcDBValue(1101, "Byte", "429.0");
                    ////plc.SetPlcDBValue(1101, "Byte", "99", "29.0");
                    //plcValue = plc.GetPlcDBValue(1101, "Byte", "430.0");
                    ////plc.SetPlcDBValue(1101, "Byte", "99", "30.0");
                    //plcValue = plc.GetPlcDBValue(1101, "Byte", "431.0");
                    ////plc.SetPlcDBValue(1101, "Byte", "99", "31.0");
                    //plcValue = plc.GetPlcDBValue(1101, "Real", "432.0");
                    ////plc.SetPlcDBValue(1101, "Real", "99", "32.0");
 
 
 
 
 
                    // 接口测试 
                    //WCSPalletBind model = new WCSPalletBind();
                    //model.PalletNo = "T2300001";
                    //model.TaskType = "001";
                    //model.SubPallet = "0";
                    //model.SkuQty = 10;
                    //model.SkuWeight = "235";
 
                    //model.SkuType = "001";
                    //model.LotNo = "2305190";
                    //model.SupplierLot = "";
                    //DALWcsMessage wcsMySql = new DALWcsMessage();
                    //string endLocat = "";                           // 取货工位号
                    //string strMsg = wcsMySql.GetLocation("T2300001", model, ref endLocat);
 
                    //plc.ClosePlc();
                    IsRunTast = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                //IsRunTast = true;
            }
        }
 
        /// <summary>
        /// 堆垛机
        /// </summary>
        //[Obsolete]
        public static void Stackers(object source, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                if (IsRunStacker)
                {
                    IsRunStacker = false;
                    // 判断wcs服务是否开启
                    if (!fuwu)
                    {
                        IsRunStacker = true;
                        return;
                    }
 
                    // 判断运行的服务器
                    bool sqlBool = false;
                    DALWcsMessage wcsSql = new DALWcsMessage();
                    try
                    {
                        sqlBool = wcsSql.GetIsWcsAutoDB1();            // 抛出异常,证明DB2在运行 
                    }
                    catch
                    {
                        IsRunStacker = true;
                        return;
                    };
 
                    PlcInteraction plcInteraction = new PlcInteraction();
                    while (fuwu && sqlBool)
                    {
                        if (plcStackVal1.Length > 0 || plcStackVal2.Length > 0)
                        {
                            if (plcStackVal1.Length > 0)
                            {
                                // 重新连接plc
                                plcStack1 = new PlcIO("192.168.21.30", 1, ref plcStackVal1);
                            }
 
                            if (plcStackVal2.Length > 0)
                            {
                                // 重新连接plc
                                plcStack2 = new PlcIO("192.168.21.40", 1, ref plcStackVal2);
                            }
                        }
                        else
                        {
                            // 自动模式
                            DataRow[] ipRows = PlcIpDt.Select(" Type = '0' ");
                            foreach (DataRow ipRow in ipRows)
                            {
                                if (ipRow["IP"].ToString() == "192.168.21.30")
                                {
                                    plcInteraction.StackersInteraction2(ipRow, PlcInfoDt, plcStack1, plcConvey);
                                }
                                else if (ipRow["IP"].ToString() == "192.168.21.40")
                                {
                                    plcInteraction.StackersInteraction2(ipRow, PlcInfoDt, plcStack2, plcConvey);
                                }
 
 
                            }
 
                        }
                    }
 
                    IsRunStacker = true;
                }
            }
            catch (Exception ex)
            {
                IsRunStacker = true;
                throw ex;
            }
        }
 
        /// <summary>
        /// 托盘运输线
        /// </summary>
        public static void Conveyors(object source, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                if (IsRunConveyor)
                {
                    IsRunConveyor = false;
 
                    // 判断wcs服务是否开启
                    if (!fuwu)
                    {
                        IsRunConveyor = true;
                        return;
                    }
 
                    // 判断运行的服务器
                    bool sqlBool = false;
                    DALWcsMessage wcsSql = new DALWcsMessage();
                    try
                    {
                        // 抛出异常,证明DB2在运行
                        sqlBool = wcsSql.GetIsWcsAutoDB1();
                    }
                    catch
                    {
                        IsRunConveyor = true;
                        return;
                    };
 
                    Logger logger = LogManager.GetCurrentClassLogger();
                    logger.Error("ASDF", "定时监控:");
 
                    PlcInteraction plcInteraction = new PlcInteraction();
                    while (fuwu && sqlBool)
                    {
                        Thread.Sleep(100);
 
                        if (plcConveyVal.Length > 0 || plcStackVal1.Length > 0 || plcStackVal2.Length > 0)
                        {
                            plcConvey.ClosePlc();
                            plcStack1.ClosePlc();
                            plcStack2.ClosePlc();
                            plcConveyVal = "";
                            plcStackVal1 = "";
                            plcStackVal2 = "";
                            // 重新连接plc
                            plcConvey = new PlcIO("192.168.21.2", 1, ref plcConveyVal);
                            plcStack1 = new PlcIO("192.168.21.30", 1, ref plcStackVal1);
                            plcStack2 = new PlcIO("192.168.21.40", 1, ref plcStackVal2);
                            logger.Error($"重新连接:输送线:{plcConveyVal},跺机1:{plcStackVal1},跺机2:{plcStackVal2}", "输送线错误重新连接关闭");
                        }
                        else
                        {
                            try
                            {
                                // 输送线
                                DataRow[] ipRows = PlcIpDt.Select(" Type = '1' ");
                                foreach (DataRow ipRow in ipRows)
                                {
                                    plcInteraction.ConveyorsInteraction2(ipRow, PlcInfoDt, plcConvey, plcStack1, plcStack2);
                                }
 
                                // 堆垛机
                                DataRow[] ipRowsDJ = PlcIpDt.Select(" Type = '0' ");
                                foreach (DataRow ipRowDj in ipRowsDJ)
                                {
                                    if (ipRowDj["IP"].ToString() == "192.168.21.30")
                                    {
                                        plcInteraction.StackersInteraction2(ipRowDj, PlcInfoDt, plcStack1, plcConvey);
                                    }
                                    else if (ipRowDj["IP"].ToString() == "192.168.21.40")
                                    {
                                        plcInteraction.StackersInteraction2(ipRowDj, PlcInfoDt, plcStack2, plcConvey);
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                plcConvey.ClosePlc();
                                plcStack1.ClosePlc();
                                plcStack2.ClosePlc();
 
                                plcConveyVal = "OFF";
                                plcStackVal1 = "OFF";
                                plcStackVal2 = "OFF";
 
                                logger.Error("异常重连:" + ex.Message, "输送线错误重新连接关闭");
                            }
                        }
                    }
 
                    IsRunConveyor = true;
                }
            }
            catch (Exception ex)
            {
                IsRunConveyor = true;
                throw ex;
            }
        }
 
        /// <summary>
        /// 件箱运输线
        /// </summary>
        public static void BoxConveyors(object source, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                if (IsRunBoxConveyor)
                {
                    IsRunBoxConveyor = false;
 
                    // 判断wcs服务是否开启
                    if (!fuwu)
                    {
                        IsRunBoxConveyor = true;
                        return;
                    }
 
                    // 判断运行的服务器
                    bool sqlBool = false;
                    DALWcsMessage wcsSql = new DALWcsMessage();
                    try
                    {
                        // 抛出异常,证明DB2在运行
                        sqlBool = wcsSql.GetIsWcsAutoDB1();
                    }
                    catch
                    {
                        IsRunBoxConveyor = true;
                        return;
                    };
 
                    Logger logger = LogManager.GetCurrentClassLogger();
                    logger.Error("件箱输送线定时运行", "定时监控:");
 
                    PlcInteraction plcInteraction = new PlcInteraction();
                    while (fuwu && sqlBool)
                    {
                        Thread.Sleep(100);
 
                        if (plcBoxConveyVal.Length > 0)
                        {
                            plcBoxConvey.ClosePlc();
                            plcBoxConveyVal = "";
                            // 重新连接plc
                            plcBoxConvey = new PlcIO("192.168.21.2", 1, ref plcConveyVal);
                            logger.Error($"重新连接:件箱输送线:{plcBoxConveyVal}", "件箱输送线错误重新连接关闭");
                        }
                        else
                        {
                            try
                            {
                                // 件箱输送线
                                DataRow[] ipRows = PlcIpDt.Select(" Type = '2' ");
                                foreach (DataRow ipRow in ipRows)
                                {
                                    plcInteraction.BoxConveyorsInteraction2(ipRow, PlcInfoDt, plcConvey);
                                }
                            }
                            catch (Exception ex)
                            {
                                plcBoxConvey.ClosePlc();
 
                                plcBoxConveyVal = "OFF";
 
                                logger.Error("异常重连:" + ex.Message, "件箱输送线错误重新连接关闭");
                            }
                        }
                    }
 
                    IsRunBoxConveyor = true;
                }
            }
            catch (Exception ex)
            {
                IsRunBoxConveyor = true;
                throw ex;
            }
        }
 
        /// <summary>
        /// 跺机地址监控
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        public static void StackerAddre(object source, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                if (IsRunStackerAddre)
                {
                    IsRunStackerAddre = false;
                    // 判断wcs服务是否开启
                    if (!fuwu)
                    {
                        IsRunStacker = true;
                        return;
                    }
 
                    // 判断运行的服务器
                    bool sqlBool = false;
                    DALWcsMessage wcsSql = new DALWcsMessage();
                    try
                    {
                        sqlBool = wcsSql.GetIsWcsAutoDB1();            // 抛出异常,证明DB2在运行 
                    }
                    catch
                    {
                        IsRunStackerAddre = true;
                        return;
                    };
 
                    PlcInteraction plcInteraction = new PlcInteraction();
                    while (fuwu && sqlBool)
                    {
                        if (plcStackVal1.Length > 0 || plcStackVal2.Length > 0)
                        {
                            if (plcStackVal1.Length > 0)
                            {
                                // 重新连接plc
                                plcStack1 = new PlcIO("192.168.21.30", 1, ref plcStackVal1);
                            }
 
                            if (plcStackVal2.Length > 0)
                            {
                                // 重新连接plc
                                plcStack2 = new PlcIO("192.168.21.40", 1, ref plcStackVal2);
                            }
 
                            if (plcStackVal3.Length > 0)
                            {
                                // 重新连接plc
                                plcStack3 = new PlcIO("192.168.21.50", 1, ref plcStackVal3);
                            }
 
                            if (plcStackVal4.Length > 0)
                            {
                                // 重新连接plc
                                plcStack4 = new PlcIO("192.168.21.60", 1, ref plcStackVal4);
                            }
 
                            if (plcStackVal5.Length > 0)
                            {
                                // 重新连接plc
                                plcStack5 = new PlcIO("192.168.21.70", 1, ref plcStackVal5);
                            }
 
                            if (plcStackVal6.Length > 0)
                            {
                                // 重新连接plc
                                plcStack6 = new PlcIO("192.168.21.80", 1, ref plcStackVal6);
                            }
 
                            if (plcStackVal7.Length > 0)
                            {
                                // 重新连接plc
                                plcStack7 = new PlcIO("192.168.21.90", 1, ref plcStackVal7);
                            }
                        }
                        else
                        {
                            // 自动模式
                            DataRow[] ipRows = PlcIpDt.Select(" Type = '0' ");
                            foreach (DataRow ipRow in ipRows)
                            {
                                if (ipRow["IP"].ToString() == "192.168.21.30")
                                {
                                    plcInteraction.StackersAddreInteraction(ipRow, PlcInfoDt, plcStack1, plcConvey);
                                }
                                else if (ipRow["IP"].ToString() == "192.168.21.40")
                                {
                                    plcInteraction.StackersAddreInteraction(ipRow, PlcInfoDt, plcStack2, plcConvey);
                                }
                                else if (ipRow["IP"].ToString() == "192.168.21.50")
                                {
                                    plcInteraction.StackersAddreInteraction(ipRow, PlcInfoDt, plcStack3, plcConvey);
                                }
                                else if (ipRow["IP"].ToString() == "192.168.21.60")
                                {
                                    plcInteraction.StackersAddreInteraction(ipRow, PlcInfoDt, plcStack4, plcConvey);
                                }
                                else if (ipRow["IP"].ToString() == "192.168.21.70")
                                {
                                    plcInteraction.StackersAddreInteraction(ipRow, PlcInfoDt, plcStack5, plcConvey);
                                }
                                else if (ipRow["IP"].ToString() == "192.168.21.80")
                                {
                                    plcInteraction.StackersAddreInteraction(ipRow, PlcInfoDt, plcStack6, plcConvey);
                                }
                                else if (ipRow["IP"].ToString() == "192.168.21.90")
                                {
                                    plcInteraction.StackersAddreInteraction(ipRow, PlcInfoDt, plcStack7, plcConvey);
                                }
 
 
 
                            }
 
                        }
                    }
 
                    IsRunStackerAddre = true;
                }
            }
            catch (Exception ex)
            {
                IsRunStackerAddre = true;
                throw ex;
            }
        }
 
        /// <summary>
        /// 清除log日志
        /// </summary>
        public static void DeleteNlogFile(object source, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                //   时   分       秒
                // 得到 hour minute second 如果等于某个值就开始执行某个程序。
                int intHour = e.SignalTime.Hour;
                int intMinute = e.SignalTime.Minute;
                //int intSecond = e.SignalTime.Second;
                // 定制时间; 比如 在10:30 :00 的时候执行某个函数
                int iHour = 00;
                int iMinute = 05;
                //int iSecond = 00;
                // 设置 在每天晚上的23点50执行
                //if (intHour == iHour && intMinute == iMinute && intSecond == iSecond)
                if (intHour == iHour && intMinute == iMinute)
                {
 
                    int count = 0;
                    string[] files = Directory.GetFiles("E:\\server\\WcsServer\\LogFile");//路径需要更改
                    //string[] files = Directory.GetFiles("D:\\WMS\\JC08Wcs\\WCS-V1.0\\wms\\LogFile");
                    foreach (string file in files)
                    {
                        FileInfo fi = new FileInfo(file);
                        var a = fi.Name.Split('.');
                        a[0].ToDate();
                        if (a[0].ToDate() < DateTime.Now.AddMonths(-1))
                        {
                            count += 1;
                            fi.Delete();
                        }
                    }
                    Logger logger = LogManager.GetCurrentClassLogger();
                    if (count > 0)
                    {
                        logger.Error("清除WCS日志消息:清除成功");
                        //调用WMS清除日志接口
                        var response = Utility.Extra.HttpHelper.DoPost("http://192.168.220.137:8081/api/DownAPi/DeleteNlogFile", null);//路径需要更改
                        if (response != "清除成功")
                        {
                            logger.Error("清除WMS日志消息:清除成功");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger logger = LogManager.GetCurrentClassLogger();
                logger.Error("清除日志异常消息:" + ex.Message, "清除日志定时器错误");
            }
 
        }
 
        /// <summary>
        /// 获取当前工位交互流程字为多少
        /// </summary>
        public static string GetPlcOrWcsPos(string Ip, string Stat, string Plcpos)
        {
            #region 与PLC交互逻辑
            //DataRow[] iProws = null;
 
            //string type = "0";
 
            ////判断是输送线连接还是垛机连接
            //if (Ip == "192.168.8.40")
            //{
            //    type = "1";
            //    // 获取运输线交互IP集合
            //    iProws = PlcInfoDt.Select("Level = '0' and Type = '1' ");
            //}
            //else
            //{
            //    // 获取跺机交互IP集合
            //    iProws = PlcInfoDt.Select("Level = '0' and Type = '0' ");
            //}
 
 
            //// 连接运输线PlC
            ////string plcIp = ipRow["PlcIP"].ToString();
            //string plcStatus = "";                                                          // PLC连接状态
            //PlcIO plc = new PlcIO(Ip, 1, ref plcStatus);
            //// 循环连接运输线设备
            //foreach (DataRow ipRow in iProws)
            //{
            //    // 循环各跺机与PLC进行交互
            //    DataRow[] rows = PlcInfoDt.Select($"Level = '2' and Type = '{type}' and PlcIP='{Ip}' ");
            //    //rows.Select(a=>a.)
            //    rows = PlcInfoDt.Select($"StationNum = '{Stat}' and PlcPos = '{Plcpos}'");
            //    foreach (DataRow row in rows)
            //    {
            //        // 读取工位流程字
            //        string dbNumber = row["DbNumber"].ToString();
            //        string posType = row["PosType"].ToString();
            //        string plcPos = row["PlcPos"].ToString();
            //        string wcsPos = row["WcsPos"].ToString();
            //        string stationNum = row["StationNum"].ToString();
            //        string plcValue = plc.GetPlcDBValue(int.Parse(dbNumber), posType, plcPos);
 
            //        //判断工位号
            //        if (stationNum == Stat)
            //        {
            //            if (plcValue == "0" || plcValue == "10" || plcValue == "20" || plcValue == "21" || plcValue == "22" || plcValue == "100" || plcValue == "110" || plcValue == "120" || plcValue == "130" || plcValue == "140" || plcValue == "200" || plcValue == "210" || plcValue == "300" || plcValue == "310" || plcValue == "320" || plcValue == "330")
            //            {
            //                // 关闭设备连接
            //                plc.ClosePlc();
            //                return plcValue;
            //            }
            //            else
            //            {
            //                continue;
            //            }
            //        }
            //        else
            //        {
            //            continue;
            //        }
            //    }
            //}
 
 
            //// 关闭设备连接
            //plc.ClosePlc();
 
            return null;
            #endregion
 
        }
 
        /// <summary>
        ///// 获取当前工位偏移量值为多少
        /// </summary>
        public static PosNameVal GetPlcOrWcsPosVal(string plcInfoId)
        {
            #region 与PLC交互逻辑
            PosNameVal list = new PosNameVal();
            DALWcsMessage wcsMySql = new DALWcsMessage();
            DataTable posDt = wcsMySql.GetPlcPos(plcInfoId); //偏移量
 
            var plcInfo = PlcInfoDt.Select($"Id={plcInfoId} ")[0];
            var ipInfo = PlcIpDt.Select($"Id = {plcInfo["PlcIP"].ToString()} ")[0];
 
            var dbNumber = plcInfo["DbNumber"].ToString();//db块
            var infoPlcPos = plcInfo["PlcPos"].ToString();//plc流程字值
            var infoPosType = plcInfo["PosType"].ToString();//流程字类型 
            var infoWcsPos = plcInfo["WcsPos"].ToString();//wcs流程字值
 
            string plcStatus = "";  // PLC连接状态
            PlcIO plc = new PlcIO(ipInfo["IP"].ToString(), 1, ref plcStatus);
            if (plcStatus.Length <= 0)
            {
                try
                {
                    string plcValue1 = plc.GetPlcDBValue(int.Parse(dbNumber), infoPosType, infoPlcPos);
                    list.PlcPos = plcValue1;
                    string plcValue2 = plc.GetPlcDBValue(int.Parse(dbNumber), infoPosType, infoWcsPos);
                    list.WcsPos = plcValue2;
 
                    foreach (var row in posDt.Select())
                    {
                        // 读取工位流程字
                        string posType = row["PosType"].ToString();
                        string plcPos = row["PlcPos"].ToString();
                        string name = row["Name"].ToString();
                        string plcValue = plc.GetPlcDBValue(int.Parse(dbNumber), posType, plcPos);
 
                        #region 赋值
                        if (PosName.PlcTaskNo.ToString() == name)
                        {
                            list.PlcTaskNo = plcValue;
                        }
                        else if (PosName.PlcPalletNo.ToString() == name)
                        {
                            list.PlcPalletNo = plcValue;
                        }
                        else if (PosName.TaskNo.ToString() == name)
                        {
                            list.TaskNo = plcValue;
                        }
                        else if (PosName.PalletNo.ToString() == name)
                        {
                            list.PalletNo = plcValue;
                        }
                        else if (PosName.StartLocatNo.ToString() == name)
                        {
                            list.StartLocatNo = plcValue;
                        }
                        else if (PosName.EndLocatNo.ToString() == name)
                        {
                            list.EndLocatNo = plcValue;
                        }
                        else if (PosName.StartRow.ToString() == name)
                        {
                            list.StartRow = plcValue;
                        }
                        else if (PosName.StartColumn.ToString() == name)
                        {
                            list.StartColumn = plcValue;
                        }
                        else if (PosName.StartLayer.ToString() == name)
                        {
                            list.StartLayer = plcValue;
                        }
                        else if (PosName.EndRow.ToString() == name)
                        {
                            list.EndRow = plcValue;
                        }
                        else if (PosName.EndColumn.ToString() == name)
                        {
                            list.EndColumn = plcValue;
                        }
                        else if (PosName.EndLayer.ToString() == name)
                        {
                            list.EndLayer = plcValue;
                        }
 
                        #endregion
                    }
                }
                catch (Exception ex)
                {
                    plc.ClosePlc();
                    throw ex;
                }
            }
 
            // 关闭设备连接
            plc.ClosePlc();
 
            return list;
            #endregion
        }
 
        /// <summary>
        /// 应用池回收的时候调用的方法
        /// </summary>
        public static void SetContent(string type)
        {
            Logger logger = LogManager.GetCurrentClassLogger();
            logger.Error(type + "执行该方法:", "iis自动回收机制");
 
        }
 
    }
}