protected override void OnLoad(EventArgs e) { _identity = null; comboUnitId.Items.Clear(); comboUnitId.ResetText(); var units = WinBio.EnumBiometricUnits(WinBioBiometricType.Fingerprint); Log(string.Format("Found {0} units", units.Length)); if (units.Length == 0) { return; } for (int i = 0; i < units.Length; i++) { Log(string.Format("- Unit id: {0}", units[i].UnitId)); comboUnitId.Items.Add(units[i].UnitId); string strDeviceInstanceId = units[i].DeviceInstanceId; Log(string.Format(" Unit id: {0}", strDeviceInstanceId)); string strFirmwareVersion = getFirmwareVersion(strDeviceInstanceId); if (strFirmwareVersion.Equals("")) { Log(string.Format(" Firmware: {0}", units[i].FirmwareVersion.ToString())); } else { Log(string.Format(" Firmware: {0}", strFirmwareVersion)); } int lastInvSlash = units[i].DeviceInstanceId.LastIndexOf("\\"); Log(string.Format(" Key code: {0}", strDeviceInstanceId.Substring(lastInvSlash + 1, strDeviceInstanceId.Length - lastInvSlash - 1))); } _unitId = units[0].UnitId; setComboxSelectedIndex(comboUnitId, 0); // use 1st one by default. Log(string.Format("Using unit id: {0}", _unitId)); _session = WinBio.OpenSession(WinBioBiometricType.Fingerprint, WinBioPoolType.System, WinBioSessionFlag.Default, null, 0); Log("Session opened: " + _session.Value); comboBoxFp.Items.Clear(); comboBoxFp.ResetText(); String[] myArr = new String[] { "Unknown",//0 "RhThumb", "RhIndexFinger", "RhMiddleFinger", "RhRingFinger", "RhLittleFinger", "LhThumb", "LhIndexFinger", "LhMiddleFinger", "LhRingFinger", "LhLittleFinger" }; //10 comboBoxFp.Items.AddRange(myArr); setComboxSelectedIndex(comboBoxFp, 1); }
private WinBioIdentity AddEnrollment(WinBioSessionHandle session, int unitId, WinBioBiometricSubType subType) { WriteLog(string.Format("Beginning enrollment of {0}:", subType)); WinBio.EnrollBegin(session, subType, unitId); var code = WinBioErrorCode.MoreData; WinBioRejectDetail rejectDetail; int good = 0; for (var swipes = 1; code != WinBioErrorCode.Ok; swipes++) { code = WinBio.EnrollCapture(session, out rejectDetail); switch (code) { case WinBioErrorCode.MoreData: WriteLog(string.Format("Swipe {0} was good", swipes)); good++; break; case WinBioErrorCode.BadCapture: WriteLog(string.Format("Swipe {0} was bad: {1}", swipes, rejectDetail)); break; case WinBioErrorCode.Ok: WriteLog(string.Format("Enrollment complete with {0} swipes", swipes)); break; default: throw new WinBioException(code, "WinBioEnrollCapture failed"); } Progress(good); } WriteLog("Committing enrollment.."); bool isNewTemplate; WinBioIdentity identity = null; try { isNewTemplate = WinBio.EnrollCommit(session, out identity); WriteLog(isNewTemplate ? "New template committed." : "Template already existing."); if (!isNewTemplate) { WinBio.Identify(session, out identity, out subType, out rejectDetail); } EnableDisableOk(true); } catch (Exception e) { WriteLog("Error on AddEnrollment. Error:" + e.Message); } return(identity); }
private void buttonEnroll_Click(object sender, EventArgs e) { WinBioBiometricSubType subType = (WinBioBiometricSubType)comboBoxFp.SelectedIndex; if (subType == WinBioBiometricSubType.Unknown) { Log("Please select a finger index, not Unknown."); return; } ThreadPool.QueueUserWorkItem(delegate { try { Log("Put your finger on sensor..."); WinBioBiometricSubType subFactor; WinBioRejectDetail rejectDetail; while (true) { _unitId = WinBio.Identify(_session, out _identity, out subFactor, out rejectDetail); Log("No. This finger has been enrolled before. Change another one..."); } } catch (WinBioException ex) { Log("OK. This finger not yet be enrolled before."); } try { _identity = AddEnrollment(_session, _unitId, subType); Log(string.Format("Identity: {0}", _identity)); } catch (WinBioException ex) { Log(ex); if (ex.ErrorCode == WinBioErrorCode.DuplicateEnrollment) { Log(string.Format("Please select another finger index or just delete it for a new one.")); } } }); }