本方法只针对的是华视cvr-100UC 二代身份证读卡。
只是写了主要的部分,可以把函数等放入公共文件中,引用,调用即可。剩下的自己琢磨吧!
先定义个机构:
TPsnMsg = record
PeoName: string; //姓名
PeoSex: string; //性别
PeoFolk: string; //
PeoBirthday: string; //生日
PeoAddress: string; //地址
PeoIDNumber: string; //身份证号
PeoDepartment: string; //发证机关
PeoStartDate: string; //起止日期
PeoEndDate: string;
PeoReserve: string;
paddaddress1: string;
m_szphoto: array [0..1023] of char;
end;
以下是函数:
function GetPsnMsg_100UC(iPort:integer):TPsnMsg;
variRet, iTimeOut :integer;
TimeCurr, TimeDelay:int64;
iFileHandle,iFileLength: Integer;
Buffer: PWideChar;
sWZ :WideString;
sDisp, iniFileName:string;
ChPeople:array[0..255] of char;
ID: Cardinal ;
szGet :array[0..70] of char;
iLenGet:integer;
begin
iRet:=CVR_InitComm(iPort); //初始化连接; iport=1001 为USB接口
if iRet<>1 then
begin
showmessage('打开串口出错');
CVR_CloseComm(); //
exit;
end
else
begin
GetManuID(@ID); //20080610 Add By Kim
//ShowMessage('请放卡');
end;
TimeCurr := GetTickCount();
TimeDelay := iTimeOut * 1000;
iRet := CVR_Authenticate(); // 卡认证;
if NOT iRet=1 then EXIT;Delay(200);
iRet := CVR_Read_Content(1); //读卡操作
CVR_CloseComm(); //关闭连接;
if iRet<>1 then
begin
//showmessage('读基本信息出错');
exit;
end;
//------------------------------------------------------------------显示资料
try
iniFileName:=ExtractFilePath(Application.ExeName) + 'ICINIT.INI';
iFileHandle := FileOpen(ExtractFilePath(Application.ExeName) +'wz.txt', fmOpenRead);
iFileLength := FileSeek(iFileHandle,0,2);
FileSeek(iFileHandle,0,0);
Buffer := PWideChar(AllocMem(iFileLength +2));
FileRead(iFileHandle, Buffer^, iFileLength);
FileClose(iFileHandle);
sWZ:=WideChartostring(buffer);
PsnMsg.PeoName:=copy(sWZ,1,15); //姓名
delete(sWZ,1,15);
if (copy(sWZ,1,1)='1') then //性别
PsnMsg.PeoSex:='男'
else
PsnMsg.PeoSex:='女';
delete(sWZ,1,1); //民族
sDisp:='';
sDisp:=copy(sWZ,1,2);
PsnMsg.PeoFolk:= GetMinZhuToName(sDisp);
delete(sWZ,1,2); //出生
sDisp:='';
PsnMsg.PeoBirthday:=copy(sWZ,1,4)+'-'+copy(sWZ,5,2)+'-'+copy(sWZ,7,2);
delete(sWZ,1,8); //住址
PsnMsg.PeoAddress:=copy(sWZ,1,35);
delete(sWZ,1,35); //身份证号
PsnMsg.PeoIDNumber:=copy(sWZ,1,18);
delete(sWZ,1,18); //签发机关
PsnMsg.PeoDepartment:=copy(sWZ,1,15);
sDisp:=''; //有效期限
delete(sWZ,1,15);
PsnMsg.PeoStartDate:=copy(sWZ,1,4)+'-'+copy(sWZ,5,2)+'-'+copy(sWZ,7,2);;
sDisp:=''; //有效期限
delete(sWZ,1,8);
PsnMsg.PeoEndDate:=copy(sWZ,1,4)+'-'+copy(sWZ,5,2)+'-'+copy(sWZ,7,2);;
delete(sWZ,1,8); //最新住址
PsnMsg.PeoReserve:=copy(sWZ,1,35);
//显示照片
//Image2.Picture.LoadFromFile(ExtractFilePath(Application.ExeName) +'zp.bmp');
//Image2.Visible := TRUE;
windows.Beep(2800,200);
Result := PsnMsg;
finally
FreeMem(Buffer);
end;
end;