示例#1
0
        /// <summary>
        /// 基础校验,检查读卡器与IC卡是否都存在
        /// 默认蜂鸣true
        /// 存在返回ok,不存在返回错误信息
        /// </summary>
        private static string check(int icdev, bool isBeep = true)
        {
            if (icdev <= 0)
            {
                ICAccess.IC_Down(icdev);
                ICAccess.IC_ExitComm(icdev);
                return("提示:IC读卡器USB初始化失败!");
            }
            int iReadDev = -1;

            byte[] sdata = new byte[9];

            iReadDev = ICAccess.IC_ReadVer(icdev, sdata);
            if (iReadDev < 0)
            {
                ICAccess.IC_Down(icdev);
                ICAccess.IC_ExitComm(icdev);
                return("提示:无法找到IC读卡器硬件版本号!");
            }
            short st = 0;

            st = ICAccess.IC_InitType(icdev, 16);
            if (st < 0)
            {
                ICAccess.IC_Down(icdev);
                ICAccess.IC_ExitComm(icdev);
                return("提示:设置IC卡类型失败!");
            }
            if (isBeep)
            {
                st = ICAccess.IC_DevBeep(icdev, 10);        //等待10毫秒
            }
            st = ICAccess.IC_Status(icdev);
            if (st == 1)
            {
                ICAccess.IC_Down(icdev);
                ICAccess.IC_ExitComm(icdev);
                return("提示:读卡器中没有插卡");
            }
            if (st != 0)
            {
                ICAccess.IC_Down(icdev);
                ICAccess.IC_ExitComm(icdev);
                return("提示:无法连接到读卡器");
            }

            return("ok");
        }
示例#2
0
        /// <summary>
        /// 判断读卡器中插入的是一张空卡
        /// </summary>
        public static bool CheckNullCard()
        {
            int icdev = 0;

            try
            {
                icdev = ICAccess.IC_InitComm(100); //初始化usb

                if (icdev <= 0)
                {
                    return(false);
                }

                int    iReadDev = -1;
                byte[] sdata    = new byte[9];

                iReadDev = ICAccess.IC_ReadVer(icdev, sdata);
                if (iReadDev < 0)
                {
                    return(false);
                }

                short st = 0;
                st = ICAccess.IC_InitType(icdev, 16);
                if (st < 0)
                {
                    return(false);
                }

                st = ICAccess.IC_DevBeep(icdev, 10);//等待10毫秒
                st = ICAccess.IC_Status(icdev);
                if (st == 1)
                {
                    return(false);
                }
                if (st != 0)
                {
                    return(false);
                }

                st = ICAccess.IC_CheckPass_4442hex(icdev, ICPass);
                if (st != 0)
                {
                    st = ICAccess.IC_CheckPass_4442hex(icdev, CommonValue.ICStorePassword);
                    if (st != 0)
                    {
                        return(false);
                    }
                }
                else
                {
                    return(true);
                }
                return(false);
            }
            finally
            {
                //对卡下电,对于逻辑加密卡,下电后必须密码变为有效,即要写卡必须重新校验密码。
                ICAccess.IC_Down(icdev);
                //关闭端口,在Windows系统中,同时只能有一个设备使用端口,所以在退出系统时,请关闭端口,以便于其它设备使用。
                ICAccess.IC_ExitComm(icdev);
            }
        }