Unit1.pas
10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,FileCtrl, ExtCtrls;
type
Pint=^integer; //定义指针类型
pbyte=^byte;
Puint=^DWORD;
TIDCardData=record
name:array[0..31] of char;
sex:array[0..5] of char;
nation:array[0..19] of char;
born:array[0..17] of char;
address:array[0..71] of char;
IDcardno:array[0..37] of char;
grantdept:array[0..31] of char;
UserLifeBegin:array[0..17] of char;
UserLifeEnd:array[0..17] of char;
reserved:array[0..37] of char;
PhotoFileName:array[0..254] of char;
end;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Button17: TButton;
Button18: TButton;
Button19: TButton;
Button1: TButton;
Button2: TButton;
lbl1: TLabel;
img1: TImage;
procedure Button1Click(Sender: TObject);
procedure Button19Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button17Click(Sender: TObject);
procedure Button18Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
PROCEDURE LOADDLL();
public
{ Public declarations }
end;
var
Form1: TForm1;
m_iPort: Integer;
implementation
{$R *.dfm}
VAR
Moudlegm:longint;
Syn_SetMaxRFByte:function (iPort:integer;ucByte:Byte;bIfOpen:integer):integer;stdcall;
Syn_GetCOMBaud:function (iPort:integer;puiBaudRate:Puint):integer;stdcall;
Syn_SetCOMBaud:function (iPort:integer;uiCurrBaud:DWORD;uiSetBaud:DWORD):integer;stdcall;
Syn_OpenPort: function (iPort:integer):integer;stdcall;
Syn_ClosePort: function (iPort:integer):integer;stdcall;
Syn_ResetSAM:function (iPort:integer;iIfOpen:integer):integer;stdcall;
Syn_GetSAMStatus:function (iPort:integer;iIfOpen:integer):integer;stdcall;
Syn_GetSAMID:function (iPort:integer;pucSAMID:pbyte;iIfOpen:integer):integer;stdcall;
Syn_GetSAMIDToStr:function (iPort:integer;pcSAMID:PCHAR;iIfOpen:integer):integer;stdcall;
Syn_StartFindIDCard: function (iPort:integer;pucManaInfo:PCHAR;iIfOpen:integer):integer;stdcall;
Syn_SelectIDCard: function (iPort:integer;pucManaMsg:pbyte;iIfOpen:integer):integer;stdcall;
Syn_ReadBaseMsg: function (iPort:integer;pucCHMsg:pbyte;puiCHMsgLen:Puint;pucPHMsg:pbyte;puiPHMsgLen:Puint;pucFPMsg:pbyte;puiFPMsgLen:Puint;iIfOpen:integer):integer;stdcall;
Syn_ReadBaseMsgToFile: function (iPort:integer;pcCHMsgFileName:PCHAR;puiCHMsgFileLen:Puint;pcPHMsgFileName:PCHAR;puiPHMsgFileLen:Puint;pcFPMsgFileName:PCHAR;puiFPMsgFileLen:Puint;iIfOpen:integer):integer;stdcall;
Syn_ReadBaseFPMsg: function (iPort:integer;pucCHMsg:pbyte;puiCHMsgLen:Puint;pucPHMsg:pbyte;puiPHMsgLen:Puint;iIfOpen:integer):integer;stdcall;
Syn_ReadBaseFPMsgToFile: function (iPort:integer;pcCHMsgFileName:PCHAR;puiCHMsgFileLen:Puint;pcPHMsgFileName:PCHAR;puiPHMsgFileLen:Puint;iIfOpen:integer):integer;stdcall;
Syn_ReadNewAppMsg: function (iPort:integer;pucAppMsg:pbyte;puiAppMsgLen:Puint;iIfOpen:integer):integer;stdcall;
Syn_GetBmp: function (iPort:integer;Wlt_File:PCHAR):integer;stdcall;
Syn_ReadMsg: function (iPort:integer;iIfOpen:integer;var pIDCardData:TIDCardData):integer;stdcall;
Syn_ReadFPMsg: function (iPort:integer;iIfOpen:integer;var pIDCardData:TIDCardData;pName:pbyte):integer;stdcall;
Syn_FindReader:function ():integer;stdcall;
Syn_FindUSBReader:function ():integer;stdcall;
Syn_SetPhotoPath: function (iOption:integer;cPhotoPath:PCHAR):integer;stdcall;
Syn_SetPhotoType: function (iType:integer):integer;stdcall;
Syn_SetPhotoName: function (iType:integer):integer;stdcall;
Syn_SetSexType: function (iType:integer):integer;stdcall;
Syn_SetNationType: function (iType:integer):integer;stdcall;
Syn_SetBornType: function (iType:integer):integer;stdcall;
Syn_SetUserLifeBType: function (iType:integer):integer;stdcall;
Syn_SetUserLifeEType: function (iType:integer;iOption:integer):integer;stdcall;
procedure TForm1.LOADDLL();
begin
Moudlegm := Loadlibrary('SynIDCardAPI.dll');
if (Moudlegm>32) then
begin
@Syn_SetMaxRFByte:=GetProcAddress(Moudlegm,'Syn_SetMaxRFByte');
@Syn_GetCOMBaud:=GetProcAddress(Moudlegm,'Syn_GetCOMBaud');
@Syn_SetCOMBaud:=GetProcAddress(Moudlegm,'Syn_SetCOMBaud');
@Syn_OpenPort:=GetProcAddress(Moudlegm,'Syn_OpenPort');
@Syn_ClosePort:=GetProcAddress(Moudlegm,'Syn_ClosePort');
@Syn_ResetSAM:=GetProcAddress(Moudlegm,'Syn_ResetSAM');
@Syn_GetSAMStatus:=GetProcAddress(Moudlegm,'Syn_GetSAMStatus');
@Syn_GetSAMID:=GetProcAddress(Moudlegm,'Syn_GetSAMID');
@Syn_GetSAMIDToStr:=GetProcAddress(Moudlegm,'Syn_GetSAMIDToStr');
@Syn_StartFindIDCard:=GetProcAddress(Moudlegm,'Syn_StartFindIDCard');
@Syn_SelectIDCard:=GetProcAddress(Moudlegm,'Syn_SelectIDCard');
@Syn_ReadBaseMsg:=GetProcAddress(Moudlegm,'Syn_ReadBaseMsg');
@Syn_ReadBaseMsgToFile:=GetProcAddress(Moudlegm,'Syn_ReadBaseMsgToFile');
@Syn_ReadBaseFPMsg:=GetProcAddress(Moudlegm,'Syn_ReadBaseFPMsg');
@Syn_ReadBaseFPMsgToFile:=GetProcAddress(Moudlegm,'Syn_ReadBaseFPMsgToFile');
@Syn_ReadNewAppMsg:=GetProcAddress(Moudlegm,'Syn_ReadNewAppMsg');
@Syn_GetBmp:=GetProcAddress(Moudlegm,'Syn_GetBmp');
@Syn_ReadMsg:=GetProcAddress(Moudlegm,'Syn_ReadMsg');
@Syn_ReadFPMsg:=GetProcAddress(Moudlegm,'Syn_ReadFPMsg');
@Syn_FindReader:=GetProcAddress(Moudlegm,'Syn_FindReader');
@Syn_SetPhotoPath:=GetProcAddress(Moudlegm,'Syn_SetPhotoPath');
@Syn_SetPhotoType:=GetProcAddress(Moudlegm,'Syn_SetPhotoType');
@Syn_SetPhotoName:=GetProcAddress(Moudlegm,'Syn_SetPhotoName');
@Syn_SetSexType:=GetProcAddress(Moudlegm,'Syn_SetSexType');
@Syn_SetNationType:=GetProcAddress(Moudlegm,'Syn_SetNationType');
@Syn_SetBornType:=GetProcAddress(Moudlegm,'Syn_SetBornType');
@Syn_SetUserLifeBType:=GetProcAddress(Moudlegm,'Syn_SetUserLifeBType');
@Syn_SetUserLifeEType:=GetProcAddress(Moudlegm,'Syn_SetUserLifeEType');
end
end;
procedure TForm1.Button1Click(Sender: TObject);
var
nPort:integer;
nCurBaud:DWORD;
begin
nPort := Syn_FindReader();
m_iPort:= nPort;
if nPort = 0 then begin
ListBox1.Items.Add( DateTimeToStr(now())+ ' 没有找到读卡器' );
end else begin
Windows.Beep(4000,200);
if nPort>1000 then begin
ListBox1.Items.Add( DateTimeToStr(Now())+' 读卡器连接在USB ' + IntToStr(nPort) + ' 上');
end else begin
Syn_GetCOMBaud(nPort,@nCurBaud);
ListBox1.Items.Add( DateTimeToStr(Now())+' 读卡器连接在COM ' + IntToStr(nPort) + ' 上');
end;
end;
end;
procedure TForm1.Button19Click(Sender: TObject);
begin
Application.Terminate();
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
LOADDLL();
end;
procedure TForm1.Button17Click(Sender: TObject);
var
nRet:Integer;
nPort:Integer;
nPhotoType:Integer;
pucIIN:array[0..3] of byte;
pucSN:array[0..7] of byte;
CardMsg:TIDCardData;
begin
nPort:=m_iPort;
nPhotoType :=0;
img1.Picture :=nil;
nRet := Syn_OpenPort(nPort);
if nRet = 0 then begin
Syn_SetMaxRFByte( nPort ,80 , 0);
Syn_StartFindIDCard( nPort , @pucIIN , 0 );
Syn_SelectIDCard( nPort , @pucSN , 0 );
if Syn_ReadMsg( nPort , 0 , CardMsg)=0 then begin
ListBox1.Items.Add(DateTimeToStr(Now())+' 读取身份证信息成功');
ListBox1.Items.Add(DateTimeToStr(Now())+' 姓名:'+trim(CardMsg.Name));
ListBox1.Items.Add(DateTimeToStr(Now())+' 性别:'+trim(CardMsg.sex));
ListBox1.Items.Add(DateTimeToStr(Now())+' 民族:'+trim(CardMsg.Nation));
ListBox1.Items.Add(DateTimeToStr(Now())+' 出生日期:'+trim(CardMsg.Born));
ListBox1.Items.Add(DateTimeToStr(Now())+' 地址:'+trim(CardMsg.address));
ListBox1.Items.Add(DateTimeToStr(Now())+' 身份证号:'+trim(CardMsg.Idcardno));
ListBox1.Items.Add(DateTimeToStr(Now())+' 有效期开始:'+trim(CardMsg.UserLifeBegin));
ListBox1.Items.Add(DateTimeToStr(Now())+' 有效期结束:'+trim(CardMsg.UserLifeEnd));
ListBox1.Items.Add(DateTimeToStr(Now())+' 发证机关:'+trim(CardMsg.grantdept));
ListBox1.Items.Add(DateTimeToStr(Now())+' 照片文件名:'+trim(CardMsg.photofilename));
if nPhotoType = 0 then begin
img1.Picture.LoadFromFile(CardMsg.photofilename);
end;
end else begin
ListBox1.Items.Add(DateTimeToStr(Now())+' 读取身份证信息错误');
end;
end else begin
ListBox1.Items.Add(DateTimeToStr(Now())+' 打开端口失败');
end;
Syn_ClosePort(nPort);
end;
procedure TForm1.Button18Click(Sender: TObject);
begin
ListBox1.Clear();
img1.Picture :=nil;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
nRet:Integer;
nPort:Integer;
nPhotoType:Integer;
pucIIN:array[0..3] of byte;
pucSN:array[0..7] of byte;
pcName:array[0..255] of char;
CardMsg:TIDCardData;
begin
nPort:=m_iPort;
nPhotoType :=0;
img1.Picture :=nil;
nRet := Syn_OpenPort(nPort);
if nRet = 0 then begin
Syn_SetMaxRFByte( nPort ,80 , 0);
Syn_StartFindIDCard( nPort , @pucIIN , 0 );
Syn_SelectIDCard( nPort , @pucSN , 0 );
if Syn_ReadFPMsg( nPort , 0 , CardMsg,@pcName)=0 then begin
ListBox1.Items.Add(DateTimeToStr(Now())+' 读取身份证信息成功');
ListBox1.Items.Add(DateTimeToStr(Now())+' 姓名:'+trim(CardMsg.Name));
ListBox1.Items.Add(DateTimeToStr(Now())+' 性别:'+trim(CardMsg.sex));
ListBox1.Items.Add(DateTimeToStr(Now())+' 民族:'+trim(CardMsg.Nation));
ListBox1.Items.Add(DateTimeToStr(Now())+' 出生日期:'+trim(CardMsg.Born));
ListBox1.Items.Add(DateTimeToStr(Now())+' 地址:'+trim(CardMsg.address));
ListBox1.Items.Add(DateTimeToStr(Now())+' 身份证号:'+trim(CardMsg.Idcardno));
ListBox1.Items.Add(DateTimeToStr(Now())+' 有效期开始:'+trim(CardMsg.UserLifeBegin));
ListBox1.Items.Add(DateTimeToStr(Now())+' 有效期结束:'+trim(CardMsg.UserLifeEnd));
ListBox1.Items.Add(DateTimeToStr(Now())+' 发证机关:'+trim(CardMsg.grantdept));
ListBox1.Items.Add(DateTimeToStr(Now())+' 照片文件名:'+trim(CardMsg.photofilename));
ListBox1.Items.Add(DateTimeToStr(Now())+' 指纹文件名:'+trim(pcName));
if nPhotoType = 0 then begin
img1.Picture.LoadFromFile(CardMsg.photofilename);
end;
end else begin
ListBox1.Items.Add(DateTimeToStr(Now())+' 读取身份证信息错误');
end;
end else begin
ListBox1.Items.Add(DateTimeToStr(Now())+' 打开端口失败');
end;
Syn_ClosePort(nPort);
end;
end.