Ejemplo n.º 1
0
        /// <summary>
        /// 初始化0区,参数:0区新卡号和原密码
        /// </summary>
        public static string WriteICCard(string card, string pwd)
        {
            int icdev = 0;

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

                string checkStr = check(icdev);
                if (!checkStr.Equals("ok"))
                {
                    return(checkStr);
                }
                int st = ICAccess.IC_CheckPass_4442hex(icdev, pwd, 0);     //下载密码到读卡器
                if (st == 0)
                {
                    st = ICAccess.IC_Write_hex(icdev, 1, len, card);            //写卡号
                    int st1 = ICAccess.IC_ChangePass(icdev, 3, 0, pwd, ICPass); //写密码
                    if (st == 0 && st1 == 0)
                    {
                        return("Success");
                    }
                }
                return("操作失败");
            }
            finally
            {
                //对卡下电,对于逻辑加密卡,下电后必须密码变为有效,即要写卡必须重新校验密码。
                ICAccess.IC_Down(icdev);
                //关闭端口,在Windows系统中,同时只能有一个设备使用端口,所以在退出系统时,请关闭端口,以便于其它设备使用。
                ICAccess.IC_ExitComm(icdev);
            }
        }