Skip to content

Instantly share code, notes, and snippets.

@cyrilCodePro
Created February 13, 2019 08:02
Show Gist options
  • Save cyrilCodePro/b7cbd15e0c9172fba018bc237f83eea1 to your computer and use it in GitHub Desktop.
Save cyrilCodePro/b7cbd15e0c9172fba018bc237f83eea1 to your computer and use it in GitHub Desktop.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;
using SecuGen.FDxSDKPro.Windows;
namespace Pos
{
public class MainForm : System.Windows.Forms.Form
{
private SGFingerPrintManager m_FPM;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.PictureBox pictureBoxR2;
private System.Windows.Forms.PictureBox pictureBoxV1;
private System.Windows.Forms.PictureBox pictureBoxR1;
private bool m_LedOn = false;
private Int32 m_ImageWidth;
private Int32 m_ImageHeight;
private Byte[] m_RegMin1;
private Byte[] m_RegMin2;
private Byte[] m_VrfMin;
private SGFPMDeviceList[] m_DevList; // Used for EnumerateDevice
private System.Windows.Forms.ComboBox comboBoxDeviceName;
private System.Windows.Forms.Label StatusBar;
private System.Windows.Forms.ComboBox comboBoxSecuLevel_V;
private System.Windows.Forms.ComboBox comboBoxSecuLevel_R;
private void MainForm_Load(object sender, System.EventArgs e)
{
m_LedOn = false;
m_RegMin1 = new Byte[400];
m_RegMin2 = new Byte[400];
m_VrfMin = new Byte[400];
comboBoxSecuLevel_R.SelectedIndex = 4;
comboBoxSecuLevel_V.SelectedIndex = 3;
m_FPM = new SGFingerPrintManager();
EnumerateBtn_Click(sender, e);
}
private void EnumerateBtn_Click(object sender, System.EventArgs e)
{
Int32 iError;
string enum_device;
comboBoxDeviceName.Items.Clear();
// Enumerate Device
iError = m_FPM.EnumerateDevice();
// Get enumeration info into SGFPMDeviceList
m_DevList = new SGFPMDeviceList[m_FPM.NumberOfDevice];
for (int i = 0; i < m_FPM.NumberOfDevice; i++)
{
m_DevList[i] = new SGFPMDeviceList();
m_FPM.GetEnumDeviceInfo(i, m_DevList[i]);
enum_device = m_DevList[i].DevName.ToString() +" : " + m_DevList[i].DevID;
comboBoxDeviceName.Items.Add(enum_device);
}
if (comboBoxDeviceName.Items.Count > 0)
{
// Add Auto Selection
enum_device = "Auto Selection";
comboBoxDeviceName.Items.Add(enum_device);
comboBoxDeviceName.SelectedIndex = 0; //First selected one
}
}
private void OpenDeviceBtn_Click(object sender, System.EventArgs e)
{
if (m_FPM.NumberOfDevice == 0)
return;
Int32 iError;
SGFPMDeviceName device_name;
Int32 device_id;
Int32 numberOfDevices = comboBoxDeviceName.Items.Count;
Int32 deviceSelected = comboBoxDeviceName.SelectedIndex;
Boolean autoSelection = (deviceSelected == (numberOfDevices - 1)); // Last index
if (autoSelection)
{
// Order of search: Hamster IV(HFDU04) -> Plus(HFDU03) -> III (HFDU02)
device_name = SGFPMDeviceName.DEV_AUTO;
device_id = (Int32)(SGFPMPortAddr.USB_AUTO_DETECT);
}
else
{
device_name = m_DevList[deviceSelected].DevName;
device_id = m_DevList[deviceSelected].DevID;
}
iError = m_FPM.Init(device_name);
iError = m_FPM.OpenDevice(device_id);
if (iError == (Int32)SGFPMError.ERROR_NONE)
{
GetBtn_Click(sender, e);
StatusBar.Text = "Initialization Success";
EnableButtons(true);
// FDU03, FDU04 or higher
if (device_name >= SGFPMDeviceName.DEV_FDU03)
CheckBoxAutoOn.Enabled = true;
}
else
DisplayError("OpenDevice()", iError);
}
private void GetImageBtn_Click(object sender, System.EventArgs e)
{
Int32 iError;
Int32 elap_time;
Byte[] fp_image;
elap_time = Environment.TickCount;
fp_image = new Byte[m_ImageWidth*m_ImageHeight];
iError = m_FPM.GetImage(fp_image);
if (iError == (Int32)SGFPMError.ERROR_NONE)
{
elap_time = Environment.TickCount - elap_time;
DrawImage(fp_image, pictureBox1 );
StatusBar.Text = "Capture Time : " + elap_time + " ms";
}
else
DisplayError("GetImage()", iError);
}
private void GetLiveImageBtn_Click(object sender, System.EventArgs e)
{
Int32 iError;
Int32 timeout;
Int32 quality;
Byte[] fp_image;
Int32 elap_time;
timeout = Convert.ToInt32(textTimeout.Text);
quality = Convert.ToInt32(textImgQuality.Text);
fp_image = new Byte[m_ImageWidth*m_ImageHeight];
elap_time = Environment.TickCount;
iError = m_FPM.GetImageEx(fp_image, timeout, this.pictureBox1.Handle.ToInt32(), quality);
if (iError == 0)
{
elap_time = Environment.TickCount - elap_time;
StatusBar.Text = "Capture Time : " + elap_time + "millisec";
}
else
DisplayError("GetLiveImageEx()", iError);
}
void DisplayError(string funcName, int iError)
{
string text ="";
switch (iError)
{
case 0: //SGFDX_ERROR_NONE = 0,
text = "Error none";
break;
case 1: //SGFDX_ERROR_CREATION_FAILED = 1,
text = "Can not create object";
break;
case 2: // SGFDX_ERROR_FUNCTION_FAILED = 2,
text = "Function Failed";
break;
case 3: // SGFDX_ERROR_INVALID_PARAM = 3,
text = "Invalid Parameter";
break;
case 4: // SGFDX_ERROR_NOT_USED = 4,
text = "Not used function";
break;
case 5: //SGFDX_ERROR_DLLLOAD_FAILED = 5,
text = "Can not create object";
break;
case 6: //SGFDX_ERROR_DLLLOAD_FAILED_DRV = 6,
text = "Can not load device driver";
break;
case 7: //SGFDX_ERROR_DLLLOAD_FAILED_ALGO = 7,
text = "Can not load sgfpamx.dll";
break;
case 51: //SGFDX_ERROR_SYSLOAD_FAILED = 51, // system file load fail
text = "Can not load driver kernel file";
break;
case 52: //SGFDX_ERROR_INITIALIZE_FAILED = 52, // chip initialize fail
text = "Failed to initialize the device";
break;
case 53: //SGFDX_ERROR_LINE_DROPPED = 53, // image data drop
text = "Data transmission is not good";
break;
case 54: //SGFDX_ERROR_TIME_OUT = 54, // getliveimage timeout error
text = "Time out";
break;
case 55: //SGFDX_ERROR_DEVICE_NOT_FOUND = 55, // device not found
text = "Device not found";
break;
case 56: //SGFDX_ERROR_DRVLOAD_FAILED = 56, // dll file load fail
text = "Can not load driver file";
break;
case 57: //SGFDX_ERROR_WRONG_IMAGE = 57, // wrong image
text = "Wrong Image";
break;
case 58: //SGFDX_ERROR_LACK_OF_BANDWIDTH = 58, // USB Bandwith Lack Error
text = "Lack of USB Bandwith";
break;
case 59: //SGFDX_ERROR_DEV_ALREADY_OPEN = 59, // Device Exclusive access Error
text = "Device is already opened";
break;
case 60: //SGFDX_ERROR_GETSN_FAILED = 60, // Fail to get Device Serial Number
text = "Device serial number error";
break;
case 61: //SGFDX_ERROR_UNSUPPORTED_DEV = 61, // Unsupported device
text = "Unsupported device";
break;
// Extract & Verification error
case 101: //SGFDX_ERROR_FEAT_NUMBER = 101, // utoo small number of minutiae
text = "The number of minutiae is too small";
break;
case 102: //SGFDX_ERROR_INVALID_TEMPLATE_TYPE = 102, // wrong template type
text = "Template is invalid";
break;
case 103: //SGFDX_ERROR_INVALID_TEMPLATE1 = 103, // wrong template type
text = "1st template is invalid";
break;
case 104: //SGFDX_ERROR_INVALID_TEMPLATE2 = 104, // vwrong template type
text = "2nd template is invalid";
break;
case 105: //SGFDX_ERROR_EXTRACT_FAIL = 105, // extraction fail
text = "Minutiae extraction failed";
break;
case 106: //SGFDX_ERROR_MATCH_FAIL = 106, // matching fail
text = "Matching failed";
break;
}
text = funcName + " Error # " + iError + " :" + text;
StatusBar.Text = text;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment