5 changed files with 241 additions and 71 deletions
@ -1,21 +1,194 @@ |
|||||||
using System; |
using AKSWebBrowser.Commen; |
||||||
|
using CPF.Controls; |
||||||
|
using CPF.Linux; |
||||||
|
using CPF.Windows; |
||||||
|
using System; |
||||||
using System.Collections.Generic; |
using System.Collections.Generic; |
||||||
|
using System.Globalization; |
||||||
using System.Linq; |
using System.Linq; |
||||||
using System.Runtime.InteropServices; |
using System.Runtime.InteropServices; |
||||||
using System.Text; |
using System.Text; |
||||||
|
using System.Threading; |
||||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||||
|
using System.Timers; |
||||||
|
|
||||||
namespace AksWebBrowser.Devices |
namespace AksWebBrowser.Devices |
||||||
{ |
{ |
||||||
//apt-get install gcc-c++ libstdc++-devel |
//apt-get install gcc-c++ libstdc++-devel |
||||||
public class Fingerprint |
public class Fingerprint |
||||||
{ |
{ |
||||||
public Fingerprint(){} |
public static int td = -1, pnWidth = 0, pnHeight = 0, init = -1; |
||||||
|
public static string callback = string.Empty, FileName = string.Empty; |
||||||
|
//开启定时 |
||||||
|
public static System.Timers.Timer timer = new System.Timers.Timer(500); |
||||||
|
|
||||||
|
public Fingerprint() { } |
||||||
|
|
||||||
|
//读取指纹 |
||||||
|
public static string LIVESCANFinger(string _callback) |
||||||
|
{ |
||||||
|
try |
||||||
|
{ |
||||||
|
callback = _callback; |
||||||
|
init = LibFingerprint.LIVESCAN_Init(); |
||||||
|
if (init == 1) |
||||||
|
{ |
||||||
|
Log.Info("初始化指纹成功"); |
||||||
|
td = LibFingerprint.LIVESCAN_GetChannelCount(); |
||||||
|
if (td > 0) |
||||||
|
{ |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Log.Info("获得采集器通道数量成功"); |
||||||
|
int pnBright = 254; |
||||||
|
int status = LibFingerprint.LIVESCAN_GetBright(td, ref pnBright); |
||||||
|
Log.Info(" 获得采集器当前的亮度:" + status); |
||||||
|
Log.Info(" 获得采集器当前的亮度:" + pnBright); |
||||||
|
int pnContrast = 254; |
||||||
|
status = LibFingerprint.LIVESCAN_GetContrast(td, ref pnContrast); |
||||||
|
Log.Info(" 获得采集器当前对比度:" + status); |
||||||
|
Log.Info(" 获得采集器当前对比度:" + pnBright); |
||||||
|
|
||||||
|
int pnWidth = 0, pnHeight = 0; |
||||||
|
status = LibFingerprint.LIVESCAN_GetMaxImageSize(td, ref pnWidth, ref pnHeight); |
||||||
|
Log.Info(" 获得采集器采集图像的宽度、高度的最大值:" + status); |
||||||
|
Log.Info(" 获得采集器采集图像的宽度、高度的最大值:" + pnWidth + "*" + pnHeight); |
||||||
|
byte[] pszDesc = new byte[1024]; |
||||||
|
status = LibFingerprint.LIVESCAN_GetDesc(pszDesc); |
||||||
|
Log.Info("获得接口规范的说明:" + status); |
||||||
|
Log.Info("获得接口规范的说明返回数据:" + Encoding.UTF8.GetString(pszDesc)); |
||||||
|
|
||||||
|
MessageBox.Show("转变采集"); |
||||||
|
|
||||||
|
string time = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); |
||||||
|
FileName = "/tmp/" + time + ".bmp"; |
||||||
|
timer.Stop(); |
||||||
|
timer.Elapsed += OnTimedEvent; |
||||||
|
timer.AutoReset = true;//重复执行 |
||||||
|
timer.Enabled = true;//启动定时器 |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
Log.Info("获得采集器通道数量失败"); |
||||||
|
} |
||||||
|
Task.Run(() => |
||||||
|
{ |
||||||
|
LibFingerprint.LIVESCAN_Close(); |
||||||
|
}); |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
Log.Info("初始化指纹失败,错误代码:" + init); |
||||||
|
} |
||||||
|
} |
||||||
|
catch (Exception ex) |
||||||
|
{ |
||||||
|
if (init == 1) |
||||||
|
{ |
||||||
|
Task.Run(() => |
||||||
|
{ |
||||||
|
LibFingerprint.LIVESCAN_Close(); |
||||||
|
}); |
||||||
|
} |
||||||
|
Log.Error("读取指纹异常:" + ex.Message); |
||||||
|
} |
||||||
|
|
||||||
|
return ""; |
||||||
|
} |
||||||
|
|
||||||
|
//定时任务 |
||||||
|
private static void OnTimedEvent(object sender, ElapsedEventArgs e) |
||||||
|
{ |
||||||
|
try |
||||||
|
{ |
||||||
|
int status = LibFingerprint.LIVESCAN_BeginCapture(td); |
||||||
|
byte[] pRawData = new byte[pnWidth * pnHeight]; |
||||||
|
status = LibFingerprint.LIVESCAN_GetFPRawData(td, pRawData); |
||||||
|
//status = LibFingerprint.LIVESCAN_GetFPBmpData(td, Encoding.UTF8.GetBytes(FileName)); |
||||||
|
if (status == 1) |
||||||
|
{ |
||||||
|
Log.Info("采集一帧图像:" + Encoding.UTF8.GetString(pRawData)); |
||||||
|
Log.Info("获取指纹成功"); |
||||||
|
timer.Stop(); |
||||||
|
Log.Info("停止采集"); |
||||||
|
} |
||||||
|
LibFingerprint.LIVESCAN_EndCapture(td); |
||||||
|
} |
||||||
|
catch (Exception ex) |
||||||
|
{ |
||||||
|
Log.Error("定时读取指纹异常:" + ex.Message); |
||||||
|
timer.Stop(); |
||||||
|
} |
||||||
|
} |
||||||
} |
} |
||||||
class LibFingerprint |
class LibFingerprint |
||||||
{ |
{ |
||||||
[DllImport("libmsprintsdk", EntryPoint = "SetInit", CharSet = CharSet.Ansi)] |
//初始化指纹 |
||||||
public static extern int SetInit(); |
[DllImport("libID_FprCap", EntryPoint = "LIVESCAN_Init", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
||||||
|
public static extern int LIVESCAN_Init(); |
||||||
|
|
||||||
|
//关闭 |
||||||
|
[DllImport("libID_FprCap", EntryPoint = " LIVESCAN_Close", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
||||||
|
public static extern int LIVESCAN_Close(); |
||||||
|
|
||||||
|
//获得采集器通道数量 |
||||||
|
[DllImport("libID_FprCap", EntryPoint = "LIVESCAN_GetChannelCount", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
||||||
|
public static extern int LIVESCAN_GetChannelCount(); |
||||||
|
|
||||||
|
//设置采集器当前的亮度 |
||||||
|
[DllImport("libID_FprCap", EntryPoint = "LIVESCAN_SetBright", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
||||||
|
public static extern int LIVESCAN_SetBright(int nChannel, int nBright); |
||||||
|
|
||||||
|
//设置采集器当前对比度 |
||||||
|
[DllImport("libID_FprCap", EntryPoint = "LIVESCAN_SetContrast", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
||||||
|
public static extern int LIVESCAN_SetContrast(int nChannel, int nContrast); |
||||||
|
|
||||||
|
//获得采集器当前的亮度 |
||||||
|
[DllImport("libID_FprCap", EntryPoint = "LIVESCAN_GetBright", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
||||||
|
public static extern int LIVESCAN_GetBright(int nChannel, ref int pnBright); |
||||||
|
|
||||||
|
//获得采集器当前对比度 |
||||||
|
[DllImport("libID_FprCap", EntryPoint = "LIVESCAN_GetContrast", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
||||||
|
public static extern int LIVESCAN_GetContrast(int nChannel, ref int pnContrast); |
||||||
|
|
||||||
|
// 获得采集器采集图像的宽度、高度的最大值 |
||||||
|
[DllImport("libID_FprCap", EntryPoint = "LIVESCAN_GetMaxImageSize", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
||||||
|
public static extern int LIVESCAN_GetMaxImageSize(int nChannel, ref int pnWidth, ref int pnHeight); |
||||||
|
|
||||||
|
//获得当前图像的采集位置、宽度和高度 |
||||||
|
[DllImport("libID_FprCap", EntryPoint = "LIVESCAN_GetCaptWindow", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
||||||
|
public static extern int LIVESCAN_GetCaptWindow(int nChannel, ref int pnOriginX, ref int pnOriginY, ref int pnWidth, ref int pnHeight); |
||||||
|
|
||||||
|
//设置当前图像的采集位置、宽度和高度 |
||||||
|
[DllImport("libID_FprCap", EntryPoint = " LIVESCAN_SetCaptWindow", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
||||||
|
public static extern int LIVESCAN_SetCaptWindow(int nChannel, int nOriginX, int nOriginY, int nWidth, int nHeight); |
||||||
|
|
||||||
|
//调用采集器的属性设置对话框 |
||||||
|
[DllImport("libID_FprCap", EntryPoint = "LIVESCAN_Setup", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
||||||
|
public static extern int LIVESCAN_Setup(); |
||||||
|
|
||||||
|
//采集器是否支持设置对话框 |
||||||
|
[DllImport("libID_FprCap", EntryPoint = "LIVESCAN_IsSupportSetup", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
||||||
|
public static extern int LIVESCAN_IsSupportSetup(); |
||||||
|
|
||||||
|
//准备采集一帧图像 |
||||||
|
[DllImport("libID_FprCap", EntryPoint = "LIVESCAN_BeginCapture", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
||||||
|
public static extern int LIVESCAN_BeginCapture(int nChannel); |
||||||
|
|
||||||
|
//采集一帧图像 |
||||||
|
[DllImport("libID_FprCap", EntryPoint = " LIVESCAN_GetFPRawData", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
||||||
|
public static extern int LIVESCAN_GetFPRawData(int nChannel, byte[] pRawData); |
||||||
|
|
||||||
|
//采集一帧 BMP 格式图像数据 |
||||||
|
[DllImport("libID_FprCap", EntryPoint = " LIVESCAN_GetFPBmpData", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
||||||
|
public static extern int LIVESCAN_GetFPBmpData(int nChannel, byte[] pBmpData); |
||||||
|
//结束采集一帧图像 |
||||||
|
[DllImport("libID_FprCap", EntryPoint = " LIVESCAN_EndCapture", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
||||||
|
public static extern int LIVESCAN_EndCapture(int nChannel); |
||||||
|
|
||||||
|
//获得接口规范的说明 |
||||||
|
[DllImport("libID_FprCap", EntryPoint = " LIVESCAN_GetDesc", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
||||||
|
public static extern int LIVESCAN_GetDesc(byte[] pszDesc); |
||||||
} |
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue