private Task <bool> Prepare(byte[] m_RegMin) { return(Task.Run <bool>(() => { var fp_image = new Byte[m_ImageWidth * m_ImageHeight]; var iError = m_FPM.GetImage(fp_image); iError = m_FPM.GetImageEx(fp_image, timeout: 10000, dispWnd: 0, quality: 50); if (iError == (Int32)SGFPMError.ERROR_NONE) { iError = m_FPM.CreateTemplate(fp_image, m_RegMin); if (iError == (Int32)SGFPMError.ERROR_NONE) { return true; } } return false; })); }
private void deviceThread() { STATE state = STATE.IDLE; COMMAND com = COMMAND.NONE; List <FingerTemplate> templates = new List <FingerTemplate>(); byte[] image = null; Int32 iError = 1; int enrollCount = 0; int quality = 50; iError = m_FPM.Init(devName); iError = m_FPM.OpenDevice(devId); GetInfo(); try { while (true) { cancelToken.Token.ThrowIfCancellationRequested(); if (state == STATE.IDLE) { com = queue.Take(cancelToken.Token); } else { // non blocking take if (queue.Count > 0) { com = queue.Take(); } } switch (com) { case COMMAND.LIVECAPTURE_START: state = STATE.TEST; break; case COMMAND.ENROLLMENT_START: state = STATE.GETFINGER; enrollCount = 0; templates.Clear(); break; case COMMAND.SINGLECAPTURE_START: state = STATE.GETSINGLE; break; case COMMAND.SINGLECAPTURE_STOP: case COMMAND.LIVECAPTURE_STOP: case COMMAND.ENROLLMENT_STOP: state = STATE.IDLE; break; } com = COMMAND.NONE; switch (state) { case STATE.TEST: SendBaseMessage("Please, touch the scanner"); // iError = m_FPM.SetLedOn(false); image = new Byte[m_ImageWidth * m_ImageHeight]; try { iError = m_FPM.GetImageEx(image, TIMEOUT_CAPTURE, 0, ENROLL_QUALITY); } catch (Exception ex) { } if (iError == (Int32)SGFPMError.ERROR_NONE) { OnBiometricsCaptured(new FingerImageSG(_BSPCode, image, m_ImageWidth, m_ImageHeight)); } else if (iError == (Int32)SGFPMError.ERROR_TIME_OUT) { OnBiometricsCaptured(null); Thread.Sleep(TIMEOUT_AFTER_CAPTURE); } else if ((iError != (Int32)SGFPMError.ERROR_INVALID_PARAM) && (iError != (Int32)SGFPMError.ERROR_LINE_DROPPED)) { state = STATE.OFFLINE; Ambassador.AddMessage(new MSignal(this, MSignal.SIGNAL.DEVICE_FAILURE)); } break; case STATE.GETSINGLE: SendBaseMessage("Please, touch the scanner"); image = new Byte[m_ImageWidth * m_ImageHeight]; state = STATE.GETSINGLEIMAGE; break; case STATE.GETSINGLEIMAGE: // iError = m_FPM.SetLedOn(false); image = new Byte[m_ImageWidth * m_ImageHeight]; iError = m_FPM.GetImageEx(image,TIMEOUT_CAPTURE,0,ENROLL_QUALITY); if (iError == 0) { OnSingleCaptured(new FingerImageSG(_BSPCode,image,m_ImageWidth,m_ImageHeight)); image = new Byte[m_ImageWidth * m_ImageHeight]; state = STATE.SINGLELIFT; } else if (iError == (Int32)SGFPMError.ERROR_TIME_OUT) { Thread.Sleep(TIMEOUT_AFTER_CAPTURE); } else if ((iError != (Int32)SGFPMError.ERROR_INVALID_PARAM) && (iError != (Int32)SGFPMError.ERROR_LINE_DROPPED)) { state = STATE.OFFLINE; Ambassador.AddMessage(new MSignal(this,MSignal.SIGNAL.DEVICE_FAILURE)); } break; case STATE.SINGLELIFT: // iError = m_FPM.SetLedOn(false); iError = m_FPM.GetImageEx(image,10,0,ENROLL_QUALITY); if (iError != 0) { state = STATE.GETSINGLE; } else { Thread.Sleep(TIMEOUT_AFTER_CAPTURE); } break; case STATE.GETFINGER: SendBaseMessage("Please, touch the scanner"); image = new Byte[m_ImageWidth * m_ImageHeight]; state = STATE.GETIMAGE; break; case STATE.GETIMAGE: // iError = m_FPM.SetLedOn(false); iError = m_FPM.GetImageEx(image,10,0,ENROLL_QUALITY); if (iError == 0) { enrollCount++; FingerImageSG fingerImage = new FingerImageSG(_BSPCode,image,m_ImageWidth,m_ImageHeight); TemplateSG tmpl = Extract(fingerImage) as TemplateSG; templates.Add(tmpl); OnBiometricsCaptured(fingerImage); OnSendProgressMessage((enrollCount) * 33); if (enrollCount < 3) { state = STATE.GETEMPTY; } else { state = STATE.FINISHENROLL; } } else if (iError == (Int32)SGFPMError.ERROR_TIME_OUT) { Thread.Sleep(TIMEOUT_AFTER_CAPTURE); } else if ((iError != (Int32)SGFPMError.ERROR_INVALID_PARAM) && (iError != (Int32)SGFPMError.ERROR_LINE_DROPPED)) { state = STATE.OFFLINE; Ambassador.AddMessage(new MSignal(this,MSignal.SIGNAL.DEVICE_FAILURE)); } break; case STATE.GETEMPTY: SendBaseMessage("Please, lift your finger up"); image = new Byte[m_ImageWidth * m_ImageHeight]; state = STATE.GETEMPTYIMAGE; break; case STATE.GETEMPTYIMAGE: // iError = m_FPM.SetLedOn(false); iError = m_FPM.GetImageEx(image,10,0,ENROLL_QUALITY); if (iError != 0) { state = STATE.GETFINGER; } else { Thread.Sleep(TIMEOUT_AFTER_CAPTURE); } break; case STATE.FINISHENROLL: state = STATE.IDLE; foreach (var template in templates) { bool matched = false; m_FPM.MatchTemplate((template as TemplateSG).Bytes,(templates[templates.Count - 1] as TemplateSG).Bytes,SGFPMSecurityLevel.NORMAL,ref matched); if (!matched) { SendPopUpMessage("Can't create template, please repeat"); OnBiometricsEnrolled(null); OnSendProgressMessage(0); } OnSendProgressMessage(100); } SendPopUpMessage("Successfully registered"); OnBiometricsEnrolled(templates.ToList()); // return new copy of list break; default: break; } } } catch (Exception ex) { log.Error(ex.Message); m_FPM.CloseDevice(); } }