js调用串口通信,读取指纹仪数据

参考资料:http://blog.csdn.net/catxl313/article/details/5244243

全部代码如下,此为读取指纹仪:

<!Doctype html>
<html>
	<head>
    	<title></title>
		<meta http-equiv=Content-Type content="text/html;charset=utf-8">
		
		<style type="text/css">
			body{
				text-align: center;
				font-size: 12px;
				margin: 0px;
				padding: 0px;
			}
			.clear{
				margin: 0px 0px 0px 0px;
				padding: 0px 0px 0px 0px;
			}
			.cssCenter{
				margin-top: 0px;
				margin-bottom: 0px;
				margin-left: auto;
				margin-right: auto;
			}
		</style>
		<script type="text/javascript">
		var ComAxCtrl=null;
		function initss(){
			document.getElementById("fingerAGM").value = "";
			document.getElementById("info").value = "";
			var flag = false;
			var flag1 = false;
			if(ComAxCtrl==null){
				flag = true;
			}
			if(flag){
				ComAxCtrl = document.getElementById("ComAxCtrl");
				ComAxCtrl.attachEvent("OnCommRecv",OnCommRecv);
				flag1 = true;
			}else{
				if(!ComAxCtrl.IsCommOpen()){
					flag1 = true;
				}
			}
			if(flag1){
				var result = ComAxCtrl.CommOpen(1,"9600,n,8,1");
				if(result==0){
					alert("无法找到指纹仪设备!");
					return false;
				}
			}
			if(!ComAxCtrl.IsCommOpen()){
				alert("指纹仪未打开!");
				return false;
			}
			
			//发送命令
			document.getElementById("info").value="";
			var cR = ComAxCtrl.CommSend(stringToHex("TPLT"));
			
		}		
		function OnCommRecv(data){
			hexToString(data);
		}	
		

		function stringToHex(str){
    		var val="";
    		for(var i = 0; i < str.length; i++){
      		if(val == "")
        		val = "0X"+str.charCodeAt(i).toString(16);
      		else
        		val += ",0X" + str.charCodeAt(i).toString(16);
    		}
    		return val;
  		}
		function hexToString(str){
		  var val="";
		  var arr = str.split(" ");
		  for(var i = 0; i<arr.length;i++){
		  		val += String.fromCharCode("0x"+arr[i]);
		  }
		  var info = document.getElementById("info").value+val;
			document.getElementById("info").value = info;
			if(info.length==280){
				//接收完数据
			}
		}
		</script>
  	</head>

  <body>
  	<object id="ComAxCtrl" classid="clsid:1D82E7E4-CDEE-4894-92C2-A3E605D4F84E" codebase="<%=basePath %>ocx/ComAxCtrl.ocx"  style="width:1px; height:1px;"></object>
  	<input type="hidden" id="fingerAGM" value="" />
	<button onclick="initss()">读取指纹</button>
	<textarea rows="20" cols="50" id="info"></textarea>
</body>
</html>

 ComAxCtrl.CommOpen(1,"9600,n,8,1"),1表示com口编号。

ComAxCtrl.CommSend();发送命令