Check the current baud rate function SDT_GetCOMBaud(iport: integer; puiBaudRate: Pinteger): integer;stdcall;External'SDTAPI.DLL';{iPort[in] represents the port, puiBaudRate[out] unsigned pointer, pointing to the current wave of the normal serial port Special rate, return value 0X90-success, 0x1-port opening failed/port number is illegal, 0x5 cannot obtain the baud rate of SAM_V, and the serial port is not available. }
Set the baud rate function of the SAM_V serial port SDT_StetCOMBaud(iPort: integer; uiCurrBaud: integer; uiSetBaud: integer): integer;stdcall;External'SDTAPI.DLL';{iPort[in] means the port, uiCurrBaud[in] calls to change the API The baud rate of the previously set service terminal communication with SAM_V (factory default is 115200). uiCurrBaud can only be 115200, 57600, 378400, 19200, 9600. If the uiCurrBaud value is not one of these values, the function returns 0x21. If it is different from the set, the function returns 0x02 to indicate that the call to the API cannot be set. The SAM_V baud rate to be set by uiSetBaud[in] can only be used for those values (same as above). If these values are not used, the return will also be the same as above function. 0x90-success, 0x1-port opening failed/port number is illegal, 0x2-timeout, The setting is not successful, the input parameters of 0x21-uiCurrBaud and uiSetBaud are incorrect}
Open serial port/USB function SDT_OpenPort(iPort: integer): integer;stdcall;External'SDTAPI.DLL';{iPort[in] represents the port number, 1-16 (decimal) is the serial port, 1001-1016 (decimal) is the USB port, The default USB device port is 1001. Function returns 0x90 - The port is successfully opened, 1 - The port is failed / the port number is illegal}
Close the serial port/USBfunction SDT_ClosePort(iPort: integer): integer;stdcall;External'SDTAPI.DLL';{iPort[in] indicates the port number, return value 0x90-closed the serial port successfully, 0x01-port number is illegal}
Reset function SDT_ResetSAM(iPort: integer; ilfOpen: integer): integer;stdcall;External'SDTAPI.DLL';{iPort[in] represents the port number. Currently, only 16 serial ports and USB support, serial ports: 0001-0016, USB: 1001-1016. ilfOpen[in] means that the serial port is not opened and closed within the function. Non-0 means that the serial port and the serial port function are included in the API function. There is no need to call SDT_OpenPort and SDT_ClosePort before the return value 0x90 - successful, other failures}
Set the maximum number of communication bytes of RF adapter function SDT_SetMaxRFByte(iPort: integer;ucByte: Char;blfOpen: integer):integer;stdcall;External'SDTAPI.DLL';{iPort[in] represents the port number, ucByte[in] is unsigned Character, 24-255, represents the maximum number of communication bytes of the RF adapter, ilfOpen[in] see SDT_ResetSAM return value 0x90-success, other-failure}
Perform status detection function on SAM_V SDT_GetSAMStatus(iPort: integer; ilfOpen: integer): integer; stdcall; External'SDTAPI.DLL';{iPort[in] indicates the port number, see ilfOpen, see SDT_ResetSAM return value 0x90-SAM_V normal, 0x60-self Failed to check, unable to receive commands, other - command failed}
Read the number of SAM_V function SDT_GetSAMID(iPort: integer;pusSAMID: Pbyte;ilfOpen: integer):integer;stdcall;External'SDTAPI.DLL';{iPort[in] indicates the port number, pusSAMID[out] unsigned string pointer SAM_V number, 16 bytes, return value 0x90 - successful, other - failed}
Read the number of SAM_V function SDT_GetSAMIDToStr(iPort: integer;pcSAMID: Pbyte;ilfOpen: integer):integer;stdcall;External'SDTAPI.DLL';{iport[in] means the port number, pusSAMID[out]SAM_V number, ilfOpen[ in] integer, see SDT_ResetSAM return value 0x90 - successful, other - failed}
Start looking for card function SDT_StartFindIDCard(iPort: integer;pucManaInfo: Pbyte; ilfOpen: integer):integer;stdcall;External'SDTAPI.DLL';{iport[in] indicates the port number, pucManaInfo[out] unsigned pointer, certificate/card Chip management number, 4 bytes, ilfOpen[in] see SDT_ResetSAM return value 0x9f-Card search successfully, 0x80-Card search failed} card selection function SDT_SelectIDCard(iPort: integer;pucManaMsg: Pbyte;ilfOpen: integer):integer;stdcall ;External'SDTAPI.DLL';{iPort[in] indicates the port number, pucManaMsg[out] unsigned pointer, certificate/card chip serial number, 8 bytes, ilfOpen[in] see SDT_ResetSAM return value 0x90-card selection succeeds , 0x81-Card selection failed}
Read card management number function SDT_ReadMngInfo(iPort: integer;pucManageMsg: Pbyte;ilfOpen: integer):integer;stdcall;External'SDTAPI.DLL';{iPort[in] represents the port number, pucManageMsg[out] unsigned character pointer , card management number, 28 bytes, ilfOpen[in] return value 0x90 - successful, other - read failed}
Read certificate/card fixed information function SDT_ReadBaseMsg(iPort: integer;pucCHMsg: Pbyte;puiCHMsgLen: Pinteger;pucPHMsg: Pbyte;puiPHMsgLen: Pinteger;ilfOpen: integer):integer;stdcall;External'SDTAPI.DLL';{iPort[in ] represents the port number, pucCHMsg[out] points to the read text information, puiCHMsgLen[out] points to the read text information length pucPHMsg[out] points to the read photo information, puiPHMsgLen[out] points to the read photo information length, ilfOpen[in] See SDT_ResetSAM return value 0x90 - Read fixed information successfully, other reading fixed information failed}
Read additional information function SDT_ReadNewAppMsg(iPort: integer;pucAppMsg: Pbyte;puiAppMsgLen: Pinteger;ilfOpen: integer):integer;;stdcall;External'SDTAPI.DLL';{iPort[in] indicates the port number, and pucAppMsg[out] points to The read additional information, puiAppMsgLen[out] points to the read additional information length, ilfOpen[in] see SDT_ResetSAM return value 0x90 - the read additional information is successful, others - the read additional information failed}
Photo decoding function function GetBmp(Wlt_File: PChar,intf: integer):integer;stdcall;External'WltRS.dll';{Wlt_File-wlt file name, intf reading device communication interface type (1-RS-232C, 2-USB) Return value: Generate *.bmp and the following return information: 1-Photo decoding is correct, 0-Call Error in calling sdtapi.dll, -1-Photo decoding is error, -2-wlt file suffix error, -3-wlt file opening error, - 4-wlt file format error, -5-software not authorized, -6-device connection error}
source code:
unit IdReader; interfaceusesSysUtils,Windows,Forms,uDatabase;constDLL_SDTAPI = 'sdtapi.dll';DLL_WLTRS = 'WltRS.dll';//Prompt message TIP_TITLE = 'Prompt';TIP_ICREADER_NO_CARD = 'No card or the card is not put in place, please Replace the card! ';TIP_ICREADER_READ_FAILED = 'Card reading failed! ';TIP_ICREADER_CALL_DLL_FAILED = 'Call Error calling sdtapi.dll! ';TIP_ICREADER_PICTURE_DECODE_FAILED = 'Photo decoding error! ';TIP_ICREADER_WLT_FILE_EXTEND_FAILED = 'wlt file suffix error! ';TIP_ICREADER_WLT_FILE_OPEN_FAILED = 'wlt file opening error! ';TIP_ICREADER_WLT_FILE_FORMAT_FAILED = 'wlt file format is wrong! ';TIP_ICREADER_NO_LICENSE = 'Software is not authorized! ';TIP_ICREADER_DEVICE_FAILED = 'Device connection error! ';TIP_PRINT_NO_CARD_FOUND = 'No ID card related information was found. Please put the ID on the antenna and try again! ';TIP_ICREADER_SAVE_SUCCESS = 'Save successfully, the identity information has been automatically entered into the local database! ';TIP_ICREADER_BLACK_CARD_FOUND = 'The persons included in the blacklist were found! ';ERROR_ICREADER_OPEN_PORT = 'The port has failed to open, please check the corresponding port or reconnect the card reader! ';typeTIdCardInfo = packed recordName: array[0..14] of WideChar;Sex: array[0..0] of WideChar;Nation: array[0..1] of WideChar;BirthDay:array[0..7] of WideChar;Addr: array[0..34] of WideChar;IdSN: array[0..17] of WideChar;IssueOrgan: array[0..14] of WideChar;VaildBegin: array[0..7] of WideChar ;VaildEnd : array[0..7] of WideChar; theNewestAddr: array[0..34] of WideChar;end;function SDT_OpenPort(iPortID: Integer): Integer; stdcall; external DLL_SDTAPI name 'SDT_OpenPort';function SDT_ClosePort(iPortID : Integer): Integer; stdcall; external DLL_SDTAPI name 'SDT_ClosePort'; function SDT_StartFindIDCard(iPortID: Integer; var pucIIN: Integer; iIfOpen: Integer): Integer; stdcall; external DLL_SDTAPI name 'SDT_StartFindIDCard'; function SDT_SelectIDCard(iPortID: Integer; var pucIIN: Integer; iIfOpen: Integer): Integer; stdcall; external DLL_SDTAPI name 'SDT_SelectIDCard'; function SDT_ReadBaseMsg(iPortID: Integer; pucCHMsg: PAnsiChar; var puiCHMsgLen: Integer; pucPHMsg: PAnsiChar; var puiPHMsgLen: Integer; iIfOpen: Integer) : Integer; stdcall; external DLL_SDTAPI name 'SDT_ReadBaseMsg';function SDT_ReadBaseMsgToFile(iPortID: Integer; fileName1: PAnsiChar; var puiCHMsgLen: Integer; fileName2: PAnsiChar; var puiPHMsgLen: Integer; iIfOpen: Integer): Integer; stdcall; external DLL_SDTAPI name ' SDT_ReadBaseMsgToFile';function GetBmp(file_name: PAnsiChar; intf: Integer): Integer; stdcall; external DLL_WLTRS name 'GetBmp';function ReadICCard(var ACardInfo: TCardInfo; var AErrMsg: string): Boolean; implementationusesClasses, Dialogs, uResource; varLstEthnic: TStrings;function EthnicNoToName(ANo: string): string;beginResult:= LstEthnic.Values[ANo];end;function FormatDateStr(AValue: string): string;beginResult:= Copy(AValue, 1, 4) + '-' + Copy(AValue, 5, 2) + '-' +Copy(AValue, 7, 2);end;function ReadICCard(var ACardInfo: TIdCardInfo; var AErrMsg: string): Boolean;variPort: Integer;intOpenPortRtn: Integer;bUsbPort: Boolean;EdziPortID: Integer;iRet: Integer;pucIIN: Integer;EdziIfOpen: Integer;pucSN: Integer;puiCHMsgLen: Integer;puiPHMsgLen: Integer;fs: TFileStream;idCardInfo:TIdCardInfo;//FileHandle: Integer; beginAErrMsg:= ''; //Result:= False;bUsbPort:= False;EdziIfOpen:= 1;EdziPortID:= 0;puiCHMsgLen:= 0;puiPHMsgLen:= 0;// Detect the machine connection of the USB port, you must first detect usbfor iPort:= 1001 to 1016 dobeginintOpenPortRtn:= SDT_OpenPort(iPort);if intOpenPortRtn = 144 thenbeginEdziPortID:= iPort;bUsbPort:= true;break;end;end;//Detection of the device connection of the serial port if not bUsbPort thenbeginfor iPort := 1 to 2 dobeginintOpenPortRtn:= SDT_OpenPort (iPort);if intOpenPortRtn = 144 thenbeginEdziPortID:= iPort;bUsbPort:= False;Break;end;end;end;if intOpenPortRtn <> 144 thenbegin//application.MessageBox(ERROR_ICREADER_OPEN_PORT, ERROR_TITLE);AErrMsg:= ERROR_ICREADER_OPEN_PORT;Result: = False;Exit;end;//Look for card iRet:= SDT_StartFindIDCard(EdziPortID, pucIIN, EdziIfOpen);if iRet <> 159 thenbeginiRet:= SDT_StartFindIDCard(EdziPortID, pucIIN, EdziIfOpen);//Look for card if iRet <> 159 thenbeginSDT_ClosePort(EdziPortID);//Application.MessageBox(TIP_ICREADER_NO_CARD, TIP_TITLE);AErrMsg:= TIP_ICREADER_NO_CARD;Result:= False;Exit;end;end;//Select card iRet:= SDT_SelectIDCard(EdziPortID, pucSN, EdziIfOpen);if iRet <> 144 thenbeginiRet:= SDT_SelectIDCard(EdziPortID, pucSN, EdziIfOpen);if iRet <> 144 thenbeginSDT_ClosePort(EdziPortID);//Application.MessageBox(TIP_ICREADER_READ_FAILED, TIP_TITLE);AErrMsg:= TIP_ICREADER_READ_FAILED;Result:= False;Exit;end ;end;//Note that here, the user must have read and write permissions to the current directory of the application if FileExists('wz.txt') then SysUtils.DeleteFile('wz.txt');if FileExists('zp.bmp' ) then SysUtils.DeleteFile('zp.bmp');if FileExists('zp.wlt') then SysUtils.DeleteFile('zp.wlt');//PAnsiChar(AnsiString(Str))iRet:= SDT_ReadBaseMsgToFile(EdziPortID, PAnsiChar(AnsiString('wz.txt')), puiCHMsgLen, PAnsiChar(AnsiString('zp.wlt')), puiPHMsgLen, 1);if iRet <> 144 thenbeginSDT_ClosePort(EdziPortID);//Application.MessageBox(TIP_ICREADER_READ_FAILED, TIP_TITLE );AErrMsg:= TIP_ICREADER_READ_FAILED;Result:= False;Exit;end;//The following is to parse the photo. Note that if there is no authorization file Termb.Lic from the machine manufacturer in the root directory of the C disk, the photo resolution will fail if bUsbPort theniRet: = GetBmp(PAnsiChar(AnsiString('zp.wlt')), 2)elseiRet:= GetBmp(PAnsiChar(AnsiString('zp.wlt')), 1);case iRet of0:beginApplication.MessageBox(TIP_ICREADER_CALL_DLL_FAILED, TIP_TITLE); end;1: //Normal beginend;-1:beginApplication.MessageBox(TIP_ICREADER_PICTURE_DECODE_FAILED, TIP_TITLE);end;-2:beginApplication.MessageBox(TIP_ICREADER_WLT_FILE_EXTEND_FAILED, TIP_TITLE);end;-3:beginApplication.MessageBox(TIP_ICREADER_WLT_FILE_OPEN_FAILED, TIP_TITLE);end ;-4: beginApplication.MessageBox(TIP_ICREADER_WLT_FILE_FORMAT_FAILED, TIP_TITLE);end;-5: beginApplication.MessageBox(TIP_ICREADER_NO_LICENSE, TIP_TITLE);end;-6: beginApplication.MessageBox(TIP_ICREADER_DEVICE_FAILED, TIP_TITLE);end;end;SDT_ClosePort(EdziPortID); fs:= TFileStream.Create('wz.txt', fmOpenRead);fs.Position:= 0;fs.Read(ACardInfo,SizeOf(ACardInfo));fs.Free;//// Name: AnsiString(idCardInfo.Name );// Gender: if AnsiString(idCardInfo.Sex)= '1' then Gender:= 'Male' else Gender:= 'Female';// Ethnic: EthnicNoToName(AnsiString(idCardInfo.Nation));// Year of birth Month and Date: FormatDateStr(AnsiString(idCardInfo.BirthDay));// Address: Address:= Trim(AnsiString(idCardInfo.Addr));// ID number: Id:= Trim(AnsiString(idCardInfo.IdSN));/ /Certificate issuing agency: Place:= Trim(AnsiString(idCardInfo.IssueOrgan));//Fee Date Begin ValidDateStart:= FormatDateStr(AnsiString(idCardInfo.VaildBegin));//Fee Date End if Trim(AnsiString(idCardInfo.VaildEnd) ) = 'Long-term' then// ValidDateEnd:= FormatDateTime('yyy-MM-dd', MaxDateTime)// else// ValidDateEnd:= FormatDateStr(AnsiString(idCardInfo.VaildEnd));//Result:= True;end; initializationLstEthnic:= TStringList.Create; with LstEthnic dobeginAdd('01' + '=' + 'Han');Add('02' + '=' + 'Mongol');Add('03' + '=' + 'Hui people');Add('04' + '=' + 'Tibetan people');Add('05' + '=' + 'Uyghur people');Add('06' + '=' + 'Miao people') ;Add('07' + '=' + 'Yi people');Add('08' + '=' + 'Zhuang people');Add('09' + '=' + 'Buyi people');Add(' 10' + '=' + 'Korean');Add('11' + '=' + 'Manchu');Add('12' + '=' + 'Dong');Add('13' + ' =' + 'Yao people');Add('14' + '=' + 'Bai people');Add('15' + '=' + 'Tujia people');Add('16' + '=' + ' Hani people');Add('17' + '=' + 'Kazakhs');Add('18' + '=' + 'Dai people');Add('19' + '=' + 'Li people') ;Add('20' + '=' + 'Lisu people');Add('21' + '=' + 'Wa people');Add('22' + '=' + 'She people');Add(' 23' + '=' + 'High Mountain Tribe');Add('24' + '=' + 'Lahu Tribe');Add('25' + '=' + 'Aqua Tribe');Add('26' + '=' + 'Dongxiang people');Add('27' + '=' + 'Naxi people');Add('28' + '=' + 'Jingpo people');Add('29' + '= ' + 'Kirgiz');Add('30' + '=' + 'Tu');Add('31' + '=' + 'Dahan');Add('32' + '=' + 'Mullao');Add('33' + '=' + 'Qiang');Add('34' + '=' + 'Brown');Add('35' + '=' + ' Salar tribe');Add('36' + '=' + 'Maonan tribe');Add('37' + '=' + 'Gelao tribe');Add('38' + '=' + 'Xibe tribe ');Add('39' + '=' + 'Achang tribe');Add('40' + '=' + 'Pumi tribe');Add('41' + '=' + 'Tajik tribe') ;Add('42' + '=' + 'Nur tribe');Add('43' + '=' + 'Uzbek tribe');Add('44' + '=' + 'Russian tribe');Add( '45' + '=' + 'Ewenki');Add('46' + '=' + 'De'ang');Add('47' + '=' + 'Baoan');Add('48 ' + '=' + 'Yugu tribe');Add('49' + '=' + 'Jing tribe');Add('50' + '=' + 'Tatar tribe');Add('51' + ' =' + 'Dulong clan');Add('52' + '=' + 'Oqqen clan');Add('53' + '=' + 'Hezhe clan');Add('54' + '=' + 'Menba');Add('55' + '=' + 'Luba');Add('56' + '=' + 'Kino');Add('57' + '=' + ' Others');Add('98' + '=' + 'Foreign naturalization');end;finalizationLstEthnic.Free;end.//Please prepare sdtapi.dll WltRS.dll WltRS.lic in advance, put In the same directory