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

2020-05-13 社会 82阅读
文件不全无法完成,而且身份证阅读有多个厂家。每个厂家的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;
}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com