예제 #1
0
        public MainWindow()
        {
            InitializeComponent();

            rfidHelper = new RFIDHelper("COM1");

            thread = new Thread(new ThreadStart(QueryEPC));
            thread.IsBackground = true;

            resetEvent = new AutoResetEvent(false);
        }
예제 #2
0
        void _RFIDHelper_evtCardState(RFIDEventType eventType, object o)
        {
            string value       = "";
            string secret      = null;
            string readCommand = null;

            switch ((int)eventType)
            {
            case (int)RFIDEventType.RMU_Exception:
                if (null != o)
                {
                }
                //MessageBox.Show("设备尚未准备就绪!");
                value = "设备出现异常!";
                if (this.labelStatus.InvokeRequired)
                {
                    this.labelStatus.Invoke(new deleUpdateContorl(UpdateStatusLable), value);
                }
                else
                {
                    UpdateStatusLable(value);
                }
                break;

            case (int)RFIDEventType.RMU_CardIsReady:
                _RFIDHelper.SendCommand(RFIDHelper.RFIDCommand_RMU_InventoryAnti3, RFIDEventType.RMU_InventoryAnti);
                //value = "设备状态正常!";
                //if (this.labelStatus.InvokeRequired)
                //{
                //    this.labelStatus.Invoke(new deleUpdateContorl(UpdateStatusLable), value);
                //}
                //else
                //{
                //    //this.statusLabel.Text = value;
                //    UpdateStatusLable(value);
                //}
                //secret = ConfigManager.GetLockMemSecret();
                //if (secret == null)
                //{
                //    secret = "12345678";
                //}

                //readCommand =
                //         RFIDHelper.RmuReadDataCommandComposer(
                //             RMU_CommandType.RMU_SingleReadData
                //                , secret,
                //                0,
                //                2,
                //                2,
                //                null);
                //_RFIDHelper.SendCommand(readCommand, RFIDEventType.RMU_SingleReadData);
                break;

            case (int)RFIDEventType.RMU_InventoryAnti:
                this.bRfidCheckClosed = false;
                if (this.button1.InvokeRequired)
                {
                    this.button1.Invoke(new deleUpdateContorl(this.UpdateButton1), "关闭");
                }
                else
                {
                    this.button1.Text = "关闭";
                }
                if (null == o)
                {
                    value = "正在检测标签...";
                }
                else
                if ((string)o != "ok")
                {
                    string id = RFIDHelper.GetEPCFormUII((string)o);
                    //string id = RFIDHelper.GetIDFromEPC((string)o);
                    value = "读取到学号:" + id;
                    // value = "读取到标签:" + (string)o;
                    // secret = ConfigManager.GetLockMemSecret();
                    // if (secret == null)
                    // {
                    //     secret = "12345678";
                    // }
                    // //读取密码段
                    //readCommand =
                    //     RFIDHelper.RmuReadDataCommandComposer(
                    //                         RMU_CommandType.RMU_SingleReadData
                    //                            , secret,
                    //                            0,
                    //                            2,
                    //                            2,
                    //                            null);
                    // _RFIDHelper.SendCommand(readCommand, RFIDEventType.RMU_SingleReadData);

                    CheckToRemoteServer(id);
                }
                if (this.labelStatus.InvokeRequired)
                {
                    this.labelStatus.Invoke(new deleUpdateContorl(UpdateStatusLable), value);
                }
                else
                {
                    //this.statusLabel.Text = value;
                    UpdateStatusLable(value);
                }
                break;

            case (int)RFIDEventType.RMU_SingleReadData:
                if (null != o)
                {
                    string data = (string)o;
                    int    n    = data.IndexOf("&");//data + & + uii
                    string uii  = data.Substring(n + 1);
                    string epc  = RFIDHelper.GetEPCFormUII(uii);
                    value = "读取到标签:" + uii;
                    if (this.labelStatus.InvokeRequired)
                    {
                        this.labelStatus.Invoke(new deleUpdateContorl(UpdateStatusLable), value);
                    }
                    else
                    {
                        UpdateStatusLable(value);
                    }
                    CheckToRemoteServer(epc);
                }
                break;

            case (int)RFIDEventType.RMU_StopGet:
                string buttonText = "";
                if (bStartOrCloseStop == true)    //如果只是开始时的初始化命令
                {
                    this.bRfidCheckClosed = false;
                    value      = "本地考勤服务开始";
                    buttonText = "关闭";
                    this.StartReadRFIDTag();
                }
                else
                {
                    _RFIDHelper.StopCallback();
                    this.bRfidCheckClosed = true;
                    value      = "本地考勤服务停止";
                    buttonText = "打开";
                }

                if (this.button1.InvokeRequired)
                {
                    this.button1.Invoke(new deleUpdateContorl(this.UpdateButton1), buttonText);
                }
                else
                {
                    this.button1.Text = buttonText;
                }

                if (this.labelStatus.InvokeRequired)
                {
                    this.labelStatus.Invoke(new deleUpdateContorl(UpdateStatusLable), value);
                }
                else
                {
                    //this.statusLabel.Text = value;
                    UpdateStatusLable(value);
                }
                break;
            }
        }