using System;
using System.Runtime.InteropServices;
using System.Threading;
using Nitgen.SDK;
namespace NitgenFingerprintExample
{
class Program
{
// Define the necessary device constants
const int DeviceIndex = 0; // Usually, 0 is the default device if only one
is connected
// Initialize the device
static INFingerScan fingerScan = null;
static void Main(string[] args)
{
// Initialize the SDK and connect to the device
InitDevice();
// Capture fingerprint
CaptureFingerprint();
// Close the device
CloseDevice();
}
// Method to initialize the fingerprint device
static void InitDevice()
{
try
{
// Initialize the Fingerprint device (using the SDK method)
fingerScan = new INFingerScan();
fingerScan.Init();
Console.WriteLine("Device initialized successfully.");
}
catch (Exception ex)
{
Console.WriteLine("Error initializing device: " + ex.Message);
}
}
// Method to capture fingerprint from the device
static void CaptureFingerprint()
{
try
{
Console.WriteLine("Please place your finger on the scanner...");
// Start the fingerprint scanning process
byte[] fingerprintData = new byte[1024]; // Array to store
fingerprint data
// Capture fingerprint data
int result = fingerScan.Capture(fingerprintData);
if (result == 0) // 0 indicates success, check the SDK
documentation for error codes
{
Console.WriteLine("Fingerprint captured successfully.");
// Here you can process the fingerprint data (e.g., store it in
the database)
}
else
{
Console.WriteLine("Failed to capture fingerprint. Error code: "
+ result);
}
}
catch (Exception ex)
{
Console.WriteLine("Error capturing fingerprint: " + ex.Message);
}
}
// Method to close the device connection
static void CloseDevice()
{
try
{
if (fingerScan != null)
{
fingerScan.Close();
Console.WriteLine("Device closed successfully.");
}
}
catch (Exception ex)
{
Console.WriteLine("Error closing device: " + ex.Message);
}
}
}
}