FrmStoreBox.cs 76.5 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.CompilerServices;
using System.Threading;
using System.IO;
using System.Runtime.InteropServices;
using OnlineStore.Common;
using System.Reflection;
using log4net;
using OnlineStore.DeviceLibrary;
using System.IO.Ports;
using OnlineStore.LoadCSVLibrary;
using CodeLibrary;

namespace OnlineStore.AutoInOutStore
{
    public partial class FrmStoreBox : FrmBase
    {

        private AC_SA_BoxBean store;
        public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        public FrmStoreBox()
        {
            Control.CheckForIllegalCrossThreadCalls = false;
            InitializeComponent();
            chbAuto.Checked = ConfigAppSettings.GetIntValue(Setting_Init.App_AutoRun).Equals(1);
        }

        #region "初始化界面数据"

        private void initValue()
        {
            InitStoreValue();
        }
        private void InitStoreValue()
        {
            this.store = StoreManager.InitStore();
            if (store == null)
            {
                LogUtil.error(LOGGER, "找不到对应的料仓");
                return;
            }

            cmbAxisList.DataSource = new List<ConfigMoveAxis>(store.moveAxisList);
            cmbAxisList.DisplayMember = "Explain";
            cmbAxisList.ValueMember = "Explain";
            cmbAxisList.SelectedIndex = 0;

            AutoStorePosition Position = null;
            if (store.PositionNumList.Count > 0)
            {
                cmbPosition.DataSource = store.PositionNumList;
                cmbPosition.SelectedIndex = 0;
                Position = CSVPositionReader<AutoStorePosition>.GetPositon(cmbPosition.Text);
                //store.PositionNumList = positionNumList;
            }

            txtMiddleP1.Text = store.Config.MiddleAxis_P1_Position.ToString();
            txtInOutP1.Text = store.Config.InOutAxis_P1_Position.ToString();
            txtComP1.Text = store.Config.CompressAxis_P1_Position.ToString();

            txtUpdownP8.Text = store.Config.UpDownAxis_OutLow_P8.ToString();
            txtUpdownP2.Text = store.Config.UpDownAxis_OutHigh_P2.ToString();
            //txtUpDownP7.Text = store.Config.UpDownAxis_DoorOBPosition_P7.ToString();
            //txtUpDownP8.Text = store.Config.UpDownAxis_DoorIBPosition_P8.ToString();
            //txtInOutP2.Text = store.Config.InOutAxis_DoorPosition_P2.ToString();
            txtUpDownP1.Text = store.Config.GetDefaultUpDownP1().ToString();
            txtUpDownDoor.Text = store.Config.UpDownAxis_Door_P7.ToString();
            if (Position != null)
            {
                txtUpDownP1.Text = store.Config.GetUpDownP1(Position.BagHeight).ToString();
                txtMiddleP2.Text = Position.MiddleAxis_Position_P2.ToString();
                txtUpDownP3.Text = Position.UpDownAxis_IHPosition_P3.ToString();
                txtUpDownP4.Text = Position.UpDownAxis_ILPosition_P4.ToString();
                txtUpDownP5.Text = Position.UpDownAxis_OHPosition_P5.ToString();
                txtUpDownP6.Text = Position.UpDownAxis_OLPosition_P6.ToString();
                txtComP2.Text = Position.CompressAxis_Position_P2.ToString();
                txtComP3.Text = Position.CompressAxis_CPosition_P3.ToString();
                txtInOutP3.Text = Position.InOutAxis_Position_P3.ToString();
                txtInOutP2.Text = Position.InOutAxis_Batch_P2.ToString();
                txtInoutP4.Text = Position.InOutAxis_DoorOutPosition_P4.ToString();
                //txtUpDownP1.Text = ktkPosition.UpDownAxis_DoorOPosition_P1.ToString(); 
            }
            txtSpeed.Text = store.Config.CompressAxis_EndSpeed.ToString();
            List<string> port = new List<string>(SerialPort.GetPortNames());
            comboBoxPortName.DataSource = port;
            if (port.IndexOf(store.Config.CompressAxis_PortName) >= 0)
            {
                comboBoxPortName.SelectedIndex = port.IndexOf(store.Config.CompressAxis_PortName);
            }
            cmbHomeType.SelectedIndex = 0;
            timer1.Enabled = true;
        }
        #endregion
        private string WaitStart = ResourceCulture.GetString(ResourceCulture.WaitStart, "等待启动");
        private string dooropen = ResourceCulture.GetString(ResourceCulture.DoorHasOpen, "   前门未关");
        private string HasWare = ResourceCulture.GetString(ResourceCulture.HasWare, "   叉子料盘检测有料,请检查");
        private string StartAuto = ResourceCulture.GetString(ResourceCulture.StartAuto,"开始自动出入库");
        private string StopAuto = ResourceCulture.GetString(ResourceCulture.StopAuto, "停止自动出入库");
        private string AutoOut = ResourceCulture.GetString(ResourceCulture.AutoOut, "自动出库:");
        private string AutoIn = ResourceCulture.GetString(ResourceCulture.AutoIn, "自动入库:");
        public static string cannotMove = ResourceCulture.GetString(ResourceCulture.CannotMove, "定位气缸不在下降端,不能移动进出轴");
        public static string warn = ResourceCulture.GetString(ResourceCulture.WarnMsg, "警告");
        public void processMenu()
        {

            string className = this.ClassName;
            CurrLanguage = ResourceCulture.CurrLanguage;
            ResourceCulture.GetString(ResourceCulture.CannotMove, "定位气缸不在下降端,不能移动进出轴");
            warn = ResourceCulture.GetString(ResourceCulture.WarnMsg, "警告");
           
            WaitStart = ResourceCulture.GetString(ResourceCulture.WaitStart, "等待启动");
            dooropen = ResourceCulture.GetString(ResourceCulture.DoorHasOpen, "   前门未关");
            HasWare = ResourceCulture.GetString(ResourceCulture.HasWare, "   叉子料盘检测有料,请检查");
            StartAuto = ResourceCulture.GetString(ResourceCulture.StartAuto,StartAuto);
            StopAuto = ResourceCulture.GetString(ResourceCulture.StopAuto, StopAuto);
            AutoOut = ResourceCulture.GetString(ResourceCulture.AutoOut, "自动出库:");
            AutoIn = ResourceCulture.GetString(ResourceCulture.AutoIn, "自动入库:");
            //摄像机调试ToolStripMenuItem.Visible = CurrLanguage.Equals(ResourceCulture.China);
            //toolStripSeparator10.Visible = CurrLanguage.Equals(ResourceCulture.China);
          
             
            
            ToolStripItemCollection collection = menuStrip1.Items;
            for (int i = 0; i < collection.Count; i++)
            {
                if (collection[i] is ToolStripMenuItem)
                {
                    string newStr = ResourceCulture.GetString(ResourceCulture.GetTextIdStr(className, collection[i].Name), collection[i].Text);
                    collection[i].Text = newStr;

                    ToolStripMenuItem a = (ToolStripMenuItem)collection[i];
                    ToolStripItemCollection newColl = a.DropDownItems;
                    for (int ii = 0; ii < newColl.Count; ii++)
                    {
                        if (newColl[ii] is ToolStripMenuItem)
                        {
                            newStr = ResourceCulture.GetString(ResourceCulture.GetTextIdStr(className, newColl[ii].Name), newColl[ii].Text);
                            newColl[ii].Text = newStr;
                        }
                    }
                }
            }
            显示ToolStripMenuItem.Text = ResourceCulture.GetString(ResourceCulture.GetTextIdStr(className, 显示ToolStripMenuItem.Name), 显示ToolStripMenuItem.Text);
            toolStripMenuItem1.Text = ResourceCulture.GetString(ResourceCulture.GetTextIdStr(className, toolStripMenuItem1.Name), toolStripMenuItem1.Text);
            notifyIcon1.Text = this.Text;
            if (CurrLanguage.Equals(ResourceCulture.China))
            {
                LogUtil.logBox = this.richTextBox1;
            }
            else
            {
                LogUtil.ClearLog();
                LogUtil.logBox = null;
                this.richTextBox1.Clear();
            }
        }

        private void start_button_Click(object sender, EventArgs e)
        {
            store.StartRun();
            if (store.storeRunStatus >= StoreRunStatus.HomeMoving)
            {
                StoreOpenStatus(true);
            }
        }

        private void stop_button_Click(object sender, EventArgs e)
        {
            try
            {
                store.StopRun();
                StoreOpenStatus(false);
            }
            catch (Exception ex)
            {
                LogUtil.error(LOGGER, "出错:" + ex.StackTrace);
            }
        }
        private bool preOpen = false;
        public void StoreOpenStatus(bool isOpen)
        {
            if (preOpen.Equals(isOpen))
            {
                return;
            }
            preOpen = isOpen;

            //btnOutStore.Enabled = isOpen;
            //btnInStore.Enabled = isOpen;

            //btnAxisAMove.Enabled = isOpen;

            //btnAxisReturnHome.Enabled = isOpen;
            //btnAxisRMove.Enabled = isOpen;
            //btnAxisVMove.Enabled = isOpen;

            启动ToolStripMenuItem.Enabled = !isOpen;
            停止ToolStripMenuItem.Enabled = isOpen;
            复位ToolStripMenuItem.Enabled = isOpen;

        }
        private bool LoadOk = false;
        private void FrmTest_Load(object sender, EventArgs e)
        {
            string language = ConfigAppSettings.GetValue(Setting_Init.Default_Language);
            if (language.Equals(ResourceCulture.China) || language.Equals(ResourceCulture.English))
            {
                ResourceCulture.SetCurrentCulture(language);
            }
            else
            {
                ResourceCulture.SetCurrentCulture(ResourceCulture.China);
                ConfigAppSettings.SaveValue(Setting_Init.Default_Language, ResourceCulture.China);
            }
            GetVersion();
            LogUtil.logBox = this.richTextBox1;
            this.ShowInTaskbar = true;
            this.Text = ConfigAppSettings.GetValue(Setting_Init.App_Title);
            HideForm();
            initValue();
             
            this.toolStripMenuItem4.Visible = StoreManager.HasDisableDoorControl;
            this.toolStripMenuItem5.Visible = StoreManager.HasDisableDoorControl;
            this.toolStripSeparator16.Visible = StoreManager.HasDisableDoorControl;
            this.toolStripSeparator18.Visible = StoreManager.HasDisableDoorControl;
            txtTempPort.Text = store.Config.Humiture_Port;
            LoadOk = true;
            cmbHomeType.SelectedIndex = 1;
            timer1.Start();
            store.ResetEvent += Store_ResetEvent;
            cmbJianGe.Items.Clear();
            for(int i = 0; i <= 20; i++)
            {
                cmbJianGe.Items.Add(i.ToString());
            }
            cmbJianGe.SelectedIndex = 1;

            DebugStatus(false);
        }

        private void Store_ResetEvent()
        {
            DebugStatus(false);
        }

        private DateTime preReadModblsTime = DateTime.Now;
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                if (this.Visible.Equals(false) )
                {
                    return;
                }
                lblTemp.Text = store.currTempStr;
                lblBatchMsg.Text = AutomaticBaiting.WarnMsg;
                lblWarnMsg.Text = store.WarnMsg;
                BatchInoutStatus(); 
                //忙碌状态不读取状态
                if (!store.storeRunStatus.Equals(StoreRunStatus.Busy))
                {
                    if (chbAutoRead.Checked)
                    {
                        string portName = GetPortName();
                        int SlvAddr = GetSlaveAddr();

                        //判断私服是否打开、
                        if (ACServerManager.ServerOnStatus(portName, SlvAddr))
                        {
                            lblServerOn.Text = ResourceCulture.GetString(ResourceCulture.servoON, "伺服ON");
                            int lOutPulse = ACServerManager.GetTargetPosition(portName, SlvAddr);
                            lblOutPulse.Text = string.Format("{0:d}", lOutPulse);
                            int lCountPulse = ACServerManager.GetActualtPosition(portName, SlvAddr);
                            lblCountPulse.Text = string.Format("{0:d}", lCountPulse);
                        }
                        else
                        {
                            lblServerOn.Text =ResourceCulture.GetString(ResourceCulture.ServoOff, "伺服OFF");
                        }
                    }
                }

                lblBatchStatus.Text = store.GetRunStr(AutomaticBaiting.AutoBaitingStatus, false);
            
                //ReadPosistion();
                if (store.storeRunStatus > StoreRunStatus.Wait)
                {
                    if (启动ToolStripMenuItem.Enabled.Equals(true))
                    {
                        StoreOpenStatus(true);
                    }
                    lblThisSta.Text = store.GetRunStr(store.storeRunStatus, true);
                    //复位按钮状态显示
                    if (复位ToolStripMenuItem.Enabled == false)
                    {
                        if ((store.storeRunStatus.Equals(StoreRunStatus.HomeMoving) || store.storeRunStatus.Equals(StoreRunStatus.Reset))
                            && store.alarmType.Equals(StoreAlarmType.None))
                        {
                        }
                        else
                        {
                            if (复位ToolStripMenuItem.Enabled.Equals(false))
                            {
                                复位ToolStripMenuItem.Enabled = true;
                            }
                        }
                    }
                    else
                    {
                        if ((store.storeRunStatus.Equals(StoreRunStatus.HomeMoving) || store.storeRunStatus.Equals(StoreRunStatus.Reset))
                            && store.alarmType.Equals(StoreAlarmType.None))
                        {
                            if (启动ToolStripMenuItem.Enabled)
                            {
                                启动ToolStripMenuItem.Enabled = false;
                                复位ToolStripMenuItem.Enabled = false;
                            }
                        }
                    }
                  
                    //string deviceMsg = "叉子上有料盘,请打开仓门检查";
                    if (store.storeRunStatus.Equals(StoreRunStatus.Runing) && store.StoreMove.MoveType.Equals(StoreMoveType.None) && IOManager.IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH))
                    {
                        lblWarnMsg.Text = lblWarnMsg.Text + HasWare;
                    }
                    if (store.TempOrHumidityIsAlarm)
                    {
                        lblWarnMsg.Text = lblWarnMsg.Text + "   温湿度报警[" + store.TempAlarmTime.ToLongTimeString() + "]";
                    }

                    if (store.autoNext)
                    {
                        string msg = store.autoMsg;
                        groupAuto.Text = msg;
                        if (btnStart.Text.Equals(StartAuto))
                        {
                            btnStart.Text = StopAuto;
                        }
                        try
                        {
                            msg = msg.Replace("自动出库:", "");
                            msg = msg.Replace("自动入库:", "");
                            int index = store.PositionNumList.IndexOf(msg);
                            if (index >= 0 && (!msg.Equals("")))
                            {
                                cmbPosition.SelectedIndex = index;
                            }
                        }
                        catch (Exception ex) { }
                    }
                    else
                    {
                        groupAuto.Text = "自动出入库操作"; 
                        btnStart.Text = StartAuto; 
                    }
                }
                else
                {
                    groupAuto.Text = StartAuto;
                    lblThisSta.Text = WaitStart;
                    //lblWarnMsg.Text = "";
                    btnStart.Text =StartAuto;
                    
                    lblDoorStatus.Text =ResourceCulture.GetString(ResourceCulture.NoDoorStatus, "仓门状态未知");
                }
            }catch(Exception ex)
            {
                LogUtil.error("主界面定时器出错:"+ex.StackTrace);
            }
        }

        private void BatchInoutStatus()
        {
            Dictionary<string, string> map = AutomaticBaiting.GetBtnStatus();
            btnWaitTrgGo.Visible = map[ParamDefine.confirmReelOut].Equals(ParamDefine.enable);
            lblWaitTragGo.Visible = map[ParamDefine.confirmReelOut].Equals(ParamDefine.enable);
            btnOpenDoor.Enabled = map[ParamDefine.openLock].Equals(ParamDefine.enable);
            btnBatchInStore.Enabled = map[ParamDefine.startBatchIn].Equals(ParamDefine.enable);
            btnGetOutTray.Enabled = map[ParamDefine.takeOutReel].Equals(ParamDefine.enable);
            btnCloseDoor.Enabled = map[ParamDefine.closeLock].Equals(ParamDefine.enable);
 
            lblDoorStatus.Text = map[ParamDefine.doorStatus];
            lblOutInfo.Visible = !lblWaitTragGo.Visible;
            lblOutInfo.Text = ResourceCulture.GetString(ResourceCulture.InstoreInfo,"批量出入库信息:    入库:" )+ AutomaticBaiting.BatchInStoreCount + "," + AutomaticBaiting.BatchInStoreHeight + "mm," +
              ResourceCulture.GetString(ResourceCulture.oustore , "出库: ") + AutomaticBaiting.BatchOutStoreCount + "," + AutomaticBaiting.BatchOutStoreHeight + "mm";

            bool isRun = HumitureController.IsRun;
            btnSelTemp.Enabled = isRun;
            btnTempClose.Enabled = isRun;
            btnTempInit.Enabled = !isRun;
        }
          
        private void ReadPosistion()
        {
            string portName = GetPortName();
            int SlvAddr = GetSlaveAddr();
            //判断私服是否打开、
            if (ACServerManager.ServerOnStatus(portName, SlvAddr))
            {
                lblServerOn.Text = "伺服ON";
            }
            else
            {
                lblServerOn.Text = "伺服OFF";
            }
            string deviceName = GetPortName();
            if (ACServerManager.ServerOnStatus(store.Config.Middle_Axis.DeviceName, store.Config.Middle_Axis.GetAxisValue()))
            {
                axis_1_Alarm.IOValue = ACServerManager.GetAlarmStatus(store.Config.Middle_Axis.DeviceName, store.Config.Middle_Axis.GetAxisValue());
                axis_1_Alarm.ShowData();
                int lOutPulse1 = ACServerManager.GetTargetPosition(store.Config.Middle_Axis.DeviceName, store.Config.Middle_Axis.GetAxisValue());
                lblOutPulse1.Text = string.Format("{0:d}", lOutPulse1);
                int lCountPulse1 = ACServerManager.GetActualtPosition(store.Config.Middle_Axis.DeviceName, store.Config.Middle_Axis.GetAxisValue());
                lblCountPulse1.Text = string.Format("{0:d}", lCountPulse1);
                txtMiddleTarget.Text = store.Config.Middle_Axis.TargetPosition.ToString();
                //if (deviceName.Equals(store.Config.Middle_Axis.DeviceName))
                    if(store.Config.Middle_Axis.IsSameAxis(deviceName,SlvAddr))
                {
                    lblOutPulse.Text = lblOutPulse1.Text;
                    lblCountPulse.Text = lblCountPulse1.Text;
                }
            }
            if (ACServerManager.ServerOnStatus(store.Config.UpDown_Axis.DeviceName, store.Config.UpDown_Axis.GetAxisValue()))
            {
                axis_2_Alarm.IOValue = ACServerManager.GetAlarmStatus(store.Config.UpDown_Axis.DeviceName, store.Config.UpDown_Axis.GetAxisValue());
                axis_2_Alarm.ShowData();
                int lOutPulse2 = ACServerManager.GetTargetPosition(store.Config.UpDown_Axis.DeviceName, store.Config.UpDown_Axis.GetAxisValue());
                lblOutPulse2.Text = string.Format("{0:d}", lOutPulse2);
                int lCountPulse2 = ACServerManager.GetActualtPosition(store.Config.UpDown_Axis.DeviceName, store.Config.UpDown_Axis.GetAxisValue());
                lblCountPulse2.Text = string.Format("{0:d}", lCountPulse2);
                txtUpdownTarget.Text = store.Config.UpDown_Axis.TargetPosition.ToString();
                //if (deviceName.Equals(store.Config.UpDown_Axis.DeviceName))
                    if (store.Config.UpDown_Axis.IsSameAxis(deviceName, SlvAddr))
                    {
                    lblOutPulse.Text = lblOutPulse2.Text;
                    lblCountPulse.Text = lblCountPulse2.Text;
                }
            }
            if (ACServerManager.ServerOnStatus(store.Config.InOut_Axis.DeviceName, store.Config.InOut_Axis.GetAxisValue()))
            {
                axis_3_Alarm.IOValue = ACServerManager.GetAlarmStatus(store.Config.InOut_Axis.DeviceName, store.Config.InOut_Axis.GetAxisValue());
                int lOutPulse3 = ACServerManager.GetTargetPosition(store.Config.InOut_Axis.DeviceName, store.Config.InOut_Axis.GetAxisValue());
                lblOutPulse3.Text = string.Format("{0:d}", lOutPulse3);
                int lCountPulse3 = ACServerManager.GetActualtPosition(store.Config.InOut_Axis.DeviceName, store.Config.InOut_Axis.GetAxisValue());
                lblCountPulse3.Text = string.Format("{0:d}", lCountPulse3);
                txtInoutTarget.Text = store.Config.InOut_Axis.TargetPosition.ToString();
                //if (deviceName.Equals(store.Config.InOut_Axis.DeviceName))
                    if (store.Config.InOut_Axis.IsSameAxis(deviceName, SlvAddr))
                    {
                    lblOutPulse.Text = lblOutPulse3.Text;
                    lblCountPulse.Text = lblCountPulse3.Text;
                }
            }
            if (ACServerManager.ServerOnStatus(store.Config.Batch_Axis.DeviceName, store.Config.Batch_Axis.GetAxisValue()))
            {
                axis_5_Alarm.IOValue = ACServerManager.GetAlarmStatus(store.Config.Batch_Axis.DeviceName, store.Config.Batch_Axis.GetAxisValue());
                int lOutPulse5 = ACServerManager.GetTargetPosition(store.Config.Batch_Axis.DeviceName, store.Config.Batch_Axis.GetAxisValue());
                lblOutPulse5.Text = string.Format("{0:d}", lOutPulse5);
                int lCountPulse5 = ACServerManager.GetActualtPosition(store.Config.Batch_Axis.DeviceName, store.Config.Batch_Axis.GetAxisValue());
                lblCountPulse5.Text = string.Format("{0:d}", lCountPulse5);
                txtBatchTarget.Text = store.Config.Batch_Axis.TargetPosition.ToString();
                //if (deviceName.Equals(store.Config.Batch_Axis.DeviceName))
                if (store.Config.Batch_Axis.IsSameAxis(deviceName, SlvAddr))
                    {
                    lblOutPulse.Text = lblOutPulse5.Text;
                    lblCountPulse.Text = lblCountPulse5.Text;
                }
            }
            lblAxisStatus.Text = ":" + DateTime.Now.ToLongTimeString();
        }

        private void Bt_ClearCounter_Click(object sender, EventArgs e)
        {
            string portName = txtAxisDeviceName.Text;
            short SlvAddr = FormUtil.GetShortValue(txtAxisValue);

            //KTKSMCManager.WSetCountPulse(portName, SlvAddr, 0);
            //KTKSMCManager.WSetOutPulse(portName, SlvAddr, 0);
        }

        

        private void FrmTest_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)//当用户点击窗体右上角X按钮或(Alt + F4)时 发生           
            {
                e.Cancel = true;
                HideForm();
            }
        }
        private void btnOutStore_Click(object sender, EventArgs e)
        {
            if (store.storeRunStatus >= StoreRunStatus.HomeMoving)
            {
                string selectPositionNum = cmbPosition.Text;
                LineMoveP ktk = LoadPostion();
                store.StartOutStoreMove(new InOutStoreParam("", selectPositionNum, ktk), false);
            }
            else
            {
                 MessageBox.Show(ResourceCulture.GetString(ResourceCulture.PleaseStartStore, "请先启动料仓!"));
            }
        }

        private void btnInStore_Click(object sender, EventArgs e)
        {
            MessageBox.Show(ResourceCulture.GetString(ResourceCulture.CanotSingleInStore,"此设备不支持单个入库"),
                ResourceCulture.GetString(ResourceCulture.MsgTitle,ResourceCulture.GetString(ResourceCulture.MsgTitle,"提示")), MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
            if (store.storeRunStatus >= StoreRunStatus.HomeMoving)
            {
                string selectPositionNum = cmbPosition.Text;
                LineMoveP ktk = LoadPostion();
                store.StartInStoreMove(new InOutStoreParam("", selectPositionNum, ktk), false);
            }
            else
            {
                 MessageBox.Show(ResourceCulture.GetString(ResourceCulture.PleaseStartStore, "请先启动料仓!"));
            }
        }

        private LineMoveP LoadPostion()
        {
            LineMoveP ktk = new LineMoveP();
            ktk.ComPress_P1 = FormUtil.GetIntValue(txtComP1);
            ktk.ComPress_P2 = FormUtil.GetIntValue(txtComP2);
            ktk.ComPress_P3 = FormUtil.GetIntValue(txtComP3);
            ktk.InOut_P1 = FormUtil.GetIntValue(txtInOutP1);
            ktk.InOut_P2 = FormUtil.GetIntValue(txtInOutP2);
            ktk.InOut_P4 = FormUtil.GetIntValue(txtInoutP4);
            ktk.InOut_P3 = FormUtil.GetIntValue(txtInOutP3);
            ktk.Middle_P1 = FormUtil.GetIntValue(txtMiddleP1);
            ktk.Middle_P2 = FormUtil.GetIntValue(txtMiddleP2);

            ktk.UpDown_P1 = FormUtil.GetIntValue(txtUpDownP1);
            ktk.UpDown_Door_P7 = FormUtil.GetIntValue(txtUpDownDoor);
            //ktk.UpDown_P2 = FormUtil.GetIntValue(txtUpDownP2);
            ktk.UpDown_P3 = FormUtil.GetIntValue(txtUpDownP3);
            ktk.UpDown_P4 = FormUtil.GetIntValue(txtUpDownP4);
            ktk.UpDown_P5 = FormUtil.GetIntValue(txtUpDownP5);
            ktk.UpDown_P6 = FormUtil.GetIntValue(txtUpDownP6);
            //ktk.UpDown_P7 = FormUtil.GetIntValue(txtUpDownP7);
            //ktk.UpDown_P8 = FormUtil.GetIntValue(txtUpDownP8);
            ktk.UpDown_OutHigh_P2 = FormUtil.GetIntValue(txtUpdownP2);
            ktk.UpDown_OutLow_P8 = FormUtil.GetIntValue(txtUpdownP8);

            return ktk;
        }
        private void btnComAlarmClear_Click(object sender, EventArgs e)
        {
            string portName = txtAxisDeviceName.Text;
            short slvAddr = FormUtil.GetShortValue(txtAxisValue);
            LogUtil.info("点击【清理报警】,端口号【" + portName + "】地址【" + slvAddr + "】 ");
            ACServerManager.AlarmClear(portName, slvAddr);
            Thread.Sleep(100);
            ACServerManager.ServoOn(portName, slvAddr);
        }

        private void cmbPosition_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbPosition.SelectedIndex >= 0)
            {
                string selectPositionNum = cmbPosition.Text;
                AutoStorePosition ktkPosition = CSVPositionReader<AutoStorePosition>.GetPositon(selectPositionNum);

                if (ktkPosition != null)
                {
                    txtMiddleP2.Text = ktkPosition.MiddleAxis_Position_P2.ToString();
                    txtUpDownP3.Text = ktkPosition.UpDownAxis_IHPosition_P3.ToString();
                    txtUpDownP4.Text = ktkPosition.UpDownAxis_ILPosition_P4.ToString();
                    txtUpDownP5.Text = ktkPosition.UpDownAxis_OHPosition_P5.ToString();
                    txtUpDownP6.Text = ktkPosition.UpDownAxis_OLPosition_P6.ToString();
                    txtComP2.Text = ktkPosition.CompressAxis_Position_P2.ToString();
                    txtComP3.Text = ktkPosition.CompressAxis_CPosition_P3.ToString();
                    txtInOutP3.Text = ktkPosition.InOutAxis_Position_P3.ToString();
                    txtInOutP2.Text = ktkPosition.InOutAxis_Batch_P2.ToString();
                    txtInoutP4.Text = ktkPosition.InOutAxis_DoorOutPosition_P4.ToString();
                    txtUpDownP1.Text = store.Config.GetUpDownP1(ktkPosition.BagHeight).ToString();
                    //txtUpDownP2.Text = ktkPosition.UpDownAxis_DoorIPosition_P2.ToString();
                    //txtUpDownP7.Text = ktkPosition.UpDownAxis_DoorOBPosition_P7.ToString();
                    //txtUpDownP8.Text = ktkPosition.UpDownAxis_DoorIBPosition_P8.ToString();
                    //txtInOutP2.Text = ktkPosition.InOutAxis_DoorPosition_P2.ToString();
                    //txtUpDownP1.Text = ktkPosition.UpDownAxis_DoorOPosition_P1.ToString(); 
                }
            }
        }
        private void cmbAxisList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.cmbAxisList.SelectedIndex >= 0)
            {
                ConfigMoveAxis SlvAddr = store.moveAxisList[cmbAxisList.SelectedIndex];
                txtAxisDeviceName.Text = SlvAddr.DeviceName;
                txtAxisValue.Text = SlvAddr.GetAxisValue().ToString();
                txtASpeed.Text = SlvAddr.TargetSpeed.ToString();
            }
        }

        private void btnAxisAMove_Click(object sender, EventArgs e)
        {
            //ConfigMoveAxis axisC = store.moveAxisList[cmbAxisList.SelectedIndex];
            string portName = txtAxisDeviceName.Text;
            short SlvAddr = FormUtil.GetShortValue(txtAxisValue);
            int position = FormUtil.GetIntValue(txtAPosition);
            int speed = FormUtil.GetIntValue(txtASpeed);
            //if (axisC.PositionIsHasLimit() && (axisC.PositionMin > position || axisC.PositionMax < position))
            //{
            //    MessageBox.Show("位置超出" + axisC.Explain + "上下限(" + axisC.PositionMin + "-" + axisC.PositionMax + ")");
            //    return;
            //}
            if (store.Config.InOut_Axis.IsSameAxis(portName,SlvAddr)   && (store.InOutAxisCanMove().Equals(false)))
            {
                MessageBox.Show( cannotMove,warn, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else if ( store.Config.Middle_Axis.IsSameAxis(portName,SlvAddr ) ||  store.Config.UpDown_Axis.IsSameAxis(portName,SlvAddr))
            {
                if (!InOutIsIsP1())
                {
                    return;
                }
            }
            LogUtil.info("点击【绝对运动】,端口号【" + portName + "】地址【" + SlvAddr + "】位置【" + position + "】速度【" + speed + "】");
            ACServerManager.AbsMove(portName, SlvAddr, position, speed);
        }
        private void btnAxisVMove_Click(object sender, EventArgs e)
        {
            //ConfigMoveAxis axisC = store.moveAxisList[cmbAxisList.SelectedIndex];
            string portName = txtAxisDeviceName.Text;
            short SlvAddr = FormUtil.GetShortValue(txtAxisValue);
            int speed = FormUtil.GetIntValue(txtASpeed);
            if (store.Config.InOut_Axis.IsSameAxis(portName, SlvAddr) && (store.InOutAxisCanMove().Equals(false)))
            {
                MessageBox.Show( cannotMove,warn, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else if (store.Config.Middle_Axis.IsSameAxis(portName, SlvAddr) || store.Config.UpDown_Axis.IsSameAxis(portName, SlvAddr))
            {
                if (!InOutIsIsP1())
                {
                    return;
                }
            }
            LogUtil.info("点击【匀速运动】,端口号【" + portName + "】地址【" + SlvAddr + "】 速度【" + speed + "】");
            ACServerManager.SpeedMove(portName, SlvAddr, speed);
        }

        private void btnAxisRMove_Click(object sender, EventArgs e)
        {
            //ConfigMoveAxis axisC = store.moveAxisList[cmbAxisList.SelectedIndex];
            string portName = txtAxisDeviceName.Text;
            short SlvAddr = FormUtil.GetShortValue(txtAxisValue);
            int position = FormUtil.GetIntValue(txtAPosition);
            int speed = FormUtil.GetIntValue(txtASpeed);
            //int currPositon = ACServerManager.GetActualtPosition(portName, SlvAddr);
            // int newPosition = position + currPositon;
            // if (axisC.PositionIsHasLimit() && (axisC.PositionMin > newPosition || axisC.PositionMax < newPosition))
            //{
            //    MessageBox.Show("位置超出"+axisC.Explain+"上下限(" + axisC.PositionMin + "-" + axisC.PositionMax + ")");
            //    return;
            //}

            if (store.Config.InOut_Axis.IsSameAxis(portName, SlvAddr) && (store.InOutAxisCanMove().Equals(false)))
            {
                MessageBox.Show( cannotMove,warn, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else if (store.Config.Middle_Axis.IsSameAxis(portName, SlvAddr) || store.Config.UpDown_Axis.IsSameAxis(portName, SlvAddr))
            {
                if (!InOutIsIsP1())
                {
                    return;
                }
            }
            LogUtil.info("点击【相对运动】,端口号【" + portName + "】地址【" + SlvAddr + "】位置【" + position + "】速度【" + speed + "】");
            ACServerManager.RelMove(portName, SlvAddr, position, speed);
        }



        private void btnAxisStop_Click(object sender, EventArgs e)
        {
            string portName = txtAxisDeviceName.Text;
            short SlvAddr = FormUtil.GetShortValue(txtAxisValue);
            LogUtil.info("点击【停止运动】,端口号【" + portName + "】地址【" + SlvAddr + "】 ");
            ACServerManager.SuddenStop(portName, SlvAddr);
        }

        private void cmbAxisList_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index < 0)
            {
                return;
            }
            e.DrawBackground();
            e.DrawFocusRectangle();
            if (this.cmbAxisList.Items.Count > e.Index)
            {
                ConfigMoveAxis SlvAddr = (ConfigMoveAxis)cmbAxisList.Items[e.Index];
                e.Graphics.DrawString(SlvAddr.DisplayStr, e.Font, new SolidBrush(e.ForeColor), e.Bounds.X, e.Bounds.Y + 3);
            }
        }

        private void btnSavePosition_Click(object sender, EventArgs e)
        {
            //料仓格子位置保存
            string selectPositionNum = cmbPosition.Text;
            AutoStorePosition ktkPosition = CSVPositionReader<AutoStorePosition>.GetPositon(selectPositionNum);
            if (ktkPosition != null)
            {
                ktkPosition.MiddleAxis_Position_P2 = FormUtil.GetIntValue(txtMiddleP2);
                ktkPosition.UpDownAxis_IHPosition_P3 = FormUtil.GetIntValue(txtUpDownP3);
                ktkPosition.UpDownAxis_ILPosition_P4 = FormUtil.GetIntValue(txtUpDownP4);

                ktkPosition.UpDownAxis_ILPosition_P4 = FormUtil.GetIntValue(txtUpDownP4);
                ktkPosition.InOutAxis_Position_P3 = FormUtil.GetIntValue(txtInOutP3);
                ktkPosition.CompressAxis_CPosition_P3 = FormUtil.GetIntValue(txtComP3);
                ktkPosition.UpDownAxis_OHPosition_P5 = FormUtil.GetIntValue(txtUpDownP5);
                ktkPosition.UpDownAxis_OLPosition_P6 = FormUtil.GetIntValue(txtUpDownP6);
                ktkPosition.CompressAxis_Position_P2 = FormUtil.GetIntValue(txtComP2);
                ktkPosition.InOutAxis_Batch_P2 = FormUtil.GetIntValue(txtInOutP2);
                ktkPosition.InOutAxis_DoorOutPosition_P4 = FormUtil.GetIntValue(txtInoutP4);
                //ktkPosition.UpDownAxis_DoorIPosition_P2 = FormUtil.GetIntValue(txtUpDownP2);
                //ktkPosition.UpDownAxis_DoorOBPosition_P7 = FormUtil.GetIntValue(txtUpDownP7);
                //ktkPosition.UpDownAxis_DoorIBPosition_P8 = FormUtil.GetIntValue(txtUpDownP8);
                //ktkPosition.InOutAxis_DoorPosition_P2 = FormUtil.GetIntValue(txtInOutP2);
                //ktkPosition.UpDownAxis_DoorOPosition_P1 = FormUtil.GetIntValue(txtUpDownP1);
            }
            //位置配置
            string appPath = Application.StartupPath;
            //如果总配置文件存在,保存到总的配置文件
            string positionConfigFile = appPath + ConfigAppSettings.GetValue(Setting_Init.Store_Position_Config);
            if (!File.Exists(positionConfigFile))
            {
                positionConfigFile = appPath + ConfigAppSettings.GetValue(Setting_Init.Store_Position_Config, "_" + store.StoreID.ToString());
            }
            bool result = CSVPositionReader<AutoStorePosition>.SavePostion(positionConfigFile, ktkPosition);
            if (!result)
            {
                MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SaveError, "保存失败"));
            }
            //料仓固定位置保存
            bool needUpdate = false;
            if (store.Config.MiddleAxis_P1_Position != FormUtil.GetIntValue(txtMiddleP1))
            {
                store.Config.MiddleAxis_P1_Position = FormUtil.GetIntValue(txtMiddleP1);
                needUpdate = true;
            }
            if (ktkPosition != null)
            {
                if (store.Config.GetUpDownP1(ktkPosition.BagHeight) != FormUtil.GetIntValue(txtUpDownP1))
                {
                    store.Config.UpdateUpDownP1(ktkPosition.BagHeight, FormUtil.GetIntValue(txtUpDownP1));
                    needUpdate = true;
                }
                if (store.Config.GetComP2(ktkPosition.BagHeight) != FormUtil.GetIntValue(txtComP2))
                {
                    store.Config.UpdateComP2(ktkPosition.BagHeight, FormUtil.GetIntValue(txtComP2));
                    needUpdate = true;
                }
            }
            if (store.Config.InOutAxis_P1_Position != FormUtil.GetIntValue(txtInOutP1))
            {
                store.Config.InOutAxis_P1_Position = FormUtil.GetIntValue(txtInOutP1);
                needUpdate = true;
            }

            if (store.Config.CompressAxis_P1_Position != FormUtil.GetIntValue(txtComP1))
            {
                store.Config.CompressAxis_P1_Position = FormUtil.GetIntValue(txtComP1);
                needUpdate = true;
            }
            if (store.Config.UpDownAxis_Door_P7 != FormUtil.GetIntValue(txtUpDownDoor))
            {
                store.Config.UpDownAxis_Door_P7 = FormUtil.GetIntValue(txtUpDownDoor);
                needUpdate = true;
            }
            if (store.Config.UpDownAxis_OutHigh_P2 != FormUtil.GetIntValue(txtUpdownP2))
            {
                store.Config.UpDownAxis_OutHigh_P2 = FormUtil.GetIntValue(txtUpdownP2);
                needUpdate = true;
            }
            //if (store.Config.UpDownAxis_DoorOBPosition_P7 != FormUtil.GetIntValue(txtUpDownP7))
            //{
            //    store.Config.UpDownAxis_DoorOBPosition_P7 = FormUtil.GetIntValue(txtUpDownP7);
            //    needUpdate = true;
            //}
            if (store.Config.UpDownAxis_OutLow_P8 != FormUtil.GetIntValue(txtUpdownP8))
            {
                store.Config.UpDownAxis_OutLow_P8 = FormUtil.GetIntValue(txtUpdownP8);
                needUpdate = true;
            }
            //if (store.Config.InOutAxis_DoorPosition_P2 != FormUtil.GetIntValue(txtInOutP2))
            //{
            //    store.Config.InOutAxis_DoorPosition_P2 = FormUtil.GetIntValue(txtInOutP2);
            //    needUpdate = true;
            //}
            //if (store.Config.UpDownAxis_DoorOPosition_P1 != FormUtil.GetIntValue(txtUpDownP1))
            //{
            //    store.Config.UpDownAxis_DoorOPosition_P1 = FormUtil.GetIntValue(txtUpDownP1);
            //    needUpdate = true;
            //}
            if (needUpdate)
            {
                //更新缓存
                StoreManager.UpdateBoxConfig(store.Config);
            }

        }

        private void btnOpenAxis_Click(object sender, EventArgs e)
        {
            string portName = txtAxisDeviceName.Text;
            short SlvAddr = FormUtil.GetShortValue(txtAxisValue);
            LogUtil.info("点击【打开伺服】,端口号【" + portName + "】地址【" + SlvAddr + "】 ");
            ACServerManager.OpenPort(portName);
            //ACServerManager.InitSlvAddr(portName, SlvAddr);
            //Thread.Sleep(100);
            ACServerManager.AlarmClear(portName, SlvAddr);
            Thread.Sleep(100);
            ACServerManager.ServoOn(portName, SlvAddr);
        }
        /// <summary>
        /// 判断进出轴是否在P1点
        /// </summary> 
        private bool InOutIsIsP1()
        {
            int InOutDefaultPosition = ConfigAppSettings.GetIntValue(Setting_Init.InOutDefaultPosition);
            //if (InOutDefaultPosition > 3000 || InOutDefaultPosition.Equals(0))
            //{
            //    InOutDefaultPosition = 3000;
            //}
            int currValue = ACServerManager.GetActualtPosition(store.Config.InOut_Axis.DeviceName, store.Config.InOut_Axis.GetAxisValue());
            if (currValue <= InOutDefaultPosition)
            {
                return true;
            }
            MessageBox.Show( ResourceCulture.GetString(ResourceCulture.InoutNotOk,"叉子不在待机位,请先将叉子退回待机位")+"(" + InOutDefaultPosition + ")!",
                ResourceCulture.GetString(ResourceCulture.InoutWarn,"警告(叉子在待机位时,才能移动升降轴和旋转轴)" ), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            return false;
        }
        private void btnCloseAxis_Click(object sender, EventArgs e)
        {
            string portName = txtAxisDeviceName.Text;
            short SlvAddr = FormUtil.GetShortValue(txtAxisValue);
            LogUtil.info("点击【关闭伺服】,端口号【" + portName + "】地址【" + SlvAddr + "】 ");
            ACServerManager.ServoOff(portName, SlvAddr);
        }
        private void AxisABSMove(ConfigMoveAxis moveAxis, int targetPosition, int targetSpeed)
        {
            moveAxis.TargetPosition = targetPosition;
            ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition, targetSpeed);
        }
        private void btnUpDownP1_Click(object sender, EventArgs e)
        {
            if (InOutIsIsP1())
            {
                int value = FormUtil.GetIntValue(txtUpDownP1);
                AxisABSMove(store.Config.UpDown_Axis, value, store.Config.UpDownAxis_P1_Speed);
            }
        }

        private void btnUpDownP2_Click(object sender, EventArgs e)
        {
            if (InOutIsIsP1())
            {
                int value = FormUtil.GetIntValue(txtUpdownP2);
                AxisABSMove(store.Config.UpDown_Axis, value, store.Config.UpDownAxis_P2_Speed);
            }
        }
        private void btnUpDownP7_Click(object sender, EventArgs e)
        {
            //if (InOutIsIsP1())
            //{
            //    int value = FormUtil.GetIntValue(txtUpDownP7);
            //    AxisABSMove(store.Config.UpDown_Axis, value, store.Config.UpDownAxis_P7_Speed);
            //}
        }

        private void btnUpDownP8_Click(object sender, EventArgs e)
        {
            if (InOutIsIsP1())
            {
                int value = FormUtil.GetIntValue(txtUpdownP8);
                AxisABSMove(store.Config.UpDown_Axis, value, store.Config.UpDownAxis_P8_Speed);
            }
        }

        private void btnUpDownP3_Click(object sender, EventArgs e)
        {
            if (InOutIsIsP1())
            {
                int value = FormUtil.GetIntValue(txtUpDownP3);
                AxisABSMove(store.Config.UpDown_Axis, value, store.Config.UpDownAxis_P3_Speed);
            }
        }

        private void btnUpDownP4_Click(object sender, EventArgs e)
        {
            if (InOutIsIsP1())
            {
                int value = FormUtil.GetIntValue(txtUpDownP4);
                AxisABSMove(store.Config.UpDown_Axis, value, store.Config.UpDownAxis_P4_Speed);
            }
        }

        private void btnUpDownP5_Click(object sender, EventArgs e)
        {
            if (InOutIsIsP1())
            {
                int value = FormUtil.GetIntValue(txtUpDownP5);
                AxisABSMove(store.Config.UpDown_Axis, value, store.Config.UpDownAxis_P5_Speed);
            }
        }

        private void btnUpDownP6_Click(object sender, EventArgs e)
        {
            if (InOutIsIsP1())
            {
                int value = FormUtil.GetIntValue(txtUpDownP6);
                AxisABSMove(store.Config.UpDown_Axis, value, store.Config.UpDownAxis_P6_Speed);
            }
        }

        private void btnMiddleP1_Click(object sender, EventArgs e)
        {
            if (InOutIsIsP1())
            {
                int value = FormUtil.GetIntValue(txtMiddleP1);
                AxisABSMove(store.Config.Middle_Axis, value, store.Config.MiddleAxis_P1_Speed);
            }
        }

        private void btnMiddleP2_Click(object sender, EventArgs e)
        {
            if (InOutIsIsP1())
            {
                int value = FormUtil.GetIntValue(txtMiddleP2);
                AxisABSMove(store.Config.Middle_Axis, value, store.Config.MiddleAxis_P2_Speed);
            }
        }

        private void btnInOutP1_Click(object sender, EventArgs e)
        {
            if (store.InOutAxisCanMove().Equals(false))
            {
                MessageBox.Show( cannotMove,warn, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            int value = FormUtil.GetIntValue(txtInOutP1);
            AxisABSMove(store.Config.InOut_Axis, value, store.Config.InOutAxis_P1_Speed);
        }

        private void btnInOutP3_Click(object sender, EventArgs e)
        {
            if (store.InOutAxisCanMove().Equals(false))
            {
                MessageBox.Show( cannotMove,warn, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            int value = FormUtil.GetIntValue(txtInOutP3);
            AxisABSMove(store.Config.InOut_Axis, value, store.Config.InOutAxis_P3_Speed);
        }

        private void btnInOutP2_Click(object sender, EventArgs e)
        {
            if (store.InOutAxisCanMove().Equals(false))
            {
                MessageBox.Show( cannotMove,warn, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            int value = FormUtil.GetIntValue(txtInOutP2);
            AxisABSMove(store.Config.InOut_Axis, value, store.Config.InOutAxis_P2_Speed);
        }

        private void btnComP2_Click(object sender, EventArgs e)
        {
            int value = FormUtil.GetIntValue(txtComP2);
            ShuoKeControls.AbsMove(store.Config.CompressAxis_Slv, value);
        }

        private void btnComP1_Click(object sender, EventArgs e)
        {
            int value = FormUtil.GetIntValue(txtComP1);
            ShuoKeControls.AbsMove(store.Config.CompressAxis_Slv, value);
        }

        private void btnComP3_Click(object sender, EventArgs e)
        {
            int value = FormUtil.GetIntValue(txtComP3);
            ShuoKeControls.AbsMove(store.Config.CompressAxis_Slv, value);
        }
        int xWidth = SystemInformation.PrimaryMonitorSize.Width;//获取显示器屏幕宽度
        int yHeight = SystemInformation.PrimaryMonitorSize.Height;//高度

        private void button1_Click(object sender, EventArgs e)
        {
            FormManager.ShowAxisDebug(store);
        }
         
        private void 轴卡点动ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            button1_Click(null, null);
        }

        private void 轴运动配置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //FormManager.ShowAxisConfig(store);
        }

        private void 启动ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            start_button_Click(null, null);
        }

        private void 停止ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            stop_button_Click(null, null);
        }

        private void 复位ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.store.Reset();
            复位ToolStripMenuItem.Enabled = false;
            复位ToolStripMenuItem.Enabled = false;
        }

        private void 查看IOToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormManager.ShowIOShow(store);
        }

        private void 清理日志ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string str = ResourceCulture.China;

            ResourceCulture.SetCurrentCulture(str);
            ConfigAppSettings.SaveValue(Setting_Init.Default_Language, str);
            this.LanguageProcess();
        }

        private void 开启DEBUGToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string str = ResourceCulture.English;
            ResourceCulture.SetCurrentCulture(str);
            ConfigAppSettings.SaveValue(Setting_Init.Default_Language, str);
            this.LanguageProcess();
        }

        private void btnClearLog_Click(object sender, EventArgs e)
        {
            //this.richTextBox1.Text = "";
            LogUtil.ClearLog();
        }


        private void 料仓运转ONToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Enabled = false;
            store.RunAxis(false);
            this.Enabled = true;
            LogUtil.info("料仓运转ON完成");
        }

        private void 扫码测试ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IOManager.IOMove(IO_Type.CameraLight_Power, IO_VALUE.HIGH);
            string message = "";
            string outMsg = "";
            //List<string> codeList = HDevelopExport.CameraScan(out outMsg);
            //foreach (string str in codeList)
            //{
            //    string code = HDevelopExport.SubStrCode(str);
            //    message = message + code + "##";
            //}
            List<string> codeList = CodeManager.CameraScan();
            foreach (string str in codeList)
            {
                message = message + str + "##";
            }
            LogUtil.info("扫码测试收到二维码【" + outMsg + "】:" + message);
            IOManager.IOMove(IO_Type.CameraLight_Power, IO_VALUE.LOW);
        }

        private void 打开舱门ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IOManager.IOMove(IO_Type.Door_Up, IO_VALUE.HIGH);
            IOManager.IOMove(IO_Type.Door_Down, IO_VALUE.LOW);
        }

        private void 料仓运转OFFToolStripMenuItem_Click(object sender, EventArgs e)
        {
            store.CloseAllAxis();
            LogUtil.info("料仓运转OFF完成");
        }

        private void 关闭仓门ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IOManager.IOMove(IO_Type.Door_Down, IO_VALUE.HIGH);
            IOManager.IOMove(IO_Type.Door_Up, IO_VALUE.LOW);
        }

        private void 回待机点ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (store.storeRunStatus >= StoreRunStatus.HomeMoving)
            {
                if (store.StoreMove.MoveType.Equals(StoreMoveType.None) && store.alarmType.Equals(StoreAlarmType.None))
                {
                    store.MoveToP1();
                }
                else
                {
                    MessageBox.Show( ResourceCulture.GetString(ResourceCulture.CanotBack,"无报警,无出入库或者重置操作时,才可以回待机点!"));
                }
            }
            else
            {
                 MessageBox.Show(ResourceCulture.GetString(ResourceCulture.PleaseStartStore, "请先启动料仓!"));
            }
        }

        private void 换肤ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormManager.NextSkin();
            SetSkin(this);
        }

        private void FrmStoreBox_Shown(object sender, EventArgs e)
        {
            SetSkin(this);
            this.btnUpDownP1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(64)))), ((int)(((byte)(0)))));
            //this.btnUpDownP2.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(64)))), ((int)(((byte)(0)))));
            this.btnUpDownP3.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(64)))), ((int)(((byte)(0)))));
            this.btnUpDownP4.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(64)))), ((int)(((byte)(0)))));
            this.btnUpDownP5.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(64)))), ((int)(((byte)(0)))));
            this.btnUpDownP6.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(64)))), ((int)(((byte)(0)))));
            //this.btnUpDownP7.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(64)))), ((int)(((byte)(0)))));
            //this.btnUpDownP8.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(64)))), ((int)(((byte)(0)))));
            //this.lblWarnMsg.ForeColor = System.Drawing.Color.Red;
            //this.lblThisSta.ForeColor = System.Drawing.Color.Red;

            this.btnComP1.ForeColor = System.Drawing.Color.Purple;
            this.btnComP3.ForeColor = System.Drawing.Color.Purple;
            this.btnComP2.ForeColor = System.Drawing.Color.Purple;

            this.btnInOutP2.ForeColor = System.Drawing.Color.Green;
            this.btnInOutP1.ForeColor = System.Drawing.Color.Green;
            this.btnInOutP3.ForeColor = System.Drawing.Color.Green;
            this.btnMiddleP1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))));
            this.btnMiddleP2.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))));


        }
        /// <summary>
        /// 判断AC伺服电机轴是否运动完成
        /// </summary> 
        protected bool ACAxisMoveIsEnd(ConfigMoveAxis moveAxis, int targetPosition, int targetSpeed, out string msg)
        {
            msg = "";
            string deviceName = moveAxis.DeviceName;
            int axisNo = moveAxis.GetAxisValue();

            bool isend = ACServerManager.GetBusyStatus(deviceName, axisNo).Equals(0);
            int outCount = ACServerManager.GetActualtPosition(deviceName, axisNo);
            int errorCount = Math.Abs(outCount - targetPosition);
            if (isend)
            {
                if (errorCount > moveAxis.CanErrorCountMax)
                {
                    msg = " DeviceName=" + deviceName + ",AxisNo=" + axisNo + ",targetPosition=" + targetPosition + ",targetSpeed=" + targetSpeed + ",当前outCount=" + outCount + ",误差值大于最大误差【" + moveAxis.CanErrorCountMax + "】,但是轴已经停止运动,需要报警";
                    LogUtil.error(LOGGER, msg);
                    return false;
                }
                else
                {
                    return true;
                }
            }
            else if (errorCount <= moveAxis.CanErrorCountMin)
            {
                LogUtil.info(LOGGER, "  DeviceName=" + deviceName + ",AxisNo=" + axisNo + ",targetPosition=" + targetPosition + ",当前outCount=" + outCount +
                        ",误差值小于最小误差【" + moveAxis.CanErrorCountMin + "】,默认轴已经停止运动");
                return true;
            }
            return false;
        }
         
        private int GetSlaveAddr()
        {
            return FormUtil.GetShortValue(txtAxisValue);
        }

        private string GetPortName()
        {
            return txtAxisDeviceName.Text;
        }
        private void btnAxisReturnHome_Click(object sender, EventArgs e)
        {
            string portName = txtAxisDeviceName.Text;
            short SlvAddr = FormUtil.GetShortValue(txtAxisValue);
            if (store.Config.InOut_Axis.IsSameAxis(portName, SlvAddr) && (store.InOutAxisCanMove().Equals(false)))
            {
                MessageBox.Show( cannotMove,warn, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else if (store.Config.Middle_Axis.IsSameAxis(portName, SlvAddr) || store.Config.UpDown_Axis.IsSameAxis(portName, SlvAddr))
            {
                if (!InOutIsIsP1())
                {
                    return;
                }
            }

            int speed = FormUtil.GetIntValue(txtASpeed);
            LogUtil.info("点击【原点返回】,端口号【" + portName + "】地址【" + SlvAddr + "】 速度【" + speed + "】");
            ACServerManager.HomeMove(portName, SlvAddr, speed);
        }

        private void btnReadPosition_Click(object sender, EventArgs e)
        {
            ReadPosistion();
        }

        private void btnGetAlarm_Click(object sender, EventArgs e)
        {
            int value = ACServerManager.GetAlarmStatus(GetPortName(), GetSlaveAddr());
            this.txtAlarmStatus.Text = value.ToString();
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            int value = ACServerManager.GetBusyStatus(GetPortName(), GetSlaveAddr());
            this.txtBusyStatus.Text = value.ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int value = ACServerManager.GetHomeEndStatus(GetPortName(), GetSlaveAddr());
            this.txtHomeStatus.Text = value.ToString();
        } 
        private void chbAuto_CheckedChanged(object sender, EventArgs e)
        {
            if (!LoadOk)
            {
                return;
            }
            if (chbAuto.Checked)
            {
                ConfigAppSettings.SaveValue(Setting_Init.App_AutoRun, 1);
                ManagerUtil.AutoRun(Application.ExecutablePath, true);
            }
            else
            {
                ConfigAppSettings.SaveValue(Setting_Init.App_AutoRun, 0);
                ManagerUtil.AutoRun(Application.ExecutablePath, false);
            }
        }

        private void 显示ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmPwd fw = new FrmPwd(10);
            DialogResult result = fw.ShowDialog();
            if (!result.Equals(DialogResult.OK))
            {
                LogUtil.info("切换界面显示时,没有正确输入密码");
                return;
            }
            DebugStatus(false);
            this.Visible = true;
            this.WindowState = FormWindowState.Maximized;
            this.notifyIcon1.Visible = false;
            this.ShowInTaskbar = true;
        }
        private void ExitApp()
        {
            try
            {
                if (this.timer1.Enabled)
                {
                    this.timer1.Enabled = false;
                }
                LogUtil.info("ExitApp:停止料仓运行"); 
                store.Exit();
                ACServerManager.CloseAllPort();
                StoreOpenStatus(false); 
                LogUtil.info("ExitApp: 端口所有IO连接");
                IOManager.instance.CloseAllConnection();
                //KNDAIManager.CloseAllConnection();
                //WCFControl.CloseWCF(); 
                ResourceCulture.LogDefaultMap();
                System.Environment.Exit(System.Environment.ExitCode);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                LogUtil.error(LOGGER, ex.StackTrace);
            }
        }
        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SureExit, "是否确定退出?"), ResourceCulture.GetString(ResourceCulture.MsgTitle, ResourceCulture.GetString(ResourceCulture.MsgTitle,"提示")), MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result.Equals(DialogResult.Yes))
            {
                ExitApp();
            }
        }
        /// <summary>
        /// 隐藏窗口
        /// </summary>
        private void HideForm()
        {
            this.ShowInTaskbar = false;
            this.notifyIcon1.Visible = true;
            this.Hide();
        }
        private void FrmStoreBox_FormClosed(object sender, FormClosedEventArgs e)
        {
            ExitApp();
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SureExit, "是否确定退出?"), ResourceCulture.GetString(ResourceCulture.MsgTitle, ResourceCulture.GetString(ResourceCulture.MsgTitle,"提示")), MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result.Equals(DialogResult.Yes))
            {
                ExitApp();
            }
        }

        private void 摄像机调试ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IOManager.IOMove(IO_Type.CameraLight_Power, IO_VALUE.HIGH);
            CodeLibrary.FrmCodeDecode frm = new FrmCodeDecode();
            frm.ShowDialog();
            IOManager.IOMove(IO_Type.CameraLight_Power, IO_VALUE.LOW);
        }

        private void 学习二维码ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IOManager.IOMove(IO_Type.CameraLight_Power, IO_VALUE.HIGH);
            string nameStr = ConfigAppSettings.GetValue(Setting_Init.CameraName);
            string codeStr = ConfigAppSettings.GetValue(Setting_Init.CodeType);
            HDCodeLearnHelper.LoadConfig(nameStr, codeStr);
            FrmCodeLearn learn = new FrmCodeLearn();
            learn.ShowDialog();
            IOManager.IOMove(IO_Type.CameraLight_Power, IO_VALUE.LOW);
        }

        private void btnReadHomeSingle_Click(object sender, EventArgs e)
        {
            int value = ACServerManager.GetHomeSingle(GetPortName(), GetSlaveAddr());
            this.txtHomeSingle.Text = value.ToString();
        }
        private void btnOpen_Click(object sender, EventArgs e)
        {
            if (StoreManager.OpenShuoKe(store))
            {
                ShuoKeControls.SetConfigSpeed(StoreManager.Config);
                FormComStatus(true);
            }
        }
        private void btnClose_Click(object sender, EventArgs e)
        {
            ShuoKeControls.ClosePort();
            FormComStatus(false);
        }
        private void btnVolMove_Click(object sender, EventArgs e)
        {
            int speed = FormUtil.GetIntValue(txtSpeed);
            ShuoKeControls.VolMove(store.Config.CompressAxis_Slv, speed);
        }
        private void btnGetPosition_Click(object sender, EventArgs e)
        {
            int value = ShuoKeControls.GetABSPosition(store.Config.CompressAxis_Slv);

            lblComMsg.Text = DateTime.Now.ToLongTimeString() + ":" + value;
        }
        private void btnStop_Click(object sender, EventArgs e)
        {
            ShuoKeControls.SuddownStop(this.store.Config.CompressAxis_Slv);
        }
        private void btnClearPosition_Click(object sender, EventArgs e)
        {
            ShuoKeControls.PositionClear(this.store.Config.CompressAxis_Slv, ShuoKeCMD.AbsPositionClear);
            ShuoKeControls.PositionClear(this.store.Config.CompressAxis_Slv, ShuoKeCMD.RelPositionClear);
        }
        private void btnHomeMove_Click(object sender, EventArgs e)
        {
            ShuoKeControls.HomeMove(this.store.Config.CompressAxis_Slv, byte.Parse(cmbHomeType.SelectedIndex.ToString()));
        }
        private void btnLineAbsMove_Click(object sender, EventArgs e)
        {
            int posi = FormUtil.GetIntValue(txtLinePosition);
            ShuoKeControls.AbsMove(this.store.Config.CompressAxis_Slv, posi);
        }
        private void btnRelMove_Click(object sender, EventArgs e)
        {
            int posi = FormUtil.GetIntValue(txtLinePosition);
            ShuoKeControls.RelativeMove(this.store.Config.CompressAxis_Slv, posi);
        }
        private void btnStatusSearch_Click(object sender, EventArgs e)
        {
            ShuoKeInfo info = ShuoKeControls.GetStatus(store.Config.CompressAxis_Slv);
            lblComMsg.Text = info.ToShowStr();
        }
        private void FormComStatus(bool isOpen)
        {
            btnOpen.Enabled = !isOpen;
            btnClose.Enabled = isOpen;
            btnClearPosition.Enabled = isOpen;
            btnVolMove.Enabled = isOpen;
            btnGetPosition.Enabled = isOpen;
            btnHomeMove.Enabled = isOpen;
            btnLineAbsMove.Enabled = isOpen;
            btnStatusSearch.Enabled = isOpen;
            // Bt_ClearCounter.Enabled = isOpen;
        }

        private void btnBatchOutTest_Click(object sender, EventArgs e)
        {
            if (store.storeRunStatus >= StoreRunStatus.HomeMoving)
            {
                string selectPositionNum = cmbPosition.Text;
                LineMoveP ktk = LoadPostion();
                store.StartOutStoreMove(new InOutStoreParam("", selectPositionNum, ktk), true);
            }
            else
            {
                 MessageBox.Show(ResourceCulture.GetString(ResourceCulture.PleaseStartStore, "请先启动料仓!"));
            }
        }



        private void button3_Click(object sender, EventArgs e)
        {
            ReadPosistion();
        }

        private void btnReadLimit1_Click(object sender, EventArgs e)
        {
            int value = ACServerManager.GetLimitPositiveSingle(GetPortName(), GetSlaveAddr());
            this.txtLimit1.Text = value.ToString();
        }

        private void btnReadLimit2_Click(object sender, EventArgs e)
        {
            int value = ACServerManager.GetLimitNegativeSingle(GetPortName(), GetSlaveAddr());
            this.txtLimit2.Text = value.ToString();
        }

        private void btnUpdateStatus_Click(object sender, EventArgs e)
        {
            btnGetAlarm_Click(null, null);
            button1_Click_1(null, null);
            button2_Click(null, null);
            btnReadHomeSingle_Click(null, null);
            btnReadLimit1_Click(null, null);
            btnReadLimit2_Click(null, null);
        }

        private void 批量上下轴ONToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IOManager.IOMove(IO_Type.Run_Sign, IO_VALUE.HIGH);
            Thread.Sleep(1000);
            string portName = store.Config.Batch_Axis.DeviceName;
            int slvAddr = store.Config.Batch_Axis.GetAxisValue();
            ACServerManager.OpenPort(portName);
            Thread.Sleep(50);

            ACServerManager.InitSlvAddr(portName, slvAddr, store.Config.Batch_Axis.TargetSpeed, store.Config.Batch_Axis.AddSpeed, store.Config.Batch_Axis.DelSpeed);
            Thread.Sleep(100);

            ACServerManager.AlarmClear(portName, slvAddr);
            Thread.Sleep(50);
            ACServerManager.ServoOn(portName, slvAddr);
        }

        private void 批量上下轴OFFToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ACServerManager.ServoOff(store.Config.Batch_Axis.DeviceName, store.Config.Batch_Axis.GetAxisValue());
            //关闭串口,等下次重新打开
            //ACServerManager.ColsePort(store.Config.Batch_Axis.DeviceName);

            Thread.Sleep(100);
            IOManager.IOMove(IO_Type.Run_Sign, IO_VALUE.LOW);
        }

        private void btnWaitTrgGo_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show(ResourceControl.GetString(ResourceControl.TakeTrayOut, "已确认料盘已手动拿出"), ResourceCulture.GetString(ResourceCulture.MsgTitle,"提示"), MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result.Equals(DialogResult.Yes))
            {
                AutomaticBaiting.doConfirmReelGo();
            }
        }

        private void btnUpDownDoor_Click(object sender, EventArgs e)
        {
            if (InOutIsIsP1())
            {
                int value = FormUtil.GetIntValue(txtUpDownDoor);
                AxisABSMove(store.Config.UpDown_Axis, value, store.Config.UpDownAxis_P7_Speed);
            }
        }
        private void BtnOpenDoor_Click(object sender, EventArgs e)
        { 
            string msg = AutomaticBaiting.doOpenDoor();
            if (!msg.Equals(""))
            {
                MessageBox.Show(msg);
            }
        }
        private void btnBatchInStore_Click(object sender, EventArgs e)
        {
            string msg = AutomaticBaiting.doStartBatchIn();
            if (!msg.Equals(""))
            {
                MessageBox.Show(msg);
            } 
        }

        private void btnStartBatchInStore_Click(object sender, EventArgs e)
        {
            string msg = AutomaticBaiting.doCloseDoor();
            if (!msg.Equals(""))
            {
                MessageBox.Show(msg);
            } 

        }
        private void btnGetOutTray_Click(object sender, EventArgs e)
        {
            string msg = AutomaticBaiting.doTakeReel();
            if (!msg.Equals(""))
            {
                MessageBox.Show(msg);
            } 
        }

        private void btnBatchOutEnd_Click(object sender, EventArgs e)
        {

            if (!AutomaticBaiting.DoorIsClose())
            {
                MessageBox.Show(ResourceCulture.GetString(ResourceCulture.PCloseDoor,"请先关闭批量上下料门"));
                return;
            }
            AutomaticBaiting.BatchDoorClose(false);

            bool result = AutomaticBaiting.Reset(false,false);
        }

        private void btnTempInit_Click(object sender, EventArgs e)
        {
            string port = txtTempPort.Text.ToString();
            if (HumitureController.IsRun)
            {
                HumitureController.Release();
            }
            HumitureController.Init(port);
        }

        private void btnTempClose_Click(object sender, EventArgs e)
        {

            HumitureController.Release();
        }

        private void btnSelTemp_Click(object sender, EventArgs e)
        {
            ASTemperateParam param = HumitureController.QueryData();
            txtTemp.Text = param.Temperate.ToString();
            txtHum.Text = param.Humidity.ToString();
        }

        private void btnUpdateSpeed_Click(object sender, EventArgs e)
        {
            string portName = txtAxisDeviceName.Text;
            int SlvAddr = FormUtil.GetIntValue(txtAxisValue);
            int speed = FormUtil.GetIntValue(txtASpeed);
            ACServerManager.SetSpeed(portName, SlvAddr, speed);
        }

        private void btnInOutP4_Click(object sender, EventArgs e)
        {
            if (store.InOutAxisCanMove().Equals(false))
            {
                MessageBox.Show( cannotMove,warn, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            int value = FormUtil.GetIntValue(txtInoutP4);
            AxisABSMove(store.Config.InOut_Axis, value, store.Config.InOutAxis_P2_Speed);
        }

        private void 上料模块复位ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!AutomaticBaiting.DoorIsClose())
            {
                MessageBox.Show(ResourceCulture.GetString(ResourceCulture.PCloseDoor, "请先关闭批量上下料门"));
                return; 
            }
            AutomaticBaiting.BatchDoorClose(false);

            bool result = AutomaticBaiting.Reset(true,false);
        }

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            IOManager.IOMove(IO_Type.CameraLight_Power, IO_VALUE.HIGH);
        }

        private void toolStripMenuItem3_Click(object sender, EventArgs e)
        {

            IOManager.IOMove(IO_Type.CameraLight_Power, IO_VALUE.LOW);
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (cmbPosition.SelectedIndex >= 0)
            {
                string selectPositionNum = cmbPosition.Text;
                ConfigAppSettings.SaveValue(Setting_Init.DebugPosId, selectPositionNum);
            }
        }

        private void toolStripMenuItem4_Click(object sender, EventArgs e)
        {
            IOManager.IOMove(IO_Type.DisableDoorControl, IO_VALUE.HIGH);
        }

        private void toolStripMenuItem5_Click(object sender, EventArgs e)
        {
            IOManager.IOMove(IO_Type.DisableDoorControl, IO_VALUE.LOW);
        }

        private void 出入库调试ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (出入库调试ToolStripMenuItem.Text.Equals("启用调试"))
            {
                DebugStatus(true);
            }
            else
            {
                DebugStatus(false);
            }
        }

        private void DebugStatus(bool status)
        { 
            if (status)
            {
                出入库调试ToolStripMenuItem.Text = "禁用调试";
            }
            else
            {
                出入库调试ToolStripMenuItem.Text = "启用调试";
            }
            groupAxis.Enabled = status;
            groupComAxis.Enabled = status;
            //groupInout.Enabled = status;
            if (!status)
            {
                checkBox1.Checked = false;
            }
            if ( store.autoNext)
            {
                groupAuto.Enabled = true;
                cmbJianGe.Enabled = false ;
                btnSave.Enabled =false ;
                checkBox1.Enabled =false ;
                btnOutStore.Enabled = false;
                btnBatchOutTest.Enabled = false; 
            }
            else
            {
                groupAuto.Enabled = status;
                btnOutStore.Enabled = status;
                btnBatchOutTest.Enabled = status;
                cmbJianGe.Enabled = status;
                checkBox1.Enabled = status;
                btnSave.Enabled = status;
            }
           
        }

        private void btnClearBuzzer_Click(object sender, EventArgs e)
        {
            IOManager.IOMove(IO_Type.Buzzer_Sign, IO_VALUE.LOW);
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            if (store.storeRunStatus >= StoreRunStatus.HomeMoving )
            {
                if (store.autoNext)
                {
                    store.autoNext = false;
                    btnStart.Text = StartAuto;
                }
                else
                {
                    DialogResult res = MessageBox.Show("确定开始自动出入库?", "提示", MessageBoxButtons.YesNo);
                    if (res.Equals(DialogResult.Yes))
                    {
                        int jiange = cmbJianGe.SelectedIndex;
                        store.autoJiange = jiange;
                        if (cmbPosition.SelectedIndex >= 0)
                        {
                            int currIndex = cmbPosition.SelectedIndex;
                            store.autoPositionIndex = currIndex;
                            store.AutoStartIndex = currIndex; 
                            string poText = cmbPosition.Text; 
                            ConfigAppSettings.SaveValue(Setting_Init.DebugPosId, poText);

                            store.autoMsg = "自动出入库:" + poText;
                            store.autoNext = true;
                            LogUtil.info(LOGGER, store.StoreName + "开启自动出入库模式,开始位置【" + poText + "】(索引=" + currIndex + "),间隔=" + jiange + "");
                            btnStart.Text = StopAuto;
                            //string msg = AutomaticBaiting.doStartBatchIn();
                            //if (msg.Equals(""))
                            //{
                            //    store.autoNext = true;
                            //    btnStart.Text = StopAuto;
                            //    LogUtil.info(LOGGER, store.StoreName + "开启自动出入库模式,开始位置【" + poText + "】(索引=" + currIndex + "),间隔=" + jiange + ",入库开始!");
                            //}
                            //else
                            //{
                            //    MessageBox.Show(msg);
                            //    store.autoNext = false;
                            //    btnStart.Text = StartAuto;
                            //    LogUtil.info(LOGGER, store.StoreName + "自动出入库失败【"+msg+"】,开始位置【" + poText + "】(索引=" + currIndex + "),间隔=" + jiange + ",入库开始!");
                            //}
                            DebugStatus(false);
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("请先启动料仓!");
            }
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (!groupInout.Enabled.Equals(checkBox1.Checked))
            {
                groupInout.Enabled = checkBox1.Checked;
            }
        }
    }
}