Example #1
0
        /// <summary>
        /// 判断读卡器中插入的是一张空卡
        /// </summary>
        public static bool CheckNullCard(string storePassword)
        {
            int icdev = 0;

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

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

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

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

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

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

                st = ICCardUtility.IC_CheckPass_4442hex(icdev, ICPass);
                if (st != 0)
                {
                    st = ICCardUtility.IC_CheckPass_4442hex(icdev, storePassword);
                    if (st == 0)
                    {
                        return(false);
                    }
                }
                return(true);
            }
            finally
            {
                //对卡下电,对于逻辑加密卡,下电后必须密码变为有效,即要写卡必须重新校验密码。
                ICCardUtility.IC_Down(icdev);
                //关闭端口,在Windows系统中,同时只能有一个设备使用端口,所以在退出系统时,请关闭端口,以便于其它设备使用。
                ICCardUtility.IC_ExitComm(icdev);
            }
        }
Example #2
0
        /// <summary>
        /// 基础校验,检查读卡器与IC卡是否都存在
        /// 默认蜂鸣true
        /// 存在返回ok,不存在返回错误信息
        /// </summary>
        private static string check(int icdev, bool isBeep = true)
        {
            if (icdev <= 0)
            {
                ICCardUtility.IC_Down(icdev);
                ICCardUtility.IC_ExitComm(icdev);
                return("提示:IC读卡器USB初始化失败!");
            }
            int iReadDev = -1;

            byte[] sdata = new byte[9];

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

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

            return("ok");
        }