MySDK.cs 29.8 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace KingLib
{
    public delegate void BaseConnectEvt(BasePar par);
    public delegate void ReTryConnectEvt();
    public delegate void BeforReTryConnecEvt(string BaseUsedByApp, out bool isReTry);

    public delegate void KeyVoteEvt(KeyData data);

    public class MySDK
    {
        public event BaseConnectEvt OnBaseConnect = null;
        public event ReTryConnectEvt OnReTryConnectEvt = null;
        public event BeforReTryConnecEvt OnBeforReTryConnecEvt = null;
        public event KeyVoteEvt OnKeyVoteEvt = null;

        public SunVote.BaseConnection BaseConn = null;
        public SunVote.BaseManage BaseMng = null;
        public SunVote.KeypadManage KeyMng = null;
        public SunVote.HardwareTest HardTest = null;


        public SunVote.SignIn SignIn = null;
        public SunVote.Choices Choices = null;
        public SunVote.Vote Vote = null;
        public SunVote.TrueFalse TrueFalse = null;
        public SunVote.Sequence Sequence = null;
        public SunVote.Number Number = null;
        public SunVote.RushAnswer RushAnswer = null;
        public SunVote.Cloze Cloze = null;
        public SunVote.Request Request = null;

        public MySDK()
        {
            try
            {
                tmrConnect.Tick += tmrConnect_Tick;

                BaseConn = new SunVote.BaseConnection();
                BaseConn.BaseOnLine += BaseConn_BaseOnLine;

                //必须注册才能使用设置键盘序列号和配对码等功能
                BaseConn.License = "sunskysdk";

                BaseMng = new SunVote.BaseManage();
                BaseMng.BaseConnection = BaseConn;

                KeyMng = new SunVote.KeypadManage();
                KeyMng.BaseConnection = BaseConn;

                HardTest = new SunVote.HardwareTest();
                HardTest.BaseConnection = BaseConn;

                //50R遥控器
                Request = new SunVote.Request();
                Request.BaseConnection = BaseConn;

                //签到,签到码签到
                SignIn = new SunVote.SignIn();
                SignIn.BaseConnection = BaseConn;
                SignIn.KeyStatus += SignIn_KeyStatus;
                SignIn.KeyStatusSN += SignIn_KeyStatusSN;

                //单选,多选,分组,判断,评议
                Choices = new SunVote.Choices();
                Choices.BaseConnection = BaseConn;
                Choices.KeyStatus += Choices_KeyStatus;
                Choices.KeyStatusSN += Choices_KeyStatusSN;

                //表决
                Vote = new SunVote.Vote();
                Vote.BaseConnection = BaseConn;
                Vote.KeyStatus += Vote_KeyStatus;
                Vote.KeyStatusSN += Vote_KeyStatusSN;

                //判断
                TrueFalse = new SunVote.TrueFalse();
                TrueFalse.BaseConnection = BaseConn;
                TrueFalse.KeyStatus += TrueFalse_KeyStatus;
                TrueFalse.KeyStatusSN += TrueFalse_KeyStatusSN;

                //排序
                Sequence = new SunVote.Sequence();
                Sequence.BaseConnection = BaseConn;
                Sequence.KeyStatus += Sequence_KeyStatus;
                Sequence.KeyStatusSN += Sequence_KeyStatusSN;

                //数字,选举,评分
                Number = new SunVote.Number();
                Number.BaseConnection = BaseConn;
                Number.KeyStatus += Number_KeyStatus;
                Number.KeyStatusSN += Number_KeyStatusSN;

                //填空
                Cloze = new SunVote.Cloze();
                Cloze.BaseConnection = BaseConn;
                Cloze.KeyStatus += Cloze_KeyStatus;
                Cloze.KeyStatusSN += Cloze_KeyStatusSN;

                //抢答
                RushAnswer = new SunVote.RushAnswer();
                RushAnswer.BaseConnection = BaseConn;
                RushAnswer.KeyStatus += RushAnswer_KeyStatus;
                RushAnswer.KeyStatusSN += RushAnswer_KeyStatusSN;

            }
            catch (Exception ex)
            {
                initInfo = ex.ToString();
            }
        }

        private void RaiseKeyVote(int KeyID, string KeyValue, double KeyTime)
        {
            if (OnKeyVoteEvt != null)
            {
                KeyData d = new KeyData();
                d.KeyID = KeyID.ToString();
                d.KeyNum = KeyID;
                d.KeyValue = KeyValue;
                d.Speed = KeyTime;

                OnKeyVoteEvt(d);
            }
        }
        private void RaiseKeyVote(string KeySN, string KeyValue, double KeyTime)
        {
            if (OnKeyVoteEvt != null)
            {
                KeyData d = new KeyData();
                d.KeyID = KeySN;
                d.KeyNum = 0;
                d.KeyValue = KeyValue;
                d.Speed = KeyTime;

                OnKeyVoteEvt(d);
            }
        }

        /// <summary>
        /// 签到
        /// </summary>
        void SignIn_KeyStatusSN(string BaseTag, string KeySN, int ValueType, string KeyValue, double KeyTime)
        {
            RaiseKeyVote(KeySN, KeyValue, KeyTime);
        }
        void SignIn_KeyStatus(string BaseTag, int KeyID, int ValueType, string KeyValue)
        {
            RaiseKeyVote(KeyID, KeyValue, 0);
        }

        /// <summary>
        /// 选择
        /// </summary>
        void Choices_KeyStatusSN(string BaseTag, string KeySN, string KeyValue, double KeyTime)
        {
            RaiseKeyVote(KeySN, KeyValue, KeyTime);
        }
        void Choices_KeyStatus(string BaseTag, int KeyID, string KeyValue, double KeyTime)
        {
            RaiseKeyVote(KeyID, KeyValue, KeyTime);
        }

        /// <summary>
        /// 表决
        /// </summary>
        void Vote_KeyStatusSN(string BaseTag, string KeySN, string KeyValue, double KeyTime)
        {
            RaiseKeyVote(KeySN, KeyValue, KeyTime);
        }
        void Vote_KeyStatus(string BaseTag, int KeyID, string KeyValue)
        {
            RaiseKeyVote(KeyID, KeyValue, 0);
        }

        void TrueFalse_KeyStatusSN(string BaseTag, string KeySN, string KeyValue, double KeyTime)
        {
            RaiseKeyVote(KeySN, KeyValue, KeyTime);
        }
        void TrueFalse_KeyStatus(string BaseTag, int KeyID, string KeyValue, double KeyTime)
        {
            RaiseKeyVote(KeyID, KeyValue, KeyTime);
        }

        /// <summary>
        /// 排序
        /// </summary>
        void Sequence_KeyStatusSN(string BaseTag, string KeySN, string KeyValue, double KeyTime)
        {
            RaiseKeyVote(KeySN, KeyValue, KeyTime);
        }
        void Sequence_KeyStatus(string BaseTag, int KeyID, string KeyValue, double KeyTime)
        {
            RaiseKeyVote(KeyID, KeyValue, KeyTime);
        }

        /// <summary>
        /// 数字
        /// </summary>
        void Number_KeyStatusSN(string BaseTag, string KeySN, string KeyValue, double KeyTime)
        {
            RaiseKeyVote(KeySN, KeyValue, KeyTime);
        }
        void Number_KeyStatus(string BaseTag, int KeyID, string KeyValue, double KeyTime)
        {
            RaiseKeyVote(KeyID, KeyValue, KeyTime);
        }

        /// <summary>
        /// 文本题
        /// </summary>
        void Cloze_KeyStatusSN(string BaseTag, string KeySN, string KeyValue, double KeyTime)
        {
            RaiseKeyVote(KeySN, KeyValue, KeyTime);
        }
        void Cloze_KeyStatus(string BaseTag, int KeyID, string KeyValue, double KeyTime)
        {
            RaiseKeyVote(KeyID, KeyValue, KeyTime);
        }

        /// <summary>
        /// 抢答
        /// </summary>
        void RushAnswer_KeyStatusSN(string BaseTag, string KeySN, string KeyValue, double KeyTime)
        {
            RaiseKeyVote(KeySN, KeyValue, KeyTime);
        }
        void RushAnswer_KeyStatus(string BaseTag, int KeyID, string KeyValue, double KeyTime)
        {
            RaiseKeyVote(KeyID, KeyValue, KeyTime);
        }

        private VoteType mVoteStartType = VoteType.None;
        public VoteType VoteStartType
        {
            get
            {
                return mVoteStartType;
            }
            set
            {
                //if ((mVoteStartType != value) && VoteStart)
                //{
                //    VoteStart = false;
                //}
                mVoteStartType = value;
            }
        }

        public int VoteStartMode { get; set; }
        /// <summary>
        /// 允许修改模式:1允许,0不允许
        /// </summary>
        public int VoteModifyMode { get; set; }
        /// <summary>
        /// 启用保密模式:0不保密,1保密
        /// </summary>
        public int VoteSecrecyMode { get; set; }

        private bool mVoteStart = false;
        public bool VoteStart
        {
            get
            {
                return mVoteStart;
            }
            set
            {
                mVoteStart = value;
                if (value)
                {
                    switch (mVoteStartType)
                    {
                        case VoteType.SignIn:
                            SignIn.StartMode = VoteStartMode;
                            SignIn.Start();
                            break;
                        case VoteType.Choices:
                            Choices.ModifyMode = VoteModifyMode;
                            Choices.SecrecyMode = VoteSecrecyMode;
                            Choices.StartMode = VoteStartMode;
                            Choices.Start();
                            break;
                        case VoteType.Vote:
                            Vote.ModifyMode = VoteModifyMode;
                            Vote.SecrecyMode = VoteSecrecyMode;
                            Vote.StartMode = VoteStartMode;
                            Vote.Start();
                            break;
                        case VoteType.TrueFalse:
                            TrueFalse.ModifyMode = VoteModifyMode;
                            TrueFalse.SecrecyMode = VoteSecrecyMode;
                            TrueFalse.StartMode = VoteStartMode;
                            TrueFalse.Start();
                            break;
                        case VoteType.Sequence:
                            Sequence.ModifyMode = VoteModifyMode;
                            Sequence.SecrecyMode = VoteSecrecyMode;
                            Sequence.StartMode = VoteStartMode;
                            Sequence.Start();
                            break;
                        case VoteType.Number:
                            Number.ModifyMode = VoteModifyMode;
                            Number.SecrecyMode = VoteSecrecyMode;
                            Number.StartMode = VoteStartMode;
                            Number.Start();
                            break;
                        case VoteType.Cloze:
                            Cloze.ModifyMode = VoteModifyMode;
                            Cloze.SecrecyMode = VoteSecrecyMode;
                            Cloze.StartMode = VoteStartMode;
                            Cloze.Start();
                            break;
                        case VoteType.RushAnswer:
                            RushAnswer.StartMode = VoteStartMode;
                            RushAnswer.Start();
                            break;
                    }
                }
                else
                {
                    switch (mVoteStartType)
                    {
                        case VoteType.SignIn:
                            SignIn.Stop();
                            break;
                        case VoteType.Choices:
                            Choices.Stop();
                            break;
                        case VoteType.Vote:
                            Vote.Stop();
                            break;
                        case VoteType.TrueFalse:
                            TrueFalse.Stop();
                            break;
                        case VoteType.Sequence:
                            Sequence.Stop();
                            break;
                        case VoteType.Number:
                            Number.Stop();
                            break;
                        case VoteType.Cloze:
                            Cloze.Stop();
                            break;
                        case VoteType.RushAnswer:
                            RushAnswer.Stop();
                            break;
                    }
                }
            }
        }

        private string initInfo = "";
        public string InitInfo
        {
            get
            {
                return initInfo;
            }
        }

        private Dictionary<int, BasePar> DicBaseCheck = new Dictionary<int, BasePar>();
        /// <summary>
        /// 已连接成功的基站列表
        /// </summary>
        public Dictionary<int, BasePar> DicBaseConnect = new Dictionary<int, BasePar>();
        /// <summary>
        /// 记录调用的连接命令true=连接,false=关闭
        /// </summary>
        private bool IsConnectCmd = false;
        Timer TmrReTryConnect = null;
        void BaseConn_BaseOnLine(int BaseID, int BaseState)
        {
            if (BaseState == -5)
            {
                if (OnBeforReTryConnecEvt != null)
                {
                    bool isReTry = false;
                    OnBeforReTryConnecEvt(BaseConn.BaseUsedByApp, out isReTry);
                    if (isReTry)
                    {
                        if (TmrReTryConnect == null)
                        {
                            TmrReTryConnect = new Timer();
                            TmrReTryConnect.Tick += TmrReTryConnect_Tick;
                        }
                        TmrReTryConnect.Interval = 10;
                        TmrReTryConnect.Enabled = true;
                    }
                }
                //if (MessageBox.Show(LanText.BaseUsedByApp + "\r\n" + BaseConn.BaseUsedByApp, "", MessageBoxButtons.RetryCancel) == DialogResult.Retry)
                //{
                //    if (TmrReTryConnect == null)
                //    {
                //        TmrReTryConnect = new Timer();
                //        TmrReTryConnect.Tick += TmrReTryConnect_Tick;
                //    }
                //    TmrReTryConnect.Interval = 10;
                //    TmrReTryConnect.Enabled = true;
                //}
                return;
            }
            if (BeCehckBase)
            {
                BasePar par = new BasePar();
                if (BaseID > 0)
                {
                    if (DicBaseCheck.ContainsKey(BaseID))
                        par = DicBaseCheck[BaseID];
                    else
                        DicBaseCheck.Add(BaseID, par);
                }
                par.BaseID = BaseID;
                par.BaseState = BaseState;

                //if (!DicBaseCheck.ContainsKey(BaseID))
                //    DicBaseCheck.Add(BaseID, new BasePar());
                //BasePar par = DicBaseCheck[BaseID];
                //par.BaseID = BaseID;
                //par.BaseState = BaseState;

                if (BaseState == 1)
                {
                    //if (!DicBaseConnect.ContainsKey(BaseID))
                    //    DicBaseConnect.Add(BaseID, new BasePar());
                    //BasePar parOK = DicBaseConnect[BaseID];
                    //parOK.BaseID = BaseID;
                    //parOK.BaseState = BaseState;

                    BasePar parOK = new BasePar();
                    if (BaseID > 0)
                    {
                        if (DicBaseConnect.ContainsKey(BaseID))
                            parOK = DicBaseConnect[BaseID];
                        else
                            DicBaseConnect.Add(BaseID, parOK);
                    }
                    parOK.BaseID = BaseID;
                    parOK.BaseState = BaseState;

                    //if (OnBaseConnect != null)
                    //    OnBaseConnect(parOK);
                }
                else if (!BeSeatchMultiBase)//杨斌 2016-09-18
                {
                    DicBaseConnect.Clear();
                }

                if ((DicBaseCheck.Count >= MaxBaseID)
                    || (!BeSeatchMultiBase && DicBaseConnect.Count > 0)) //搜索完了,重新连
                {
                    BaseCehck = "";
                    foreach (var v in DicBaseCheck)
                    {
                        if (v.Value.BaseState == 1)
                        {
                            if (BaseCehck.Length > 0)
                                BaseCehck += ",";
                            BaseCehck += v.Key;
                        }
                    }

                    if (IsConnectCmd)
                    {
                        tmrConnect.Interval = 1;
                        tmrConnect.Enabled = true;
                    }
                }
            }
            else
            {
                BasePar parOK = new BasePar();

                if (BaseID > 0)
                {
                    if (DicBaseConnect.ContainsKey(BaseID))
                        parOK = DicBaseConnect[BaseID];
                    else
                        DicBaseConnect.Add(BaseID, parOK);
                }
                parOK.BaseID = BaseID;
                parOK.BaseState = BaseState;

                if (OnBaseConnect != null)
                    OnBaseConnect(parOK);

                if (BaseState == -3)
                {
                    if (DicBaseConnect.Count > 0)
                        DicBaseConnect.Clear();
                }
                else if (BaseState != 1)
                {
                    if (DicBaseConnect.ContainsKey(BaseID))
                        DicBaseConnect.Remove(BaseID);
                }
            }
        }

        void TmrReTryConnect_Tick(object sender, EventArgs e)
        {
            TmrReTryConnect.Enabled = false;
            if (OnReTryConnectEvt != null)
                OnReTryConnectEvt();
        }

        public string BaseConnectOkIDs()
        {
            string res = "";
            if (DicBaseConnect.Count > 0)
            {
                List<int> lst = DicBaseConnect.Keys.OrderBy(o => o).ToList();
                List<string> sLst = new List<string>();
                foreach (var v in lst)
                    sLst.Add(v.ToString());
                res = string.Join(",", sLst);
            }
            return res;
        }

        void tmrConnect_Tick(object sender, EventArgs e)
        {
            tmrConnect.Enabled = false;
            if (IsConnectCmd)
            {
                if (connectMode == 1)
                    BaseConnect(BaseCehck);
                else if (connectMode == 2)
                {
                    string[] aryIP = BaseConn.BaseIP.Split(',');
                    if (aryIP.Length > 0)
                        BaseConnectIPOne(aryIP[0], BaseCehck);
                }
            }
        }

        Timer tmrConnect = new Timer();

        /// <summary>
        /// 自动查找的最大基站编号
        /// </summary>
        public static int MaxBaseID = 32;
        private bool BeCehckBase = false;
        private string BaseCehck = "";
        /// <summary>
        /// 搜索多基站
        /// </summary>
        private bool BeSeatchMultiBase = false;
        private int connectMode = 1;
        public int ConnectMode
        {
            get
            {
                return connectMode;
            }
        }
        private string connectBaseID = "";
        public string ConnectBaseID
        {
            get
            {
                return connectBaseID;
            }
        }
        private string connectIPAddress = "";
        public string ConnectIPAddress
        {
            get
            {
                return connectIPAddress;
            }
        }

        public void BaseConnect(string baseID = "", bool beMultiBase = false)
        {
            DicBaseConnect.Clear();
            string baseIDConn = "";
            if (baseID.Length > 0)
            {
                BeCehckBase = false;
                BeSeatchMultiBase = false;
                baseIDConn = baseID;
            }
            else
            {
                DicBaseCheck.Clear();
                DicBaseCheck.Clear();
                BeSeatchMultiBase = beMultiBase;//杨斌 2016-09-18
                BeCehckBase = beMultiBase;
                if (beMultiBase)
                    baseIDConn = "1-" + MaxBaseID;
                else
                    baseIDConn = "0";
            }
            if (BaseConn != null)
            {
                BaseConn.Open(1, baseIDConn);
            }
            connectMode = 1;
            connectBaseID = baseIDConn;
            IsConnectCmd = true;
        }
        public void BaseConnect(string baseID, string ipAddress)
        {
            DicBaseConnect.Clear();
            BeCehckBase = false;
            if (BaseConn != null)
            {
                BaseConn.BaseIP = ipAddress;
                BaseConn.Open(2, baseID);
            }
            connectMode = 2;
            connectBaseID = baseID;
            connectIPAddress = BaseConn.BaseIP;
            IsConnectCmd = true;
        }

        public void BaseConnectIPOne(string ipAddress, string baseID = "")
        {
            DicBaseConnect.Clear();
            BeSeatchMultiBase = false;
            string baseIDConn = "";
            if (BaseConn != null)
            {
                if (baseID.Length > 0)
                {
                    BeCehckBase = false;
                    BaseConn.BaseIP = ipAddress;
                    baseIDConn = baseID;
                }
                else
                {
                    BeCehckBase = true;
                    DicBaseCheck.Clear();
                    baseIDConn = "1-" + MaxBaseID;
                    if (ipAddress.Length > 0)
                    {
                        string[] ary = ipAddress.Split(',');
                        string ips = "";
                        for (int i = 1; i <= MaxBaseID; i++)
                        {
                            if (ips.Length > 0)
                                ips += ",";
                            ips += ary[0];
                        }
                        BaseConn.BaseIP = ips;
                    }
                    else
                        BaseConn.BaseIP = ipAddress;
                }
                BaseConn.Open(2, baseIDConn);
            }
            connectMode = 2;
            connectBaseID = baseIDConn;
            connectIPAddress = BaseConn.BaseIP;
            IsConnectCmd = true;
        }

        public void BaseDisConnect()
        {
            tmrConnect.Stop();
            tmrConnect.Enabled = false;

            if (BaseConn != null)
            {
                IsConnectCmd = false;
                BaseConn.Close();
                DicBaseConnect.Clear();
            }
        }

        private static Dictionary<string, string> DicBaseType = new Dictionary<string, string>();
        /// <summary>
        /// 取基站型号
        /// </summary>
        /// <param name="HModel"></param>
        /// <returns></returns>
        public static string GetBaseType(int HModel)
        {
            string res = "";
            string hex = HModel.ToString("X");

            if (DicBaseType.Count < 1)
            {
                DicBaseType.Add("B1", "EA1000");
                DicBaseType.Add("B2", "EA2000T");
                DicBaseType.Add("B3", "PVS-3000/2.4G");
                DicBaseType.Add("B4", "PVS-2010/2.4G");
                DicBaseType.Add("B5", "PVS-2010/433M");
                DicBaseType.Add("B6", "C1000");
                DicBaseType.Add("B7", "EA2100T");
                DicBaseType.Add("B8", "C2000T");
                DicBaseType.Add("B9", "EA4000T");
                DicBaseType.Add("BA", "EA4000R");
                DicBaseType.Add("BB", "C1200");//(建议取消)
                DicBaseType.Add("BC", "EA1200");
                DicBaseType.Add("BD", "EA4100T");
                DicBaseType.Add("BE", "C4000T");
                DicBaseType.Add("BF", "EA4200W");//WiFi
            }

            if (DicBaseType.ContainsKey(hex))
                res = DicBaseType[hex];

            return res;
        }
    }

    public enum VoteType
    {
        None = 0,
        SignIn,
        Choices,
        Vote,
        TrueFalse,
        Sequence,
        Number,
        Cloze,
        RushAnswer,
    }

    public class VoteSet
    {
        public VoteType VoteStartType = VoteType.None;
        public int ModifyMode = 1;
        public int SecrecyMode = 0;
    }

    public class KeypadTypeInfo
    {
        public string KeypadType = "";
        /// <summary>
        /// 小于此电压为低电量
        /// </summary>
        public double BatteryVoltageLow = 0;
        /// <summary>
        /// 小于此电压为报警电量。杨斌 2016-08-16
        /// </summary>
        public double BatteryVoltageWarning = 0;

        public static void InitKeypadType()
        {
            DicKeypadType.Clear();

            AddKeypad("M52Plus", 2.7, 2.84);
            AddKeypad("M52Li", 3.7, 3.84);
            AddKeypad("M52", 2.7, 2.84);
            AddKeypad("M50", 2.7, 2.84);
            AddKeypad("M50Plus", 2.7, 2.84);
            AddKeypad("M50Plus", 2.7, 2.84);
            AddKeypad("M30", 2.7, 2.84);//杨斌 2017-02-07
            //AddKeypad("F00", 3.3);
            //AddKeypad("M40", 2.6);
            AddKeypad("M40L", 2.7, 2.84);
            //AddKeypad("V52", 3.3);//李慧文说,跟M52Li一样的
            AddKeypad("V52Li", 3.7, 3.84);
            AddKeypad("S50", 2.7, 2.84);
            AddKeypad("S50Plus", 2.7, 2.84);
            AddKeypad("S50Li", 3.7, 3.84);
            AddKeypad("S52", 2.7, 2.84);
            AddKeypad("S52Plus", 2.7, 2.84);
            AddKeypad("S56", 2.7, 2.84);
            //AddKeypad("S56PLUS", 2.3);
            //AddKeypad("S70", 2.4);
            AddKeypad("E10", 3.7, 3.84);
        }

        public static Dictionary<string, KeypadTypeInfo> DicKeypadType = new Dictionary<string, KeypadTypeInfo>();
        private static void AddKeypad(string keypadType, double batteryVoltageLow, double batteryVoltageWarning = 0)
        {
            if (!DicKeypadType.ContainsKey(keypadType))
            {
                DicKeypadType.Add(keypadType,
                    new KeypadTypeInfo()
                    {
                        KeypadType = keypadType,
                        BatteryVoltageLow = batteryVoltageLow,
                        BatteryVoltageWarning = batteryVoltageWarning
                    });
            }
        }
    }

    public class BasePar
    {
        /// <summary>
        /// 基站连接状态
        /// </summary>
        public int BaseState = 0;
        public int BaseID = 0;
        public int BaseChannel = 0;
        public int KeyIDMin = 0;
        public int KeyIDMax = 0;
        public int RFPower = 0;
        /// <summary>
        /// 系统特性-键盘报告模式
        /// </summary>
        public int KeyReportMode = 0;
        public int KeyOffTime = 0;
        public int BackLightMode = 0;
        public int BuzzerMode = 0;
        public int CommitMode = 0;
        /// <summary>
        /// 基站序列号
        /// </summary>
        public string HSerial = "";
        public int HModel = 0;
        public string HVer = "";
        public string SVer = "";
        /// <summary>
        /// 基站型号,根据HModel决定
        /// </summary>
        public string BaseType = "";
        /// <summary>
        /// 基站IP地址
        /// </summary>
        public string TcpIPAddress = "";
        public string TcpSubnetMask = "";
        public string TcpGatewayAddress = "";
        public string TcpMACAddress = "";
        /// <summary>
        /// 基站配对码
        /// </summary>
        public string MatchCode = "";
        public int MatchMode = 0;
        public string BaseName = "";
        /// <summary>
        /// WiFi基站模式
        /// </summary>
        public int BaseMode = 0;
        public string RouterName = "";
        public int AuthMode = 0;
        public int EncryMode = 0;
        public string RouterPwd = "";
    }

    public class BaseParBackup
    {
        /// <summary>
        /// 备份时间
        /// </summary>
        public string BaseBackupTime = "";
        public int BaseID = 0;
        public int BaseChannel = 0;
        public int KeyIDMin = 0;
        public int KeyIDMax = 0;
        public int RFPower = 0;
        /// <summary>
        /// 系统特性-键盘报告模式
        /// </summary>
        public int KeyReportMode = 0;
        public int KeyOffTime = 0;
        public int BackLightMode = 0;
        public int BuzzerMode = 0;
        public int CommitMode = 0;
        /// <summary>
        /// 基站序列号
        /// </summary>
        public string HSerial = "";
        public int HModel = 0;
        public string HVer = "";
        public string SVer = "";
        /// <summary>
        /// 基站IP地址
        /// </summary>
        public string TcpIPAddress = "";
        public string TcpSubnetMask = "";
        public string TcpGatewayAddress = "";
        public string TcpMACAddress = "";
        /// <summary>
        /// 基站配对码
        /// </summary>
        public string MatchCode = "";
        public int MatchMode = 0;
        public string BaseName = "";
    }

    public class KeyData
    {
        /// <summary>
        /// 关键字,键盘编号或SN
        /// </summary>
        public string KeyID = "";
        /// <summary>
        /// 用来按数字排序,键盘编号1-9999范围
        /// </summary>
        public int KeyNum = 0;
        public string KeyValue = "";
        public double Speed = 0;
        public double BatteryVoltage = 0;
        public int LowBattery = 0;
        public int WarningBattery = 0;
        public int CommitOK = -1;//杨斌 2020-06-12
    }

    public class KeySNInfo
    {
        public int KeyNum = 0;
        public string KeySN = "";
    }
}