delphi 国腾GTICR100 二代身份证的读取

来源:互联网 发布:怎么判断usb2.0端口 编辑:程序博客网 时间:2024/04/27 23:42

================================以下是DLL定义文件==============================

unit Comm_GoldTel_Dll;


///////国腾GTICR100

interface

uses Controls,sysutils,Quickrpt,QDialogs,Classes;

const NameLen                  = 30;
const SexLen                  = 5;
const NationLen                = 10;
const DateLen                  = 8;
const AddrLen                  = 70;
const IdLen                      = 18;
const DepartmentLen          = 30;
const ReserveLen            = 36;

type
  TPeopleBaseInfo = record
    PeoName:           array [0..NameLen]          of char;
    PeoSex:            array [0..SexLen]           of char;
    PeoFolk:           array [0..NationLen]        of char;
    PeoBirthday:       array [0..DateLen]          of char;
    PeoAddress:        array [0..AddrLen]          of char;
    PeoIDNumber:       array [0..IdLen]            of char;
    PeoDepartment:     array [0..DepartmentLen]    of char;
    PeoStartDate:      array [0..DateLen]          of char;
    PeoEndDate:        array [0..DateLen]          of char;
    PeoReserve:        array [0..ReserveLen]       of char;
    paddaddress1:      array [0..AddrLen]          of char;
    m_szphoto:         array [0..1023]             of char;
  end;
  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 GetBmp(Wlt_File: pchar; intf: integer): integer; stdcall;external 'WltRS.dll';
  function InitComm(iPort: Integer):integer;stdcall;external 'termb.dll';
  function Authenticate():integer;stdcall;external 'termb.dll';
  function Read_Content(iActive : integer):integer;stdcall;external 'termb.dll';
  function CloseComm():integer;stdcall;external 'termb.dll';

  function GetPeopleName(szName:pchar;iLen:integer):integer;stdcall;external 'termb.dll';
  function GetPeopleSex(szSex:pchar;iLen:integer):integer;stdcall;external 'termb.dll';
  function GetPeopleNation(szNation:pchar;iLen:integer):integer;stdcall;external 'termb.dll';
  function GetPeopleBirthday(szBirthday:pchar;iLen:integer):integer;stdcall;external 'termb.dll';
  function GetPeopleAddress(szAddress:pchar;iLen:integer):integer;stdcall;external 'termb.dll';
  function GetPeopleIDCode(szID:pchar;iLen:integer):integer;stdcall;external 'termb.dll';
  function GetDepartment(szDepartment:pchar;iLen:integer):integer;stdcall;external 'termb.dll';
  function GetStartDate(szStartDate:pchar;iLen:integer):integer;stdcall;external 'termb.dll';
  function GetEndDate(szEndDate:pchar;iLen:integer):integer;stdcall;external 'termb.dll';

  function GetPort:integer;
  FUNCTION GetPersonalMsg(Port:integer):TPsnMsg;
var
  m_szDllPath : string;
//  PsnMsg:TPeopleBaseInfo;
  PsnMsg:TPsnMsg;
  IDCard_Port:integer = 0;

implementation

function GetPort:integer;
var
  i,iRet:integer;
begin
  IDCard_Port:=0;
  i:=1;
  while i<=6 do begin
     iRet := InitComm(i);
     if iRet = 1 then
     begin
//       ShowMessage('打开COM--> '+inttostr(i));
       IDCard_Port:=i;
       Result:=i;
       break;
     end;
     i:=i+1;
  end;
  if iRet <> 1 then begin
     i:=1001;
     while i<=1006  do begin
        iRet := InitComm(i);
        if iRet = 1 then  begin
//           ShowMessage('打开USB-->'+inttostr(i));
           IDCard_Port:=i;
           Result:=i;
           break;
         end;
         i:=i+1;
      end;
  end;
end;

function GetPersonalMsg(Port:integer):TPsnMsg;
var
  iRet : integer;
  szName:Array[0..NameLen] of char;
  szSex:Array[0..SexLen] of char;
  szNation:Array[0..NationLen] of char;
  szBirthday:Array[0..DateLen] of char;
  szAddress:Array[0..AddrLen] of char;
  szID:Array[0..IdLen] of char;
  szDepartment:Array[0..DepartmentLen] of char;
  szStartDate:Array[0..DateLen] of char;
  szEndDate:Array[0..DateLen] of char;
begin
//  Image1.Picture.Assign(nil);

  FillChar(szName,sizeof(szName),0);
  if IDCard_Port < 1 then
  begin
    ShowMessage('打开串口失败!');
    exit;
  end;

  iRet := InitComm(IDCard_Port);
  if  iRet <> 1 then
  begin
    ShowMessage('打开串口失败!');
    exit;
  end;

  Authenticate();

  iRet := Read_Content(1);
  if iRet <> 1 then
  begin
    ShowMessage('读卡失败!');
    CloseComm();
    exit;
  end;


  iRet := GetPeopleName(szName,sizeof(szName));
  iRet := GetPeopleSex(szSex,sizeof(szSex));
  iRet := GetPeopleNation(szNation,sizeof(szNation));
  iRet := GetPeopleBirthday(szBirthday,sizeof(szBirthday));
  iRet := GetPeopleAddress(szAddress,sizeof(szAddress));
  iRet := GetPeopleIDCode(szID,sizeof(szID));
  iRet := GetDepartment(szDepartment,sizeof(szDepartment));
  iRet := GetStartDate(szStartDate,sizeof(szStartDate));
  iRet := GetEndDate(szEndDate,sizeof(szEndDate));


  CloseComm();

  if iRet = 0 then
  begin
    ShowMessage('获取卡信息失败!');
    exit;
  end;

  PsnMsg.PeoName := szName;
  PsnMsg.PeoSex  := szSex;
  PsnMsg.PeoBirthday  := szBirthday;
  PsnMsg.PeoIDNumber  := szID;
  PsnMsg.PeoDepartment  := szDepartment;
  PsnMsg.PeoStartDate := szStartDate;
  PsnMsg.PeoFolk  := szNation;
  PsnMsg.PeoAddress := szAddress;
  PsnMsg.PeoEndDate := szEndDate;

  Result := PsnMsg;

end;


end.




=======================================对函数的调用===========================

步骤1:

   调用获得

   _Port := inttostr(GetPort);  //初始化读卡器,并且获得端口号.


步骤2:
procedure TPsnFrm.BtnReadCardClick(Sender: TObject);
var
  _PsnMsg:TPsnMsg;
begin
  inherited;
  if IDCard_Port >= 1 then begin
    _PsnMsg:=GetPersonalMsg(IDCard_Port);
    T1NAME.AsString:=_PsnMsg.PeoName;
    T1CSNY.AsString:=copy(_PsnMsg.PeoBirthday,1,4)+'-'+copy(_PsnMsg.PeoBirthday,5,2)+'-'+copy(_PsnMsg.PeoBirthday,7,2);
    T1IDNO.AsString:=_PsnMsg.PeoIDNumber;
    T1NATION.AsString:=_PsnMsg.PeoFolk;
    T1ADDRESS.AsString:=_PsnMsg.PeoAddress;

    if _PsnMsg.PeoSex = '男' then begin
       T1SEXS.AsString:='1';
    end
    else begin
       T1SEXS.AsString:='0';
    end;
  end;
end;



原创粉丝点击