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

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/sjj5395426/article/details/84438750

参考资料: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 οnclick="initss()">读取指纹</button>
	<textarea rows="20" cols="50" id="info"></textarea>
</body>
</html>

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

ComAxCtrl.CommSend();发送命令

展开阅读全文

[原创]JNI调用指纹仪接口示例

03-11

首先国际惯例,先说明概念rn什么是Native Methodrn 简单地讲,一个Native Method就是一个java调用非java代码的接口。一个Native Method是这样一个java的方法:该方法的实现由非java语言实现,比如C。这个特征并非java所特有,很多其它的编程语言都有这一机制,比如在C++中,你可以用extern "C"告知C++编译器去调用一个C的函数。rn "A native method is a Java method whose implementation is provided by non-java code."rn 在定义一个native method时,并不提供实现体(有些像定义一个java interface),因为其实现体是由非java语言在外面实现的。下面就是一个中控指纹仪比对的接口: rn[code=Java]rnpackage com.yujie.util;rnrnpublic class MatchClassLoader rn //比对指纹模板本地接口,ARegTemplate是登记模板,AVerTemplate是比对模板,比对成功返回True,失败返回False。rn public native boolean process(String ARegTemplate, String AVerTemplate);rn rnrn public MatchClassLoader()rn staticrn //System.out.println(System.getProperty("java.library.path"));rn System.loadLibrary("matchload");//把Match.dll复制到tomcat_home/binrn rn //使用单例模式,注意这是private 只供内部调用 rn private static MatchClassLoader instance = new MatchClassLoader(); rn //这里提供了一个供外部访问本class的静态方法,可以直接访问 rn public static MatchClassLoader getInstance() rn return instance; rn rn /**rn * 比对方法rn * @param regrn * @param verrn * @returnrn */rn public static boolean match(String reg,String ver)rn if(reg==null || ver ==null)rn return false;rn else if(reg.indexOf("/////")!=-1 || ver.indexOf("/////")!=-1)rn //System.out.println("不能有转义符");rn //return false;rn rn return MatchClassLoader.getInstance().process(reg,ver);rn rnrnrn[/code]rnrn上面这个接口要把Match.dll复制到JAVA_HOME/bin目录下rn然后就开始编译接口,并用javah生成C的接口rnjavac com.yujie.util.MatchClassLoader.javarnjavah -jni com.yujie.util.MatchClassLoaderrn好了,接下来就是写C程序了,我是用Mingw的gcc来编译的rn下载地址http://sourceforge.net/projects/mingw/rn下载装完后配置几个环境变量就可以用啦:rnPATH d:\MinGW\bin;rnLIBRARY_PATH d:\MinGW\librnC_INCLUDEDE_PATH d:\MinGW\includernCPLUS_INCLUDE_PATH d:\MinGW\include\c++\3.4.2;d:\MinGW\include\c++\3.4.2\mingw32;d:\MinGW\include\c++\3.4.2\backward;d:\MinGW\includernrn现在写个matchload.c实现刚才生成.h文件的方法,重点就是在这里了,这个C程序必须实现调用DLL并返回执行结果,里面涉及Java跟C的数据类型转换,和字符串转换rn[code=C/C++]rn#include rn#include "com_yujie_util_MatchClassLoader.h"rn#includern#include rn#include rnrnJNIEXPORT jboolean JNICALL Java_com_yujie_util_MatchClassLoader_processrn (JNIEnv * env, jobject obj, jstring str1, jstring str2)rn //printf("Hello Java_com_yujie_util_MatchClassLoader_process !\n");rn //把jstring转成c的charrn const char *cstr1 = (*env)->GetStringUTFChars(env, str1, 0);rn const char *cstr2 = (*env)->GetStringUTFChars(env, str2, 0);rn typedef jboolean(* TESTDLL)(jstring a,jstring b);rn HINSTANCE hmod;rn TESTDLL lpproc =NULL;rn jboolean result=0;//返回结果rn //加载DLLrn hmod = LoadLibrary("Match.dll");rn if(hmod == NULL) rn printf("hmod is null Not found Match.dll ! Please check Runtime environment \n");rn return result;rn rn //调用Process方法rn lpproc = (TESTDLL)GetProcAddress(hmod,"Process");rn //printf("debug \n");rn result = lpproc(cstr1,cstr2);rn FreeLibrary(hmod);rn return result; rnrnrn[/code]rnrn接下来再写个抛出方法定义文件matchload.def,这个可别忘了,没写是调不到的rn[code=INIFile]rnEXPORTSrnJava_com_yujie_util_MatchClassLoader_processrn[/code]rn最后就可以开始编译了,激动人心的时刻到啦!rn1.生成.o文件rngcc -c -I%JAVA_HOME%\include -I%JAVA_HOME%\include\win32 -o matchload.o matchload.crn2.生成.dll文件rngcc -shared -o matchload.dll matchload.o matchload.defrn人品好的话,就可以看到matchload.dll文件啦,复制到JAVA_HOME/bin目录下然后调用MatchClassLoader.match()静态方法实现指纹对比rn完 论坛

vfp中控指纹调用出错

05-20

*** ActiveX Control Event ***rnLPARAMETERS actionresultrnrnsTemp = thisform.OleControl1.EncodeTemplate1(thisform.OleControl1.GetTemplate())rnIf FMatchType = 1 Thenrn RegChanged = .F.rn SELECT lsrn ZAPrn If thisform.OleControl1.VerFingerFromFile('c:\1.xxx', thisform.OleControl1.VerTplFileName, .F., @RegChanged)rn APPEND BLANKrn REPLACE ls1 WITH 1rn REPLACE ls2 WITH '拇'rn ELSErn APPEND BLANKrn REPLACE ls1 WITH 0rn REPLACE ls2 WITH '拇'rn ENDIFrn IF thisform.OleControl1.VerFingerFromFile('c:\2.xxx', thisform.OleControl1.VerTplFileName, .F., @RegChanged)rn APPEND BLANKrn REPLACE ls1 WITH 1rn REPLACE ls2 WITH '食'rn ELSErn APPEND BLANKrn REPLACE ls1 WITH 0rn REPLACE ls2 WITH '食'rn ENDIFrn IF thisform.OleControl1.VerFingerFromFile('c:\3.xxx', thisform.OleControl1.VerTplFileName, .F., @RegChanged)rn APPEND BLANKrn REPLACE ls1 WITH 1rn REPLACE ls2 WITH '中'rn ELSErn APPEND BLANKrn REPLACE ls1 WITH 0rn REPLACE ls2 WITH '中'rn ENDIFrn IF thisform.OleControl1.VerFingerFromFile('c:\4.xxx', thisform.OleControl1.VerTplFileName, .F., @RegChanged)rn APPEND BLANKrn REPLACE ls1 WITH 1rn REPLACE ls2 WITH '无名'rn ELSErn APPEND BLANKrn REPLACE ls1 WITH 0rn REPLACE ls2 WITH '无名'rn ENDIFrn IF thisform.OleControl1.VerFingerFromFile('c:\5.xxx', thisform.OleControl1.VerTplFileName, .F., @RegChanged)rn APPEND BLANKrn REPLACE ls1 WITH 1rn REPLACE ls2 WITH '小拇'rn ELSErn APPEND BLANKrn REPLACE ls1 WITH 0rn REPLACE ls2 WITH '小拇'rn ENDIFrnrn LOCATE FOR ls1=1rn IF FOUND()rn MessageBox(ALLTRIM(fingprin.xming)+'、'+ALLTRIM(fingprin.zfxming)+ALLTRIM(ls.ls2)+'指指纹比对成功!')rn[color=#0000FF] oSpeech = CreateObject("SAPI.SpVoice") &&连接到系统的语音功能rn sWord=ALLTRIM(fingprin.xming)+ALLTRIM(fingprin.zfxming)+'指纹比对成功'rn oSpeech.Speak(sWord) &&让系统读出字符串里的内容rn oSpeech=NULL[/color]rn Elsern MessageBox(ALLTRIM(fingprin.xming)+'、'+ALLTRIM(fingprin.zfxming)+'指纹比对失败,请换手指重试!')rn [color=#0000FF] oSpeech = CreateObject("SAPI.SpVoice") &&连接到系统的语音功能rn sWord=ALLTRIM(fingprin.xming)+ALLTRIM(fingprin.zfxming)+'指纹比对失败,请换手指重试!'rn oSpeech.Speak(sWord) &&让系统读出字符串里的内容rn oSpeech=NULL[/color] rn EndIfrnelse rn if FMatchType = 2 Then rn Score = 8rn ProcessNum = 0rn fi = thisform.OleControl1.IdentificationFromFileInFPCacheDB(fpcHandle, thisform.OleControl1.VerTplFileName, @Score, @ProcessNum)rn If fi = -1 Thenrn MessageBox(ALLTRIM(fingprin.xming)+'、'+ALLTRIM(fingprin.zfxming)+'指纹比对失败,请换手指重试!')rn Else rn MessageBox(ALLTRIM(fingprin.xming)+'、'+ALLTRIM(fingprin.zfxming)+'指纹比对成功!')rn EndIfrnendif rnrnENDIFrnrn 在OnCaptureToFile中执行蓝色部分出错“OLE错误码0x80004005 Unspecified error”,把蓝色代码放在command中,执行“click”thisform.command12.click出现同样错误。rn请问各位版主问题出在何处?如何解决?rn 论坛

没有更多推荐了,返回首页