Exemple #1
0
        /// <summary>
        /// 读取卡号
        /// </summary>
        /// <returns></returns>
        public string ReadCardOrgNo()
        {
            string result = string.Empty;

            try
            {
                if (this._icDev <= 0)
                {
                    this.Open();
                }
                if (this._icDev > 0)
                {
                    short num = Rf32Controller.rf_card(this._icDev, 0, out this.cardNo);
                    if (num == 0)
                    {
                        result = this.cardNo.ToString();
                        Rf32Controller.rf_beep(_icDev, 20);
                    }
                    else
                    {
                        IcCardReaderLogger.Error(string.Format("ReadCardOrgNo读卡失败,原因:{0}", num));
                    }
                }
                else
                {
                    IcCardReaderLogger.Error("ReadCardOrgNo打开IC读卡器失败!_icDev=" + _icDev.ToString());
                }
            }
            catch (Exception ex)
            {
                IcCardReaderLogger.Error("ReadCardOrgNo执行异常!_icDev=" + _icDev.ToString(), ex);
            }
            return(result);
        }
Exemple #2
0
        /// <summary>
        /// 读卡回调函数
        /// </summary>
        /// <param name="paramObject"></param>
        private void MonitorCard(object paramObject)
        {
            uint  cardNo;
            short result = Rf32Controller.rf_card(_icDev, 0, out cardNo);

            //Debug.WriteLine("jianshi:" + result);
            if (result != 0)
            {
                _monitorCardNumNoReadCount++;
            }
            else
            {
                // Rf32Controller.rf_reset(_icDev, 3);
                _monitorCardNumNoReadCount = 0;
            }
            if (_monitorCardNumNoReadCount >= 3)
            {
                //触发移卡事件
                if (OnRemoveCard != null)
                {
                    //_monitorCardNoTimer.Change(-1, -1);
                    _monitorCardNumNoReadCount = 0;
                    OnRemoveCard(_icCardCfg.ComPort);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// 初始化设备
        /// </summary>
        /// <returns></returns>
        public bool Open()
        {
            bool rtn = false;

            try
            {
                if (_icDev > 0)
                {
                    this.Stop();
                    this.Close();
                    Thread.Sleep(1000);
                }
                _icDev = Rf32Controller.rf_init(short.Parse(_icCardCfg.ComPort), int.Parse(_icCardCfg.Baudrate.Substring(0, _icCardCfg.Baudrate.Length - 3)));

                if (_icDev > 0)
                {
                    IcCardReaderLogger.Debug("打开IC读卡器成功!");
                    Rf32Controller.rf_beep(_icDev, 20);
                    IcCardReaderLogger.Debug("IC读卡器播放声音!");
                    rtn = true;
                }
                else
                {
                    IcCardReaderLogger.Error("打开IC读卡器失败!_icDev=" + _icDev.ToString());
                    string msg = GetErrMsgByErrCode(_icDev);
                    ShowMsg(msg);
                }
            }
            catch (Exception ex)
            {
                IcCardReaderLogger.Error("打开IC读卡器异常!", ex);
                ShowMsg("IC读卡器初始化异常.");
            }
            return(rtn);
        }
Exemple #4
0
        /// <summary>
        /// 读卡回调函数
        /// </summary>
        /// <param name="paramObject"></param>
        private void Alarm()
        {
            int temp = 1000;//默认寻卡时间

            int.TryParse(_icCardCfg.Interval, out temp);
            IcCardReaderLogger.Debug("读取IC读卡器寻卡时间!Interval=" + temp);
            while (_searchCard)
            {
                short result = Rf32Controller.rf_card(_icDev, 0, out cardNo);
                IcCardReaderLogger.Debug("IC读卡器寻卡!result=" + result.ToString());
                if (result == 0)
                {
                    Rf32Controller.rf_beep(_icDev, 20);
                    IcCardReaderLogger.Debug("读卡成功");
                    if (OnReadCardNo != null && _canReadCard)
                    {
                        if (_isDebug)
                        {
                            OnReadCardNo(_icCardCfg.ComPort, "B35CADE2");
                        }
                        else
                        {
                            IcCardReaderLogger.Debug(string.Format("触发读卡事件。ComPort={0},cardNo={1}", _icCardCfg.ComPort, cardNo.ToString()));
                            OnReadCardNo(_icCardCfg.ComPort, cardNo.ToString());
                        }
                    }

                    ////启动监控定时器
                    //TimerCallback callBack = new TimerCallback(MonitorCard);
                    //_monitorCardNoTimer = new Timer(MonitorCard, null, Timeout.Infinite, 500);
                    //_monitorCardNoTimer.Change(100, 500);
                }
                Thread.Sleep(temp);
            }
        }
Exemple #5
0
        /// <summary>
        /// 注销设备
        /// </summary>
        /// <returns></returns>
        public bool Close()
        {
            bool rtn = false;

            IcCardReaderLogger.Debug("关闭IC卡读卡器!_icDev=" + _icDev.ToString());
            if (_icDev > 0)
            {
                if (Rf32Controller.rf_exit(_icDev) == 0)
                {
                    ;
                }
                {
                    IcCardReaderLogger.Debug("关闭IC卡读卡器成功!");
                    _icDev = -1;
                }
                rtn = true;
                //_log.Info(string.Format("关闭退出IC卡定时器,退出成功。", _icDev));
            }
            return(rtn);
        }