ControlCenter.cs 61.3 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 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Web.Script.Serialization;
using RestSharp;
using common = DoubleLine.Common;

namespace BLL
{
    public class ControlCenter
    {
        //public delegate void StatusEvent(int idx);
        //public event StatusEvent Status;
        public delegate void ActionEvent(int idx, string s);
        public event ActionEvent ABB_ActionChanged;

        private bool loop;
        private Asa.File.Log log = common.log;
        private Thread tWeb;
        private List<BindType> bindRFID;
        private BindType packRFID;

        private bool part_Shelf_Enter = true;
        private int step_Shelf_Enter = 0;
        private ShelfEnter step_Shelf_Enter2 = ShelfEnter.FirstShelf;
        private string type_Need_Enter = "";
        private int time_Shelf_Enter = 0;
        private int smallEmpty_Enter;
        private int bigEmpty_Enter;
        private int packageEmpty_Enter;

        private bool part_Shelf_Ready = true;
        private ShelfReady step_Shelf_Ready = ShelfReady.JudgeCount;



        private bool part_ABB_Right = false;
        private int step_ABB_Right = 0;
        private bool start_ABB_Right = false;
        private int shelf_ABB_Right = 0;
        private int time_ABB_Right = 0;
        private int disk_ABB_Right = 0;
        private string virtualRfid_ABB_Right = "";
        private string realRfid_ABB_Right = "";
        private string code_ABB_Right = "";
        private string type2 = "";
        private int smallEmpty_Right;
        private int bigEmpty_Right;
        private int packageEmpty_Right;


        private bool part_ABB_Left = false;
        private int step_ABB_Left = 0;
        private bool start_ABB_Left = false;
        private int shelf_ABB_Left = 0;
        private int time_ABB_Left = 0;
        private int disk_ABB_Left = 0;
        private string virtualRfid_ABB_Left = "";
        private string realRfid_ABB_Left = "";
        private string code_ABB_Left = "";
        private string type3 = "";
        private int smallEmpty_Left;
        private int bigEmpty_Left;
        private int packageEmpty_Left;




        private bool part_ABB_Down = false;
        private int step_ABB_Down = 0;
        private int time_ABB_Down = 0;
        private string barcode_Down = "";
        /// <summary>
        /// 大料架上可放包装料数量
        /// </summary>
        private int emptyInBig_Down;
        /// <summary>
        /// 包装料架上剩余的包装料数量
        /// </summary>
        private int reelInPackage_Down;
        /// <summary>
        /// 剩余的包装料任务
        /// </summary>
        private int packageTask_Down;
        private int packageLoc_Down;
        private int bigLoc_Down;
        private string bigRfid_Down = "";
        private string realBigRfid_Down = "";



        private System.Collections.Concurrent.ConcurrentQueue<string> _barcode;
        private System.Collections.Concurrent.ConcurrentQueue<string> _rfidLoc;
        private System.Collections.Concurrent.ConcurrentQueue<string> _robotIndex;

        //public event Common.StatusEvent IOStatus;
        //public event Common.OutTextEvent AGVText;

        private const int SLEEP = 50;


        private enum ABB_Step
        {
            /// <summary>
            /// 检查信号
            /// </summary>
            CheckSignal,
            /// <summary>
            /// 延迟
            /// </summary>
            Delay,
            GetShelf,
            GetDisk,
            GetStart,
            GetEnd,
            PutStart,
            PutEnd,
            /// <summary>
            /// 架子到达工位1左侧
            /// </summary>
            ShelfArrive

        }

        private enum ShelfEnter
        {
            Reset,
            /// <summary>
            /// 第一个料架
            /// </summary>
            FirstShelf,
            /// <summary>
            /// 需要C料架
            /// </summary>
            NeedC,
            /// <summary>
            /// 需要D料架
            /// </summary>
            NeedD,
            /// <summary>
            /// C料架到达前端
            /// </summary>
            ArriveC,
            /// <summary>
            /// D料架到达前端
            /// </summary>
            ArriveD,
            /// <summary>
            /// 料架准备好
            /// </summary>
            Ready,
            /// <summary>
            /// 等待
            /// </summary>
            Wait,
            Place2Leave
        }

        private enum ShelfReady
        {
            /// <summary>
            /// 判断数量,用于是否需要放行料架
            /// </summary>
            JudgeCount
        }



        /// <summary>
        /// 控制中心
        /// </summary>
        public ControlCenter()
        {
            _barcode = new System.Collections.Concurrent.ConcurrentQueue<string>();
            _rfidLoc = new System.Collections.Concurrent.ConcurrentQueue<string>();
            _robotIndex = new System.Collections.Concurrent.ConcurrentQueue<string>();
            packRFID = new BindType();
            bindRFID = new List<BindType>();

            //log1 = new Asa.File.Log(Common.LOG_PATH, "ControlCenter");
            //log1.OutString("=====程序启动=====");

            //log2 = new Asa.File.Log(Common.LOG_PATH, "MiR_Command");
            //log2.OutString("=====程序启动=====");
        }

        /// <summary>
        /// 是否连接服务器
        /// </summary>
        public bool IsConn { private set; get; } = false;

        /// <summary>
        /// 打开
        /// </summary>
        public void Start()
        {
            common.log.OutInfo("开启控制中心");
            tWeb = new Thread(new ThreadStart(WebProcess)) { Name = "WebProcess" };
            loop = true;
            tWeb.Start();
        }

        /// <summary>
        /// 关闭
        /// </summary>
        public void Exit()
        {
            loop = false;
            common.log.OutInfo("关闭控制中心");
        }

        public bool ServerPause { set; get; } = false;

        public string TestBind()
        {
            string s = "";
            for (int i = 0; i < bindRFID.Count; i++)
            {
                s += i + " real=" + bindRFID[i].RealRFID + " virtual=" + bindRFID[i].VirtualRFID;
            }
            return s;
        }






        /// <summary>
        /// 和WebServers交互的处理线程
        /// </summary>
        private void WebProcess()
        {


            bool autoModeInit = false;

            //string smallEmpty2 = "";
            //string bigEmpty2 = "";
            //bool bind2 = false;
            //string smallEmpty3 = "";
            //string bigEmpty3 = "";
            //bool bind3 = false;

           


            while (loop)
            {
                Thread.Sleep(SLEEP);
                if (ServerPause) continue;

                #region 切换自动
                if (common.LineDouble.AutoMode)
                {
                    if (!autoModeInit)
                    {
                        part_Shelf_Enter = true;
                        //part_Shelf_Ready = true;
                        //part_ABB_Right = false;
                        //part_ABB_Left = false;
                        //part_ABB_Down = false;

                        //step_Shelf_Enter = 0;
                        //step_Shelf_Enter2 = ShelfEnter.FirstShelf;
                        //step_ABB_Right = 0;
                        //step_ABB_Left = 0;
                        //step_ABB_Down = 0;

                        //time_Shelf_Enter = 0;
                        //time_ABB_Right = 0;
                        //time_ABB_Left = 0;
                        //time_ABB_Down = 0;

                        //start_ABB_Right = false;
                        //start_ABB_Left = false;

                        autoModeInit = true;
                        //bindRFID.Clear();
                        common.log.OutInfo("控制中心开启自动化");
                    }
                }
                else
                {
                    autoModeInit = false;
                    continue;
                }
                #endregion

                //架子进入工位
                if (part_Shelf_Enter)
                    Shelf_Enter_Action2();

                //架子准备好
                //if (part_Shelf_Ready)
                //    Shelf_Ready_Action();

                //右侧ABB
                if (part_ABB_Right && common.ABB_Info[0].IsOpen && common.LineDouble.Place1Ready)
                    ABB_Right_Action();

                //左侧ABB
                if (part_ABB_Left && common.ABB_Info[1].IsOpen && common.LineDouble.Place1Ready)
                    ABB_Left_Action();

                //下侧ABB
                if (part_ABB_Down && common.ABB_Info[2].IsOpen && common.LineDouble.Place2Ready)
                    ABB_Down_Action();
            }
        }

        private void Shelf_Enter_Action()
        {
            if (step_Shelf_Enter == 0)  //从web服务器读取所需料架
            {
                if (time_Shelf_Enter == 0)
                {
                    common.Web.ShelfFinish("", "", "", "", out smallEmpty_Enter, out bigEmpty_Enter, out packageEmpty_Enter);
                    
                    if (smallEmpty_Enter != 0)
                        type_Need_Enter = "D";
                    else if (bigEmpty_Enter != 0)
                        type_Need_Enter = "C";
                    else if (packageEmpty_Enter != 0)
                        type_Need_Enter = "C";
                    else
                        type_Need_Enter = "";

                    if (type_Need_Enter.Equals(""))
                    {
                        common.log.OutInfo("没有得到任务");
                        time_Shelf_Enter += SLEEP;
                        return;
                    }
                    else if (type_Need_Enter.Equals("D"))
                    {
                        common.LineDouble.NeedTypeD = DoubleLine.DeviceAction.Start;
                        common.log.OutInfo("需要D料架");
                        step_Shelf_Enter = 1;
                    }
                    else if (type_Need_Enter.Equals("C"))
                    {
                        common.LineDouble.NeedTypeC = DoubleLine.DeviceAction.Start;
                        common.log.OutInfo("需要C料架");
                        step_Shelf_Enter = 2;
                    }
                }
                else
                {
                    if (time_Shelf_Enter >= 2000)
                        time_Shelf_Enter = 0;
                    else
                        time_Shelf_Enter += SLEEP;
                }
            }
            else if (step_Shelf_Enter == 1)  //D料架
            {
                if (common.LineDouble.NeedTypeD == DoubleLine.DeviceAction.Stop)
                {
                    common.log.OutInfo("到达工位1前端");
                    common.LineDouble.GoPlace1 = DoubleLine.DeviceAction.Start;
                    step_Shelf_Enter = 3;
                }
                else if (common.LineDouble.NeedTypeD == DoubleLine.DeviceAction.Error)
                {
                    common.log.OutInfo("没有D料架");
                    step_Shelf_Enter = 0;
                    time_Shelf_Enter += SLEEP;
                }
            }
            else if (step_Shelf_Enter == 2)  //C料架
            {
                if (common.LineDouble.NeedTypeC == DoubleLine.DeviceAction.Stop)
                {
                    common.LineDouble.GoPlace1 = DoubleLine.DeviceAction.Start;
                    common.log.OutInfo("到达工位1前端");
                    step_Shelf_Enter = 3;
                }
                else if (common.LineDouble.NeedTypeC == DoubleLine.DeviceAction.Error)
                {
                    common.log.OutInfo("没有C料架");
                    step_Shelf_Enter = 0;
                    time_Shelf_Enter += SLEEP;
                }
            }
            else if (step_Shelf_Enter == 3)  //判断料架到位
            {
                if (common.LineDouble.GoPlace1 == DoubleLine.DeviceAction.Stop)
                {
                    common.log.OutInfo(type_Need_Enter + "料架到达工位1");


                    bindRFID.Add(new BindType(common.LineDouble.Place1RFID, ""));
                    for (int i = 0; i < bindRFID.Count; i++)
                        common.log.OutInfo("Key=" + bindRFID[i].RealRFID + ",Value=" + bindRFID[i].VirtualRFID);

                    step_Shelf_Enter = 4;
                    //part1 = false;
                    time_Shelf_Enter = 0;
                    step_ABB_Right = 0;
                    part_ABB_Right = true;
                    step_ABB_Left = 0;
                    part_ABB_Left = true;
                    step_ABB_Down = 0;
                    part_ABB_Down = false;
                }
                else if (common.LineDouble.GoPlace1 == DoubleLine.DeviceAction.Error)
                {
                    common.log.OutInfo("不能去工位1");
                    return;
                }
            }
            else if (step_Shelf_Enter == 4)
            {
                if (time_Shelf_Enter == 0)
                {
                    string barcode = "";
                    //if (!_barcode.TryDequeue(out barcode))
                    //    barcode = "";

                    string rfidLoc = "";
                    //if (!_rfidLoc.TryDequeue(out rfidLoc))
                    //    rfidLoc = "";

                    string robotIndex = "";
                    //if (!_robotIndex.TryDequeue(out robotIndex))
                    //    robotIndex = "";
                    common.Web.ShelfFinish(common.LineDouble.Place1RFID, barcode, rfidLoc, robotIndex, out smallEmpty_Enter, out bigEmpty_Enter, out packageEmpty_Enter);

                    time_Shelf_Enter = SLEEP;

                    if (common.LineDouble.Place2Count > 0)
                    {
                        if (packageEmpty_Enter == 0 && common.ABB_Info[2].PutEnd)
                        {
                            common.LineDouble.Place2Leave = DoubleLine.DeviceAction.Start;
                            part_ABB_Down = false;
                            step_Shelf_Enter = 8;
                        }
                    }
                    else if (common.LineDouble.Place1Count > 0 && common.LineDouble.Place1RFID[0] == 'D')
                    {
                        if (smallEmpty_Enter == 0 &&
                            !common.LineDouble.Place1Right &&
                            common.LineDouble.Place2Count == 0 &&
                            common.ABB_Info[0].PutEnd &&
                            common.ABB_Info[1].PutEnd)
                        {
                            common.LineDouble.Place1Leave = DoubleLine.DeviceAction.Start;
                            step_Shelf_Enter = 5;
                            if (bindRFID.Count == 1)
                            {
                                if (bindRFID[0].RealRFID.Equals(common.LineDouble.Place1RFID))
                                    bindRFID.RemoveAt(0);
                            }
                            else
                            {
                                if (bindRFID[0].RealRFID.Equals(common.LineDouble.Place1RFID))
                                    bindRFID.RemoveAt(0);
                                else if (bindRFID[1].RealRFID.Equals(common.LineDouble.Place1RFID))
                                    bindRFID.RemoveAt(1);
                            }
                            common.log.OutString("Place1RFID=" + common.LineDouble.Place1RFID);
                        }
                    }
                    else if (common.LineDouble.Place1Count > 0 && common.LineDouble.Place1RFID[0] == 'C')
                    {
                        if (bigEmpty_Enter == 0 &&
                            !common.LineDouble.Place1Right &&
                            common.LineDouble.Place2Count == 0 && 
                            common.ABB_Info[0].PutEnd &&
                            common.ABB_Info[1].PutEnd)
                        {
                            common.LineDouble.Place1ToPlace2 = DoubleLine.DeviceAction.Start;
                            if (bindRFID.Count == 1)
                            {
                                if (bindRFID[0].RealRFID.Equals(common.LineDouble.Place1RFID))
                                    bindRFID.RemoveAt(0);
                            }
                            else
                            {
                                if (bindRFID[0].RealRFID.Equals(common.LineDouble.Place1RFID))
                                    bindRFID.RemoveAt(0);
                                else if (bindRFID[1].RealRFID.Equals(common.LineDouble.Place1RFID))
                                    bindRFID.RemoveAt(1);
                            }
                            common.log.OutInfo("工位1到工位2");
                            step_Shelf_Enter = 6;
                        }
                    }
                }
                else
                {
                    if (time_Shelf_Enter >= 2000)
                        time_Shelf_Enter = 0;
                    else
                        time_Shelf_Enter += SLEEP;
                }

            }
            else if (step_Shelf_Enter == 5)
            {
                if (common.LineDouble.Place1Leave == DoubleLine.DeviceAction.Stop)
                {
                    //if (bindRFID[0].Key.Equals(common.LineDouble.Place1RFID))
                    //    bindRFID.RemoveAt(0);
                    //else if (bindRFID[1].Key.Equals(common.LineDouble.Place1RFID))
                    //    bindRFID.RemoveAt(1);
                    if (common.LineDouble.Place1Left)
                    {
                        common.LineDouble.GoPlace1 = DoubleLine.DeviceAction.Start;
                        step_Shelf_Enter = 7;
                        common.log.OutInfo("工位1左侧去工位1");
                    }
                    else
                    {
                        step_Shelf_Enter = 0;
                        time_Shelf_Enter = 0;
                        common.log.OutInfo("工位1出库完成,回到起始");
                    }
                }
            }
            else if (step_Shelf_Enter == 6)
            {
                if (common.LineDouble.Place1ToPlace2 == DoubleLine.DeviceAction.Stop)
                {
                    step_Shelf_Enter = 4;
                    part_ABB_Down = true;
                    step_ABB_Down = 0;
                    time_ABB_Down = 0;
                }
            }
            else if (step_Shelf_Enter == 7)
            {
                if (common.LineDouble.GoPlace1 == DoubleLine.DeviceAction.Stop)
                {
                    step_Shelf_Enter = 4;
                    time_Shelf_Enter = 0;
                }
            }
            else if (step_Shelf_Enter == 8)
            {
                if (common.LineDouble.Place2Leave == DoubleLine.DeviceAction.Stop)
                {
                    step_Shelf_Enter = 0;
                    time_Shelf_Enter = 0;
                }
            }
        }

        private void Shelf_Enter_Action2()
        {
            if (step_Shelf_Enter2 == ShelfEnter.Reset)
            {

            }
            else if (step_Shelf_Enter2 == ShelfEnter.FirstShelf)
            {
                if (time_Shelf_Enter == 0)
                {
                    common.Web.ShelfFinish("", "", "", "", out smallEmpty_Enter, out bigEmpty_Enter, out packageEmpty_Enter);
                    if (smallEmpty_Enter != 0)
                    {
                        type_Need_Enter = "D";
                        step_Shelf_Enter2 = ShelfEnter.NeedD;
                    }
                    else if (bigEmpty_Enter != 0)
                    {
                        type_Need_Enter = "C";
                        step_Shelf_Enter2 = ShelfEnter.NeedC;
                    }
                    else if (packageEmpty_Enter != 0)
                    {
                        type_Need_Enter = "C";
                        step_Shelf_Enter2 = ShelfEnter.NeedC;
                    }
                    else
                    {
                        type_Need_Enter = "";
                        common.log.OutInfo("没有得到任务");
                        time_Shelf_Enter += SLEEP;
                    }
                }
                else
                {
                    //没有任务的时候,每2s调用一次接口
                    if (time_Shelf_Enter >= 2000)
                        time_Shelf_Enter = 0;
                    else
                        time_Shelf_Enter += SLEEP;
                }
            }
            else if (step_Shelf_Enter2 == ShelfEnter.NeedC)
            {
                common.LineDouble.NeedTypeC = DoubleLine.DeviceAction.Start;
                step_Shelf_Enter2 = ShelfEnter.ArriveC;
                common.log.OutInfo("需要C料架");
            }
            else if (step_Shelf_Enter2 == ShelfEnter.NeedD)
            {
                common.LineDouble.NeedTypeD = DoubleLine.DeviceAction.Start;
                step_Shelf_Enter2 = ShelfEnter.ArriveD;
                common.log.OutInfo("需要D料架");
            }
            else if (step_Shelf_Enter2 == ShelfEnter.ArriveC)
            {
                if (common.LineDouble.NeedTypeC == DoubleLine.DeviceAction.Stop)
                {
                    common.log.OutInfo("到达工位1前端");
                    common.LineDouble.GoPlace1 = DoubleLine.DeviceAction.Start;
                    step_Shelf_Enter2 = ShelfEnter.Ready;
                }
                else if (common.LineDouble.NeedTypeC == DoubleLine.DeviceAction.Error)
                {
                    common.log.OutInfo("没有C料架,或者有阻挡不能获取C料架");
                    step_Shelf_Enter2 = ShelfEnter.FirstShelf;
                    time_Shelf_Enter = SLEEP;
                }
            }
            else if (step_Shelf_Enter2 == ShelfEnter.ArriveD)
            {
                if (common.LineDouble.NeedTypeD == DoubleLine.DeviceAction.Stop)
                {
                    common.log.OutInfo("到达工位1前端");
                    common.LineDouble.GoPlace1 = DoubleLine.DeviceAction.Start;
                    step_Shelf_Enter2 = ShelfEnter.Ready;
                }
                else if (common.LineDouble.NeedTypeD == DoubleLine.DeviceAction.Error)
                {
                    common.log.OutInfo("没有D料架,或者有阻挡不能获取D料架");
                    step_Shelf_Enter2 = ShelfEnter.FirstShelf;
                    time_Shelf_Enter = SLEEP;
                }
            }
            else if (step_Shelf_Enter2 == ShelfEnter.Ready)
            {
                if (common.LineDouble.GoPlace1 == DoubleLine.DeviceAction.Stop)
                {
                    common.log.OutInfo(type_Need_Enter + "料架到达工位1");
                    int idx = bindRFID.FindIndex(s => s.RealRFID == common.LineDouble.Place1RFID);
                    if (idx == -1) bindRFID.Add(new BindType(common.LineDouble.Place1RFID, ""));
                    type_Need_Enter = "";
                    step_Shelf_Enter2 = ShelfEnter.Wait;
                    part_ABB_Left = true;
                    step_ABB_Left = 0;
                    part_ABB_Right = true;
                    step_ABB_Right = 0;

                    for (int i = 0; i < bindRFID.Count; i++)
                        common.log.OutInfo("real=" + bindRFID[i].RealRFID + ",virtual=" + bindRFID[i].VirtualRFID);
                }
                else if (common.LineDouble.GoPlace1 == DoubleLine.DeviceAction.Error)
                {
                    common.log.OutInfo("不能去工位1");
                }
            }
            else if (step_Shelf_Enter2 == ShelfEnter.Wait)
            {
                if (type_Need_Enter == "C")
                    step_Shelf_Enter2 = ShelfEnter.NeedC;
                else if (type_Need_Enter == "D")
                    step_Shelf_Enter2 = ShelfEnter.NeedD;
                else
                {
                    if (packRFID.Leave)
                    {
                        common.LineDouble.Place2Leave = DoubleLine.DeviceAction.Start;
                        step_Shelf_Enter2 = ShelfEnter.Place2Leave;
                    }
                    //common.Web.ShelfFinish("", "", "", "", out smallEmpty_Enter, out bigEmpty_Enter, out packageEmpty_Enter);
                    //if (smallEmpty_Enter == 0)
                    //{
                    //}
                    //else if (bigEmpty_Enter == 0)
                    //{
                    //}
                    //else if (packageEmpty_Enter == 0)
                    //{
                    //}
                    //else
                    //{
                    //}
                }
            }
            else if (step_Shelf_Enter2 == ShelfEnter.Place2Leave)
            {
                if (common.LineDouble.Place2Leave == DoubleLine.DeviceAction.Stop)
                {
                    step_Shelf_Enter2 = ShelfEnter.FirstShelf;
                }
            }
        }

        private void Shelf_Ready_Action()
        {
            if (step_Shelf_Ready == ShelfReady.JudgeCount)
            {
                if (common.LineDouble.Place1Ready)
                {
                    //common.Web.ShelfFinish(common.LineDouble.Place1RFID, "", "", "", out smallEmpty_Enter, out bigEmpty_Enter, out packageEmpty_Enter);

                }

                if (common.LineDouble.Place2Ready)
                {
                }

            }

        }

        private void ABB_Left_Action()
        {
            if (step_ABB_Left == 0)  //信号到位
            {
                Asa.IOModule.Box_Sta sta = common.IO_Info[4].Box.ReadDI((int)IO26_DI.X673);
                if (sta == Asa.IOModule.Box_Sta.On)
                {
                    if (shelf_ABB_Right == -1)
                    {
                    }
                    else if (common.LineDouble.Place1RFID.IndexOf("D") > -1 && shelf_ABB_Right < 47 && start_ABB_Right)
                    {
                        ABB_ActionChanged?.Invoke(1, "等待ABB1");
                    }
                    else if (common.LineDouble.Place1RFID.IndexOf("C") > -1 && shelf_ABB_Right < 7 && start_ABB_Right)
                    {
                        ABB_ActionChanged?.Invoke(1, "等待ABB1");
                    }
                    else
                    {
                        shelf_ABB_Left = -1;
                        start_ABB_Left = true;
                        time_ABB_Left = 0;
                        step_ABB_Left = 1;
                        ABB_ActionChanged?.Invoke(1, "收到信号");
                        common.log.OutInfo("左侧收到信号 X673=true");
                    }
                }
            }
            else if (step_ABB_Left == 1)
            {
                if (time_ABB_Left >= 1000)
                {
                    step_ABB_Left = 2;
                    common.log.OutInfo("延时1s");
                }
                else
                {
                    time_ABB_Left += SLEEP;
                }
            }
            else if (step_ABB_Left == 2)
            {
                common.Web.GetDiskInfo(2, common.LineDouble.Place1RFID, out disk_ABB_Left, out shelf_ABB_Left, out virtualRfid_ABB_Left, out realRfid_ABB_Left, out code_ABB_Left);

                if (realRfid_ABB_Left != "")  //有真实RFID
                {
                    if (realRfid_ABB_Left == common.LineDouble.Place1RFID)  //真实RFID是当前料架的RFID
                    {
                        step_ABB_Left = 21;
                    }
                    else
                    {
                        int idx = bindRFID.FindIndex(s => s.RealRFID == realRfid_ABB_Left);
                        if (idx == -1)
                        {
                            if (bindRFID.Count == 1)
                            {
                            }
                            else if (bindRFID.Count == 2)
                            {
                            }
                        }
                        else
                        {
                            common.log.OutInfo("切换料架");
                        }
                    }

                }
                else if (virtualRfid_ABB_Left != "")  //只有虚拟RFID
                {
                    int idx = bindRFID.FindIndex(s => s.VirtualRFID == virtualRfid_ABB_Left);
                    if (idx == -1)
                    {
                        if (virtualRfid_ABB_Left.IndexOf("C") > -1)  //需要C料架
                        {
                            idx = bindRFID.FindIndex(s => s.RealRFID.StartsWith("C") && s.VirtualRFID == "");
                            if (idx == -1)
                            {
                                type_Need_Enter = "C";
                                common.log.OutInfo("需要D料架");
                            }
                            else
                                bindRFID[idx].VirtualRFID = virtualRfid_ABB_Left;
                        }
                        else if (virtualRfid_ABB_Left.IndexOf("D") > -1)  //需要D料架
                        {
                            type_Need_Enter = "D";
                            common.log.OutInfo("需要D料架");
                        }
                    }
                    else
                    {
                        if (bindRFID[idx].RealRFID == common.LineDouble.Place1RFID)
                        {
                            step_ABB_Left = 21;
                        }
                        else
                        {
                            common.log.OutInfo("切换料架");
                        }
                    }
                }






                //if (realRfid_ABB_Left == "" && virtualRfid_ABB_Left != "")  //首盘补盘,第一次
                //{
                //    type3 = "";
                //    for (int i = 0; i < bindRFID.Count; i++)
                //    {
                //        if (bindRFID[i].RealRFID != "" && bindRFID[i].VirtualRFID == "")
                //        {
                //            common.log.OutInfo("3 Key=" + bindRFID[i].RealRFID + ",Value=" + bindRFID[i].VirtualRFID);
                //            if (virtualRfid_ABB_Left.IndexOf(bindRFID[i].RealRFID[0]) > -1)
                //            {
                //                bindRFID[i].VirtualRFID = virtualRfid_ABB_Left;
                //                type3 = bindRFID[i].RealRFID;
                //                break;
                //            }
                //        }
                //    }

                //    //用于第二次服务器还没有绑定的情况
                //    if (type3 == "")
                //    {
                //        for (int i = 0; i < bindRFID.Count; i++)
                //        {
                //            if (bindRFID[i].RealRFID != "" && bindRFID[i].VirtualRFID == virtualRfid_ABB_Left)
                //            {
                //                common.log.OutInfo("4 Key=" + bindRFID[i].RealRFID + ",Value=" + bindRFID[i].VirtualRFID);
                //                type3 = bindRFID[i].RealRFID;
                //                break;
                //            }
                //        }
                //    }


                //    if (type3 == "")
                //    {
                //        int idx3 = bindRFID.FindIndex(s => s.VirtualRFID == virtualRfid_ABB_Left);
                //        if (idx3 == -1) bindRFID.Add(new BindType("", virtualRfid_ABB_Left));
                //        step_ABB_Left = 5;
                //    }
                //    else
                //    {
                //        if (type3 == common.LineDouble.Place1RFID)
                //            step_ABB_Left = 21;
                //        else
                //            step_ABB_Left = 5;
                //    }
                //}
                //else if (realRfid_ABB_Left != "" && virtualRfid_ABB_Left != "")  //首盘第二次以上
                //{
                //    if (realRfid_ABB_Left == common.LineDouble.Place1RFID)
                //        step_ABB_Left = 21;
                //    else
                //        step_ABB_Left = 5;
                //}
                //else if (realRfid_ABB_Left != "" && virtualRfid_ABB_Left == "")  //补盘第二次以上
                //{
                //    if (realRfid_ABB_Left == common.LineDouble.Place1RFID)
                //        step_ABB_Left = 21;
                //    else
                //        step_ABB_Left = 5;
                //}
                for (int i = 0; i < bindRFID.Count; i++)
                    common.log.OutInfo("3RFID real=" + bindRFID[i].RealRFID + ",virtual=" + bindRFID[i].VirtualRFID);

            }
            else if (step_ABB_Left == 21)
            {
                if (common.LineDouble.Place1RFID.IndexOf("D") > -1 && shelf_ABB_Left > 46 && start_ABB_Right)
                { }
                else if (common.LineDouble.Place1RFID.IndexOf("C") > -1 && shelf_ABB_Left > 6 && start_ABB_Right)
                { }
                else
                {
                    step_ABB_Left = 3;
                    common.log.OutInfo("左侧21 RFID=" + common.LineDouble.Place1RFID + ",shelf_left=" + shelf_ABB_Left + ",start_right=" + start_ABB_Right);

                }
            }
            else if (step_ABB_Left == 3)
            {
                if (common.LineDouble.Place1Ready)
                {
                    common.ABB.MoveGet(1, "p" + disk_ABB_Left, common.ABB_Info[1].Speed);
                    ABB_ActionChanged?.Invoke(1, "moveget p" + disk_ABB_Left);
                    common.log.OutInfo("ABB2 moveget 开始");
                    step_ABB_Left = 31;
                }
            }
            else if (step_ABB_Left == 31)
            {
                if (common.ABB_Info[1].GetEnd)
                {
                    ABB_ActionChanged?.Invoke(1, "moveget 完成");
                    common.log.OutInfo("ABB2 moveget 完成");
                    step_ABB_Left = 4;
                }
            }
            else if (step_ABB_Left == 4)
            {
                string pointLeft = common.LineDouble.Place1RFID.ToLower()[0] + "p" + shelf_ABB_Left.ToString();
                common.ABB.MovePut(1, pointLeft, common.ABB_Info[1].Speed);
                ABB_ActionChanged?.Invoke(1, "moveput " + pointLeft);
                common.log.OutInfo("ABB2 moveput 开始");
                step_ABB_Left = 41;
            }
            else if (step_ABB_Left == 41)
            {
                if (common.ABB_Info[1].PutIn)
                {
                    common.log.OutInfo("ABB2 moveput 放入");
                    //_barcode.Enqueue(code_ABB_Left);
                    //_rfidLoc.Enqueue(shelf_ABB_Left.ToString());
                    //_robotIndex.Enqueue("2");

                    common.Web.ShelfFinish(common.LineDouble.Place1RFID, code_ABB_Left, shelf_ABB_Left.ToString(), "1", out smallEmpty_Left, out bigEmpty_Left, out packageEmpty_Left);
                    if (common.LineDouble.Place1RFID.StartsWith("D"))
                    {
                        if (smallEmpty_Left == 0)
                        {
                            int idx = bindRFID.FindIndex(s => s.RealRFID == common.LineDouble.Place1RFID);
                            if (idx > -1) bindRFID[idx].Leave = true;
                        }
                    }
                    else if (common.LineDouble.Place1RFID.StartsWith("C"))
                    {
                        if (bigEmpty_Left == 0)
                        {
                            int idx = bindRFID.FindIndex(s => s.RealRFID == common.LineDouble.Place1RFID);
                            if (idx > -1) bindRFID[idx].Leave = true;
                        }
                    }

                    step_ABB_Left = 42;
                }
            }
            else if (step_ABB_Left == 42)
            {
                if (common.ABB_Info[1].PutEnd)
                {
                    step_ABB_Left = 0;
                    start_ABB_Left = false;

                    _barcode.Enqueue(code_ABB_Left);
                    _rfidLoc.Enqueue(shelf_ABB_Left.ToString());
                    _robotIndex.Enqueue("2");

                    ABB_ActionChanged?.Invoke(1, "moveput 完成");
                    common.log.OutInfo("ABB2 moveput 完成");
                }
            }
            else if (step_ABB_Left == 5)
            {
                if (!start_ABB_Right)
                {
                    if (common.LineDouble.Place1Count == 1)  //工位只有一个架子
                    {
                        if (virtualRfid_ABB_Left.Contains("C"))
                        {
                            common.LineDouble.NeedTypeC = DoubleLine.DeviceAction.Start;
                            common.log.OutInfo("需要C料架");
                        }
                        else if (virtualRfid_ABB_Left.Contains("D"))
                        {
                            common.LineDouble.NeedTypeD = DoubleLine.DeviceAction.Start;
                            common.log.OutInfo("需要D料架");
                        }
                        else
                        {
                            common.log.OutInfo("无法识别");
                        }
                        step_ABB_Left = 6;
                    }
                    else if (common.LineDouble.Place1Count == 2)
                    {
                        common.LineDouble.PlaceMove = DoubleLine.DeviceAction.Start;
                        common.log.OutInfo("料架开始左右切换");
                        step_ABB_Left = 7;
                    }
                }
            }
            else if (step_ABB_Left == 6)
            {
                if (common.LineDouble.NeedTypeC == DoubleLine.DeviceAction.Stop && 
                    common.LineDouble.NeedTypeD == DoubleLine.DeviceAction.Stop)
                {
                    common.LineDouble.PlaceMove = DoubleLine.DeviceAction.Start;
                    common.log.OutInfo("料架开始左右切换");
                    step_ABB_Left = 7;
                }
            }
            else if (step_ABB_Left == 7)
            {
                if (common.LineDouble.PlaceMove == DoubleLine.DeviceAction.Stop &&
                    common.LineDouble.PlaceLeft == DoubleLine.DeviceAction.Stop &&
                    common.LineDouble.PlaceRight == DoubleLine.DeviceAction.Stop)
                {
                    step_ABB_Left = 3;
                    common.log.OutInfo("料架切换完成");
                    if (type3.Equals(""))
                    {
                        bindRFID[bindRFID.Count - 1].RealRFID = common.LineDouble.Place1RFID;
                    }
                }
            }
            else if (step_ABB_Left == 8)
            {
                if (common.LineDouble.Place1Leave == DoubleLine.DeviceAction.Stop)
                {
                    if (common.LineDouble.Place1Count > 0)
                        common.LineDouble.GoPlace1 = DoubleLine.DeviceAction.Start;
                    step_ABB_Right = 9;
                }
            }
            else if (step_ABB_Left == 9)
            {
                if (common.LineDouble.GoPlace1 == DoubleLine.DeviceAction.Stop)
                {
                    part_Shelf_Enter = true;
                    part_ABB_Right = false;
                    part_ABB_Left = false;
                    step_Shelf_Enter = 0;
                    start_ABB_Left = false;
                }
            }

        }

        private void ABB_Right_Action()
        {
            if (step_ABB_Right == 0)  //信号到位
            {
                Asa.IOModule.Box_Sta sta = common.IO_Info[5].Box.ReadDI((int)IO27_DI.X683);
                if (sta == Asa.IOModule.Box_Sta.On)
                {
                    if (shelf_ABB_Left == -1)
                    {
                    }
                    else if (common.LineDouble.Place1RFID.IndexOf("D") > -1 && shelf_ABB_Left > 46 && start_ABB_Left)
                    {
                        ABB_ActionChanged?.Invoke(0, "等待ABB2");
                    }
                    else if (common.LineDouble.Place1RFID.IndexOf("C") > -1 && shelf_ABB_Left > 6 && start_ABB_Left)
                    {
                        ABB_ActionChanged?.Invoke(0, "等待ABB2");
                    }
                    else
                    {
                        shelf_ABB_Right = -1;
                        start_ABB_Right = true;
                        time_ABB_Right = 0;
                        step_ABB_Right = 1;
                        ABB_ActionChanged?.Invoke(0, "收到信号");
                        common.log.OutInfo("右侧收到信号 X683=true");
                    }
                }
            }
            else if (step_ABB_Right == 1)
            {
                if (time_ABB_Right >= 500)
                {
                    step_ABB_Right = 2;
                    common.log.OutInfo("延时500ms");
                }
                else
                {
                    time_ABB_Right += SLEEP;
                }
            }
            else if (step_ABB_Right == 2)
            {
                common.Web.GetDiskInfo(1, common.LineDouble.Place1RFID, out disk_ABB_Right, out shelf_ABB_Right, out virtualRfid_ABB_Right, out realRfid_ABB_Right, out code_ABB_Right);

                if (realRfid_ABB_Right != "")  //有真实RFID
                {
                    if (realRfid_ABB_Right == common.LineDouble.Place1RFID)  //真实RFID是当前料架的RFID
                    {
                        step_ABB_Right = 21;
                    }
                    else
                    {
                        int idx = bindRFID.FindIndex(s => s.RealRFID == realRfid_ABB_Right);
                        if (idx == -1)
                        {
                            if (bindRFID.Count == 1)
                            {
                            }
                            else if (bindRFID.Count == 2)
                            {
                            }
                        }
                        else
                        {
                            common.log.OutInfo("切换料架");
                        }
                    }

                }
                else if (virtualRfid_ABB_Right != "")  //只有虚拟RFID
                {
                    int idx = bindRFID.FindIndex(s => s.VirtualRFID == virtualRfid_ABB_Right);
                    if (idx == -1)
                    {
                        if (virtualRfid_ABB_Right.IndexOf("C") > -1)  //需要C料架
                        {
                            idx = bindRFID.FindIndex(s => s.RealRFID.StartsWith("C") && s.VirtualRFID == "");
                            if (idx == -1)
                            {
                                type_Need_Enter = "C";
                                common.log.OutInfo("需要C料架");
                            }
                            else
                            {
                                bindRFID[idx].VirtualRFID = virtualRfid_ABB_Right;
                                step_ABB_Right = 21;
                            }
                        }
                        else if (virtualRfid_ABB_Right.IndexOf("D") > -1)  //需要D料架
                        {
                            idx = bindRFID.FindIndex(s => s.RealRFID.StartsWith("D") && s.VirtualRFID == "");
                            if (idx == -1)
                            {
                                type_Need_Enter = "D";
                                common.log.OutInfo("需要D料架");
                            }
                            else
                            {
                                bindRFID[idx].VirtualRFID = virtualRfid_ABB_Right;
                                step_ABB_Right = 21;
                            }
                        }
                    }
                    else
                    {
                        if (bindRFID[idx].RealRFID == common.LineDouble.Place1RFID)
                        {
                            step_ABB_Right = 21;
                        }
                        else
                        {
                            common.log.OutInfo("切换料架");
                        }
                    }
                }








                //if (realRfid_ABB_Right == "" && virtualRfid_ABB_Right != "")  //首盘补盘,第一次
                //{
                //    type2 = "";
                //    for (int i = 0; i < bindRFID.Count; i++)
                //    {
                //        if (bindRFID[i].RealRFID != "" && bindRFID[i].VirtualRFID == "")
                //        {
                //            common.log.OutInfo("1 Key=" + bindRFID[i].RealRFID + ",Value=" + bindRFID[i].VirtualRFID);
                //            if (virtualRfid_ABB_Right.IndexOf(bindRFID[i].RealRFID[0]) > -1)
                //            {
                //                bindRFID[i].VirtualRFID = virtualRfid_ABB_Right;
                //                type2 = bindRFID[i].RealRFID;
                //                break;
                //            }
                //        }
                //    }

                //    //用于第二次服务器还没有绑定的情况
                //    if (type2 == "")
                //    {
                //        for (int i = 0; i < bindRFID.Count; i++)
                //        {
                //            if (bindRFID[i].RealRFID != "" && bindRFID[i].VirtualRFID == virtualRfid_ABB_Right)
                //            {
                //                common.log.OutInfo("2 Key=" + bindRFID[i].RealRFID + ",Value=" + bindRFID[i].VirtualRFID);
                //                type2 = bindRFID[i].RealRFID;
                //                break;
                //            }
                //        }
                //    }


                //    if (type2 == "")
                //    {
                //        int idx2 = bindRFID.FindIndex(s => s.VirtualRFID == virtualRfid_ABB_Right);
                //        if (idx2 == -1) bindRFID.Add(new BindType("", virtualRfid_ABB_Right));
                //        step_ABB_Right = 5;
                //    }
                //    else
                //    {
                //        if (type2 == common.LineDouble.Place1RFID)
                //            step_ABB_Right = 21;
                //        else
                //            step_ABB_Right = 5;
                //    }
                //}
                //else if (realRfid_ABB_Right != "" && virtualRfid_ABB_Right != "")  //首盘第二次以上
                //{
                //    if (realRfid_ABB_Right == common.LineDouble.Place1RFID)
                //        step_ABB_Right = 21;
                //    else
                //        step_ABB_Right = 5;
                //}
                //else if (realRfid_ABB_Right != "" && virtualRfid_ABB_Right == "")  //补盘第二次以上
                //{
                //    if (realRfid_ABB_Right == common.LineDouble.Place1RFID)
                //        step_ABB_Right = 21;
                //    else
                //        step_ABB_Right = 5;
                //}
                for (int i = 0; i < bindRFID.Count; i++)
                    common.log.OutInfo("real=" + bindRFID[i].RealRFID + ",virtual=" + bindRFID[i].VirtualRFID);

            }
            else if (step_ABB_Right == 21)
            {
                if (common.LineDouble.Place1RFID.IndexOf("D") > -1 && shelf_ABB_Right < 47 && start_ABB_Left)
                { }
                else if (common.LineDouble.Place1RFID.IndexOf("C") > -1 && shelf_ABB_Right < 7 && start_ABB_Left)
                { }
                else
                {
                    step_ABB_Right = 3;
                    common.log.OutInfo("右侧21 RFID=" + common.LineDouble.Place1RFID + ",shelf_right=" + shelf_ABB_Right + ",start_left=" + start_ABB_Left);

                }
            }
            else if (step_ABB_Right == 3)
            {
                if (common.LineDouble.Place1Ready)
                {
                    common.ABB.MoveGet(0, "p" + disk_ABB_Right, common.ABB_Info[0].Speed);
                    ABB_ActionChanged?.Invoke(0, "moveget p" + disk_ABB_Right);
                    common.log.OutInfo("ABB1 moveget 开始");
                    step_ABB_Right = 31;
                }
            }
            else if (step_ABB_Right == 31)
            {
                if (common.ABB_Info[0].GetEnd)
                {
                    ABB_ActionChanged?.Invoke(0, "moveget 完成");
                    common.log.OutInfo("ABB1 moveget 完成");
                    step_ABB_Right = 4;
                }
            }
            else if (step_ABB_Right == 4)
            {
                string pointRight = common.LineDouble.Place1RFID.ToLower()[0] + "p" + shelf_ABB_Right.ToString();
                common.ABB.MovePut(0, pointRight, common.ABB_Info[0].Speed);
                ABB_ActionChanged?.Invoke(0, "moveput " + pointRight);
                common.log.OutInfo("ABB1 moveput 开始");
                step_ABB_Right = 41;
            }
            else if (step_ABB_Right == 41)
            {
                if (common.ABB_Info[0].PutIn)
                {
                    common.log.OutInfo("ABB1 moveput 放入");
                    //_barcode.Enqueue(code_ABB_Right);
                    //_rfidLoc.Enqueue(shelf_ABB_Right.ToString());
                    //_robotIndex.Enqueue("1");

                    common.Web.ShelfFinish(common.LineDouble.Place1RFID, code_ABB_Right, shelf_ABB_Right.ToString(), "1", out smallEmpty_Right, out bigEmpty_Right, out packageEmpty_Right);
                    if (common.LineDouble.Place1RFID.StartsWith("D"))
                    {
                        if (smallEmpty_Right == 0)
                        {
                            int idx = bindRFID.FindIndex(s => s.RealRFID == common.LineDouble.Place1RFID);
                            if (idx > -1) bindRFID[idx].Leave = true;
                        }
                    }
                    else if (common.LineDouble.Place1RFID.StartsWith("C"))
                    {
                        if (bigEmpty_Right == 0)
                        {
                            int idx = bindRFID.FindIndex(s => s.RealRFID == common.LineDouble.Place1RFID);
                            if (idx > -1) bindRFID[idx].Leave = true;
                        }
                    }

                    step_ABB_Right = 42;
                }
            }
            else if (step_ABB_Right == 42)
            {
                if (common.ABB_Info[0].PutEnd)
                {
                    step_ABB_Right = 0;
                    start_ABB_Right = false;

                    //_barcode.Enqueue(code_ABB_Right);
                    //_rfidLoc.Enqueue(shelf_ABB_Right.ToString());
                    //_robotIndex.Enqueue("1");

                    ABB_ActionChanged?.Invoke(0, "moveput 完成");
                    common.log.OutInfo("ABB1 moveput 完成");
                }
            }
            else if (step_ABB_Right == 5)
            {
                if (!start_ABB_Left)
                {
                    if (common.LineDouble.Place1Count == 1)  //工位只有一个架子
                    {
                        if (virtualRfid_ABB_Right.Contains("C"))
                        {
                            common.LineDouble.NeedTypeC = DoubleLine.DeviceAction.Start;
                            common.log.OutInfo("需要C料架");
                        }
                        else if (virtualRfid_ABB_Right.Contains("D"))
                        {
                            common.LineDouble.NeedTypeD = DoubleLine.DeviceAction.Start;
                            common.log.OutInfo("需要D料架");
                        }
                        else
                        {
                            common.log.OutInfo("无法识别");
                        }
                        step_ABB_Right = 6;
                    }
                    else if (common.LineDouble.Place1Count == 2)
                    {
                        common.LineDouble.PlaceMove = DoubleLine.DeviceAction.Start;
                        common.log.OutInfo("料架左右切换");
                        step_ABB_Right = 7;
                    }
                }
            }
            else if (step_ABB_Right == 6)
            {
                if (common.LineDouble.NeedTypeC == DoubleLine.DeviceAction.Stop && 
                    common.LineDouble.NeedTypeD == DoubleLine.DeviceAction.Stop)
                {
                    common.LineDouble.PlaceMove = DoubleLine.DeviceAction.Start;
                    common.log.OutInfo("料架左右切换");
                    step_ABB_Right = 7;
                }
            }
            else if (step_ABB_Right == 7)
            {
                if (common.LineDouble.PlaceMove == DoubleLine.DeviceAction.Stop && 
                    common.LineDouble.PlaceLeft == DoubleLine.DeviceAction.Stop && 
                    common.LineDouble.PlaceRight == DoubleLine.DeviceAction.Stop)
                {
                    step_ABB_Right = 3;
                    common.log.OutInfo("料架切换完成");
                    if (type2.Equals(""))
                    {
                        bindRFID[bindRFID.Count - 1].RealRFID = common.LineDouble.Place1RFID;
                    }
                }
            }
            else if (step_ABB_Right == 8)
            {
                if (common.LineDouble.Place1Leave == DoubleLine.DeviceAction.Stop)
                {
                    if (common.LineDouble.Place1Count > 0)
                        common.LineDouble.GoPlace1 = DoubleLine.DeviceAction.Start;
                    step_ABB_Right = 9;
                }
            }
            else if (step_ABB_Right == 9)
            {
                if (common.LineDouble.GoPlace1 == DoubleLine.DeviceAction.Stop)
                {
                    part_Shelf_Enter = true;
                    part_ABB_Right = false;
                    part_ABB_Left = false;
                    step_Shelf_Enter = 0;
                    start_ABB_Right = false;
                }
            }

        }

        private void ABB_Down_Action()
        {
            if (step_ABB_Down == 0)
            {
                if (common.LinePack.RFID != "" || common.LinePack.RFID != "00")
                {
                    step_ABB_Down = 3;
                    time_ABB_Down = 0;
                }
                else
                {
                    if (time_ABB_Down == 0)
                    {
                        common.Web.GetPackInfo(common.LineDouble.Place2RFID, "", out barcode_Down, out emptyInBig_Down, out reelInPackage_Down, out packageTask_Down, out packageLoc_Down, out bigLoc_Down, out bigRfid_Down, out realBigRfid_Down);
                        if (emptyInBig_Down != 0) step_ABB_Down = 1;
                    }
                    else
                    {
                        if (time_ABB_Down > 2000)
                            time_ABB_Down = 0;
                        else
                            time_ABB_Down += SLEEP;
                    }
                }
            }
            else if (step_ABB_Down == 1)
            {
                if (common.LinePack.PlaceLeft)
                {
                    packRFID = new BindType();
                    common.LinePack.GoPlace = DoubleLine.DeviceAction.Start;
                    step_ABB_Down = 2;
                }
            }
            else if (step_ABB_Down == 2)
            {
                if (common.LinePack.GoPlace == DoubleLine.DeviceAction.Stop)
                {
                    step_ABB_Down = 3;
                    time_ABB_Down = 0;
                    //common.LinePack.RFID = common.RFID.ReadStr(common.RFID_Info[6].IP);
                }
                else if(common.LinePack.GoPlace == DoubleLine.DeviceAction.Error)
                {
                    step_ABB_Down = 1;
                }
            }
            else if (step_ABB_Down == 3)
            {
                if (time_ABB_Down == 0)
                {
                    common.Web.GetPackInfo(common.LineDouble.Place2RFID, common.LinePack.RFID, out barcode_Down, out emptyInBig_Down, out reelInPackage_Down, out packageTask_Down, out packageLoc_Down, out bigLoc_Down, out bigRfid_Down, out realBigRfid_Down);
                    if (emptyInBig_Down == 0)
                    {
                        packRFID.Leave = true;
                        step_ABB_Down = 0;
                        time_ABB_Down = 0;
                        part_ABB_Down = false;
                        common.log.OutInfo("放行大料架,emptyInBig=0");
                    }
                    if (reelInPackage_Down == 0)
                    {
                        if (common.LinePack.PlaceExist)
                        {
                            common.LinePack.PlaceLeave = DoubleLine.DeviceAction.Start;
                            step_ABB_Down = 9;
                            common.log.OutInfo("放行包装料架,reelInPackage=0");
                        }
                        else
                        {
                            step_ABB_Down = 0;
                            common.log.OutInfo("没有包装料架可以放行");
                        }
                    }
                    else
                    {
                        if (common.LinePack.PlaceExist)
                        {
                            if (packageLoc_Down > 0 && bigLoc_Down > 0)
                            {
                                if (packRFID.RealRFID == "" && packRFID.VirtualRFID == "")
                                {
                                    packRFID.RealRFID = realBigRfid_Down;
                                    packRFID.VirtualRFID = bigRfid_Down;
                                    step_ABB_Down = 4;
                                }
                                else
                                {
                                    if (packRFID.VirtualRFID == bigRfid_Down)
                                        step_ABB_Down = 4;
                                    else
                                        step_ABB_Down = 10;
                                }
                            }
                            else
                            {
                                step_ABB_Down = 0;
                                common.log.OutInfo("抓取位置错误");
                            }
                        }
                        else
                        {
                            step_ABB_Down = 0;
                            common.log.OutInfo("没有包装料架可以抓取");
                        }
                    }

                    time_ABB_Down += SLEEP;
                }
                else
                {
                    if (time_ABB_Down > 2000)
                        time_ABB_Down = 0;
                    else
                        time_ABB_Down += SLEEP;
                }
            }
            else if (step_ABB_Down == 4)
            {
                if (!common.LinePack.RobotBlock)
                {
                    common.ABB.MoveGet(2, "p" + packageLoc_Down, common.ABB_Info[2].Speed);
                    common.log.OutInfo("ABB3 moveget 开始");
                    step_ABB_Down = 5;
                }
            }
            else if (step_ABB_Down == 5)
            {
                if (common.ABB_Info[2].GetEnd)
                {
                    common.log.OutInfo("ABB3 moveget 完成");
                    step_ABB_Down = 6;
                }
            }
            else if (step_ABB_Down == 6)
            {
                string pointDown = common.LineDouble.Place2RFID[0] + "p" + bigLoc_Down;
                common.ABB.MovePut(2, pointDown, common.ABB_Info[2].Speed);
                common.log.OutInfo("ABB3 moveput 开始");
                step_ABB_Down = 7;
            }
            else if (step_ABB_Down == 7)
            {
                if (common.ABB_Info[2].PutIn)
                {
                    common.log.OutInfo("ABB3 moveput 放入");
                    common.Web.PackFinish(barcode_Down, common.LinePack.RFID, packageLoc_Down, common.LineDouble.Place2RFID, bigLoc_Down);
                    step_ABB_Down = 8;
                }
            }
            else if (step_ABB_Down == 8)
            {
                if (common.ABB_Info[2].PutEnd)
                {
                    step_ABB_Down = 3;
                    time_ABB_Down = 0;
                    common.log.OutInfo("ABB3 moveput 完成");
                }
            }
            else if (step_ABB_Down == 9)
            {
                if (common.LinePack.PlaceLeave == DoubleLine.DeviceAction.Stop)
                {
                    step_ABB_Down = 0;
                    common.log.OutInfo("包装料架离开工位");
                }
            }
            else if (step_ABB_Down == 10)
            {
                common.log.OutInfo("包装料架不一致");
                common.log.OutTextBox("包装料架不一致");
            }
        }

    }

    internal class BindType
    {
        internal string RealRFID;
        internal string VirtualRFID;
        internal bool Leave;

        internal BindType()
        {
            RealRFID = "";
            VirtualRFID = "";
            Leave = false;
        }

        internal BindType(string realRFID, string virtualRFID)
        {
            RealRFID = realRFID;
            VirtualRFID = virtualRFID;
        }
    }



}