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

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

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