TinStoreBean.cs 77.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 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870

using CodeLibrary;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System; 
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace OnlineStore.DeviceLibrary
{
    public partial class TinStoreBean : KTK_Store
    {
        private static bool IsIntSlvBlock = false;
        public string CID = "";
        public TieStoreConfig Config;
        public bool UseBuzzer = ConfigAppSettings.GetIntValue(Setting_Init.UseBuzzer).Equals(1);
        private System.Timers.Timer serverConnectTimer = new System.Timers.Timer();
        private System.Timers.Timer IoCheckTimer = new System.Timers.Timer();


        public TinStoreBean(TieStoreConfig config)
        {
            Init();
            serverConnectTimer = new System.Timers.Timer();
            serverConnectTimer.Interval = 1000;
            serverConnectTimer.AutoReset = true;
            serverConnectTimer.Enabled = false;
            serverConnectTimer.Elapsed += server_connect_timer_Tick;
            IoCheckTimer = new System.Timers.Timer();
            IoCheckTimer.Interval = 200;
            IoCheckTimer.AutoReset = true;
            IoCheckTimer.Enabled = false;
            IoCheckTimer.Elapsed += IoCheckTimer_Elapsed;
            //添加调试
            if (config.IsInDebug == 1)
            {
                IsDebug = true;
            }
            Name = ("锡膏料仓" + config.Id + " ").ToUpper();
            this.StoreID = config.Id;
            this.Config = config;


            moveAxisList = new List<ConfigMoveAxis>();
            MoveAxisConfig();
            List<TinStorePosition> positionList = CSVPositionReader<TinStorePosition>.getPositionList();
            PositionNumList = new List<string>();
            foreach (TinStorePosition position in positionList)
            {
                if (position.StoreId.Equals(StoreID))
                {
                    bool result = TinStorePosition.CheckPosition(position, Config);
                    if (result)
                    {
                        PositionNumList.Add(position.PositionNum);
                    }
                }
            }

            //初始化摄像机配置  
            CodeManager.LoadConfig();
            IOManager.Init();
            IOManager.instance.ConnectionIOList(Config.DIODeviceNameList);

            
            LoadCurrStirInfo();
            RefrigeratorController.Init(Config.Refrigerator_Port);
            RefrigeratorController.queryData(Config.Refrigerator_Port,out _, out _, out _);
            //Task.Run(() => {
            //    Task.Delay(1000).Wait();
            //    RefrigeratorController.Release(); });
            
            mainTimer.Enabled = false;
            if (ConfigAppSettings.GetIntValue(Setting_Init.App_AutoRun).Equals(1))
            {
                mainTimer.Enabled = true;
            }
            Thread.Sleep(300);
            CloseAllLed();
        }


        public override bool StartRun()
        {
            LogUtil.info(Name + "开始启动:" + StartTime.ToString());

            autoNext = false;
            mainTimer.Enabled = false;
            alarmType = StoreAlarmType.None;

            //急停按钮和气压检测需要一起判断
            IO_VALUE suddenBtn = IOManager.IOValue(IO_Type.SuddenStop_BTN);
            IO_VALUE airCheck = IOManager.IOValue(IO_Type.Airpressure_Check);
            IOManager.IOMove(IO_Type.Device_Led, IO_VALUE.HIGH);
            Task.Run(() => {
                for (int i = 0; i < 10; i++)
                {
                    LogUtil.info(Name + $"{i}:SuddenStop_BTN:{StoreManager.Config.StoreDIList.ContainsKey(IO_Type.SuddenStop_BTN)}:{suddenBtn}:{IOManager.IOValue(IO_Type.SuddenStop_BTN)}, Airpressure_Check:{StoreManager.Config.StoreDIList.ContainsKey(IO_Type.Airpressure_Check)}:{airCheck}");
                    Task.Delay(500).Wait();
                }
            });
            
            if (suddenBtn == IO_VALUE.HIGH && airCheck == IO_VALUE.HIGH)
            {
                lastAirCloseTime = DateTime.Now;
                if (!RunAxis(true))
                {
                    return false;
                }
                //启动温湿度服务器 
                HumitureController.OpenAll(new string[] { Config.Humiture_Warming_Port, Config.Humiture_Colding_Port });
                OKLEController.OpenAll(new string[] { Config.Weight_Left_Port, Config.Weight_Right_Port });
                runStatus = StoreRunStatus.HomeMoving;
                StartReset();
                StartTime = DateTime.Now;
                mainTimer.Enabled = true;
                IoCheckTimer.Enabled = true;
                serverConnectTimer.Enabled = true;

                return true;
            }
            else
            {
                if (suddenBtn.Equals(IO_VALUE.LOW))
                {
                    LogUtil.error(" (" + Name + ")启动出现错误:急停没开 !启动失败!.");
                }
                else
                {
                    LogUtil.error(" (" + Name + ")启动出现错误:没有气压信号 !启动失败!.");
                }
                return false;
            }
        }

        #region  复位处理


        public void MoveToP1()
        {
            //压紧轴回原点,叉子回到P1,关闭门旋转轴和升降轴回到P1
            MoveInfo.NewMove(MoveType.StoreReset);
            MoveInfo.NextMoveStep(StoreMoveStep.P01_InOutToP1);
            LogUtil.info(Name + "到待机状态,进出轴到P1");
            ACAxisMove(Config.InOut_Axis, Config.InOutAxis_P1, Config.InOutAxis_P1_Speed);
        }

        public override void Reset(bool isNeedClearAuto = true)
        {
            //复位之前先停止运行
            if (isNeedClearAuto)
            {
                autoNext = false;
            }
            MoveInfo.EndMove();
            StopAllAxis();
            runStatus = StoreRunStatus.Reset;
            if (!RunAxis(true))
            {
                LogUtil.info(Name + "复位时打开轴失败,需要再次复位,直接报警停止复位");
                return;
            }
            mainTimer.Enabled = false;
            isInPro = false;
            StartReset();
            mainTimer.Enabled = true;
        }

        private void CloseAllLed()
        {
            IOManager.IOMove(IO_Type.Alarm_HddLed, IO_VALUE.LOW);
            IOManager.IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW);
            IOManager.IOMove(IO_Type.RunSign_HddLed, IO_VALUE.LOW);
        }

        private void StartReset()
        {
            WarnMsg = "";
            isInSuddenDown = false;
            isNoAirCheck = false;
            CurrInOutCount = 0;
            CurrInOutACount = 0;
            CloseAllLed();
            IOManager.IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.HIGH);
            alarmType = StoreAlarmType.None;
            UpdateLastStatus(StoreStatus.ResetMove);
            MoveInfo.NewMove(MoveType.StoreReset);
            MoveInfo.NextMoveStep(StoreMoveStep.R01_InOutBack);
            CylinderMove(MoveInfo, IO_Type.Clamping_Tighten, IO_Type.Clamping_Relax);
            ACAxisHomeMove(Config.InOut_Axis);
            LogUtil.info(Name + "开始原点返回,清空左右侧参数信息,先把进出轴回原点");
            LeftOutParam = null;
            RightOutParam = null;
            FixtureOutParam = null;
            MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
        }

        protected override void ResetProcess()
        {
            if (MoveInfo.IsInWait)
            {
                CheckWait();
            }
            if (MoveInfo.IsInWait)
            {
                return;
            }
            switch (MoveInfo.MoveStep)
            {
                case StoreMoveStep.R01_InOutBack:
                    Thread.Sleep(200);
                    MoveInfo.NextMoveStep(StoreMoveStep.R02_InOutToP1);
                    ResetLog("复位: 进出轴回P1,提升搅拌定位气缸");
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                    ACAxisMove(Config.InOut_Axis, Config.InOutAxis_P1, Config.InOutAxis_P1_Speed);
                    
                    CylinderMove(MoveInfo, IO_Type.StirLocation_Down, IO_Type.StirLocation_Up);
                    //CylinderMove(MoveInfo, IO_Type.Door_Up, IO_Type.Door_Down);
                    OpenDoor(MoveInfo);
                    break;
                case StoreMoveStep.R02_InOutToP1:
                    //如果此时轴三还在报警,需要提示错误并等待 
                    if (ACServerManager.GetAlarmStatus(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue()) > 0)
                    {
                        WarnMsg = "进出轴报警!复位失败,请检查!";
                        LogUtil.error("进出轴报警!复位失败,请检查!");
                        return;
                    }
                    MoveInfo.NextMoveStep(StoreMoveStep.R03_OtherAxisBack_wait);
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                    ResetLog(" 复位:升降轴,旋转轴,搅拌轴,回温轴,冷藏轴原点返回,关闭冷藏门");
                    CylinderMove(MoveInfo, IO_Type.ColdDoor_Open, IO_Type.ColdDoor_Close);
                    ACAxisHomeMove(Config.Middle_Axis);
                    ACAxisHomeMove(Config.UpDown_Axis);
                    ACAxisHomeMove(Config.Stir_Axis);
                    ACAxisHomeMove(Config.Warming_Axis);
                    ACAxisHomeMove(Config.Colding_Axis);
                    break;
                case StoreMoveStep.R03_OtherAxisBack_wait:
                    MoveInfo.NextMoveStep(StoreMoveStep.R03_OtherAxisBack);
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                    break;
                case StoreMoveStep.R03_OtherAxisBack:
                    MoveInfo.NextMoveStep(StoreMoveStep.R04_AxisToP1);
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                    ResetLog("复位:旋转轴,升降轴,搅拌轴到待机点");
                    ACAxisMove(Config.Middle_Axis, Config.MiddleAxis_P1, Config.MiddleAxis_P1_Speed);
                    ACAxisMove(Config.UpDown_Axis, Config.UpDownAxis_OL_P1, Config.UpDownAxis_P1_Speed);
                    ACAxisMove(Config.Stir_Axis, Config.Stir_Axis_P1, Config.StirAxis_P1_Speed);
                    break;
                case StoreMoveStep.R04_AxisToP1:
                    MoveInfo.NextMoveStep(StoreMoveStep.R05_StartWork);
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                    ResetLog("复位:启动吹气冷气,冷藏旋转,回温旋转 ");
                    StartWork();
                    break;
                case StoreMoveStep.R05_StartWork:
                    CloseDoor(MoveInfo);
                    LogUtil.info(Name + "复位完成");
                    runStatus = StoreRunStatus.Runing;
                    MoveInfo.EndMove();
                    UpdateLastStatus(StoreStatus.StoreOnline);
                    if (alarmType.Equals(StoreAlarmType.None))
                    {
                        WarnMsg = "";
                    }
                    break;
                case StoreMoveStep.P01_InOutToP1:
                    MoveInfo.NextMoveStep(StoreMoveStep.P02_AxisToP1);
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                    ResetLog("复位: 进出轴回P1,冷藏门 ,搅拌气缸上升");
                    ACAxisMove(Config.InOut_Axis, Config.InOutAxis_P1, Config.InOutAxis_P1_Speed);
                    //      CylinderMove(MoveInfo, IO_Type.Door_Up, IO_Type.Door_Down);
                    
                    CylinderMove(MoveInfo, IO_Type.StirLocation_Down, IO_Type.StirLocation_Up);
                    break;
                case StoreMoveStep.P02_AxisToP1:                    
                    MoveInfo.NextMoveStep(StoreMoveStep.P03_StartWork);
                    Stir_Axis_ServOn();
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                    ResetLog("复位:启动吹气冷气,冷藏旋转,回温旋转,判断搅拌区是否需要搅拌 ");
                    StartWork();
                    if (CurrStirInfo.InStirWork && CurrStirInfo.MoveStatus.Equals(3))
                    {
                        if (CurrStirInfo.StopTime > DateTime.Now)
                        {
                            LogUtil.info(Name + "搅拌区【" + CurrStirInfo.StirParam.LogName + "】状态【" + CurrStirInfo.MoveStatus + "】结束时间【" + CurrStirInfo.StopTime.ToLongTimeString() + "】开始继续搅拌 ");
                            ACServerManager.SpeedMove(Config.Stir_Axis.DeviceName, Config.Stir_Axis.GetAxisValue(), Config.StirAxis_P1_Speed);
                        }
                    }
                    break;
                case StoreMoveStep.P03_StartWork:
                    LogUtil.info(Name + "到待机状态完成");

                    MoveInfo.EndMove();
                    UpdateLastStatus(StoreStatus.StoreOnline);
                    runStatus = StoreRunStatus.Runing;
                    if (alarmType.Equals(StoreAlarmType.None))
                    {
                        WarnMsg = "";
                    }
                    break;

                default: break;
            }
        }

        internal void MoveAxisConfig()
        {
            TieStoreConfig.ConfigAxis(Config);

            moveAxisList = new List<ConfigMoveAxis>();
            moveAxisList.Add(Config.Middle_Axis);
            moveAxisList.Add(Config.UpDown_Axis);
            moveAxisList.Add(Config.InOut_Axis);
            moveAxisList.Add(Config.Warming_Axis);
            moveAxisList.Add(Config.Colding_Axis);
            moveAxisList.Add(Config.Stir_Axis);

            this.AxisAlarmCodeMap = new Dictionary<string, AxisAlarmInfo>();
            foreach (ConfigMoveAxis axis in moveAxisList)
            {
                this.AxisAlarmCodeMap.Add(axis.GetNameStr(), new AxisAlarmInfo());
            }
        }

        #endregion
        /// <summary>
        /// 冷藏和回温区开始工作
        /// </summary>
        /// <param name="posType">1=冷藏区匀速旋转。2=回温区匀速旋转</param>
        private void StartWork(int posType = 0)
        {
            if (!AutoStartWork)
            {
                return;
            }
            //IOManager.IOMove(IO_Type.Colding_Start, IO_VALUE.HIGH);
            IOManager.IOMove(IO_Type.Warming_Start, IO_VALUE.HIGH);

            //匀速旋转
            if (posType.Equals(0) || posType.Equals(1))
            {
                if (ACServerManager.GetBusyStatus(Config.Colding_Axis.DeviceName, Config.Colding_Axis.GetAxisValue()).Equals(0))
                {
                    ACServerManager.SpeedMove(Config.Colding_Axis.DeviceName, Config.Colding_Axis.GetAxisValue(), Config.ColdingAxis_P1_Speed);
                }
            }
            if (posType.Equals(0) || posType.Equals(2) || posType >= 100)
            {
                if (ACServerManager.GetBusyStatus(Config.Warming_Axis.DeviceName, Config.Warming_Axis.GetAxisValue()).Equals(0))
                {
                    ACServerManager.SpeedMove(Config.Warming_Axis.DeviceName, Config.Warming_Axis.GetAxisValue(), Config.WarmingAxis_P1_Speed);
                }
            }
        }

        public bool AutoStartWork = true ;

        public bool RunAxis(bool isCheck)
        {
            //打开所有轴
            foreach (ConfigMoveAxis moveAxis in moveAxisList)
            {
                string portName = moveAxis.DeviceName;
                short slvAddr = moveAxis.GetAxisValue();
                ACServerManager.OpenPort(portName);
                Thread.Sleep(50);
                if (!IsIntSlvBlock)
                {
                    ACServerManager.InitSlvAddr(portName, slvAddr, moveAxis.TargetSpeed, moveAxis.AddSpeed, moveAxis.DelSpeed);
                    Thread.Sleep(100);
                }
                ACServerManager.AlarmClear(portName, slvAddr);
                Thread.Sleep(50);
                ACServerManager.ServoOn(portName, slvAddr);
            }
            Thread.Sleep(1000);
            //打开所有轴
            if (isCheck)
            {
                if (!OpenAllAxis())
                {
                    return false;
                }
            }
            IsIntSlvBlock = true;
            return true;
        }

        private bool OpenAllAxis()
        {
            //判断轴是否正常
            foreach (ConfigMoveAxis axis in moveAxisList)
            {
                if (ACServerManager.ServerOnStatus(axis.DeviceName, axis.GetAxisValue()))
                {
                    LogUtil.info(Name + "成功打开轴:" + axis.Explain);
                }
                else
                {
                    //清理报警,再重新打开一次
                    LogUtil.info(Name + "第一次打开轴" + axis.Explain + "失败,先清理一下报警,再重新打开一次");
                    ACServerManager.AlarmClear(axis.DeviceName, axis.GetAxisValue());
                    System.Threading.Thread.Sleep(1200);
                    ACServerManager.ServoOn(axis.DeviceName, axis.GetAxisValue());
                    System.Threading.Thread.Sleep(100);
                    if (ACServerManager.ServerOnStatus(axis.DeviceName, axis.GetAxisValue()))
                    {
                        LogUtil.info(Name + "清理报警后重新打卡轴成功:" + axis.Explain);
                    }
                    else
                    {
                        ACServerManager.ServoOff(axis.DeviceName, axis.GetAxisValue());

                        WarnMsg = Name + "打开轴" + axis.Explain + "失败 ";
                        LogUtil.info(Name + WarnMsg);
                        Alarm(StoreAlarmType.AxisAlarm, axis.ProName, WarnMsg, MoveInfo.MoveType);
                        return false;
                    }
                }
            }
            return true;
        }
        public  void Stir_Axis_ServOn() {
            ACServerManager.AlarmClear(Config.Stir_Axis.DeviceName, Config.Stir_Axis.GetAxisValue());
            Thread.Sleep(50);
            ACServerManager.ServoOn(Config.Stir_Axis.DeviceName, Config.Stir_Axis.GetAxisValue());
            Thread.Sleep(50);
        }
       public  void Stir_Axis_ServOff() { ACServerManager.ServoOff(Config.Stir_Axis.DeviceName, Config.Stir_Axis.GetAxisValue()); }
        public void CloseAllAxis()
        {
            LogUtil.info(Name + "关闭伺服");
            foreach (ConfigMoveAxis axis in moveAxisList)
            {
                ACServerManager.ServoOff(axis.DeviceName, axis.GetAxisValue());
            }
        }

        public override void StopRun()
        {
            runStatus = StoreRunStatus.Wait;
            autoNext = false;
            IoCheckTimer.Enabled = false;
            serverConnectTimer.Enabled = false;
            mainTimer.Enabled = false;
            StopMove(true);
            TimeSpan span = DateTime.Now - StartTime;
            IOManager.instance.CloseAllDO();
            lastAutoRun = IO_VALUE.LOW;
            LogUtil.info(Name + ",停止运行,总运行时间:" + span.ToString());
            mainTimer.Enabled = true;
        }

        public override void Alarm(StoreAlarmType alarmType, string alarmDetial, string alarmMsg, MoveType storeMoveType)
        {
            SaveAlarmInfo(alarmType, alarmDetial, alarmMsg, storeMoveType);
            autoNext = false;

            if (this.alarmType.Equals(alarmType) && alarmType != StoreAlarmType.SuddenStop && alarmType != StoreAlarmType.NoAirCheck)
            {
                return;
            }
            LogUtil.error(Name + " 报警,报警类型:" + alarmType);

            this.alarmType = alarmType;
            if (alarmType.Equals(StoreAlarmType.AxisAlarm) | alarmType.Equals(StoreAlarmType.AxisMoveError))
            {
                LogUtil.error(Name + "轴报警,停止运动,关闭轴,打开报警灯");
                StopMove(true);
            }
            else if (alarmType == StoreAlarmType.SuddenStop)
            {
                isInSuddenDown = true;
                LogUtil.error(Name + "收到急停信号,停止运动,关闭轴,打开报警灯 ");
                MoveInfo.EndMove();
                StopMove(true);
                UpdateLastStatus(StoreStatus.SuddenStop);
            }
            else if (alarmType.Equals(StoreAlarmType.NoAirCheck))
            {
                isNoAirCheck = true;
                LogUtil.error(Name + " 未检测到气压信号 ,停止运动,关闭轴,打开报警灯 ");

                MoveInfo.EndMove();
                StopMove(true);
                UpdateLastStatus(StoreStatus.SuddenStop);
            }
        }

        #region 定时器处理

        private bool InProcess = false;
        private Stopwatch stopwatch = new Stopwatch();
        private IO_VALUE preAirValue = IO_VALUE.HIGH;
        private IO_VALUE lastAutoRun = IO_VALUE.LOW;
        protected override void timersTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (InProcess && stopwatch.Elapsed.TotalSeconds < 30)
            {
                return;
            }
            try
            {
                InProcess = true;
                stopwatch.Restart();
                IoCheckProcess();
                TimerProcess();
                //检查运动轴报警
                if (runStatus > StoreRunStatus.Wait && (!isInSuddenDown) && (!isNoAirCheck))
                {
                    CheckAxisAlarm();
                }
            }
            catch (Exception ex)
            {
                LogUtil.error(Name + "定时处理出错:" + ex.ToString());
            }
            InProcess = false;
        }
        private void AirCheckProcess()
        {
            IO_VALUE currAirValue = IOManager.IOValue(IO_Type.Airpressure_Check);
            if (isInSuddenDown)
            {
                return;
            }
            if (isNoAirCheck)
            {
                return;
            }
            if (currAirValue.Equals(IO_VALUE.LOW))
            {
                //判断是否持续了3秒
                if (preAirValue.Equals(IO_VALUE.LOW))
                {
                    TimeSpan span = DateTime.Now - lastAirCloseTime;
                    if (span.TotalSeconds > Config.AirCheckSeconds)
                    {
                        WarnMsg = "未检测到气压信号";
                        preAirValue = IO_VALUE.LOW;
                        LogUtil.info("已持续【" + FormUtil.GetSpanStr(span) + "】未检测到气压信号,报警");
                        Alarm(StoreAlarmType.NoAirCheck, "2", WarnMsg, MoveType.None);
                        return;
                    }
                }
                else
                {
                    lastAirCloseTime = DateTime.Now;
                    isNoAirCheck = false;
                }
            }
            else
            {
                isNoAirCheck = false;
            }
            preAirValue = currAirValue;
        }

        private void IoCheckProcess()
        {
            DateTime time = DateTime.Now;
            if (runStatus.Equals(StoreRunStatus.Wait))
            {
                //取新的Io状态
                IO_VALUE autoSingle = IOManager.IOValue(IO_Type.AutoRun_Signal);
                if (ConfigAppSettings.GetIntValue(Setting_Init.App_AutoRun).Equals(1))
                {
                    if (autoSingle.Equals(IO_VALUE.HIGH) && lastAutoRun.Equals(IO_VALUE.LOW))
                    {
                        //没有启动时收到复位按钮,相当于启动按钮
                        LogUtil.info(Name + "没有启动时收到复位按钮,相当于启动按钮,开始调用启动方法!");
                        bool result = StartRun();
                        if (result.Equals(false))
                        {
                            LogUtil.error("料仓启动失败,继续等待下次启动!");
                            lastAutoRun = IO_VALUE.LOW;
                            mainTimer.Enabled = true;
                            return;
                        }
                    }
                    lastAutoRun = autoSingle;
                    return;
                }
                lastAutoRun = autoSingle;
            }
            //判断急停 
            else if (runStatus >= StoreRunStatus.HomeMoving)
            {
                //取新的Io状态 
                IO_VALUE suddenBtn = IOManager.IOValue(IO_Type.SuddenStop_BTN);
                IO_VALUE resetBtn = IOManager.IOValue(IO_Type.Reset_BTN);

                //急停按钮 
                if (suddenBtn.Equals(IO_VALUE.LOW))
                {
                    AirCheckProcess();
                }
                else if (resetBtn.Equals(IO_VALUE.HIGH))
                {
                    //收到复位信号,若报警直接复位,若不报警且无操作,回到待机点
                    if (alarmType.Equals(StoreAlarmType.None) && isInSuddenDown.Equals(false) && isNoAirCheck.Equals(false))
                    {
                        if (MoveInfo.MoveType.Equals(MoveType.None))
                        {
                            LogUtil.info("收到复位信号但是没有报警,且当前无操作,只回到待机点");
                            MoveToP1();
                        }
                        else
                        {
                            LogUtil.info("收到复位信号但是已经在" + MoveInfo.MoveType + "处理中,且无报警,不处理");
                            //WarnMsg = "收到复位信号但是已经在" + StoreMove.MoveType + "处理中,且无报警,不处理";
                        }
                    }
                    else
                    {
                        //判断已经在复位中并且没有报警,不需要重新复位
                        if (MoveInfo.MoveType.Equals(MoveType.StoreReset) && alarmType.Equals(StoreAlarmType.None))
                        {
                            LogUtil.error("收到复位信号:已经在复位中且没有报警,不需要重新复位!");
                        }
                        else
                        {
                            //收到复位信号
                            LogUtil.info("收到复位信号,自动复位");
                            WarnMsg = "收到复位信号,自动复位";
                            Reset();
                        }
                    }
                }
            }

            //ShowTimeLog("复位和启动按钮");
            ////检查运动轴报警
            //if (storeRunStatus > StoreRunStatus.Wait && (!isInSuddenDown) )
            //{
            //    ShowTimeLog("开始检测轴报警");
            //    CheckAxisAlarm(); 
            //    ShowTimeLog("轴报警检测完成");
            //}
        }

        private void IoCheckTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            //判断急停 
            if (runStatus >= StoreRunStatus.HomeMoving)
            {
                if (IOManager.IOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.LOW))
                {
                    if (isInSuddenDown.Equals(false))
                    {
                        isInSuddenDown = true;
                        LogUtil.error(Name + "收到急停信号,报警急停");
                        WarnMsg = Name + "收到急停信号,报警急停";

                        //报警时会关闭所有轴
                        Alarm(StoreAlarmType.SuddenStop, "1", WarnMsg, MoveType.None);
                    }
                }
                else
                {
                    //光栅处理
                    SafetyLightProcess();
                }
            }
        }


        private void TimerProcess()
        {
            try
            {
                DateTime time = DateTime.Now;
                if (MoveInfo.MoveType != MoveType.None)
                {
                    BusyMoveProcess();
                }
                else if (runStatus.Equals(StoreRunStatus.Runing))
                {
                    InstoreCheck();

                    AutoResetProcess();
                    IOTimeOutProcess();

                }
                if (CurrStirInfo.InStirWork && CurrStirInfo.MoveStatus.Equals(3))
                {
                    if (CurrStirInfo.StopTime <= DateTime.Now)
                    {
                        
                        LogUtil.info(CurrStirInfo.StirParam.LogName + "到达搅拌结束时间,搅拌轴停止运动,更新状态=4    ");
                        AxisSuddenStop(Config.Stir_Axis);
                        Thread.Sleep(2000);
                        UpdateCurrStirState(4);
                    }
                }
                
                if (LeftOutParam != null && IOManager.IOValue(IO_Type.TinCheck_DoorLeft).Equals(IO_VALUE.LOW))
                {
                    LogUtil.info(Name + " 左侧出库锡膏" + LeftOutParam.ToStr() + " 被拿走,清理 LeftOutParam");
                    LeftOutParam = null;
                }
                if (RightOutParam != null && IOManager.IOValue(IO_Type.TinCheck_DoorRight).Equals(IO_VALUE.LOW))
                {
                    LogUtil.info(Name + " 右侧出库锡膏" + RightOutParam.ToStr() + " 被拿走,清理 RightOutParam");
                    RightOutParam = null;
                }
                if (FixtureOutParam != null && IOManager.IOValue(IO_Type.TinCheck_Fixture).Equals(IO_VALUE.LOW))
                {
                    LogUtil.info(Name + " 出库夹具" + RightOutParam.ToStr() + " 被拿走,清理 FixtureOutParam");
                    FixtureOutParam = null;
                }
            }
            catch (Exception ex)
            {
                LogUtil.error(Name + "定时处理出错" + ex.ToString());
            }
        }

        private Stopwatch checkWatch_0 = new Stopwatch();
        private Stopwatch checkWatch_1 = new Stopwatch();
        private Stopwatch checkWatch_2 = new Stopwatch();
        //判断是否需要出入库
        private void InstoreCheck()
        {
            if (IsDebug)
            {
                return;
            }
            if (MoveInfo.MoveType.Equals(MoveType.None) && alarmType.Equals(StoreAlarmType.None))
            {
                if (IsScanCode)
                {
                    return;
                }
                //string msg = "两侧都有锡膏,暂不扫码入库";
                //if (IOManager.IOValue(IO_Type.TinCheck_DoorLeft).Equals(IO_VALUE.HIGH) &&
                //    IOManager.IOValue(IO_Type.TinCheck_DoorRight).Equals(IO_VALUE.HIGH) &&
                // IOManager.IOValue(IO_Type.TinCheck_Fixture).Equals(IO_VALUE.LOW))
                //{
                //    CodeMsg = msg;
                //}else if (CodeMsg.Equals(msg))
                //{
                //    msg = "";
                //}

                //判断料门口是否有料
                if (IOManager.IOValue(IO_Type.TinCheck_Fixture).Equals(IO_VALUE.HIGH))
                {
                    if (FixtureOutParam == null)
                    {
                        checkWatch_1.Stop();
                        checkWatch_2.Stop();
                        if (StoreManager.checkWatch(checkWatch_0, 1500, true))
                        {
                            LogUtil.info(Name + "检测到 夹具信号,默认重量200,开始扫码");
                            StartScan(0, 200);
                        }
                    }
                }
                else if (IOManager.IOValue(IO_Type.TinCheck_DoorLeft).Equals(IO_VALUE.HIGH))
                {
                    if (LeftOutParam == null)
                    {
                        checkWatch_0.Stop();
                        checkWatch_2.Stop();

                        if (StoreManager.checkWatch(checkWatch_1, 1500, true))
                        {
                            double leftWeight = OKLEController.CalWeight(OKLEController.queryData(Config.Weight_Left_Port), Config.LeftDefWeight, Config.Weight_Left_Divisor);
                            if (leftWeight >= 50)
                            {
                                LogUtil.info(Name + "检测到 左侧锡膏, " + leftWeight + "g,开始扫码");
                                StartScan(1, leftWeight);
                            }
                        }
                    }
                }
                else if (IOManager.IOValue(IO_Type.TinCheck_DoorRight).Equals(IO_VALUE.HIGH))
                {
                    if (RightOutParam == null)
                    {
                        checkWatch_0.Stop();
                        checkWatch_1.Stop();

                        if (StoreManager.checkWatch(checkWatch_2, 1500, true))
                        {
                            double rightWeight = OKLEController.CalWeight(OKLEController.queryData(Config.Weight_Right_Port), Config.RightDefWeight, Config.Weight_Right_Divisor);
                            if (rightWeight >= 50)
                            {
                                LogUtil.info(Name + "检测到 右侧锡膏, " + rightWeight + "g,开始扫码");
                                StartScan(2, rightWeight);
                            }
                        }
                    }
                }
                else
                {
                    checkWatch_0.Stop();
                    checkWatch_1.Stop();
                    checkWatch_2.Stop();
                }
            }
        }


        private DateTime preIoTimerOutTime = DateTime.Now;
        private void IOTimeOutProcess()
        {
            try
            {
                TimeSpan span = DateTime.Now - preIoTimerOutTime;
                if (span.TotalSeconds > 1)
                {
                    preIoTimerOutTime = DateTime.Now;
                    if (!alarmType.Equals(StoreAlarmType.IoSingleTimeOut))
                    {
                        return;
                    }
                    if (runStatus < StoreRunStatus.Runing)
                    {
                        return;
                    }
                    if (isInSuddenDown || isNoAirCheck)
                    {
                        return;
                    }

                    //若BOX和移栽都没有在等待Io的过程中则此Io超时异常可能已经处理过
                    if (MoveInfo.IsInWait == false)
                    {
                        LogUtil.info(Name + "之前有IO超时异常【" + alarmInfo.alarmDetail + "】,但是当前已经没有在等待中,清理信号超时异常!");
                        alarmType = StoreAlarmType.None;
                        WarnMsg = "";
                    }
                }
            }
            catch (Exception ex)
            {
                LogUtil.error("IOTimeOutProcess出错:" + ex.ToString());
            }
        }

        private void AutoResetProcess()
        {
            try
            {
                if (CurrInOutACount >= this.Config.Box_ResetACount)
                {
                    if (runStatus.Equals(StoreRunStatus.Runing) && MoveInfo.MoveType.Equals(MoveType.None))
                    {
                        LogUtil.info(Name + "已经累计出入库" + CurrInOutACount + "次,需要复位一下");
                        Reset();
                    }
                }
                else if (CurrStirInfo.InStirWork && CurrStirInfo.MoveStatus.Equals(4) && CurrStirInfo.StirParam != null)
                {
                    if (runStatus.Equals(StoreRunStatus.Runing) && MoveInfo.MoveType.Equals(MoveType.None))
                    {
                        LogUtil.info(Name + CurrStirInfo.StirParam.LogName + ",搅拌已完成,开始回库操作");
                        StartStirBackPos(CurrStirInfo.StirParam);
                    }
                }
                else if (!IsDebug)
                {
                    InOutParam param = null;

                    if (WaitMoveParamList.Count > 0 && CanStarMove())
                    {
                        bool result = WaitMoveParamList.TryDequeue(out param);
                    }

                    if (param != null)
                    {  //出库
                        if (param.PosCode.Equals(""))
                        {
                            LogUtil.info(Name + "开始执行排队中的 " + param.LogName + "");
                            bool result = false;
                            if (param.paramType.Equals(MoveType.OutStore))
                            {
                                result = StartOutStore(param);
                            }
                            else if (param.paramType.Equals(MoveType.MovePos))
                            {
                                result = StartMovement(param);
                            }
                            else if (param.paramType.Equals(MoveType.Stirring))
                            {
                                result = StartStirring(param);
                            }
                            if (!result)
                            {
                                LogUtil.info(Name + " 执行排队中的 " + param.LogName + "失败,重新加入等待队列");
                                AddWaitMoveParam(param);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogUtil.error("处理出入库排队列表出错:" + ex.ToString());
            }
        }

        private DateTime checkAlarmTime = DateTime.Now;
        private bool CheckAxisAlarm()
        {
            if (alarmType.Equals(StoreAlarmType.AxisAlarm) || alarmType.Equals(StoreAlarmType.AxisMoveError))
            {
                return true;
            }
            TimeSpan span = DateTime.Now - checkAlarmTime;
            //在回原点,复位,出入库时,检测报警间隔减小
            if (runStatus.Equals(StoreRunStatus.Busy) || runStatus.Equals(StoreRunStatus.HomeMoving) || runStatus.Equals(StoreRunStatus.Reset))
            {
                if (span.TotalSeconds < 1)
                {
                    return false;
                }
            }
            else
            {
                if (span.TotalSeconds < 3)
                {
                    return false;
                }
            }
            checkAlarmTime = DateTime.Now;
            bool isInAlarm = false;
            //Task.Factory.StartNew(delegate
            // {
            foreach (ConfigMoveAxis axisInfo in moveAxisList)
            {
                short axis = axisInfo.GetAxisValue();
                string deviceName = axisInfo.GetNameStr();
                AxisAlarmInfo info = AxisAlarmCodeMap[deviceName];

                int alarmIo = ACServerManager.GetAlarmStatus(deviceName, axis);

                if (alarmIo.Equals(1))
                {
                    WarnMsg = Name + " 运动轴" + axisInfo.Explain + "报警";
                    LogUtil.error(WarnMsg);
                    info.AlarmIoValue = alarmIo;
                    Alarm(StoreAlarmType.AxisAlarm, axisInfo.ProName, WarnMsg, MoveType.None);
                    isInAlarm = true;
                }
                else if (!info.AlarmIoValue.Equals(alarmIo))
                {
                    if (alarmInfo.Equals(0))
                    {
                        LogUtil.error(Name + "  运动轴  " + axisInfo.Explain + ",报警已解除!");
                        info.AlarmIoValue = alarmIo;
                    }
                }
                AxisAlarmCodeMap[deviceName] = info;
            }
            //});
            //判断报警状态
            return isInAlarm;
        }
        #endregion

        #region 光栅处理
        private object safetyInProcess = "";

        private void SafetyLightProcess()
        {
            if (Monitor.TryEnter(safetyInProcess))
            {
                try
                {
                    //遮挡光栅信号
                    if (IOManager.IOValue(IO_Type.SafetyLightCurtains).Equals(IO_VALUE.LOW))
                    {
                        if (NeedCheckSafetyLight.Equals(1))
                        {
                            if (MoveInfo.MoveType.Equals(MoveType.OutStore) && MoveInfo.IsStep(StoreMoveStep.SO_13_InoutToP2))
                            {
                                NeedCheckSafetyLight = 2;
                                LogUtil.info("出库 " + MoveInfo.MoveStep + " 运动中,光栅被遮挡,停止进出轴运动");
                                ACServerManager.SuddenStop(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue());
                            }
                            else if (MoveInfo.MoveType.Equals(MoveType.InStore) && MoveInfo.IsStep(StoreMoveStep.SI_05_InoutToP2))
                            {
                                NeedCheckSafetyLight = 2;
                                LogUtil.info("入库 " + MoveInfo.MoveStep + " 运动中,光栅被遮挡,停止进出轴运动");
                                ACServerManager.SuddenStop(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue());
                            }
                        }
                    }
                    else
                    {
                        if (NeedCheckSafetyLight.Equals(2))
                        {
                            if (MoveInfo.MoveType.Equals(MoveType.OutStore) && MoveInfo.IsStep(StoreMoveStep.SO_13_InoutToP2))
                            {
                                LogUtil.info("出库 " + MoveInfo.MoveStep + " 运动中,光栅已恢复,继续进出轴运动");
                                SO_13_InoutToP2();
                            }
                            else if (MoveInfo.MoveType.Equals(MoveType.InStore) && MoveInfo.IsStep(StoreMoveStep.SI_05_InoutToP2))
                            {
                                LogUtil.info("入库 " + MoveInfo.MoveStep + " 运动中,光栅已恢复,继续进出轴运动");
                                SI_05_InoutToP2();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogUtil.error("光栅处理出错:" + ex.ToString());
                }
                finally
                {
                    Monitor.Exit(safetyInProcess);
                }
            }
        }

        #endregion


        public override void StopMove(bool IsCloseAxis = false)
        {
            StopAllAxis();

            if (IsCloseAxis)
            {
                CloseAllAxis();
            }
            LogUtil.info(Name + "StopMove");
            IOManager.IOMove(IO_Type.Door_Down, IO_VALUE.LOW);
            IOManager.IOMove(IO_Type.Door_Up, IO_VALUE.LOW);

            isInPro = false;
        }

        private void StopAllAxis()
        {
            foreach (ConfigMoveAxis axis in moveAxisList)
            {
                ACServerManager.SuddenStop(axis.DeviceName, axis.GetAxisValue());
            }
        }

        private  bool CanStarMove()
        {
            if (isInSuddenDown || isNoAirCheck)
            {
                return false;
            }
            if (runStatus.Equals(StoreRunStatus.Runing) && MoveInfo.MoveType.Equals(MoveType.None))
            {
                return true;
            }
            return false;
        }


        #region  获取库位号
        private DateTime StartWaitScanTime = DateTime.Now;
        //private bool IsNotScanCode = false;
        private bool IsScanCode = false;
        private void CodeRevice(int doorType,int weight, string message)
        {
            try
            {
                message = ScanCodeManager.ReplaceCode(message);
                //if (message.Equals("") || string.IsNullOrEmpty(message))
                //{
                //    IsNotScanCode = true;
                //    IsScanCode = false;
                //    CodeMsg = "未扫到二维码信息,请重新放入";
                //    LogUtil.info(Name + "未扫到二维码信息,请重新放入");
                //    return;
                //}
                //IsNotScanCode = false;

                if (runStatus.Equals(StoreRunStatus.Wait))
                {
                    LogUtil.info(Name + "CodeRevice【 " + message + "】,设备未启动,不需要发送服务器");
                    IsScanCode = false;
                    return;
                } 
                LogUtil.info(Name + "CodeRevice【 " + message + "】,发送给服务器获取入库PosID");
                //发送扫码内容到服务器进行入库操作
                Operation operation = getLineBoxStatus();
                operation.op = 1;
                operation.data = new Dictionary<string, string>() {
                    { "code", message },
                    { "boxId", StoreID.ToString() },
                    {"weight" ,weight .ToString()}
                };
                string server = ConfigAppSettings.GetValue(Setting_Init.http_server);
            
                Operation resultOperation = HttpHelper.Post(StoreManager.GetPostApi(server), operation, false);
                if (resultOperation == null)
                {
                    LogUtil.info(Name + "CodeRevice【" + message + "】没有收到服务器反馈!");
                    IsScanCode = false;
                    return;
                }
                else if (!string.IsNullOrEmpty(resultOperation.msg))
                {
                    LogUtil.info(Name + "   CodeRevice【" + message + "】 服务器反馈 :" + resultOperation.msg);
                    IsScanCode = false;
                    return;
                }
                OpCheck(resultOperation, message, doorType);

                IsScanCode = false;
            }
            catch (Exception ex)
            {
                IsScanCode = false;
                LogUtil.error(Name + ex.StackTrace);
            }
        }

        #endregion

        #region  扫码 

        public  string CodeMsg = "";
        private string spiltStr = "##";
        private DateTime LastScanTime = DateTime.Now;
        public void StartScan(int doorType = 0, double weight = 0)
        {
            if (IsInScan())
            {
                LogUtil.info("上次扫码还未执行完毕,请稍后!");
                return;
            }
            IsScanCode = true;
            Task.Factory.StartNew(delegate
            {
                LastScanTime = DateTime.Now;

                IOManager.IOMove(IO_Type.Camera_Led, IO_VALUE.HIGH);

                string message = "";
                List<CodeInfo> codeList = CodeManager.CameraScan();
                LogUtil.info($"doorType:{doorType},weight:{weight}");
                message = ProcessCode(codeList,doorType,weight);
                //string codeSize = "";
                //foreach (CodeInfo obj in codeList)
                //{
                //    string ncode = obj.CodeStr;
                //    //根据二维码开头获取固定尺寸
                //    codeSize = Config.GetCodeSize(ref ncode); 
                //}

                //foreach (CodeInfo obj in codeList)
                //{
                //    string codeR = "";
                //    string ncode =  obj.CodeStr;
                //    int y = 2748 / 2;
                //    //判断左右,默认左侧条码X<1500
                //    if (doorType.Equals(1) && codeList.Count >= 2 && obj.Y > y)
                //    {
                //        LogUtil.info(Name + "左侧锡膏,弃用条码:" + obj.X + "x" + obj.Y + "=" + obj.CodeStr);
                //        continue;
                //    }
                //    if (doorType.Equals(2) && codeList.Count >= 2 && obj.Y < y)
                //    {
                //        LogUtil.info(Name + "右侧锡膏,弃用条码:" + obj.X + "x" + obj.Y + "=" + obj.CodeStr);
                //        continue;
                //    }

                //    //根据二维码开头获取固定尺寸
                //    //string codeSize = Config.GetCodeSize(ref ncode);
                //    if (String.IsNullOrEmpty(codeSize))
                //    {
                //        codeSize = Config.Tin_Width + "x" + Config.Tin_Height;
                //        if (doorType.Equals(0))
                //        {
                //            codeSize = Config.Fixture_Width + "x" + Config.Fixture_Height;
                //        }
                //    }
                //    if (!String.IsNullOrEmpty(ncode))
                //    {

                //        codeR = "=1+" + obj.X + "x" + obj.Y + "-" + codeSize + "=" + ncode;
                //        message = message + codeR + spiltStr;
                //    }
                //}

                IOManager.IOMove(IO_Type.Camera_Led, IO_VALUE.LOW);

                CodeRevice(doorType,(int)weight,message);
            });
        }
        private string ProcessCode(List<CodeInfo> codeList, int doorType = 0, double weight = 0)
        {
            string message = "";
            string codeSize = "";
            string sizeCode = "";
            foreach (CodeInfo obj in codeList)
            {
                string ncode = obj.CodeStr;
                //根据二维码开头获取固定尺寸
                codeSize = Config.GetCodeSize(ref ncode);
                if (!String.IsNullOrEmpty(codeSize))
                {
                    sizeCode = obj.CodeStr;
                    break;
                }
            }

            foreach (CodeInfo obj in codeList)
            {
                string codeR = "";
                string ncode = obj.CodeStr;
                int y = 2748 / 2;
                //判断左右,默认左侧条码X<1500
                if (doorType.Equals(1) && codeList.Count >= 2 && obj.Y > y)
                {
                    LogUtil.info(Name + "左侧锡膏,弃用条码:" + obj.X + "x" + obj.Y + "=" + obj.CodeStr);
                    continue;
                }
               if (doorType.Equals(2) && codeList.Count >= 2 && obj.Y < y)
                {
                    LogUtil.info(Name + "右侧锡膏,弃用条码:" + obj.X + "x" + obj.Y + "=" + obj.CodeStr);
                    continue;
                }
                if ((!String.IsNullOrEmpty(codeSize)) && ncode.Equals(sizeCode))
                {
                    LogUtil.info(Name + "夹具弃用条码【"+ codeSize + "】:" + obj.X + "x" + obj.Y + "=" + obj.CodeStr);
                    //ncode = $"{ncode};{ncode};1";
                    continue;
                }

                //根据二维码开头获取固定尺寸
                //string codeSize = Config.GetCodeSize(ref ncode);
                if (String.IsNullOrEmpty(codeSize))
                {
                    codeSize = Config.Tin_Width + "x" + Config.Tin_Height;
                    if (doorType.Equals(0))
                    {
                        codeSize = Config.Fixture_Width + "x" + Config.Fixture_Height;
                    }
                }
                if (!String.IsNullOrEmpty(ncode))
                {

                    codeR = "=1+" + obj.X + "x" + obj.Y + "-" + codeSize + "=" + ncode;
                    message = message + codeR + spiltStr;
                }
            }
            return message;
        }
        private bool IsInScan()
        {
            if (!IsScanCode)
            {
                return false;
            }
            TimeSpan span = DateTime.Now - LastScanTime;
            if (span.TotalSeconds > 60)
            {
                //大于60秒表示超时了,可以重新开始扫码
                return false;
            }
            return true;
        }

        #endregion


        #region 与服务器通信定时器
        private float Max_Humidity = 0;
        private float Max_Temperature = 0;

        public string currTempStr = "";
        private void HumidityProcess()
        {
            try
            {
                ASTemperateParam param = HumitureController.ColdLastData;
                currTempStr = "";
                if (param != null)
                {
                    currTempStr = ("冷藏区湿度:" + param.Humidity.ToString() + " 温度:" + param.Temperate.ToString() + " \n");
                }
                param = HumitureController.WarmLastData;
                if (param != null)
                {
                    currTempStr += ("回温区湿度:" + param.Humidity.ToString() + " 温度:" + param.Temperate.ToString() + "\n");
                }
            }
            catch (Exception ex)
            {
                LogUtil.error(Name + "HumidityProcess出错:" + ex.ToString());
            }
        }
        private bool isInProcess = false;
        string RefrigeratorAlerm = "";
        public void server_connect_timer_Tick(object sender, EventArgs e)
        {
            if (isInProcess)
            {
                return;
            }
            isInProcess = true;
            if (StoreManager.IsConnectServer)
            {
                try
                {
                    SendLineStatus();
                }
                catch (Exception ex)
                {
                    LogUtil.error("定时给服务器发送消息出错:" + ex.ToString());
                }
            }
            HumitureController.QueryColdData(Config.Humiture_Colding_Port);
            HumitureController.QueryWarmData(Config.Humiture_Warming_Port);
            HumitureController.ColdLastData.Temperate = RefrigeratorController.queryData(Config.Refrigerator_Port, out _, out RefrigeratorAlerm, out _);
            HumidityProcess();
            LedProcess();
            isInProcess = false;
        }

        private Operation getLineBoxStatus()
        {
            //构建发送给服务器的对象
            Operation lineOperation = new Operation(CID);
            BoxStatus boxStatus = new BoxStatus();
            boxStatus.boxId = StoreID;
            boxStatus.status = (int)storeStatus;
             
            bool isWarn = (WarnMsg!="");


            string sendMsg = WarnMsg;
            if (sendMsg.Equals(""))
            {
                sendMsg = CodeMsg;
            }
            if (sendMsg.Equals("") && !string.IsNullOrEmpty(RefrigeratorAlerm))
                sendMsg = RefrigeratorAlerm;
            if (sendMsg.Equals(""))
            {
                if (runStatus.Equals(StoreRunStatus.Runing) && IOManager.IOValue(IO_Type.TinCheck_Clamping).Equals(IO_VALUE.HIGH))
                {
                    sendMsg = "夹爪检测有料,请检查";
                }
            }
            CodeMsg = "";
            boxStatus.msg = sendMsg;
            lineOperation.msg = sendMsg;

            //状态
            boxStatus.status = (int)storeStatus;
            if (IsDebug)
            {
                boxStatus.status = (int)StoreStatus.Debugging;
            }
            else if (sendLastStatus)
            {
                boxStatus.status = (int)lastPosIdStatus;
                if (lastPosId != "")
                {
                    LogUtil.info("SendLineStatus:" + Name + ",status【" + lastPosIdStatus + "】posId【" + lastPosId + "】");
                }
                sendLastStatus = false;
            }
       

            if (boxStatus.status.Equals((int)StoreStatus.StoreOnline) && isWarn)
            {
                boxStatus.status = (int)StoreStatus.Warning; 
            }
            if(boxStatus.status.Equals((int)StoreStatus.StoreOnline))
            {
                ////是否在搅拌中
                //if (CurrStirInfo.InStirWork && CurrStirInfo.MoveStatus.Equals(3))
                //{
                //    boxStatus.status = (int)StoreStatus.Mixing;
                //    lastPosId = CurrStirInfo.StirParam.PosId;
                //    if (CurrStirInfo.StirParam.TarPosition.PosType < 100)
                //    {
                //        lastSecondPosId = CurrStirInfo.StirParam.TarPosId;
                //    }
                //}
                //else
                {
                    lastPosId = ""; lastSecondPosId = "";
                }
            }
            if (!lastPosId.Equals(""))
            {
                boxStatus.data.Add(ParamDefine.posId, lastPosId);
                lineOperation.data.Add(ParamDefine.posId, lastPosId);
                lastPosId = "";
            }
            if (!lastSecondPosId.Equals(""))
            {
                boxStatus.data.Add(ParamDefine.secondPosId, lastSecondPosId);
                lineOperation.data.Add(ParamDefine.secondPosId, lastSecondPosId);
                lastSecondPosId = "";
            }
            lineOperation .status= boxStatus.status; 

            //温湿度
            //ASTemperateParam param = HumitureServer.GetTemperateParam(Config.Temperate_Serveraddress);
            ASTemperateParam param = HumitureController.ColdLastData;
            if (param != null)
            {
                boxStatus.humidity = param.Humidity.ToString();
                boxStatus.temperature = param.Temperate.ToString();
            }
            lineOperation.boxStatus.Add(StoreID, boxStatus);

            if (!alarmType.Equals(StoreAlarmType.None))
            {
                lineOperation.alarmList.Add(alarmInfo);
            }
            return lineOperation;
        }

        private void SendLineStatus()
        {
            DateTime time = DateTime.Now;
            //构建发送给服务器的对象
            Operation lineOperation = getLineBoxStatus();
            //如果还没湿度范围,先获取
            if (Max_Humidity <= 0 || (Max_Temperature <= 0))
            {
                if (lineOperation.status.Equals((int)StoreStatus.StoreOnline) && lineOperation.op <= 0)
                {
                    lineOperation.op = 5;
                    LogUtil.info(Name + "没有湿度预警范围,需要从服务器获取,发送OP=" + lineOperation.op);
                }
            }
            string server = ConfigAppSettings.GetValue(Setting_Init.http_server);
            Operation resultOperation = HttpHelper.Post(StoreManager.GetPostApi(server), lineOperation, false);
            OpCheck(resultOperation);
            TimeSpan span = DateTime.Now - time;
            if (span.TotalMilliseconds > 10000)
            {
                LogUtil.info(Name + "执行 SendLineStatus 共处理了【" + span.TotalMilliseconds + "】毫秒");
            }
        }

        private void OpCheck(Operation operation, string codeStr = "", int doorType = 0)
        {
            if (operation != null && operation.op > 0)
            {
                LogUtil.debug("OpCheck=" + operation.op);
                if (operation.op.Equals(OP.PUT_IN_1))
                {
                    ProcessInstoreCMD(doorType, codeStr, operation);
                }
                else if (operation.op.Equals(OP.CHECKOUT_2))
                {
                    ProcessOutstoreCMD(operation);
                }
                else if (operation.op.Equals(OP.ALARM_DATA_5))
                {
                    ProcessHumidityCMD(operation);
                }
                else if (operation.op.Equals(OP.REWARM_TAKING_6))
                {
                    ProcessRewarmCMD(operation);
                }
                else if (operation.op.Equals(OP.MIX_8))
                {
                    ProcessMixCMD(operation);
                }
                else
                {
                    LogUtil.error("收到服务器命令:op=" + operation.op + ",未找到对应处理");
                }
            }
            else if (operation != null && operation.data != null)
            {
                Dictionary<string, string> dataMap = operation.data;
                //closeDoor = doit   和 openDoor = doit
                if (dataMap.ContainsKey(ParamDefine.closeDoor) && dataMap[ParamDefine.closeDoor].Equals(ParamDefine.doit))
                {
                    LogUtil.info(Name + "收到服务器命令:closeDoor=doit");
                    CloseDoor(null);
                }
                else if (dataMap.ContainsKey(ParamDefine.openDoor) && dataMap[ParamDefine.openDoor].Equals(ParamDefine.doit))
                {
                    LogUtil.info(Name + "收到服务器命令:openDoor=doit");
                    OpenDoor(null);
                }

            }
        }

        private void ProcessMixCMD(Operation operation)
        {
            string posId = operation.GetData(ParamDefine.posId);
            int weight = operation.GetIntData(ParamDefine.weight);
            string barcode = operation.GetData(ParamDefine.barcode);
            int mixTime = operation.GetIntData(ParamDefine.mixTime);
            if (posId != "" && weight > 0 && mixTime > 0)
            {

                LogUtil.info("收到服务器搅拌消息:posId=" + posId + ",weight=" + weight + ", code=" + barcode + ",time=" + mixTime);

                TinStorePosition position = CSVPositionReader<TinStorePosition>.GetPositon(posId);
                if (position == null)
                {
                    WarnMsg = Name + "搅拌未找库位:【" + posId + "】";
                    LogUtil.error("收到服务器搅拌命令:未找到【" + posId + "】的库位信息");
                    return;
                }
                if (!position.PosType.Equals(2))
                {
                    WarnMsg = Name + "搅拌失败:【" + posId + "】不是回温区库位";
                    LogUtil.error("收到服务器搅拌命令:搅拌失败【" + posId + "】不是回温区库位");
                    return;
                }
                InOutParam param = InOutParam.NewStirParam(posId, barcode, weight, "", "", 0, mixTime);
                if (mixTime <= 0)
                {
                    WarnMsg = Name + "【" + param.LogName  + "】搅拌时间="+mixTime +",不需要搅拌";
                    LogUtil.error("收到服务器搅拌命令:【" + param.LogName + "】搅拌时间=" + mixTime + ",不需要搅拌");
                    return;
                }

                if (CanStarMove() && StartStirring(param))
                {
                    return;
                }
                else
                {
                    LogUtil.error("执行搅拌【" + param.ToStr() + "】失败,加入等待队列");
                    AddWaitMoveParam(param);
                }
            }
            else
            {
                LogUtil.info("ProcessMixCMD 参数不完整");
            }
        }

        private void ProcessRewarmCMD(Operation operation)
        {
            string posId = operation.GetData(ParamDefine.posId);
            string secondPosId = operation.GetData(ParamDefine.secondPosId);
            string code = operation.GetData(ParamDefine.barcode);
            if (posId != "" && (secondPosId != ""))
            {

                LogUtil.info("收到服务器回温消息:posId=" + posId + ",secondPosId=" + secondPosId); 
                if (CSVPositionReader<TinStorePosition>.GetPositon(posId) == null)
                {
                    WarnMsg = Name + "回温未找库位:【" + posId + "】";
                    LogUtil.error("收到服务器回温命令:未找到【" + posId + "】的库位信息");
                    return;
                }
                if (CSVPositionReader<TinStorePosition>.GetPositon(secondPosId) == null)
                {
                    WarnMsg = Name + "回温未找库位:【" + posId + "】";
                    LogUtil.error("收到服务器回温命令:未找到【" + posId + "】的库位信息");
                    return;
                } 
                InOutParam currInOutFixture = InOutParam.NewMovePosParam(posId, secondPosId, code);
                if (CanStarMove() && StartMovement(currInOutFixture))
                {
                    return;
                }
                else
                {
                    LogUtil.error("执行回温【" + currInOutFixture.ToStr() + "】失败,加入等待队列");
                    AddWaitMoveParam(currInOutFixture);
                }

            }
            else
            {
                LogUtil.info("ProcessRewarmCMD 参数不完整");
            }
        }

        private void ProcessHumidityCMD(Operation operation)
        {
            Dictionary<string, string> data = operation.data;
            if (data != null && data.ContainsKey(ParamDefine.maxHumidity) && data.ContainsKey(ParamDefine.maxTemperature))
            {
                string maxHumidity = data[ParamDefine.maxHumidity];
                string maxTemp = data[ParamDefine.maxTemperature];
                LogUtil.info("收到服务器温湿度预警值:maxHumidity=" + maxHumidity + ",maxTemperature=" + maxTemp);

                try
                {
                    this.Max_Humidity = (float)Convert.ToDouble(maxHumidity);
                    this.Max_Temperature = (float)Convert.ToDouble(maxTemp);
                    LogUtil.info("保存温湿度预警值:Max_Humidity=" + Max_Humidity + ",Max_Temperature=" + Max_Temperature);
                }
                catch (Exception ex)
                {
                    LogUtil.error("转换温湿度失败:" + ex.ToString());
                }
            }
        }

        private void ProcessOutstoreCMD(Operation operation)
        { 
            Dictionary<string, string> data = operation.data;
            if (data != null && data.ContainsKey(ParamDefine.posId)
                   && data.ContainsKey(ParamDefine.plateH) && data.ContainsKey(ParamDefine.plateW))
            {
                string posIdStr = data[ParamDefine.posId];
                string plateWStr = data[ParamDefine.plateW];
                string plateHStr = data[ParamDefine.plateH];
                string code = operation.GetData(ParamDefine.barcode);
                LogUtil.info("收到服务器出库消息:poaIs=" + posIdStr + ",platew=" + plateWStr + ",plateh=" + plateHStr);
                char splitChar = '|';
                string[] posIdArray = posIdStr.Split(splitChar);
                string[] plateWArray = plateWStr.Split(splitChar);
                string[] plateHArray = plateHStr.Split(splitChar);
                int index = -1;
                foreach (string posId in posIdArray)
                {
                    index++;
                    int plateW = Convert.ToInt32(plateWArray[index]);
                    int plateH = Convert.ToInt32(plateHArray[index]);
                    
                    TinStorePosition position = CSVPositionReader<TinStorePosition>.GetPositon(posId);
                    if (position == null)
                    { 
                        WarnMsg = Name + "出库未找库位:【" + posId + "】";
                        LogUtil.error("收到服务器出库命令:未找到【" + posId + "】的库位信息");
                        continue;
                    }
                    else
                    {
                        InOutParam currInOutFixture = new InOutParam(MoveType.OutStore, posId, 0,code, plateW, plateH);
                        if (CanStarMove())
                        {
                            bool result = StartOutStore(currInOutFixture);
                            if (!result)
                            {
                                LogUtil.info(Name + " 执行出库【" + currInOutFixture.ToStr() + "】失败,加入等待队列");
                                AddWaitMoveParam(currInOutFixture);
                            }
                        }
                        else
                        {
                            LogUtil.error("执行出库【" + currInOutFixture.ToStr() + "】失败,当前在忙碌中,加入等待队列");
                            AddWaitMoveParam(currInOutFixture);
                        }
                    }

                }

            }
        
            else
            {
                LogUtil.info("ProcessOutstoreCMD 参数不完整");
            }
        }
    

        public void ProcessInstoreCMD(int doorType, string message, Operation operation)
        {
            // 【http://localhost/myproject/service/store/communication】
            //发送【{"boxStatus":{"1":{"boxId":1,"status":1,"msg":"","temperature":"25.3","humidity":"87.9","data":{}}},"alarmList":[],"cid":"tin1","seq":3476,"op":1,"data":{"code":"=1+1178x378-60x75=pn;A100046;1000##","boxId":"1","weight":"586"},"status":1,"msg":""}】
            //string msg="{\"cid\":\"tin1\",\"seq\":3476,\"op\":1,\"data\":{\"code\":\"=1+1178x378-60x75=pn;A100046;1000##\",\"boxId\":\"1\",\"weight\":\"586\",\"posId\":\"1#AC1_1_1_1\",\"plateW\":\"60\",\"plateH\":\"75\",\"barcode\":\"=1+1178x378-60x75=pn;A100046;1000##\",\"singleOut\":\"false\"},\"msgData\":{},\"status\":1,\"msg\":\"\",\"msgEn\":\"\",\"boxStatus\":{\"1\":{\"boxId\":1,\"status\":1,\"data\":{},\"msg\":\"\",\"temperature\":\"25.3\",\"humidity\":\"87.9\",\"posId\":null}},\"alarmList\":[],\"time\":1595043813183,\"lastSaveTime\":1595043813183,\"available\":true,\"code\":\"=1+1178x378-60x75=pn;A100046;1000##\",\"doorReelSingnal\":\"-1\",\"posId\":\"1#AC1_1_1_1\",\"weight\":586,\"codeBoxId\":\"1\"}";
            //    operation = JsonHelper.DeserializeJsonToObject<Operation>(msg);
            Dictionary<string, string> data = operation.data;
            if (data != null && data.ContainsKey(ParamDefine.posId) && data.ContainsKey(ParamDefine.plateH) && data.ContainsKey(ParamDefine.plateW))
            {
                //服务器返回时有:posId库位编号,plateW:料盘宽度,plateH:料盘高度,
                //postId格式BoxId#位置
                string posId = data[ParamDefine.posId];
                string code = operation.GetData(ParamDefine.barcode);
                int plateW = Convert.ToInt32(data[ParamDefine.plateW].Trim());
                int plateH = Convert.ToInt32(data[ParamDefine.plateH].Trim());

                TinStorePosition position = CSVPositionReader<TinStorePosition>.GetPositon(posId);
                if (position == null)
                {
                    WarnMsg = "入库未找到库位:二维码【" + message + "】库位【" + posId + "】 ";
                    LogUtil.error("收到服务器入库命令:入库未找到库位:二维码【" + message + "】库位【" + posId + "】");
                    return;
                }
                if (CanStarMove())
                {
                    IsScanCode = false;
                    InOutParam param = new InOutParam(MoveType.InStore, posId, doorType, message, plateH, plateW);

                    StartInStore(param);
                    //如果当前正在出入库中,需要记录下来,等待空闲时执行
                    LogUtil.info(Name + " 收到服务器入库命令:库位号【" + posId + "】二维码【" + message + "】 开始入库!");
                }
                else
                {
                    LogUtil.info(Name + " 收到服务器入库命令:库位号【" + posId + "】二维码【" + message + "】 正在忙碌中,无法入库!");
                    IsScanCode = false;
                }
            }
            else
            {
                LogUtil.info("ProcessInstoreCMD 参数不完整");
            }
        }

        

        private void LedProcess()
        {
            try
            {
                //                机器状态 顶灯显示 
                //                                              绿 黄  红
                //机器复位中                             闪 灭   灭
                //机器待机中                             亮 灭   灭
                //机器出入库中                          闪 闪   灭
                //温湿度超限报警中                   亮 闪   灭
                //温湿度超限报警中超过30分钟  亮 闪   闪
                //机器未启动                             灭 灭   灭
                //机器设备故障(非温湿度)报警    亮   灭 闪

                //报警时只需要亮红灯

                DateTime time = DateTime.Now;

                bool isNeedAlarmLed = false;
                //报警灯
                if (!alarmType.Equals(StoreAlarmType.None))
                {
                    isNeedAlarmLed = true;
                }
                if (isNeedAlarmLed && IOManager.IOValue(IO_Type.Alarm_HddLed).Equals(IO_VALUE.LOW))
                {
                    IOManager.IOMove(IO_Type.Alarm_HddLed, IO_VALUE.HIGH);
                }
                else
                {
                    if (IOManager.IOValue(IO_Type.Alarm_HddLed).Equals(IO_VALUE.HIGH))
                    {
                        IOManager.IOMove(IO_Type.Alarm_HddLed, IO_VALUE.LOW);
                    }
                }


                //报警时绿灯和黄灯灭
                if (isNeedAlarmLed)
                {
                    if (IOManager.IOValue(IO_Type.AutoRun_HddLed).Equals(IO_VALUE.HIGH))
                    {
                        IOManager.IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW);
                    }
                    if (IOManager.IOValue(IO_Type.RunSign_HddLed).Equals(IO_VALUE.HIGH))
                    {
                        IOManager.IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW);
                    }
                    if (UseBuzzer && IOManager.IOValue(IO_Type.Alarm_Buzzer).Equals(IO_VALUE.LOW))
                    {
                        IOManager.IOMove(IO_Type.Alarm_Buzzer, IO_VALUE.HIGH);
                    }
                    else if(!UseBuzzer){
                        IOManager.IOMove(IO_Type.Alarm_Buzzer, IO_VALUE.LOW);
                    }
                    return;
                }

                if (!UseBuzzer)
                {
                    IOManager.IOMove(IO_Type.Alarm_Buzzer, IO_VALUE.LOW);
                }

                //绿灯闪
                if ((MoveInfo.MoveType.Equals(MoveType.InStore) || MoveInfo.MoveType.Equals(MoveType.OutStore)
                  || runStatus.Equals(StoreRunStatus.HomeMoving) || runStatus.Equals(StoreRunStatus.Reset))
                  && IOManager.IOValue(IO_Type.AutoRun_HddLed).Equals(IO_VALUE.HIGH))
                {
                    IOManager.IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW);
                }
                else
                {
                    //绿灯亮
                    IOManager.IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.HIGH);
                }
                //黄灯
                if (MoveInfo.MoveType.Equals(MoveType.InStore) || MoveInfo.MoveType.Equals(MoveType.OutStore))
                {
                    if (IOManager.IOValue(IO_Type.RunSign_HddLed).Equals(IO_VALUE.HIGH))
                    {
                        IOManager.IOMove(IO_Type.RunSign_HddLed, IO_VALUE.LOW);
                    }
                    else
                    {
                        IOManager.IOMove(IO_Type.RunSign_HddLed, IO_VALUE.HIGH);
                    }
                }
                else
                {
                    if (IOManager.IOValue(IO_Type.RunSign_HddLed).Equals(IO_VALUE.HIGH))
                    {
                        IOManager.IOMove(IO_Type.RunSign_HddLed, IO_VALUE.LOW);
                    }
                }
            }
            catch (Exception ex)
            {
                LogUtil.error(Name + "灯处理定时器出错:" + ex.ToString());
            }
        }
        #endregion

        private void AxisSuddenStop(ConfigMoveAxis axis)
        {
            ACServerManager.SuddenStop(axis.DeviceName, axis.GetAxisValue());
        }

        public void CylinderMove(StoreMoveInfo moveInfo, string IoLowType, string IoHighType)
        {
            try
            {
                if (moveInfo != null)
                {
                    moveInfo.WaitList.Add(WaitResultInfo.WaitIO(IoLowType, IO_VALUE.LOW));
                    moveInfo.WaitList.Add(WaitResultInfo.WaitIO(IoHighType, IO_VALUE.HIGH));
                }
                IOManager.IOMove(IoLowType, IO_VALUE.LOW);
                IOManager.IOMove(IoHighType, IO_VALUE.HIGH);
            }
            catch (Exception ex)
            {
                LogUtil.error(Name + "CylinderMove  [" + IoLowType + "] [" + IoHighType + "]  出错:" + ex.ToString());
            }

        }
        public virtual string GetMoveStr()
        {
            string msg = "";
            msg += "" + runStatus + " _ " + storeStatus + "\n";
            msg += MoveInfo.MoveType + " _ " + MoveInfo.MoveStep + "\n";
            msg +="AlarmType= " + alarmType + "\n";
            msg += currTempStr;
            return msg;
        }
        public virtual string GetAxisInfo()
        {
            int leng = 5;
            string msg = "";
            msg += Config.Middle_Axis.Explain.PadLeft(leng, ' ') + ":" + Config.Middle_Axis.TargetPosition + "\n";
            msg += Config.UpDown_Axis.Explain.PadLeft(leng, ' ') + ":" + Config.UpDown_Axis.TargetPosition + "\n";
            msg += Config.InOut_Axis.Explain.PadLeft(leng, ' ') + ":" + Config.InOut_Axis.TargetPosition + "\n";
            msg += Config.Warming_Axis.Explain.PadLeft(leng, ' ') + ":" + Config.Warming_Axis.TargetPosition + "\n";
            msg += Config.Colding_Axis.Explain.PadLeft(leng, ' ') + ":" + Config.Colding_Axis.TargetPosition + "\n";
            msg += Config.Stir_Axis.Explain.PadLeft(leng, ' ') + ":" + Config.Stir_Axis.TargetPosition + "\n";
            return msg;
        }

        public void CloseDoor(StoreMoveInfo moveInfo = null)
        { 
            CylinderMove(moveInfo, IO_Type.Door_Up, IO_Type.Door_Down);
        }
        public void OpenDoor(StoreMoveInfo moveInfo = null)
        { 
            CylinderMove(moveInfo, IO_Type.Door_Down, IO_Type.Door_Up);
        }
    }
}