一:前言
设备已经安装好100UC的USB驱动,设备能正常工作
二:获取数据介绍
通过调取sdk接口获取数据,sdk同http模式不同,初始化完成以后,然后使用 CVR_Authenticate 来确认是否存在身份证,如果存在则去获取身份证信息通过事件反馈给客户端上层,程序读取完一次后 sdk 关闭了数据获取,需要手动拿起身份证卡片后才能再次确认身份证是否存在,限制了读卡次数。开发包还提供和 http 相同的模式,初始化完成以后,使用 CVR_AuthenticateForNoJudge 关闭身份证验证,则可以一直读取身份证信息,取消读卡次数,无需拿起再放下。
三:反馈客户端身份证信息 IDCardNetSDK 类模块代码包含下面三部分
1.先用C#翻译C++的接口
public class ClientInterfance { /// <summary> /// 用于第二代居民身份证阅读器连接 /// </summary> /// <param name="Port">端口编号:连接串口(com1~com16)或者usb口(1001~1016)</param> /// <returns>1:正确,2:端口打开失败,-1:未知错误,-2:动态库加载失败</returns> [DllImport("termb.dll")] public static extern int CVR_InitComm(int Port); /// <summary> /// 读卡器和卡片之间的合法身份确认,卡循环间隔大于300ms。若卡片放置后认证失败,重新放置。 /// </summary> /// <returns>1:卡片认证成功,2:寻卡失败,3:选卡失败,4:未连接读卡器,0:动态库未加载</returns> [DllImport("termb.dll")] public static extern int CVR_Authenticate(); /// <summary> /// 关闭卡片身份确认,使卡片可以一直读,此函数只返回1. /// </summary> /// <returns></returns> [DllImport("termb.dll")] public static extern int CVR_AuthenticateForNoJudge(); /// <summary> /// 通过阅读器从第二代居民身份证读取信息。卡认证成功一候才可读卡操作,读卡完毕若继续读卡应移走二代证卡片重新放置做卡认证 /// </summary> /// <returns>1:正确,0:错误,读取失败,4:读卡器未连接,99:动态库未加载</returns> [DllImport("termb.dll")] public static extern int CVR_Read_FPContent(); /// <summary> /// 关闭pc到阅读器的连接 /// </summary> /// <returns>1:关闭成功,0:端口号不合法,-1:端口已经关闭,-2动态库加载失败</returns> [DllImport("termb.dll")] public static extern int CVR_CloseComm(); /// <summary> /// 得到姓名信息 /// </summary> /// <param name="strTmp"></param> /// <param name="strLen"></param> /// <returns></returns> [DllImport("termb.dll")] public static extern int GetPeopleName(ref byte strTmp,ref int strLen); /// <summary> /// 得到性别信息 /// </summary> /// <param name="strTmp"></param> /// <param name="strLen"></param> /// <returns></returns> [DllImport("termb.dll")] public static extern int GetPeopleSex(ref byte strTmp, ref int strLen); /// <summary> /// //得到民族信息 /// </summary> /// <param name="strTmp"></param> /// <param name="strLen"></param> /// <returns></returns> [DllImport("termb.dll")] public static extern int GetPeopleNation(ref byte strTmp, ref int strLen); /// <summary> /// 得到出生日期 /// </summary> /// <param name="strTmp"></param> /// <param name="strLen"></param> /// <returns></returns> [DllImport("termb.dll")] public static extern int GetPeopleBirthday(ref byte strTmp, ref int strLen); /// <summary> /// 得到地址信息 /// </summary> /// <param name="strTmp"></param> /// <param name="strLen"></param> /// <returns></returns> [DllImport("termb.dll")] public static extern int GetPeopleAddress(ref byte strTmp, ref int strLen); /// <summary> /// 得到卡号信息 /// </summary> /// <param name="strTmp"></param> /// <param name="strLen"></param> /// <returns></returns> [DllImport("termb.dll")] public static extern int GetPeopleIDCode(ref byte strTmp, ref int strLen); /// <summary> /// 得到发证机关信息 /// </summary> /// <param name="strTmp"></param> /// <param name="strLen"></param> /// <returns></returns> [DllImport("termb.dll")] public static extern int GetDepartment(ref byte strTmp, ref int strLen); /// <summary> /// 得到有效开始日期 /// </summary> /// <param name="strTmp"></param> /// <param name="strLen"></param> /// <returns></returns> [DllImport("termb.dll")] public static extern int GetStartDate(ref byte strTmp, ref int strLen); /// <summary> /// 得到有效截止日期 /// </summary> /// <param name="strTmp"></param> /// <param name="strLen"></param> /// <returns></returns> [DllImport("termb.dll")] public static extern int GetEndDate(ref byte strTmp, ref int strLen); }
2.设备初始化、检查卡片合法性、是否读取卡片、读取卡片
public bool isIniCoom() { for (int i = 1001; i <= 1016; i++) { if(ClientInterfance.CVR_InitComm(i) == 1) { return true; } } return false; } public bool isAuthen() { if (ClientInterfance.CVR_Authenticate() == 1) { return true; } return false; } public bool isReadCont() { if (ClientInterfance.CVR_Read_FPContent() == 1) { return true; } return false; } public void isReaded() { IDCardMessage idcard = new IDCardMessage(); byte[] name = new byte[30]; int length = 30; ClientInterfance.GetPeopleName(ref name[0], ref length); idcard.Name = Encoding.GetEncoding("GB2312").GetString(name).Replace("