精伦iDR210二代身份证读卡器二次开发
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
类(ReadIDCardService.cs):
class ReadIDCardService
{
public IDCard ReadIDCard(int Port)
{
StringBuilder Name = new StringBuilder(31);
StringBuilder Gender = new StringBuilder(3);
StringBuilder Folk = new StringBuilder(10);
StringBuilder BirthDay = new StringBuilder(9);
StringBuilder Code = new StringBuilder(19);
StringBuilder Address = new StringBuilder(71);
StringBuilder Agency = new StringBuilder(31);
StringBuilder ExpireStart = new StringBuilder(9);
StringBuilder ExpireEnd = new StringBuilder(9);
//初始化端口
//int intOpenRet = InitComm(1001);
//if (intOpenRet != 1)
//{
// throw new Exception("");
//}
//设定当前操作的HID接口iDR210
if (HIDSelect(Port))
{
//卡认证
int intReadRet = Authenticate();
if (intReadRet != 1)
{
//CloseComm();
throw new Exception("");
}
//读身份证信息
int intReadBaseInfosRet = ReadBaseInfos(Name, Gender, Folk, BirthDay, Code, Address, Agency, ExpireStart, ExpireEnd);
if (intReadBaseInfosRet != -3)
{
//CloseComm();
throw new Exception("");
}
//HID_BeepLED(true,true, 200);
IDCard CardData = new IDCard();
CardData.CardNo = Code.ToString().Trim();
= Name.ToString().Trim();
CardData.Sex = Gender.ToString().Trim();
CardData.Nationality = Folk.ToString().Trim();
CardData.Birthday = BirthDay.ToString().Trim();
CardData.Address = Address.ToString().Trim();
CardData.Institution = Agency.ToString().Trim();
CardData.Begin_validity = ExpireStart.ToString().Trim();
CardData.End_validity = ExpireEnd.ToString().Trim();
CardData.PhotoDirectory = System.IO.Directory.GetCurrentDirectory() + "//photo.bmp";
//CloseComm();
return CardData;
}
else
{
//CloseComm();
throw new Exception("");
}
}
[DllImport("sdtapi.dll")]
private static extern int InitComm(int Port);//初始化
[DllImport("Sdtapi.dll")]
private static extern int Authenticate();//卡认证
[DllImport("sdtapi.dll")]
private static extern void CloseComm(); //关闭端口
[DllImport("sdtapi.dll")]
private static extern int ReadBaseInfos(StringBuilder Name,
StringBuilder Gender, StringBuilder Folk, StringBuilder BirthDay, StringBuilder Code, StringBuilder Address,
StringBuilder Agency, StringBuilder ExpireStart, StringBuilder ExpireEnd);//读取数据[DllImport("sdtapi.dll")]
private static extern int HID_BeepLED(bool BeepON, bool LEDON, int duration); //蜂鸣器[DllImport("sdtapi.dll")]
private static extern bool HIDSelect(int index); //设定当前操作的HID接口iDR210
[DllImport("sdtapi.dll")]
private static extern int CardOn(); //判断身份证是否在设备上
}
类(IDCard.cs):