Sunteți pe pagina 1din 17

Lab 1

Lab 1: Biometrics (Finger Print Enrollment)


Objective : To allow students to make use of the futronic SDK(Soft ware development
kit) to program a GUI(Graphic User Interface) to allow enrollment of finger print of the
user into the database.
Items required for the lab:
1. ftrSDKHelper8.dll
2. DbRecord.cs
3. EnrollmentName.cs
4. Finger print scanner
5. C# visual Studio 2008
6. PC with Windows OS
The program developed will be used for all subsequent Job Sheets.
Students are to save their programs and keep them safe.
Step 1 Run C# program

Press once on C#
2008

Press once on Start

Step 2 Start new program


Press once on File

Press once on New


Project

ITE College West


EC5004PA Integrated Security System Design

Lab 1

Step 3 Name the program as Fingerprint Biometrics

Press once on
Windows Form
Applications

Set the name as


Fingerprint Biometrics
Click on
OK

Step 4 Change the size of the Form properties

Properties of Form1
Text: Fingerprint
Biometrics
Size : 712, 497

ITE College West


EC5004PA Integrated Security System Design

Lab 1

Step 5 Design the Form according to the graphic user interface below:

Properties of
Properties of
Properties of
Properties of
groupBox
button1
button2
button3
Name: groupBox1
Name: btnEnroll
Name: btnStop
Name: btnExit
Location: 12, 12
Location: 16, 32
Location: 97, 90
Location: 619, 431
Size : 184, 124
Size : 75, 23
Size : 75, 23
Size : 75, 23
Text: Operations
Text: Enroll
Text: Stop
Text: Exit
Properties of
Properties of
Properties of
PictureBox1
PictureBox2
PictureBox3
Name: FingerPrint1
Name: FingerPrint2
Name: FingerPrint3
BorderStyle: Fixed3D
BorderStyle: Fixed3D
BorderStyle: Fixed3D
Location: 202, 8
Location: 368, 8
Location: 534, 8
Size : 160, 210
Size : 160, 210
Size : 160, 210
SizeMode:
SizeMode:
SizeMode:
Properties of Label
Name: lblMessage
AutoSize: False
BorderStyle: FixedSingle
Location: 10, 221
Size : 684, 23
Text:

ITE College West


EC5004PA Integrated Security System Design

Lab 1

Step 6 Load the ftrSDKHelper8.dll into the program


Right click on the
reference

click on Add reference

click on Browse and look


for the ftrSDKHelper8.dll

ITE College West


EC5004PA Integrated Security System Design

Lab 1

Step 7 Add the object DbRecord.cs into the program.

Right click on Fingerprint


Biometrics

Left Click on the


Add
Left Click on the
Existing Item

Browse through
the harddisk to
find the programs
for DbRecord.cs

ITE College West


EC5004PA Integrated Security System Design

Lab 1

Step 7 Add the object EnrollmentName.cs into the program.

Right click on Fingerprint


Biometrics

Left Click on the


Add
Left Click on the
Existing Item

Browse through
the harddisk to
find the programs
for
EnrollmentName.

ITE College West


EC5004PA Integrated Security System Design

Lab 1

Step 8a coding.

using System.IO; //Consist library for IO Exception


using Futronic.SDKHelper; //Consist library Finger Print Scanner

Step 8b coding.

private bool m_bExit;


/// <summary>
/// The type of this parameter is depending from current operation. For
/// enrollment operation this is DbRecord.
/// </summary>
private Object m_OperationObj;
/// <summary>
/// Contain reference for current operation object
/// </summary>
private FutronicSdkBase m_Operation;
/// <summary>
/// This delegate enables asynchronous calls for setting
/// the text property on a status control.
/// </summary>
/// <param name="text"></param>
delegate void SetTextCallback(string text);
/// <summary>
/// This delegate enables asynchronous calls for setting
/// the Enable property on a buttons.
/// </summary>
/// <param name="bEnable">true to enable buttons, otherwise to disable</param>
delegate void EnableControlsCallback(bool bEnable);

ITE College West


EC5004PA Integrated Security System Design

Lab 1
/// <summary>
/// A directory name to write user's information.
/// </summary>
private String m_DatabaseDir;
/// <summary>
/// This delegate enables asynchronous calls for setting
/// the Image property on a PictureBox control.
/// </summary>
/// <param name="hBitmap">the instance of Bitmap class</param>
delegate void SetImageCallback(Bitmap hBitmap);
///
///
///
///

<summary>
This int allows the program to count the number of finger print
template has been captured.
</summary>

int FingerPrintNum = 1;

Step 8c coding.

try
{

m_DatabaseDir = GetDatabaseDir();
}
catch (IOException)
{
MessageBox.Show(this, "Initialization failed. Application will be
close.\nCan not create database folder",
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}

ITE College West


EC5004PA Integrated Security System Design

Lab 1

Step 8d. Coding for GetDatabaseDir() function.

///
///
///
///
{

<summary>
Get the database directory.
</summary>
<returns>returns the database directory.</returns>
public static String GetDatabaseDir()
String szDbDir;
szDbDir = Path.Combine(Directory.GetCurrentDirectory(), "Database");
//Create the directory of the database at the Bin folder of the program.
if (!Directory.Exists(szDbDir))
{
Directory.CreateDirectory(szDbDir);
//Create the directory of the database at the Bin folder
}
return szDbDir;

Step 8e. At the solution explorer, double click on the Form1.cs

Double click on the Form1.cs

ITE College West


EC5004PA Integrated Security System Design

Lab 1

Step 8f. Double click on the enroll button to type the coding for enrollment.

Double click on the Enroll


button to doing program the

Step 8g. Type the coding onto the indicated field.

FingerPrint1.BackgroundImage = null;
FingerPrint2.BackgroundImage = null;
FingerPrint3.BackgroundImage = null;
DbRecord User = new DbRecord();
// Get user name
EnrollmentName frmName = new EnrollmentName();
frmName.ShowDialog( this );
if (frmName.DialogResult != DialogResult.OK )
{
return;
}
if( frmName.UserName.Length == 0)
{
MessageBox.Show( this, "You must enter a username.", this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Exclamation );
return;
}
// Try creat the file for user's information
if( isUserExists(frmName.UserName) )
{
DialogResult nResponse;
nResponse = MessageBox.Show("User already exists. Do you want replace it?",
"C# example for Futronic SDK", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (nResponse == DialogResult.No)
return;

} ITE College West

EC5004PA Integrated Security System Design

10

Lab 1
else
{
try
{
CreateFile(frmName.UserName);
}
catch (DirectoryNotFoundException)
{
MessageBox.Show(this, "Can not create file to save an user's information.",
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
catch (IOException )
{
MessageBox.Show(this, String.Format("Bad user name '{0}'.", frmName.UserName),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
}
User.UserName = frmName.UserName;
m_OperationObj = User;
if (m_Operation != null)
{
m_Operation.Dispose();
m_Operation = null;
}
m_Operation = new FutronicEnrollment();
// Set control properties
m_Operation.FakeDetection = true;
m_Operation.FFDControl = true;
m_Operation.FARN = 166;
((FutronicEnrollment)m_Operation).MIOTControl = true;
((FutronicEnrollment)m_Operation).MaxModels = 3;
EnableControls(false);
// register events
m_Operation.OnPutOn += new OnPutOnHandler(this.OnPutOn);
m_Operation.OnTakeOff += new OnTakeOffHandler(this.OnTakeOff);
m_Operation.UpdateScreenImage += new UpdateScreenImageHandler(this.UpdateScreenImage);
m_Operation.OnFakeSource += new OnFakeSourceHandler(this.OnFakeSource);

((FutronicEnrollment)m_Operation).OnEnrollmentComplete += new
OnEnrollmentCompleteHandler(this.OnEnrollmentComplete);
// start enrollment process
((FutronicEnrollment)m_Operation).Enrollment();

Step 8h. Program the function isUserExists, EnableControls, OnPutOn, SetStatusText,


ITE College West
EC5004PA Integrated Security System Design

11

Lab 1

OnTakeOff, UpdateScreenImage, OnFakeSource, OnEnrollmentComplete.

private void
Progress)
protected
boolOnTakeOff(FTR_PROGRESS
isUserExists(String UserName)
{{
this.SetStatusText("Remove
thumb/finger from device");
String
szFileName;
}
szFileName = Path.Combine(m_DatabaseDir, UserName );
return File.Exists(szFileName);
}private void UpdateScreenImage(Bitmap hBitmap)
{
Do not
change the state bEnable)
control during application closing.
private//void
EnableControls(bool
if (m_bExit)
{
return;
// Do not
change the state control during application closing.
if (m_bExit)
if (FingerPrintNum
== 1)
return;
{
if (this.InvokeRequired)
if (FingerPrint1.InvokeRequired)
{
{
EnableControlsCallback
d = new EnableControlsCallback(this.EnableControls);
SetImageCallback
= new SetImageCallback(this.UpdateScreenImage);
this.Invoke(d,
new object[] { dbEnable
});
this.Invoke(d, new object[] { hBitmap });
}
}
else
else
{
{
btnEnroll.Enabled
= bEnable;
FingerPrint1.Image
= hBitmap;
btnStop.Enabled
= !bEnable;
FingerPrintNum++;
}
}
}
}
private void OnPutOn(FTR_PROGRESS Progress)
else if (FingerPrintNum == 2)
{
{
this.SetStatusText("Place
thumb/finger on device.");
if (FingerPrint2.InvokeRequired)
}
{
SetImageCallbacktext)
d = new SetImageCallback(this.UpdateScreenImage);
private void SetStatusText(String
this.Invoke(d,
new
object[] { hBitmap });
{
}
// Do not change the state control during application closing.
else )
if( m_bExit
{
return;
FingerPrint2.Image = hBitmap;
FingerPrintNum++;
if( this. lblMessage.InvokeRequired
)
}
{
SetTextCallback d = new SetTextCallback(this.SetStatusText);
}
this.Invoke( d, new object[] { text } );
}
else if (FingerPrintNum == 3)
else
{{
if (FingerPrint3.InvokeRequired)
this.
lblMessage.Text = text;
{ this.Update();
SetImageCallback d = new SetImageCallback(this.UpdateScreenImage);
}
this.Invoke(d, new object[] { hBitmap });
}
}
else
{
ITE College WestFingerPrint3.Image = hBitmap;
12
FingerPrintNum
= 1;
EC5004PA Integrated
Security System
Design
}
}
}

Lab 1

private bool OnFakeSource(FTR_PROGRESS Progress)


{
if( m_bExit )
return true;

);
}

DialogResult result;
result = MessageBox.Show("Fake source detected. Do you want continue process?",
"C# example for Futronic SDK",MessageBoxButtons.YesNo, MessageBoxIcon.Question
return (result == DialogResult.No);

private void OnEnrollmentComplete(bool bSuccess, int nRetCode )


{
StringBuilder szMessage = new StringBuilder();
if (bSuccess)
{
// set status string
szMessage.Append("Enrollment of fingerprint successful");
szMessage.Append("Quality: ");
szMessage.Append(((FutronicEnrollment)m_Operation).Quality.ToString() );
this.SetStatusText( szMessage.ToString() );
// Set template into user's information and save it
DbRecord User = (DbRecord)m_OperationObj;
User.Template = ((FutronicEnrollment)m_Operation).Template;
String szFileName = Path.Combine(m_DatabaseDir, User.UserName );
if (!User.Save(szFileName) )
{
MessageBox.Show( "Error - Cannot save users information to file " +
szFileName, "C# example for Futronic SDK",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
else
{
szMessage.Append("Enrollment failed.");
szMessage.Append("Error description: ");
szMessage.Append(FutronicSdkBase.SdkRetCode2Message(nRetCode));
this.SetStatusText(szMessage.ToString() );
}
m_OperationObj = null;
EnableControls(true);
}
protected void CreateFile(String UserName)
{
String West
szFileName;
ITE College
szFileName = Path.Combine(m_DatabaseDir, UserName);
EC5004PA
Integrated Security System Design
File.Create(szFileName).Close();
File.Delete(szFileName);
}

13

Lab 1

Step 8h. On solution explorer double click on the Form1.cs.

ITE College West


EC5004PA Integrated Security System Design

14

Lab 1

Double click on the Form1.cs

Step 8i. Double click on the Stop button.

Double click on the Stop button

Step 8j. Coding for the Stop button.

m_Operation.OnCalcel();

Step 8k, Double click on the Form1.cs in solution explorer.

Double click on the Form1.cs

Step 8l Double click on the Exit button.


ITE College West
EC5004PA Integrated Security System Design

15

Lab 1

Double click on the Exit


button

Step 8m Programming for the Exit button.

base.Hide();
m_bExit = true;
this.Close();

Step 9. Build the solution by keying F5, and run debug by pressing F6.
Step 10: When there is no error, test your program with the Finger Print Scanner.
Step 11: Save your project.

Conclusion
ITE College West
EC5004PA Integrated Security System Design

16

Lab 1

1. State what these program codes do


codes

What they do

SetStatusText(Hello)
Close()
String szFileName;
szFileName =
Path.Combine(m_DatabaseDir, UserName);
File.Create(szFileName).Close();
File.Delete(szFileName);
FingerPrint1.BackgroundImage = null;
MessageBox.Show(Welcome)
szDbDir =
Path.Combine(Directory.GetCurrentDirectory()
, "Database");
szMessage.Append("Enrollment process
failed.");
szMessage.Append("Error description: ");

2. State 2 problems faced when trying to enroll fingerprint.

ITE College West


EC5004PA Integrated Security System Design

17

S-ar putea să vă placă și