You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

231 lines
5.3 KiB

using System.Text;
namespace EC.AutoWeightServer.IfManager.FingerPrint
{
/// <summary>
/// 暂时只测试了 USB 接口
/// </summary>
public class FingerPrintManager
{
//连接参数
private readonly FingerPrintParam _fpParam;
//通讯句柄
private int _handle;
//返回码
private int _ret;
public FingerPrintManager()
{
_fpParam = new FpUsbParam();
}
public FingerPrintManager(FingerPrintParam fpParam)
{
_fpParam = fpParam;
}
#region Start & Stop Server
/// <summary>
/// 开启服务
/// </summary>
/// <returns></returns>
public bool StartServer()
{
_ret = TesoLiveSDK.TcCreateHDL(_fpParam.Port, _fpParam.NPort, _fpParam.NRidx, _fpParam.NSped);
_handle = _ret;
return _ret >= 0;
}
/// <summary>
/// 停止服务
/// </summary>
/// <returns></returns>
public bool StopServer()
{
if (!IsConnected())
return true;
_ret = TesoLiveSDK.TcDeleteHDL(_handle);
if (_ret < 0)
return false;
_handle = -1;
return true;
}
#endregion Start & Stop Server
#region Tool Methods
/// <summary>
/// 获取设备内核号
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public bool GetDevKerNel(ref string data)
{
if (!IsConnected())
return false;
var builder = new StringBuilder();
_ret = TesoLiveSDK.TcGetDevVsin(_handle, builder);
data = _ret >= 0 ? builder.ToString() : string.Empty;
return _ret >= 0;
}
/// <summary>
/// 获取设备序列号
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public bool GetDevSn(ref string data)
{
if (!IsConnected())
return false;
var builder = new StringBuilder();
_ret = TesoLiveSDK.TcReadDevSn(_handle, builder);
data = _ret >= 0 ? builder.ToString() : string.Empty;
return _ret >= 0;
}
/// <summary>
/// 注册窗体默认开启
/// </summary>
/// <param name="able"></param>
/// <returns></returns>
public bool SetRegBoxAble(bool able)
{
if (!IsConnected())
return false;
var nIdx = 16;//#define T_SHOWREG 16 弹出注册窗体
var nVal = able ? 1 : 0;
_ret = TesoLiveSDK.TcExtnEntry(_handle, 0, nIdx, nVal, null);
return _ret >= 0;
}
/// <summary>
/// 认证窗体默认关闭
/// </summary>
/// <param name="able"></param>
/// <returns></returns>
public bool SetVerBoxAble(bool able)
{
if (!IsConnected())
return false;
var nIdx = 17;//#define T_SHOWVER 17 弹出认证窗体
var nVal = able ? 1 : 0;
_ret = TesoLiveSDK.TcExtnEntry(_handle, 0, nIdx, nVal, null);
return _ret >= 0;
}
/// <summary>
/// 控制设备上的 LED 闪灯和 BUZZER 蜂鸣,声光同时提示
/// </summary>
/// <param name="mode">0=短嘀,1=长嘀,2=嘀嘀</param>
/// <returns></returns>
public bool SetBeepLight(int mode)
{
if (!IsConnected())
return false;
mode %= 3;
_ret = TesoLiveSDK.TcBeepLight(_handle, mode);
return _ret >= 0;
}
/// <summary>
/// 设置注册窗口等待时间
/// </summary>
/// <param name="msTime">超时量默认 30000</param>
/// <returns></returns>
public bool SetRegTime(int msTime)
{
if (!IsConnected())
return false;
var nIdx = 6;//#define T_REGTMOT 6 注册 ms 超时量=30000
_ret = TesoLiveSDK.TcExtnEntry(_handle, 0, nIdx, msTime, null);
return _ret >= 0;
}
/// <summary>
/// 设置认证窗口等待时间
/// </summary>
/// <param name="msTime">超时量默认 18000</param>
/// <returns></returns>
public bool SetVerTime(int msTime)
{
if (!IsConnected())
return false;
var nIdx = 7;//#define T_VERTMOT 7 认证 ms 超时量=18000
_ret = TesoLiveSDK.TcExtnEntry(_handle, 0, nIdx, msTime, null);
return _ret >= 0;
}
/// <summary>
/// 获取指纹模板
/// </summary>
/// <param name="regFp"></param>
/// <returns></returns>
public bool GetRegFingerPrint(ref string regFp)
{
if (!IsConnected())
return false;
var builder = new byte[513];
_ret = TesoLiveSDK.TcDoTemplet(_handle, builder);
regFp = Encoding.ASCII.GetString(builder).Trim('\0');
return _ret >= 0;
}
/// <summary>
/// 获取指纹特征
/// </summary>
/// <param name="verFp"></param>
/// <returns></returns>
public bool GetVerFingerPrint(ref string verFp)
{
if (!IsConnected())
return false;
var builder = new byte[513];
_ret = TesoLiveSDK.TcDoFeature(_handle, builder);
verFp = Encoding.ASCII.GetString(builder).Trim('\0');
return _ret >= 0;
}
/// <summary>
/// 对比指纹模板和特征
/// </summary>
/// <param name="regFp"></param>
/// <param name="verFp"></param>
/// <returns></returns>
public bool MatchFingerPrint(string regFp, string verFp)
{
if (!IsConnected())
return false;
if (string.IsNullOrEmpty(regFp) || string.IsNullOrEmpty(verFp))
return false;
_ret = TesoLiveSDK.TcSafeMatch(_handle, verFp, regFp);
return _ret >= 0;
}
/// <summary>
/// 判断设备是否连接
/// </summary>
/// <returns></returns>
public bool IsConnected()
{
var builder = new StringBuilder();
_ret = TesoLiveSDK.TcReadDevSn(_handle, builder);
return _ret >= 0;
}
/// <summary>
/// 返回函数运行返回码
/// </summary>
/// <returns>返回码</returns>
public int GetResultCode()
{
return _ret;
}
#endregion Tool Methods
}
}