用C# 做一个读取身份证阅读程序

我已经有sdtapi.dll,WltRS.dll两个最基本的类库,请高手提供详细代码,谢谢!... 我已经有sdtapi.dll,WltRS.dll两个最基本的类库,请高手提供详细代码,谢谢! 展开
 我来答
shuibiyy
推荐于2017-12-15 · TA获得超过1724个赞
知道小有建树答主
回答量:446
采纳率:100%
帮助的人:143万
展开全部
文件不全无法完成,而且身份证阅读有多个厂家。每个厂家的SDK包都不一样。

下面只是个简单的例子,作参考
//首先,声明通用接口
[DllImport("sdtapi.dll")]
public static extern int SDT_OpenPort(int iPortID);
[DllImport("sdtapi.dll")]
public static extern int SDT_ClosePort(int iPortID);
[DllImport("sdtapi.dll")]
public static extern int SDT_PowerManagerBegin(int iPortID, int iIfOpen);
[DllImport("sdtapi.dll")]
public static extern int SDT_AddSAMUser(int iPortID, string pcUserName, int iIfOpen);
[DllImport("sdtapi.dll")]
public static extern int SDT_SAMLogin(int iPortID, string pcUserName, string pcPasswd, int iIfOpen);
[DllImport("sdtapi.dll")]
public static extern int SDT_SAMLogout(int iPortID, int iIfOpen);
[DllImport("sdtapi.dll")]
public static extern int SDT_UserManagerOK(int iPortID, int iIfOpen);
[DllImport("sdtapi.dll")]
public static extern int SDT_ChangeOwnPwd(int iPortID, string pcOldPasswd, string pcNewPasswd, int iIfOpen);
[DllImport("sdtapi.dll")]
public static extern int SDT_ChangeOtherPwd(int iPortID, string pcUserName, string pcNewPasswd, int iIfOpen);
[DllImport("sdtapi.dll")]
public static extern int SDT_DeleteSAMUser(int iPortID, string pcUserName, int iIfOpen);

[DllImport("sdtapi.dll")]
public static extern int SDT_StartFindIDCard(int iPortID, ref int pucIIN, int iIfOpen);
[DllImport("sdtapi.dll")]
public static extern int SDT_SelectIDCard(int iPortID, ref int pucSN, int iIfOpen);
[DllImport("sdtapi.dll")]
public static extern int SDT_ReadBaseMsg(int iPortID, string pucCHMsg, ref int puiCHMsgLen, string pucPHMsg, ref int puiPHMsgLen, int iIfOpen);
[DllImport("sdtapi.dll")]
public static extern int SDT_ReadBaseMsgToFile(int iPortID, string fileName1, ref int puiCHMsgLen, string fileName2, ref int puiPHMsgLen, int iIfOpen);

[DllImport("sdtapi.dll")]
public static extern int SDT_WriteAppMsg(int iPortID, ref byte pucSendData, int uiSendLen, ref byte pucRecvData, ref int puiRecvLen, int iIfOpen);
[DllImport("sdtapi.dll")]
public static extern int SDT_WriteAppMsgOK(int iPortID, ref byte pucData, int uiLen, int iIfOpen);

[DllImport("sdtapi.dll")]
public static extern int SDT_CancelWriteAppMsg(int iPortID, int iIfOpen);
[DllImport("sdtapi.dll")]
public static extern int SDT_ReadNewAppMsg(int iPortID, ref byte pucAppMsg, ref int puiAppMsgLen, int iIfOpen);
[DllImport("sdtapi.dll")]
public static extern int SDT_ReadAllAppMsg(int iPortID, ref byte pucAppMsg, ref int puiAppMsgLen, int iIfOpen);
[DllImport("sdtapi.dll")]
public static extern int SDT_UsableAppMsg(int iPortID, ref byte ucByte, int iIfOpen);

[DllImport("sdtapi.dll")]
public static extern int SDT_GetUnlockMsg(int iPortID, ref byte strMsg, int iIfOpen);
[DllImport("sdtapi.dll")]
public static extern int SDT_GetSAMID(int iPortID, ref byte StrSAMID, int iIfOpen);

[DllImport("sdtapi.dll")]
public static extern int SDT_SetMaxRFByte(int iPortID, byte ucByte, int iIfOpen);
[DllImport("sdtapi.dll")]
public static extern int SDT_ResetSAM(int iPortID, int iIfOpen);

[DllImport("WltRS.dll")]
public static extern int GetBmp(string file_name, int intf);

public delegate void De_ReadICCardComplete(clsEDZ objEDZ);
public event De_ReadICCardComplete ReadICCardComplete;
private clsEDZ objEDZ = new clsEDZ();
private int EdziIfOpen = 1; //自动开关串口
int EdziPortID;
public clsICCard()
{

}
public bool ReadICCard()
{
bool bUsbPort = false;
int intOpenPortRtn = 0;
int rtnTemp = 0;
int pucIIN = 0;
int pucSN = 0;
int puiCHMsgLen = 0;
int puiPHMsgLen = 0;

objEDZ = new clsEDZ();
//检测usb口的机具连接,必须先检测usb
for (int iPort = 1001; iPort <= 1016; iPort++)
{
intOpenPortRtn = SDT_OpenPort(iPort);
if (intOpenPortRtn == 144)
{
EdziPortID = iPort;
bUsbPort = true;
break;
}
}
//检测串口的机具连接
if (!bUsbPort)
{
for (int iPort = 1; iPort <= 2; iPort++)
{
intOpenPortRtn = SDT_OpenPort(iPort);
if (intOpenPortRtn == 144)
{
EdziPortID = iPort;
bUsbPort = false;
break;
}
}
}
if (intOpenPortRtn != 144)
{
MessageBox.Show("端口打开失败,请检测相应的端口或者重新连接读卡器!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式