IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 移动开发 -> JS使用Active Ocx控件读写IC卡、NFC标签 -> 正文阅读

[移动开发]JS使用Active Ocx控件读写IC卡、NFC标签

读写器介绍:https://item.taobao.com/item.htm?spm=a1z10.5-c.w4002-17663462238.11.1935789e9DJT8b&id=615391857885https://item.taobao.com/item.htm?spm=a1z10.5-c.w4002-17663462238.11.1935789e9DJT8b&id=615391857885

????????

?

<html>

<head>
	<meta name="renderer" content="ie-stand"><!--页面默认用IE标准模式-->
    <meta http-equiv="Content-Language" content="zh-cn">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>USB IC 卡读卡器控件调用例程 V1.1</title>
	
	

	

<script language="javascript">
var strls = "";
var errorno = "";

//控制字定义,控制字指定,控制字的含义请查看本公司网站提供的动态库说明

//javascript无法自定义常量, 你可以使用变量代替

var BLOCK0_EN = 0x01;//读第一块的(16个字节)
var BLOCK1_EN = 0x02;//读第二块的(16个字节)
var BLOCK2_EN = 0x04;//读第三块的(16个字节)
var NEEDSERIAL = 0x08;//仅读指定序列号的卡
var EXTERNKEY = 0x10;//用明码认证密码,产品开发完成后,建议把密码放到设备的只写区,然后用该区的密码后台认证,这样谁都不知道密码是多少,需要这方面支持请联系
var NEEDHALT = 0x20;//读/写完卡后立即休眠该卡,相当于这张卡不在感应区。要相重新操作该卡必要拿开卡再放上去

var myctrlword = 0;
var myareano = 0;
var authmode = 0;

var mypiccserial = "";
var mypicckey = ""; 
var piccdata0_2 = ""; 

var mypicckey_old = "";//旧密码
var mypicckey_new = "";//新密码

var myblockaddr = 1;//本次读卡的开始块号
	
var myblocksize = 8;//读8个块

function isUIntNum(val){
    var testval = /^\d+$/; // 非负整数 

    return (testval.test(val)); 
}

function isHex(val){
    var testval = /^(\d|[A-F]|[a-f])+$/; // 十六进制数 

    return (testval.test(val)); 
}

function readcard()
{
	//指定控制字
	myctrlword=BLOCK0_EN + BLOCK1_EN + BLOCK2_EN + EXTERNKEY;
	//指定区号
	myareano = 8; //指定为第8区
	//批定密码模式
	authmode = 1; //大于0表示用A密码认证,推荐用A密码认证
	
	//指定序列号,未知卡序列号时可指定为8个0
	mypiccserial="00000000";

	//指定密码,以下密码为厂家出厂密码
	mypicckey = "ffffffffffff";
	
	strls=IcCardReader.piccreadex(myctrlword, mypiccserial,myareano,authmode,mypicckey);
	errorno = strls.substr(0,4);

	
	switch(errorno)
	{
		case "ER08":
			CardIDShower.value = CardIDShower.value +  "错误号:" + errorno + ",表示寻不到卡\r\n";
			break;	
		case "ER09":
			CardIDShower.value = CardIDShower.value +  "错误号:" + errorno + ",表示寻不到卡\r\n";
			break;	
		case "ER10":
			CardIDShower.value = CardIDShower.value +  "错误号:" + errorno + ",表示寻不到卡\r\n";
			break;	

		case "ER11":
			CardIDShower.value = "密码认证错误\r\n";
			CardIDShower.value = CardIDShower.value + strls + "\r\n";
			CardIDShower.value = CardIDShower.value + "其中错误号为:" + errorno + "\r\n";
			CardIDShower.value = CardIDShower.value + "卡十六进制序列号为:" + strls.substr(5,8) + "\r\n";
			alert("密码认证错误");
			break;	
		case "ER12":
			CardIDShower.value = "密码认证错误" + "\r\n";
			CardIDShower.value = CardIDShower.value + strls + "\r\n";
			CardIDShower.value = CardIDShower.value + "其中错误号为:" + errorno + "\r\n";
			CardIDShower.value = CardIDShower.value + "卡十六进制序列号为:" + strls.substr(5,8) + "\r\n";
			alert("密码认证错误");
			break;
		case "ER13":
			CardIDShower.value = "读卡错误" + "\r\n";
			CardIDShower.value = CardIDShower.value + strls + "\r\n";
			CardIDShower.value = CardIDShower.value + "其中错误号为:" + errorno + "\r\n";
			CardIDShower.value = CardIDShower.value + "卡十六进制序列号为:" + strls.substr(5,8) + "\r\n";
			alert("读卡错误");
			break;	
			
		case "ER21":

			CardIDShower.value = CardIDShower.value +  "错误号:" + errorno + ",表示没找到动态库\r\n";
			break;
			
		case "ER22":

			CardIDShower.value = CardIDShower.value +  "错误号:" + errorno + ",表示动态库或驱动程序异常\r\n";
			break;	
		
		case "ER23":

			CardIDShower.value = CardIDShower.value +  "错误号:" + errorno + ",表示读卡器未插上或动态库或驱动程序异常\r\n";
			break;	
		case "ER24":
			alert("");
			CardIDShower.value = CardIDShower.value +  "错误号:" + errorno + ",表示操作超时,一般是动态库没有反应\r\n";
			break;	
		case "ER25":

			CardIDShower.value = CardIDShower.value +  "错误号:" + errorno + ",表示发送字数不够\r\n";
			break;
		case "ER26":

			CardIDShower.value = CardIDShower.value +  "错误号:" + errorno + ",表示发送的CRC错\r\n";
			break;	
		case "ER27":
	
			CardIDShower.value = CardIDShower.value +  "错误号:" + errorno + ",表示接收的字数不够\r\n";
			break;	
		case "ER28":

			CardIDShower.value = CardIDShower.value +  "错误号:" + errorno + ",表示接收的CRC错\r\n";
			break;
		case "ER29":
			CardIDShower.value = CardIDShower.value +  "错误号:" + errorno + ",表示函数输入参数格式错误,请仔细查看\r\n";
			break;
			
		default :
			//读卡成功,其中ER00表示完全成功,ER01表示完全没读到卡数据,ER02表示仅读该卡的第一块成功,,ER02表示仅读该卡的第一二块成功,这是刷卡太快原因
			CardIDShower.value = "读卡成功" + "\r\n";
			CardIDShower.value = CardIDShower.value + strls + "\r\n";
			CardIDShower.value = CardIDShower.value + "其中错误号为:" + errorno + "\r\n";
			CardIDShower.value = CardIDShower.value + "卡十六进制序列号为:" + strls.substr(5,8) + "\r\n";
			CardIDShower.value = CardIDShower.value + "该区第一块十六进制数据为:" + strls.substr(14,32) + "\r\n";
			CardIDShower.value = CardIDShower.value + "该区第二块十六进制数据为:" + strls.substr(46,32) + "\r\n";
			CardIDShower.value = CardIDShower.value + "该区第三块十六进制数据为:" + strls.substr(78,32) + "\r\n";
			break;
	
		

	}



	
}

function writecard()
{
	//指定控制字
	myctrlword=BLOCK0_EN + BLOCK1_EN + BLOCK2_EN + EXTERNKEY;
	
	//指定区号
	myareano = 8; //指定为第8区
	
	//批定密码模式
	authmode = 1; //大于0表示用A密码认证,推荐用A密码认证
	
	//指定序列号,未知卡序列号时可指定为8个0
	mypiccserial="00000000";

	//指定密码,以下密码为厂家出厂密码
	mypicckey = "ffffffffffff";

	//指定写卡内容,长度为48个字节,其中每个字节以两个字符表示为十六进制数
	piccdata0_2 = "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F";
	strls=IcCardReader.piccwriteex(myctrlword, mypiccserial,myareano,authmode,mypicckey,piccdata0_2);
	errorno = strls.substr(0,4);
	switch(errorno)
	{
		case "ER08":
			CardIDShower.value = CardIDShower.value +  "错误号:" + errorno + ",表示寻不到卡\r\n";
			break;	
		case "ER09":
			CardIDShower.value = CardIDShower.value +  "错误号:" + errorno + ",表示寻不到卡\r\n";
			break;	
		case "ER10":
			CardIDShower.value = CardIDShower.value +  "错误号:" + errorno + ",表示寻不到卡\r\n";
			break;	
		case "ER11":
			CardIDShower.value = "密码认证错误" + "\r\n";
			CardIDShower.value = CardIDShower.value + strls + "\r\n";
			CardIDShower.value = CardIDShower.value + "其中错误号为:" + errorno + "\r\n";
			CardIDShower.value = CardIDShower.value + "卡十六进制序列号为:" + strls.substr(5,8) + "\r\n";
			alert("密码认证错误");
			break;
		case "ER12":
			CardIDShower.value = "密码认证错误" + "\r\n";
			CardIDShower.value = CardIDShower.value + strls + "\r\n";
			CardIDShower.value = CardIDShower.value + "其中错误号为:" + errorno + "\r\n";
			CardIDShower.value = CardIDShower.value + "卡十六进制序列号为:" + strls.substr(5,8) + "\r\n";
			alert("密码认证错误");
			break;
		case "ER13":
			CardIDShower.value = "读卡错误" + "\r\n";
			CardIDShower.value = CardIDShower.value + strls + "\r\n";
			CardIDShower.value = CardIDShower.value + "其中错误号为:" + errorno + "\r\n";
			CardIDShower.value = CardIDShower.value + "卡十六进制序列号为:" + strls.substr(5,8) + "\r\n";
			alert("读卡错误");	
			break;
			
		case "ER14":
			CardIDShower.value = "写卡错误" + "\r\n";
			CardIDShower.value = CardIDShower.value + strls + "\r\n";
			CardIDShower.value = CardIDShower.value + "其中错误号为:" + errorno + "\r\n";
			CardIDShower.value = CardIDShower.value + "卡十六进制序列号为:" + strls.substr(5,8) + "\r\n";
			alert("写卡错误");
			break;	
			
		case "ER21":

			CardIDShower.value = CardIDShower.value +  "错误号:" + errorno + ",表示没找到动态库\r\n";
			break;
			
		case "ER22":

			CardIDShower.value = CardIDShower.value +  "错误号:" + errorno + ",表示动态库或驱动程序异常\r\n";
			break;	
		
		case "ER23":

			CardIDShower.value = CardIDShower.value +  "错误号:" + errorno + ",表示读卡器未插上或动态库或驱动程序异常\r\n";
			break;	
		case "ER24":
			alert("");
			CardIDShower.value = CardIDShower.value +  "错误号:" + errorno + ",表示操作超时,一般是动态库没有反应\r\n";
			break;	
		case "ER25":

			CardIDShower.value = CardIDShower.value +  "错误号:" + errorno + ",表示发送字数不够\r\n";
			break;
		case "ER26":

			CardIDShower.value = CardIDShower.value +  "错误号:" + errorno + ",表示发送的CRC错\r\n";
			break;	
		case "ER27":
	
			CardIDShower.value = CardIDShower.value +  "错误号:" + errorno + ",表示接收的字数不够\r\n";
			break;	
		case "ER28":

			CardIDShower.value = CardIDShower.value +  "错误号:" + errorno + ",表示接收的CRC错\r\n";
			break;

		case "ER29":
		
			alert("");
			CardIDShower.value = CardIDShower.value +  "错误号:" + errorno + ",表示函数输入参数格式错误,请仔细查看\r\n";
			break;
		default ://写卡成功,其中ER00表示完全成功,ER01表示完全没写到卡数据,ER02表示仅写该卡的第一块成功,,ER02表示仅写该卡的第一二块成功,这是刷卡太快原因
			CardIDShower.value = "写卡成功" + "\r\n";
			CardIDShower.value = CardIDShower.value + strls + "\r\n";
			CardIDShower.value = CardIDShower.value + "其中错误号为:" + errorno + "\r\n";
			CardIDShower.value = CardIDShower.value + "卡十六进制序列号为:" + strls.substr(5,8) + "\r\n";
			break;
	}
}

function changecardkeyex()
{
	//指定控制字
	myctrlword= EXTERNKEY;
	
	//指定区号
	myareano = 8; //指定为第8区
	
	//批定密码模式
	authmode = 1; //大于0表示用A密码认证,推荐用A密码认证
	
	//指定序列号,未知卡序列号时可指定为8个0
	mypiccserial="00000000";

	//旧密码
	mypicckey_old = "ffffffffffff";

	//新密码
	mypicckey_new = "ffffffffffffFF078069ffffffffffff";//其中最前面的ffffffffffff为A密码,中间的FF078069为访问控制位,最后面的ffffffffffff为B密码

	strls=IcCardReader.piccchangesinglekeyex(myctrlword, mypiccserial,myareano,authmode,mypicckey_old,mypicckey_new)
	errorno = strls.substr(0,4);
	
	if(errorno == "ER00")
	{
		CardIDShower.value = "修改密码成功,卡序列为:" + strls.substr(strls.length - 8,8) + "\r\n";
	} 
	else if((errorno == "ER08") || (errorno == "ER09") || (errorno == "ER10"))
	{
		CardIDShower.value = CardIDShower.value +  "错误号:" + errorno + ",表示寻不到卡\r\n";
	} 
	else
	{
		CardIDShower.value = CardIDShower.value + "错误号:" + errorno  + "\r\n";
	}

}

function getdevicenumber()
{
	strls=IcCardReader.pcdgetdevicenumber();
	errorno = strls.substr(0,4);
	if(errorno == "ER00")
    {

		CardIDShowerdev.value = CardIDShowerdev.value + "读取成功,设备硬件号为:" + strls.substr(strls.length - 8,8) + "\r\n";
	
	}
	else if(errorno == "ER23")
	{
		CardIDShowerdev.value = CardIDShowerdev.value + "请先用USB接口连接读写器" + "\r\n";
	}
	else 
	{
		CardIDShowerdev.value = CardIDShowerdev.value + "错误号:" + errorno + "\r\n";
	}
}

function beep()
{
	IcCardReader.pcdbeep(100);//100表示响100毫秒
}

function clears1()
{
	CardIDShower.value = "";
}

function clearsntag()
{
	CardIDShowerNtag.value = "";
}

function clearsdev()
{
	CardIDShowerdev.value = "";
}

//Ntag21x测试
function readcard_ntag()
{
	//指定序列号,未知卡序列号时可指定为14个0,因为NTAG21x卡是7个字节的卡序列号
	strls = ntagserial.value.trim();
	if(strls=="")
	{
		mypiccserial="00000000000000";
	}
	else
	{
		if(!isHex(strls))
		{
			CardIDShowerNtag.value = CardIDShowerNtag.value +  "卡号输入错误\r\n";
			ntagserial.focus();
			ntagserial.select();
			return;
		}
		mypiccserial = strls;
	}

	//指定密码,NTAG21x卡密码为4个字节,卡出厂时密码功能不启用,这样无需密码也能读写卡
	if(check3.checked)
	{
		//指定控制字
		myctrlword=EXTERNKEY;//无需密码为0,当需要密码时为EXTERNKEY;
		strls = ntagkey3.value.trim();
		if(!isHex(strls))
		{
			CardIDShowerNtag.value = CardIDShowerNtag.value +  "密码输入错误\r\n";
			ntagkey3.focus();
			ntagkey3.select();
			return;
		}
		mypicckey = strls;
	}
	else
	{
		//指定控制字
		myctrlword = 0;//无需密码为0,当需要密码时为EXTERNKEY;
	}
	
	//起始页号
	strls = ntagstartno.value.trim();
	
	if(!isUIntNum(strls))
	{
		CardIDShowerNtag.value = CardIDShowerNtag.value +  "起始页号输入错误\r\n";
		ntagstartno.focus();
		ntagstartno.select();
		return;
	}

	myblockaddr = parseInt(strls);//本次读卡的开始块号
	
	//页数
	strls = ntagpagenumber.value.trim();
	
	if(!isUIntNum(strls))
	{
		CardIDShowerNtag.value = CardIDShowerNtag.value +  "页数输入错误\r\n";
		ntagpagenumber.focus();
		ntagpagenumber.select();
		return;
	}
	myblocksize = parseInt(strls);//读4个块
	
	strls=IcCardReader.piccreadex_ntag(myctrlword,mypiccserial,mypicckey,myblockaddr,myblocksize);

	errorno = strls.substr(0,4);
	
	switch(errorno)
	{
		case "ER08":
			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示寻不到卡\r\n";
			break;	
		case "ER09":
			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示寻不到卡\r\n";
			break;	
		case "ER10":
			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示寻不到卡\r\n";
			break;		

		case "ER11":
			CardIDShowerNtag.value = "密码认证错误\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + strls + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "其中错误号为:" + errorno + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "卡十六进制序列号为:" + strls.substr(5,14) + "\r\n";

			break;	
		case "ER12":
			CardIDShowerNtag.value = "密码认证错误" + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + strls + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "其中错误号为:" + errorno + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "卡十六进制序列号为:" + strls.substr(5,14) + "\r\n";

			break;
		case "ER13":
			CardIDShowerNtag.value = "读卡错误" + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + strls + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "其中错误号为:" + errorno + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "卡十六进制序列号为:" + strls.substr(5,14) + "\r\n";

			break;	
			
		case "ER21":

			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示没找到动态库\r\n";
			break;
			
		case "ER22":

			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示动态库或驱动程序异常\r\n";
			break;	
		
		case "ER23":

			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示读卡器未插上或动态库或驱动程序异常\r\n";
			break;	
		case "ER24":
			alert("");
			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示操作超时,一般是动态库没有反应\r\n";
			break;	
		case "ER25":

			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示发送字数不够\r\n";
			break;
		case "ER26":

			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示发送的CRC错\r\n";
			break;	
		case "ER27":
	
			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示接收的字数不够\r\n";
			break;	
		case "ER28":

			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示接收的CRC错\r\n";
			break;

		case "ER29":
			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",函数输入参数格式错误,请仔细查看\r\n";
			break;
		case "ER00":
			//读卡成功
			CardIDShowerNtag.value = "读卡成功" + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + strls + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "其中错误号为:" + errorno + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "卡十六进制序列号为:" + strls.substr(5,14) + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "本次读取的十六进制数据为:" + strls.substr(20) + "\r\n";
			
			ntagserial.value = strls.substr(5,14);
			ntagdata.value = strls.substr(20);

			break;
	}

}

function writecard_ntag()
{
	//指定序列号,未知卡序列号时可指定为14个0,因为NTAG21x卡是7个字节的卡序列号
	strls = ntagserial.value.trim();
	if(strls=="")
	{
		mypiccserial="00000000000000";
	}
	else
	{
		if(!isHex(strls))
		{
			CardIDShowerNtag.value = CardIDShowerNtag.value +  "卡号输入错误\r\n";
			ntagserial.focus();
			ntagserial.select();
			return;
		}
		mypiccserial = strls;
	}

	//指定密码,NTAG21x卡密码为4个字节,卡出厂时密码功能不启用,这样无需密码也能读写卡
	if(check3.checked)
	{
		//指定控制字
		myctrlword=EXTERNKEY;//无需密码为0,当需要密码时为EXTERNKEY;
		strls = ntagkey3.value.trim();
		if(!isHex(strls))
		{
			CardIDShowerNtag.value = CardIDShowerNtag.value +  "密码输入错误\r\n";
			ntagkey3.focus();
			ntagkey3.select();
			return;
		}
		mypicckey = strls;
	}
	else
	{
		//指定控制字
		myctrlword = 0;//无需密码为0,当需要密码时为EXTERNKEY;
	}
	
	//起始页号
	strls = ntagstartno.value.trim();
	
	if(!isUIntNum(strls))
	{
		CardIDShowerNtag.value = CardIDShowerNtag.value +  "起始页号输入错误\r\n";
		ntagstartno.focus();
		ntagstartno.select();
		return;
	}

	myblockaddr = parseInt(strls);//本次读卡的开始块号
	
	//页数
	strls = ntagpagenumber.value.trim();
	
	if(!isUIntNum(strls))
	{
		CardIDShowerNtag.value = CardIDShowerNtag.value +  "页数输入错误\r\n";
		return;
	}
	myblocksize = parseInt(strls);
	
	//数据
	strls = ntagdata.value.trim();
	
	if(!isHex(strls))
	{
		CardIDShowerNtag.value = CardIDShowerNtag.value +  "数据输入错误\r\n";
		ntagdata.focus();
		ntagdata.select();
		return;
	}
	
	strls=IcCardReader.piccwriteex_ntag(myctrlword,mypiccserial,mypicckey,myblockaddr,myblocksize,strls);

	errorno = strls.substr(0,4);
	
	switch(errorno)
	{
		case "ER08":
			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示寻不到卡\r\n";
			break;	
		case "ER09":
			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示寻不到卡\r\n";
			break;	
		case "ER10":
			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示寻不到卡\r\n";
			break;		

		case "ER11":
			CardIDShowerNtag.value = "密码认证错误\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + strls + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "其中错误号为:" + errorno + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "卡十六进制序列号为:" + strls.substr(5,14) + "\r\n";
			alert("密码认证错误");
			break;	
		case "ER12":
			CardIDShowerNtag.value = "密码认证错误" + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + strls + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "其中错误号为:" + errorno + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "卡十六进制序列号为:" + strls.substr(5,14) + "\r\n";

			break;

		case "ER14":
			CardIDShowerNtag.value = "写卡错误" + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + strls + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "其中错误号为:" + errorno + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "卡十六进制序列号为:" + strls.substr(5,14) + "\r\n";

			break;	
		case "ER20":
			CardIDShowerNtag.value = "写卡错误,禁止写配置页或页号超过此卡最大页" + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + strls + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "其中错误号为:" + errorno + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "卡十六进制序列号为:" + strls.substr(5,14) + "\r\n";

			break;
			
		case "ER21":

			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示没找到动态库\r\n";
			break;
			
		case "ER22":

			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示动态库或驱动程序异常\r\n";
			break;	
		
		case "ER23":

			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示读卡器未插上或动态库或驱动程序异常\r\n";
			break;	
		case "ER24":
			alert("");
			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示操作超时,一般是动态库没有反应\r\n";
			break;	
		case "ER25":

			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示发送字数不够\r\n";
			break;
		case "ER26":

			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示发送的CRC错\r\n";
			break;	
		case "ER27":
	
			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示接收的字数不够\r\n";
			break;	
		case "ER28":

			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示接收的CRC错\r\n";
			break;

		case "ER29":

			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",函数输入参数格式错误,请仔细查看\r\n";
			break;
		case "ER00":
			//写卡成功
			CardIDShowerNtag.value = "写卡成功" + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + strls + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "其中错误号为:" + errorno + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "卡十六进制序列号为:" + strls.substr(5,14) + "\r\n";
			
			ntagserial.value = strls.substr(5,14);
			ntagdata.value = strls.substr(20);
			
			break;
	}
}

function piccinit_ntag()
{
	//指定序列号,未知卡序列号时可指定为14个0,因为NTAG21x卡是7个字节的卡序列号
	mypiccserial="00000000000000";
	
	//指定密码,NTAG21x卡密码为4个字节,卡出厂时密码功能不启用,这样无需密码也能读写卡
	if(check1.checked)
	{
		//指定控制字
		myctrlword=EXTERNKEY;//无需密码为0,当需要密码时为EXTERNKEY;
		strls = ntagkey1.value.trim();
		if(!isHex(strls))
		{
			CardIDShowerNtag.value = CardIDShowerNtag.value +  "密码输入错误\r\n";
			ntagkey1.focus();
			ntagkey1.select();
			return;
		}
		mypicckey = strls;
	}
	else
	{
		//指定控制字
		myctrlword = 0;//无需密码为0,当需要密码时为EXTERNKEY;
	}
	
	//数据准备
	if(select1.selectedIndex==1)
	{//开启密码保护功能,写保护功能生效,但读保护需要下面的数据设定
		//取新密码
		strls = ntagkey2.value.trim();

		if(strls.length != 8)
		{
			CardIDShowerNtag.value = CardIDShowerNtag.value +  "新密码长度必须为8位\r\n";
			ntagkey2.focus();
			ntagkey2.select();
			return;
		}
		
		strls = ntagkey2.value.trim();
		if(!isHex(strls))
		{
			CardIDShowerNtag.value = CardIDShowerNtag.value +  "新密码输入错误\r\n";
			ntagkey2.focus();
			ntagkey2.select();
			return;
		}
		
		
		strls1=protectpageno.value.trim();//起始保护页号
		if(!isUIntNum(strls1))
		{
			CardIDShowerNtag.value = CardIDShowerNtag.value +  "起始保护页号输入错误\r\n";
			protectpageno.focus();
			protectpageno.select();
			return;
		}
		
		strls1 = "0"+parseInt(strls1).toString(16);
		strls1 = strls1.substring(strls1.length-2);
		
		mypiccdata = "000000" + strls1;
		myctrlword = myctrlword + 0x01; //更新控制字
		
		//计数器
		strls1=keyerrortimes.value.trim();//允许密码错误次数
		if(!isUIntNum(strls1))
		{
			CardIDShowerNtag.value = CardIDShowerNtag.value +  "允许密码错误次数输入错误\r\n";
			protectpageno.focus();
			protectpageno.select();
			return;
		}
		
		i = parseInt(strls1);

                i = i % 8;
		
		if(check2.checked)
		{
			i = i + 128;
		}
		strls1 = "0"+i.toString(16);
		strls1 = strls1.substring(strls1.length-2);
		
		mypiccdata = mypiccdata + strls1;
		
		mypiccdata = mypiccdata + "000000";
		
		mypiccdata = mypiccdata + strls;//新密码
		
		//PACK
		//PACK
		//RFUI
		//RFUI
		mypiccdata = mypiccdata + "16160000";
		
		myctrlword = myctrlword + 0x02; //更新控制字	
	}
	else
	{
		mypiccdata = "000000FF";//MIRROR,RFUI,MIRROR_PAGE,AUTH0
		
		myctrlword = myctrlword + 0x01; //更新控制字	
		
		mypiccdata = mypiccdata + "00000000";
		myctrlword = myctrlword + 0x02; //更新控制字	
		
	}

	strls=IcCardReader.piccinit_ntag(myctrlword,mypiccserial,mypicckey,mypiccdata);

	errorno = strls.substr(0,4);
	
	switch(errorno)
	{
		case "ER08":
			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示寻不到卡\r\n";
			break;	
		case "ER09":
			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示寻不到卡\r\n";
			break;	
		case "ER10":
			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示寻不到卡\r\n";
			break;		

		case "ER11":
			CardIDShowerNtag.value = "密码认证错误\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + strls + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "其中错误号为:" + errorno + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "卡十六进制序列号为:" + strls.substr(5,14) + "\r\n";
			alert("密码认证错误");
			break;	
		case "ER12":
			CardIDShowerNtag.value = "密码认证错误" + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + strls + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "其中错误号为:" + errorno + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "卡十六进制序列号为:" + strls.substr(5,14) + "\r\n";

			break;

		case "ER14":
			CardIDShowerNtag.value = "设置失败,可能需要验证密码" + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + strls + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "其中错误号为:" + errorno + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "卡十六进制序列号为:" + strls.substr(5,14) + "\r\n";

			break;	

		case "ER21":

			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示没找到动态库\r\n";
			break;
			
		case "ER22":

			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示动态库或驱动程序异常\r\n";
			break;	
		
		case "ER23":

			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示读卡器未插上或动态库或驱动程序异常\r\n";
			break;	
		case "ER24":
			alert("");
			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示操作超时,一般是动态库没有反应\r\n";
			break;	
		case "ER25":

			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示发送字数不够\r\n";
			break;
		case "ER26":

			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示发送的CRC错\r\n";
			break;	
		case "ER27":
	
			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示接收的字数不够\r\n";
			break;	
		case "ER28":

			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",表示接收的CRC错\r\n";
			break;

		case "ER29":

			CardIDShowerNtag.value = CardIDShowerNtag.value +  "错误号:" + errorno + ",函数输入参数格式错误,请仔细查看\r\n";
			break;
		case "ER00":
			//初始化卡成功
			CardIDShowerNtag.value = "初始化卡成功" + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + strls + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "其中错误号为:" + errorno + "\r\n";
			CardIDShowerNtag.value = CardIDShowerNtag.value + "卡十六进制序列号为:" + strls.substr(5,14) + "\r\n";
			
			break;
	}
}

window.onerror=function()
{
	alert("不好意思,出错了!");
	return true;//屏蔽系统事件
}

</script>

<style type="text/css">
	input {float: left;margin-right: 10px;margin-top: 10px;margin-bottom: 10px;padding: 5px 10px}
	input[type="text"]:focus {border:2px solid #ff9800}
</style>

</head>
<body>
	<div style="width:100%">
		<object classid="clsid:05782014-9FF7-468C-BE96-8EDC73084202" id="IcCardReader" viewastext="" width="0" height="0"></object>
		
		<div style=" float:left; COLOR: #FFF;BACKGROUND-COLOR: #FF9800;padding: 2px 5px;">
			设备操作
		</div>
		<div style="width:100%; float:left;">
			<div style="border-top: 2px solid #ff9800;padding: 2px 5px;color: #2196f3;">
				<span>提示:</span>
				<br/>
				<textarea rows="3" cols="98" id="CardIDShowerdev" name="S3" style="width:100%;overflow:auto;"></textarea>
				<br/>
				<input type="button" value="蜂鸣器响" onclick="beep()">
				<input type="button" value="读取读写器硬件号" onclick="getdevicenumber()">
				<input type="button" value="清空提示" onclick="clearsdev()">
				
			</div>
		</div>
		
		<div style=" float:left; COLOR: #FFF;BACKGROUND-COLOR: #FF9800;padding: 2px 5px;">
			M1卡测试
		</div>
		<div style="width:100%; float:left;">
			<div style="border-top: 2px solid #ff9800;padding: 2px 5px;color: #2196f3;">
				<span>提示:</span>
				<br/>
				<textarea rows="10" cols="98" id="CardIDShower" name="S1" style="width: 100%;overflow:auto;"></textarea>
				
				<br/>
				<input type="button" value=" 读 卡 " onclick="readcard()">
				<input type="button" value=" 写 卡 " onclick="writecard()">
				<input type="button" value="更改卡密码" onclick="changecardkeyex()">
				<input type="button" value="清空提示" onclick="clears1()">
				
			</div>
		</div>
		
		<div style=" float:left; COLOR: #FFF;BACKGROUND-COLOR: #FF9800;padding: 2px 5px;">
			Ntag21x卡测试
		</div>

		<div style="width:100%; float:left;">
			<div style="border-top: 2px solid #ff9800;padding: 2px 5px;color: #2196f3;">

				<span>提示:</span>
				<br>
				<textarea rows="10" cols="98" id="CardIDShowerNtag" name="S2" style="width: 100%;overflow:auto;"></textarea>
				<br/>
				<input type="button" value="清空提示" onclick="clearsntag()">
				<br/>
				<div style="width:100%; float:left;">

					<label>
						<input name="check1" type="checkbox" style="float:none;margin-right:0px;padding:0px;vertical-align:middle" />
						<span style="vertical-align:middle">需要认证卡密码才能继续操作,密码:</span>
					</label> 
					
					<input type="text" name="ntagkey1"  value ="12345678" style="width:6em;float:none;margin-right:0px;padding:0px;vertical-align:middle"/>
					<br/>
					<select name="select1" style="width:12em;">
						<option>取消密码保护功能</option>
						<option>开启密码保护功能</option>
					</select>
					<br/>
					<label>
						<span style="vertical-align:middle">从</span>
						<input type="text" name="protectpageno"  value ="144" style="width:2em;float:none;margin-right:0px;padding:0px;vertical-align:middle"/>
						<span style="vertical-align:middle">页开始有密码保护</span>
						
					</label> 
					
					<label>
						<input name="check2" type="checkbox" style="float:none;margin-right:0px;padding:0px;vertical-align:middle" />
						<span style="vertical-align:middle">开启读操作密码保护</span>
					</label>
					
					<br/>

					<span style="vertical-align:middle">新密码:</span>
					<input type="text" name="ntagkey2"  value ="12345678" style="width:6em;float:none;margin-right:0px;padding:0px;vertical-align:middle"/>
					<span style="vertical-align:middle">允许密码错误次数(0为不限次):</span>
					<input type="text" name="keyerrortimes"  value ="0" style="width:2em;float:none;margin-right:0px;padding:0px;vertical-align:middle"/>

					<br/>
					<input type="button" value=" 设置卡密码及保护机制(写错卡作废,千万小心) " onclick="piccinit_ntag()">
					<br/>
					<div style="width:100%; float:left;border-top: 3px solid #eaebdc;"></div>
					<br/>
					<label>
						<input name="check3" type="checkbox" style="float:none;margin-right:0px;padding:0px;vertical-align:middle" />
						<span style="vertical-align:middle">需要认证卡密码才能继续操作,密码:</span>
					</label> 
					<input type="text" name="ntagkey3"  value ="12345678" style="width:6em;float:none;margin-right:0px;padding:0px;vertical-align:middle"/>
					
					<table style="color:#e58800;width:100%;table-layout:fixed;">
						<colgroup>
							<col width="85">
							<col width="50">
							<col width="50">
							<col width="auto">
						</colgroup>
						<tr>
							<td style="text-align:right">
								<span style="vertical-align:middle">起始页号:</span>
							</td>
							
							<td>
								<input type="text" name="ntagstartno"  value ="8" style="width:2em;float:none;margin-right:0px;padding:0px;vertical-align:middle"/>
							</td>
							<td>
								<span style="vertical-align:middle">卡号:</span>
							</td>
							
							<td>
								<input type="text" name="ntagserial" value="" style="max-width: 16em;width:100%;float:none;margin-right:0px;padding:0px;vertical-align:middle;overflow:auto;">
							</td>
							
						</tr>
						
						<tr>
							<td style="text-align:right">
								<span style="vertical-align:middle">页数:</span>
							</td>
							
							<td>
								<input type="text" name="ntagpagenumber"  value ="4" style="width:2em;float:none;margin-right:0px;padding:0px;vertical-align:middle;" />
							</td>
							<td>
								<span style="vertical-align:middle;">数据:</span>
							</td>
							
							<td>

								<input type="text" name="ntagdata" value="" style="width:100%;float:none;margin-right:0px;padding:0px;vertical-align:middle;overflow:auto; ">
							</td>
							
						</tr>	
					</table>
					

					<input type="button" value=" 轻松读卡,最多一次12页 " onclick="readcard_ntag()">
					<input type="button" value=" 轻松写卡,最多一次11页 " onclick="writecard_ntag()">
					<br/>
					
					<div style="width:100%; float:left;border-top: 3px solid #eaebdc;"></div>
					
					<br/>
					
				</div>
				

				

			</div>
		</div>

		<div style="width:100%; float:left;">
		
			<table style="color:#e58800">
			
				<colgroup>
					<col width="20">
					<col width="auto">
				</colgroup>
				<tr>
					<td colspan="2">
					说明:
					</td>
					
				</tr>
				
				<tr>
					<td valign="top">
					1、
					</td>
					
					<td valign="top">
					<p>
						运行本例程前,需先注册 IcCardReader 控件,注册方法:如果64位操作系统,以管理员身份运行"复制及注册IcCardReader控件win10_64.bat",如果是32位操作系统,以管理员身份运行"复制及注册IcCardReader控件win_32.bat",这两个文件在当前目录下。</p>
					</td>
					
				</tr>
				<tr>
					<td valign="top">
					2、
					</td>
					
					<td valign="top">
					<p>
						<p>在IE的Internet 属性设定,让浏览器允许运行 ActiveX 控件。</p>
					</td>
					
				</tr>
				<tr>
					<td valign="top">
					3、
					</td>
					
					<td valign="top">
					<p>
						<p>如果是在服务器端运行本网页,还需在IE的Internet 属性中设定,将服务器网址设为可信站点,否则网页无权运行本地控件。</p>
					</td>
					
				</tr>
				<tr>
					<td valign="top">
					4、
					</td>
					
					<td valign="top">
					<p>
						<p>如果是用IE以外的浏览器,如360浏览器,需开启兼容模式(可在网上加&lt;meta name="renderer" content="ie-stand"&gt;),不能用极速模式。</p>
					</td>
					
				</tr>
				
			</table>
			
		</div>
	
	</div>
	


</body>
</html>

  移动开发 最新文章
Vue3装载axios和element-ui
android adb cmd
【xcode】Xcode常用快捷键与技巧
Android开发中的线程池使用
Java 和 Android 的 Base64
Android 测试文字编码格式
微信小程序支付
安卓权限记录
知乎之自动养号
【Android Jetpack】DataStore
上一篇文章      下一篇文章      查看所有文章
加:2022-03-24 00:42:07  更:2022-03-24 00:43:19 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/24 20:04:36-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码