中控指纹开发DLEPHI版demo源码.docx
《中控指纹开发DLEPHI版demo源码.docx》由会员分享,可在线阅读,更多相关《中控指纹开发DLEPHI版demo源码.docx(30页珍藏版)》请在冰豆网上搜索。
中控指纹开发DLEPHI版demo源码
demo:
unit comsdktest;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, zkemkeeper_TLB, Menus, Buttons, Grids,
ValEdit, ExtCtrls;
type
TForm1 = class(TForm)
CZKEM1:
TCZKEM;
Label1:
TLabel;
btnConnect:
TButton;
Memo1:
TMemo;
SaveDialog1:
TSaveDialog;
gbOP:
TGroupBox;
btnSetTime:
TButton;
vleDevInfo:
TValueListEditor;
btnLoadDevInfo:
TBitBtn;
btnSaveDevInfo:
TBitBtn;
Button3:
TButton;
GroupBox1:
TGroupBox;
btnClearData:
TButton;
Button5:
TButton;
Button6:
TButton;
btnBackupUser:
TButton;
btnRestore:
TButton;
Button9:
TButton;
OpenDialog1:
TOpenDialog;
btnDeleteUser:
TButton;
btnSetName:
TButton;
Button10:
TButton;
btnAutoTest:
TButton;
edtNetAddress:
TLabeledEdit;
edtNetPort:
TLabeledEdit;
edtBaudRate:
TEdit;
sbtnRS232:
TSpeedButton;
sbtnTCPIP:
TSpeedButton;
Label5:
TLabel;
btnACUnlock:
TButton;
edtPassword:
TEdit;
Label2:
TLabel;
chkEnabled:
TCheckBox;
Button7:
TButton;
Button8:
TButton;
Button12:
TButton;
Button11:
TButton;
Button14:
TButton;
Button13:
TButton;
Button15:
TButton;
Button16:
TButton;
Button17:
TButton;
Button18:
TButton;
Button19:
TButton;
Button20:
TButton;
btnSMS:
TButton;
Button1:
TButton;
SaveDialog2:
TSaveDialog;
OpenDialog2:
TOpenDialog;
Button2:
TButton;
procedure FormCreate(Sender:
TObject);
procedure btnConnectClick(Sender:
TObject);
procedure btnLoadDevInfoClick(Sender:
TObject);
procedure btnSaveDevInfoClick(Sender:
TObject);
procedure btnSetTimeClick(Sender:
TObject);
procedure btnClearDataClick(Sender:
TObject);
procedure Button5Click(Sender:
TObject);
procedure Button6Click(Sender:
TObject);
procedure Button9Click(Sender:
TObject);
procedure Button3Click(Sender:
TObject);
procedure btnBackupUserClick(Sender:
TObject);
procedure btnRestoreClick(Sender:
TObject);
procedure vleDevInfoValidate(Sender:
TObject; ACol, ARow:
Integer;
const KeyName, KeyValue:
String);
procedure btnSetNameClick(Sender:
TObject);
procedure btnDeleteUserClick(Sender:
TObject);
procedure btnAutoTestClick(Sender:
TObject);
procedure sbtnRS232Click(Sender:
TObject);
procedure sbtnTCPIPClick(Sender:
TObject);
procedure btnACUnlockClick(Sender:
TObject);
procedure chkEnabledClick(Sender:
TObject);
procedure Button1Click(Sender:
TObject);
procedure Button4Click(Sender:
TObject);
procedure btnSMSClick(Sender:
TObject);
procedure Button7Click(Sender:
TObject);
procedure Button8Click(Sender:
TObject);
procedure Button12Click(Sender:
TObject);
procedure Button11Click(Sender:
TObject);
procedure Button14Click(Sender:
TObject);
procedure Button13Click(Sender:
TObject);
procedure Button15Click(Sender:
TObject);
procedure Button16Click(Sender:
TObject);
procedure Button17Click(Sender:
TObject);
procedure Button18Click(Sender:
TObject);
procedure CZKEM1FingerFeature(ASender:
TObject; Score:
Integer);
procedure CZKEM1Verify(ASender:
TObject; UserID:
Integer);
procedure Button19Click(Sender:
TObject);
procedure Button20Click(Sender:
TObject);
procedure Button2Click(Sender:
TObject);
//procedure GroupBox1Click(Sender:
TObject);
private
{ Private declarations }
DevID:
integer;
Commport:
integer;
Modified:
string;
AppPath:
string;
procedure AddInfo(const s:
string);
procedure ReadDeviceStatus;
procedure BackupUser(const fn:
string);
procedure RestoreUser(const fn:
string);
function SaveGLogs(const fn:
string):
integer;
function BTimeEncode(MinuteSecond:
integer):
string;
function BTimeDecode(const TimeStr:
string):
integer;
function BNetSpeedEncode(speed:
integer):
string;
function BNetSpeedDecode(const speed:
string):
integer;
public
{ Public declarations }
end;
var
Form1:
TForm1;
function decodedata(const s:
string):
string;
function encodedata(const BinData; size:
integer):
string;
function LoadFile(const fn:
string):
string;
procedure SaveFileData(const fn:
string; const Data; size:
integer);
procedure SaveFile(const fn:
string; Data:
string);
implementation
uses inifiles, uUser;
{$R *.dfm}
const
HexOfNum:
array[0..15] of char=('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
StatusNames:
array[1..12] of string=(
'Tatal administrator',
'Tatal users',
'Tatal FP',
'Tatal Password',
'Tatal manage record',
'Tatal In and out record',
'Nominal FP number',
'Nominal user number',
'Nominal In and out record number',
'Remain FP number',
'Remain user number',
'Remain In and out record number');
Languages:
array[0..2] of string=(
'English',
'Simplified Chinese',
'Traditional Chinese');
BaudRates:
array[0..6] of string=(
'1200 bps',
'2400 bps',
'4800 bps',
'9600 bps',
'19200 bps',
'38400 bps',
'115200 bps');
CRCs:
array[0..2] of string=(
'Nothing',
'Even',
'Odd');
StopBits:
array[0..1] of string=(
'One',
'Two');
DateSps:
array[0..1] of string=(
'"/"',
'"-"');
MSpeeds:
array[0..2] of string=(
'Low speed',
'High speed',
'Auto');
OnOffs:
array[0..1] of string=(
'Off',
'On');
YesNos:
array[0..1] of string=(
'No',
'Yes');
DateFormats:
array[0..9] of string=(
'YY-MM-DD','YY/MM/DD','YY.MM.DD',
'MM-DD-YY','MM/DD/YY','MM.DD.YY',
'DD-MM-YY','DD/MM/YY','DD.MM.YY',
'YYYYMMDD');
NetSpeeds:
array[0..4] of string=
('10M_H','100M_H','10M_F','100M_F','AUTO');
NetSpeedValues:
array[0..4] of integer=(0,1,4,5,8);
procedure TForm1.FormCreate(Sender:
TObject);
var
s:
widestring;
i,j:
integer;
begin
AppPath:
= ExtractFilePath(application.exename);
CZKEM1.GetSDKVersion(s);
label1.Caption :
= s;
vleDevInfo.ItemProps[2].EditStyle :
= esPickList;
for i:
=0 to length(Languages)-1 do
vleDevInfo.ItemProps[2].PickList.Add(Languages[i]);
vleDevInfo.ItemProps[8].EditStyle :
= esPickList;
for i:
=0 to length(BaudRates)-1 do
vleDevInfo.ItemProps[8].PickList.Add(BaudRates[i]);
vleDevInfo.ItemProps[9].EditStyle :
= esPickList;
for i:
=0 to length(CRCs)-1 do
vleDevInfo.ItemProps[9].PickList.Add(CRCs[i]);
vleDevInfo.ItemProps[10].EditStyle :
= esPickList;
for i:
=0 to length(StopBits)-1 do
vleDevInfo.ItemProps[10].PickList.Add(StopBits[i]);
vleDevInfo.ItemProps[11].EditStyle :
= esPickList;
for i:
=0 to length(DateSps)-1 do
vleDevInfo.ItemProps[11].PickList.Add(DateSps[i]);
for j :
= 12 to 15 do
begin
vleDevInfo.ItemProps[j].EditStyle :
= esPickList;
for i:
=0 to length(OnOffs)-1 do
vleDevInfo.ItemProps[j].PickList.Add(OnOffs[i]);
end;
vleDevInfo.ItemProps[16].EditStyle :
= esPickList;
for i:
=0 to length(MSpeeds)-1 do
vleDevInfo.ItemProps[16].PickList.Add(MSpeeds[i]);
end;
function LoadFile(const fn:
string):
string;
var
f:
tmemorystream;
begin
result :
= '';
f :
= tmemorystream.Create;
try
f.LoadFromFile(fn);
f.Position :
= 0;
if f.Size>0 then
begin
setlength(result, f.size);
f.Read(result[1], length(result));
end;
finally
f.Free;
end;
end;
procedure SaveFile(const fn:
string; Data:
string);
var
f:
tmemorystream;
begin
f :
= tmemorystream.Create;
try
if length(data)>0 then
f.Write(Data[1], length(data));
f.Position :
= 0;
f.SaveToFile(fn);
finally
f.Free;
end;
end;
procedure SaveFileData(const fn:
string; const Data; size:
integer);
var
f:
tmemorystream;
begin
f :
= tmemorystream.Create;
try
if size>0 then
f.Write(Data, size);
f.Position :
= 0;
f.SaveToFile(fn);
finally
f.Free;
end;
end;
procedure TForm1.btnConnectClick(Sender:
TObject);
var
ErrorCode:
integer;
c:
boolean;
begin
if btnConnect.Tag = 1 then
begin
CZKEM1.RefreshData(DevId);
CZKEM1.EnableDevice(DevId, TRUE);
CZKEM1.Disconnect;
btnConnect.Tag :
= 0;
btnConnect.Caption :
= 'Connect';
end
else
begin
devid:
=strtoint(edtNetPort.Text);
if edtPassword.Text>'' then
CZKEM1.SetCommPassword(strtoint(edtPassword.Text));
if pos('COM', uppercase(edtNetAddress.text))=1 then
begin
commport:
=ord(edtNetAddress.text[4])-ord('0');
CZKEM1.CommPort :
= commport;
c:
=CZKEM1.Connect_Com( commport, DevID, strtoint(edtBaudRate.text));
end
else
begin
c:
=CZKEM1.Connect_net(edtNetAddress.text, Devid);
Devid:
=1;
end;
if c then
begin
AddInfo('Device Connected.');
ReadDeviceStatus;
btnConnect.Tag :
= 1;
btnConnect.Caption :
= 'Disconnect';
end
else
begin
CZKEM1.GetLastError(ErrorCode);
AddInfo(format('!
ConnectDevice ErrorNo.=%d',[ErrorCode]));
end;
AddInfo(' ');
end;
end;
procedure TForm1.AddInfo(const s:
string);
begin
memo1.Lines.Add(s);
memo1.Refresh;
end;
procedure TForm1.btnLoadDevInfoClick(Sender:
TObject);
var
ErrorCode, Value, i:
integer;
begin
for i:
=1 to vleDevInfo.RowCount-1 do
if CZKEM1.GetDeviceInfo(devid, i, value) then
begin
if i=29 then
begin
vleDevInfo.Strings.ValueFromIndex[i-1]:
=BNetSpeedEncode(Value);
end
else if vleDevInfo.ItemProps[i-1].HasPickList then
begin
if (value>=0) and (value vleDevInfo.Strings.ValueFromIndex[i-1]:
=vleDevInfo.ItemProps[i-1].Pick