Esempio n. 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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        /// <summary>
        /// 开始
        /// </summary>
        public bool Start()
        {
            bool rtn = true;

            try
            {
                if (_icDev <= 0)
                {
                    IcCardReaderLogger.Debug("在启动时打开IC读卡器!");
                    rtn = Open();
                }

                if (_icDev > 0)
                {
                    if (threadICCardReader != null)
                    {
                        while (threadICCardReader.IsAlive)
                        {
                            threadICCardReader.Abort();
                            IcCardReaderLogger.Debug("强制结束IC读卡器寻卡线程。");
                        }
                    }
                    threadICCardReader = new Thread(new ThreadStart(Alarm));
                    threadICCardReader.IsBackground = true;
                    _searchCard = true;
                    threadICCardReader.Start();
                    IcCardReaderLogger.Debug("启动IC读卡器寻卡线程。");
                }
                else
                {
                    rtn = false;
                    IcCardReaderLogger.Debug("设备故障,无法启动寻卡线程。_icDev=" + _icDev.ToString());
                    ShowMsg(string.Format("IC卡打开失败,返回值={0}", _icDev.ToString()));
                }
            }
            catch (Exception ex)
            {
                rtn = false;
                IcCardReaderLogger.Error("启动IC读卡器寻卡异常!", ex);
                throw ex;
            }
            return(rtn);
        }
Esempio n. 4
0
        /// <summary>
        /// 创建实例
        /// 如果遇到多个卡,其中有的是相同的品牌,一个程序集不能加载两次
        /// </summary>
        /// <returns></returns>
        private IIcController CreateInstance(ICCard pICCardConfig)
        {
            IIcController io = null;

            try
            {
                string driverPath = System.AppDomain.CurrentDomain.BaseDirectory;
                driverPath = Path.Combine(driverPath, pICCardConfig.Driver);
                //修改开始 20181120
                Assembly assembly = null;
                if (loadedAssmbly.ContainsKey(driverPath))
                {
                    assembly = loadedAssmbly[driverPath];
                }
                else
                {
                    assembly = Assembly.LoadFile(driverPath);
                }

                //修改介绍  下面一句被注释掉
                // Assembly assembly = Assembly.LoadFile(driverPath);

                string name = assembly.FullName.Split(',')[0] + ".IcController";
                Type   type = assembly.GetType(name);
                IcCardReaderLogger.Debug(string.Format("载入硬件封装模块!DLL={0}", driverPath));
                io = Activator.CreateInstance(type, pICCardConfig, _canReadData) as IIcController;
                IcCardReaderLogger.Debug("创建IC读卡器实例成功!");
                //添加到数据字典
                loadedAssmbly.Add(driverPath, assembly);
            }
            catch (Exception ex)
            {
                IcCardReaderLogger.Error("创建IC读卡器实例失败!原因:" + ex.Message);
                throw ex;
            }
            return(io);//
        }