⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 idcardreader.cpp

📁 配合第二代身份阅读器
💻 CPP
字号:

#include "stdafx.h"
#include "IdCardReader.h"


CString	ChinaFolksTable[56] = {
		"汉族",  
		"蒙古族",  
		"回族",  
		"藏族",  
		"维吾尔族",  
		"苗族",  
		"彝族",  
		"壮族",  
		"布依族",  
		"朝鲜族",  
		"满族",  
		"侗族",  
		"瑶族",  
		"白族",  
		"土家族",  
		"哈尼族",  
		"哈萨克族",  
		"傣族",  
		"黎族",  
		"傈僳族",  
		"佤族",  
		"畲族",  
		"高山族",  
		"拉祜族",  
		"水族",  
		"东乡族",  
		"纳西族",  
		"景颇族",  
		"柯尔克孜族",  
		"土族",  
		"达斡尔族",  
		"仫佬族",  
		"羌族",  
		"布朗族",  
		"撒拉族",  
		"毛南族",  
		"仡佬族",  
		"锡伯族",  
		"阿昌族",  
		"普米族",  
		"塔吉克族",  
		"怒族",  
		"乌孜别克族",  
		"俄罗斯族",  
		"鄂温克族",  
		"德昴族",  
		"保安族",  
		"裕固族",  
		"京族",  
		"塔塔尔族",  
		"独龙族",  
		"鄂伦春族",  
		"赫哲族",  
		"门巴族",  
		"珞巴族",  
		"基诺族"
	};

CString	SexTable[2] = {"男",  "女"};

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CIdCardReader::CIdCardReader()
{
	iPort=1001;
	st=0;
	iIfOpen = 1;



}

CIdCardReader::~CIdCardReader()
{

}


bool CIdCardReader::Init()
{
	SDT_OpenPort(iPort);

	if(SDT_GetSAMStatus(iPort, 0) != 0x90)
	{
		SDT_ResetSAM(iPort, 0);
		Sleep(300);

		SDT_ClosePort(iPort);

		return FALSE;
	}else
	{
		if(SDT_SetMaxRFByte(iPort, 200, 0) != 0x90)
		{
			SDT_ClosePort(iPort);
			return FALSE;
		}else
		{
			SDT_ClosePort(iPort);
			return TRUE;
		}
	}
}


bool CIdCardReader::ReadCard()
{
	int iResultValue, ichar;	

	//读卡
	iResultValue=SDT_StartFindIDCard(iPort,pucManaInfo, iIfOpen);
//	if(iResultValue!=0x9f)	return FALSE;
	iResultValue=SDT_SelectIDCard(iPort,pucManaMsg, iIfOpen);
//	if(iResultValue!=0x90)	return FALSE;
	iResultValue = SDT_ReadBaseMsg(iPort, pucCHMsg, &puiCHMsgLen, pucPHMsg, &puiPHMsgLen, iIfOpen);

	memcpy(&wt_Name[0], &pucCHMsg[0], 30);
	memcpy(&wt_Sex[0], &pucCHMsg[30], 2);
	memcpy(&wt_Folk[0], &pucCHMsg[32], 4);
	memcpy(&wt_Birth[0], &pucCHMsg[36], 16);
	memcpy(&wt_Address[0], &pucCHMsg[52], 70);
	memcpy(&wt_IDNu[0], &pucCHMsg[122], 36);
	memcpy(&wt_SignDepart[0], &pucCHMsg[158], 30);
	memcpy(&wt_UseLife[0], &pucCHMsg[188], 32); 
    	
	ichar = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, wt_Name, -1, hxcName, 30, NULL, NULL);     
	ichar = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, wt_Sex, -1, hxcSex, 2, NULL, NULL);     
	ichar = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, wt_Folk, -1, hxcFolk, 4, NULL, NULL);     
	ichar = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, wt_Birth, -1, hxcBirth, 16, NULL, NULL);     
	ichar = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, wt_Address, -1, hxcAddress, 70, NULL, NULL);     
	ichar = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, wt_IDNu, -1, hxcIDNu, 36, NULL, NULL);     
	ichar = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, wt_SignDepart, -1, hxcSignDepart, 30, NULL, NULL);     
	ichar = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, wt_UseLife, -1, hxcUseLife, 32, NULL, NULL);     
	
	chczeroend(hxcName, 30);
	chczeroend(hxcSex, 2);
	chczeroend(hxcFolk, 4);
	chczeroend(hxcBirth, 16);
	chczeroend(hxcAddress, 70);
	chczeroend(hxcIDNu, 36);
	chczeroend(hxcSignDepart, 30);
	chczeroend(hxcUseLife, 32);

	int nSex = atoi(hxcSex);
	int nFolk = atoi(hxcFolk);
	CString Year, Month, Day;
	CString TempBirth, TempBirth0, TempBirth1;
	
	if((nSex >= 1) && (nSex <= 2))	strcpy(hxcSex, SexTable[nSex-1]); 
	if((nFolk >= 1) && (nFolk <= 56))	strcpy(hxcFolk, ChinaFolksTable[nFolk-1]); 

	TempBirth = hxcBirth;
	Year = TempBirth.Left(4);
	Month = TempBirth.Left(6).Right(2);
	Day = TempBirth.Left(8).Right(2);
	TempBirth = Year+"年"+Month+"月"+Day+"日";
	strcpy(hxcBirth, TempBirth); 

	// 有效期-起始
	TempBirth = hxcUseLife;
	TempBirth = TempBirth.Left(8);
	int n = TempBirth.GetLength();
	Year = TempBirth.Left(4);
	Month = TempBirth.Left(6).Right(2);
	Day = TempBirth.Right(2);
	TempBirth = Year+"年"+Month+"月"+Day+"日";

	// 有效期-结束  或“长期”
	TempBirth0 = hxcUseLife;
	TempBirth1 = TempBirth0.Mid(n,4);
	TempBirth0 = TempBirth0.Mid(n, 8);
	if(TempBirth1 != "长期")
	{
		Year = TempBirth0.Left(4);
		Month = TempBirth0.Left(6).Right(2);
		Day = TempBirth0.Right(2);
		TempBirth0 = Year+"年"+Month+"月"+Day+"日";

		TempBirth0 = TempBirth + "  -  " + TempBirth0;
		strcpy(hxcUseLife, TempBirth0);
	}else
	{
		TempBirth0 = TempBirth + "  -  " + TempBirth1;
		strcpy(hxcUseLife, TempBirth0); 
	}

	FILE *MyFile;
	char pcPHMsgFileName[MAX_PATH];

	strcpy(pcPHMsgFileName,"picture.wlt");
	
	if ((MyFile = fopen(pcPHMsgFileName,"wb"))==NULL) return	FALSE;     //建立或打开文件(写)
	fwrite(pucPHMsg,sizeof(unsigned char),puiPHMsgLen,MyFile);
	fclose(MyFile);

	iRet = GetBmp("picture.wlt",  1);
	if (iRet != 1)	return	FALSE;

	return	TRUE;
}


int CIdCardReader::chczeroend(char * pucAppMsg, int chlength)
{
	for (int i = 0; i < chlength; i ++)
	{
		if (pucAppMsg[i] == 0x3f)
		{
			pucAppMsg[i] = '\0';  
			return (i + 1);
		}

	}

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -