1#!/usr/bin/python 2# Author: Zion Orent <zorent@ics.com> 3# Copyright (c) 2015 Intel Corporation. 4# 5# Permission is hereby granted, free of charge, to any person obtaining 6# a copy of this software and associated documentation files (the 7# "Software"), to deal in the Software without restriction, including 8# without limitation the rights to use, copy, modify, merge, publish, 9# distribute, sublicense, and/or sell copies of the Software, and to 10# permit persons to whom the Software is furnished to do so, subject to 11# the following conditions: 12# 13# The above copyright notice and this permission notice shall be 14# included in all copies or substantial portions of the Software. 15# 16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 24import time, sys, signal, atexit 25import pyupm_zfm20 as upmZfm20 26 27# Instantiate a ZFM20 Fingerprint reader on UART 0 28myFingerprintSensor = upmZfm20.ZFM20(0) 29 30 31## Exit handlers ## 32# This stops python from printing a stacktrace when you hit control-C 33def SIGINTHandler(signum, frame): 34 raise SystemExit 35 36# This function lets you run code on exit, 37# including functions from myFingerprintSensor 38def exitHandler(): 39 print "Exiting" 40 sys.exit(0) 41 42# Register exit handlers 43atexit.register(exitHandler) 44signal.signal(signal.SIGINT, SIGINTHandler) 45 46 47# make sure port is initialized properly. 57600 baud is the default. 48if (not myFingerprintSensor.setupTty(upmZfm20.cvar.int_B57600)): 49 print "Failed to setup tty port parameters" 50 sys.exit(1) 51 52 53# This example demonstrates registering a fingerprint on the zfm20 54# module. The procedure is as follows: 55# 56# 1. get an image, store it in characteristics buffer 1 57# 2. get another image, store it in characteristics buffer 2 58# 3. store the image, assuming the two fingerprints match 59 60# first, we need to register our address and password 61 62myFingerprintSensor.setPassword(upmZfm20.ZFM20_DEFAULT_PASSWORD) 63myFingerprintSensor.setAddress(upmZfm20.ZFM20_DEFAULT_ADDRESS) 64 65# now verify the password. If this fails, any other commands 66# will be ignored, so we just bail. 67if (myFingerprintSensor.verifyPassword()): 68 print "Password verified." 69else: 70 print "Password verification failed." 71 sys.exit(1) 72 73 74print " " 75 76# get the first image 77print "Place a finger on the sensor." 78while (myFingerprintSensor.generateImage() != upmZfm20.ZFM20.ERR_OK): 79 pass 80 81# in theory, we have an image 82print "Image captured, converting..." 83 84rv = myFingerprintSensor.image2Tz(1) 85 86if (rv != upmZfm20.ZFM20.ERR_OK): 87 print "Image conversion failed with error code %d" % rv 88 sys.exit(1) 89 90print "Image conversion succeeded, remove finger." 91time.sleep(1) 92 93while (myFingerprintSensor.generateImage() != upmZfm20.ZFM20.ERR_NO_FINGER): 94 pass 95 96print " " 97print "Now place the same finger on the sensor." 98 99while (myFingerprintSensor.generateImage() == upmZfm20.ZFM20.ERR_NO_FINGER): 100 pass 101 102print "Image captured, converting..." 103 104# save this one in slot 2 105rv = myFingerprintSensor.image2Tz(2) 106if (rv != upmZfm20.ZFM20.ERR_OK): 107 print "Image conversion failed with error code %d" % rv 108 sys.exit(1) 109 110print "Image conversion succeeded, remove finger." 111print " " 112 113print "Storing fingerprint at id 1" 114 115# create the model 116rv = myFingerprintSensor.createModel() 117if (rv != upmZfm20.ZFM20.ERR_OK): 118 if (rv == upmZfm20.ZFM20.ERR_FP_ENROLLMISMATCH): 119 print "Fingerprints did not match." 120 else: 121 print "createModel failed with error code %d" % rv 122 sys.exit(1) 123 124# now store it, we hard code the id (second arg) to 1 here 125rv = myFingerprintSensor.storeModel(1, 1) 126if (rv != upmZfm20.ZFM20.ERR_OK): 127 print "storeModel failed with error code %d" % rv 128 sys.exit(1) 129 130print " " 131print "Fingerprint stored at id 1." 132 133