/// <summary> /// 初始化 /// </summary> private void Init() { ClearVal(); ChangeText("请将手指放到指纹仪"); Task.Run(() => { try { //连接指纹 if ((n = FingerPrintHelper.PSOpenDeviceEx(out pHandle, 2, 1)) == (int)ReturnValue.PS_OK) { //清除指纹库模板信息 if (FingerPrintFuc(() => { return(FingerPrintHelper.PSEmpty(pHandle, nAddr)); })) { //实例化Timer类,设置间隔时间为10000毫秒; aTimer = new System.Timers.Timer(1500); aTimer.Elapsed += new ElapsedEventHandler(Objtimer_Tick); aTimer.AutoReset = true; aTimer.Enabled = true; aTimer.Start(); } } else { ShowTip("连接指纹仪失败", "请确定已插入指纹仪后重试"); LogHelper.AsnyWriteLog("连接指纹仪失败"); } } catch (Exception ex) { ShowTip("连接指纹仪失败", "请确定已插入指纹仪后重试"); LogHelper.AsnyWriteLog(ex.ToString()); } }); }
/// <summary> /// 获取生成后的特征码 可存储到数据库 /// </summary> /// <returns></returns> private unsafe string UpChar() { byte[] data = new byte[512]; fixed(byte *arry = data) { int length = 0; if (FingerPrintHelper.PSUpChar(pHandle, nAddr, iBufferID, arry, out length) == (int)ReturnValue.PS_OK) { string hexStr = FingerPrintHelper.ToHexString(data); if (FingerPrintFuc(() => { return(FingerPrintHelper.PSEmpty(pHandle, nAddr)); })) { return(hexStr); } } return(string.Empty); } }
/// <summary> /// 比对现有指纹库 /// </summary> /// <returns></returns> private unsafe bool DownChar(string hexstr) { //连接指纹 if ((n = FingerPrintHelper.PSOpenDeviceEx(out pHandle, 2, 1)) == (int)ReturnValue.PS_OK) { //清除指纹库模板信息 if (FingerPrintFuc(() => { return(FingerPrintHelper.PSEmpty(pHandle, nAddr)); })) { byte[] tempbyte = FingerPrintHelper.strToHexByte(hexstr); fixed(byte *arry = tempbyte) { if (FingerPrintHelper.PSDownChar(pHandle, nAddr, iBufferID, arry, 512) == (int)ReturnValue.PS_OK) { iBufferID++; System.Timers.Timer upTimer = new System.Timers.Timer(1500); upTimer.Elapsed += (o, e) => { if (FingerPrintFuc(() => { return(FingerPrintHelper.PSGetImage(pHandle, nAddr)); }, false)) { if (FingerPrintFuc(() => { return(FingerPrintHelper.PSGenChar(pHandle, nAddr, iBufferID)); })) { //比对两个区后就是是否成功 if (FingerPrintFuc(() => { return(FingerPrintHelper.PSMatch(pHandle, nAddr, out iScore)); })) { ThisDelegate(() => { MessageBox.Show(string.Format("比对成功,分数{0}", iScore)); }); } } } }; upTimer.AutoReset = true; upTimer.Enabled = true; upTimer.Start(); } } } } return(true); }