Пример #1
0
        private ReadCardRetVal InitComm(ref int port)
        {
            ReadCardRetVal ret = new ReadCardRetVal();

            ret.init();
            try
            {
                //循环设置对应的端口
                ret.retVal = HD_InitComm(port);
                if (ret.retVal != 0)
                {
                    for (int iport = 1001; iport < 1017; iport++)
                    {
                        ret.retVal = HD_InitComm(iport);
                        if (ret.retVal == 0)
                        {
                            port = iport;
                            //记录端口到ini文件中,如果ini读取不对再重新循环
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ret.retVal = -1;
                if (!ex.Message.Equals(""))
                {
                    ret.retMsg = ex.Message;
                }
            }
            return(ret);
        }
Пример #2
0
        public IICCardModel ReadCard()
        {
            HDICCardModel cardModel = new HDICCardModel(false);
            int           iport     = 1001;

            try
            {
                ReadCardRetVal ret = new ReadCardRetVal();
                ret.init();


                ret = InitComm(ref iport);

                if (ret.retVal == 0)
                {
                    //在这循环处理对应的内容
                    ret.init();
                    int xh = 0;
                    while (true)
                    {
                        //华大的设备需要放卡才会有反馈,默认20次不行需退出,不能死循环
                        ret = Authenticate();
                        if (ret.retVal == 0)
                        {
                            break;
                        }
                        xh++;
                        if (xh > 20)
                        {
                            break;
                        }
                        System.Threading.Thread.Sleep(200);
                    }
                    if (ret.retVal == 0)
                    {
                        ret.init();

                        cardModel = Read_BaseInfo(iport);
                    }
                }
                cardModel.ErrorMessage = GetReadCardMessage(ret.retVal);
            }
            catch (Exception ex)
            {
                cardModel.ErrorMessage = "读卡失败:" + ex.Message;
            }
            finally
            {
                CloseComm(iport);
            }
            return(cardModel);
        }
Пример #3
0
        private ReadCardRetVal Authenticate()
        {
            ReadCardRetVal ret = new ReadCardRetVal();

            ret.init();
            try
            {
                ret.retVal = HD_Authenticate();
            }
            catch (Exception ex)
            {
                ret.retVal = -1;
                if (!ex.Message.Equals(""))
                {
                    ret.retMsg = ex.Message;
                }
            }
            return(ret);
        }
Пример #4
0
        private ReadCardRetVal CloseComm(int iport)
        {
            ReadCardRetVal ret = new ReadCardRetVal();

            ret.init();
            try
            {
                //这华大说报错不处理,在前端就不判断了
                ret.retVal = HD_CloseComm(iport);
            }
            catch (Exception ex)
            {
                ret.retVal = -1;
                if (!ex.Message.Equals(""))
                {
                    ret.retMsg = ex.Message;
                }
            }
            return(ret);
        }