如何在DELPhi写三科考勤机接口 ( 积分: 200 )

  • 主题发起人 主题发起人 dxmqjy
  • 开始时间 开始时间
D

dxmqjy

Unregistered / Unconfirmed
GUEST, unregistred user!
我有如下的接口文件:
About kqdll.dll
在此动态库中共包含有8个函数,以下一个介绍其调用方法及参数说明:
1、long : GetDataNum(int port,int n) port为计算机端口号,n为考勤机机号;
2、bool : GetData(char *w) : char *w 为一个空的字符串值,长度为20以上;
两函数相辅作用,GetDataNum为返回考勤机机内记录总数(返回long类型值),
GetData为遂条取得机内数据(返回bool表示是否成功取得每一笔数据);例VB:
Private Sub Command1_Click()
Dim s As String * 23, n As Long, i As Long

Text1.Text = ""
n = FastGetDataNum(1, 1) //GetDataNum(int port,int n)
If n = -1 then
MsgBox "ERROR!"
Exit Sub
End If
ProgressBar1.Max = n
i = 1
Me.MousePointer = 11
MsgBox s
do
While FastGetData(s) //GetData(char *w)
ProgressBar1.Value = i
i = i + 1
Text1.Text = Text1.Text + s + vbCrLf
Text1.SelStart = Len(Text1.Text)
Me.Refresh
Loop
Me.MousePointer = 0
MsgBox "OK!"
End Sub

3、long: FastGetDataNum(int port,int n) port为端口号,n 为考勤机机号
4、bool: FastGetData(char *d) d为一个空的字符串值,长度大于20
同样这两个函数也为下载函数,用法同上,不同的是上两个函数下载函数偏慢,
这两个下载函数速度快得多。

5、bool: CheckTime(int port,int n) port为端口号,n 为考勤机机号
6、bool: ClearData(int port,int n) port为端口号,n 为考勤机机号
这两个函数分别为设置考勤机时间和清除机器内的记录,都返加bool值,表
示是否操作成功.
7、bool: SetOpenCard(int port,int n,unsigned char *kh) port为端口号,n为考勤机机号,kh为一个5位的字符串
8、bool: DelOpenCard(int port,int n,unsigned char *kh)
这两个函数只适用于SKM2000型的考勤门禁一体机或门禁机,SetOpenCard为赋予一张卡开门的权限,kh为该张卡
的后五位ABA号码,DelOpenCard为取消开门卡的开门权限,两函数都返加bool值,表操作是否成功.

以下是各函数在VB中的声明方法:
1、private declare function GetDataNum lib "kqdll.dll"
(byval port as integer,byval n as integer) as long
2、private declare function GetData lib "kqdll.dll"
(byval s as string) as boolean
3、private declare function FastGetDataNum lib "kqdll.dll"
(byval port as integer,byval n as integer) as long
4、private declare function FastGetData lib "kqdll.dll"
(byval s as string) as boolean
5、private declare function CheckTime lib "kqdll.dll"
(byval port as integer,byval n as integer) as boolean
6、private declare function ClearData lib "kqdll.dll"
(byval port as integer,byval n as integer) as boolean
7、private declare function SetOpenCard lib "kqdll.dll"
(ByVal port As Long, ByVal jh As Long, ByVal kh As String) As Boolean
7、private declare function DelOpenCard lib "kqdll.dll"
(ByVal port As Long, ByVal jh As Long, ByVal kh As String) As Boolean

GetData与FastGetData的仅是速度上的区别,FastGetData比GetData快一倍
但FastGetData不支持早期版本考勤机。
用FastGetData或GetData取得的记录格式说明如下:
记录格式为:00000000:0000000000000
前六位为卡号,00:00为时间,再八位为时间如20010806,再二两位为机
器编号,最后一位为类型标识
    类型标识:1为中途外入,2为中途外出,3为门禁读头读卡,0为正常读卡
我在DELPHI中声名:
unit OneSub;
interface
uses Dialogs,DBTables,Registry,Controls,SysUtils,Windows,Forms,Classes;
function GetDataNum(port:integer;n:integer):integer;stdcall;export;external 'KQDLL.dll';
function GetData(s:string):Boolean;stdcall;export;external 'KQDLL.dll';
function FastGetDataNum(port:integer;n:integer):integer;stdcall;export;external 'KQDLL.dll';
function FastGetData(s:Pchar):Boolean;stdcall;export;external 'KQDLL.dll';
function CheckTime(port:integer;n:integer):Boolean;stdcall;export;external 'KQDLL.dll';
function ClearData(port:integer;n:integer):Boolean;stdcall;export;external 'KQDLL.dll';
implementation
end.

在调用:
procedure Tm_updata1.btn_CollectClick(Sender: TObject);
label loop,loop1;
var
n,i,machineId,bunchId:Integer;
s:string;
begin

ListBox2.Items.Clear;
n:=0;
S:='';
i:=0;
machineId:=ComboBox1.ItemIndex+1;
bunchId:=ComboBox2.ItemIndex+1;
n:=GetDataNum(bunchId,machineId);
if n<>-1 then
begin
for i:=0 to n-1do
GetData(s);
ListBox2.Items.Strings:=s;
end;

可以读到总条数,但再次执行时出错,请那位高手帮忙小弟。小弟实为感激不尽。
 
我有如下的接口文件:
About kqdll.dll
在此动态库中共包含有8个函数,以下一个介绍其调用方法及参数说明:
1、long : GetDataNum(int port,int n) port为计算机端口号,n为考勤机机号;
2、bool : GetData(char *w) : char *w 为一个空的字符串值,长度为20以上;
两函数相辅作用,GetDataNum为返回考勤机机内记录总数(返回long类型值),
GetData为遂条取得机内数据(返回bool表示是否成功取得每一笔数据);例VB:
Private Sub Command1_Click()
Dim s As String * 23, n As Long, i As Long

Text1.Text = &quot;&quot;
n = FastGetDataNum(1, 1) //GetDataNum(int port,int n)
If n = -1 then
MsgBox &quot;ERROR!&quot;
Exit Sub
End If
ProgressBar1.Max = n
i = 1
Me.MousePointer = 11
MsgBox s
do
While FastGetData(s) //GetData(char *w)
ProgressBar1.Value = i
i = i + 1
Text1.Text = Text1.Text + s + vbCrLf
Text1.SelStart = Len(Text1.Text)
Me.Refresh
Loop
Me.MousePointer = 0
MsgBox &quot;OK!&quot;
End Sub

3、long: FastGetDataNum(int port,int n) port为端口号,n 为考勤机机号
4、bool: FastGetData(char *d) d为一个空的字符串值,长度大于20
同样这两个函数也为下载函数,用法同上,不同的是上两个函数下载函数偏慢,
这两个下载函数速度快得多。

5、bool: CheckTime(int port,int n) port为端口号,n 为考勤机机号
6、bool: ClearData(int port,int n) port为端口号,n 为考勤机机号
这两个函数分别为设置考勤机时间和清除机器内的记录,都返加bool值,表
示是否操作成功.
7、bool: SetOpenCard(int port,int n,unsigned char *kh) port为端口号,n为考勤机机号,kh为一个5位的字符串
8、bool: DelOpenCard(int port,int n,unsigned char *kh)
这两个函数只适用于SKM2000型的考勤门禁一体机或门禁机,SetOpenCard为赋予一张卡开门的权限,kh为该张卡
的后五位ABA号码,DelOpenCard为取消开门卡的开门权限,两函数都返加bool值,表操作是否成功.

以下是各函数在VB中的声明方法:
1、private declare function GetDataNum lib &quot;kqdll.dll&quot;
(byval port as integer,byval n as integer) as long
2、private declare function GetData lib &quot;kqdll.dll&quot;
(byval s as string) as boolean
3、private declare function FastGetDataNum lib &quot;kqdll.dll&quot;
(byval port as integer,byval n as integer) as long
4、private declare function FastGetData lib &quot;kqdll.dll&quot;
(byval s as string) as boolean
5、private declare function CheckTime lib &quot;kqdll.dll&quot;
(byval port as integer,byval n as integer) as boolean
6、private declare function ClearData lib &quot;kqdll.dll&quot;
(byval port as integer,byval n as integer) as boolean
7、private declare function SetOpenCard lib &quot;kqdll.dll&quot;
(ByVal port As Long, ByVal jh As Long, ByVal kh As String) As Boolean
7、private declare function DelOpenCard lib &quot;kqdll.dll&quot;
(ByVal port As Long, ByVal jh As Long, ByVal kh As String) As Boolean

GetData与FastGetData的仅是速度上的区别,FastGetData比GetData快一倍
但FastGetData不支持早期版本考勤机。
用FastGetData或GetData取得的记录格式说明如下:
记录格式为:00000000:0000000000000
前六位为卡号,00:00为时间,再八位为时间如20010806,再二两位为机
器编号,最后一位为类型标识
    类型标识:1为中途外入,2为中途外出,3为门禁读头读卡,0为正常读卡
我在DELPHI中声名:
unit OneSub;
interface
uses Dialogs,DBTables,Registry,Controls,SysUtils,Windows,Forms,Classes;
function GetDataNum(port:integer;n:integer):integer;stdcall;export;external 'KQDLL.dll';
function GetData(s:string):Boolean;stdcall;export;external 'KQDLL.dll';
function FastGetDataNum(port:integer;n:integer):integer;stdcall;export;external 'KQDLL.dll';
function FastGetData(s:Pchar):Boolean;stdcall;export;external 'KQDLL.dll';
function CheckTime(port:integer;n:integer):Boolean;stdcall;export;external 'KQDLL.dll';
function ClearData(port:integer;n:integer):Boolean;stdcall;export;external 'KQDLL.dll';
implementation
end.

在调用:
procedure Tm_updata1.btn_CollectClick(Sender: TObject);
label loop,loop1;
var
n,i,machineId,bunchId:Integer;
s:string;
begin

ListBox2.Items.Clear;
n:=0;
S:='';
i:=0;
machineId:=ComboBox1.ItemIndex+1;
bunchId:=ComboBox2.ItemIndex+1;
n:=GetDataNum(bunchId,machineId);
if n<>-1 then
begin
for i:=0 to n-1do
GetData(s);
ListBox2.Items.Strings:=s;
end;

可以读到总条数,但再次执行时出错,请那位高手帮忙小弟。小弟实为感激不尽。
 
function GetData(s:string):Boolean;stdcall;export;external 'KQDLL.dll';
改为:
function GetData(s: PChar):Boolean;stdcall;export;external 'KQDLL.dll';
var
s: array[0..100] of Char;
GetData(s);
 
这个问题你应该问厂商,
 
声明:
function GetDataNum(port:integer;n:integer):integer;stdcall;export;external 'KQDLL.dll';
function GetData(s:pchar):Boolean;stdcall;export;external 'KQDLL.dll';
function FastGetDataNum(port:integer;n:integer):integer;stdcall;export;external 'KQDLL.dll';
function FastGetData(s:Pchar):Boolean;stdcall;export;external 'KQDLL.dll';
function CheckTime(port:integer;n:integer):Boolean;stdcall;export;external 'KQDLL.dll';
function ClearData(port:integer;n:integer):Boolean;stdcall;export;external 'KQDLL.dll';
调用:
rocedure Tm_updata1.btn_CollectClick(Sender: TObject);
label loop,loop1;
var
n,i,machineId,bunchId:Integer;
s:array[0..255] of char;
begin
ListBox2.Items.Clear;
n:=0;
S:='';
i:=0;
machineId:=ComboBox1.ItemIndex+1;
bunchId:=ComboBox2.ItemIndex+1;
n:=GetDataNum(bunchId,machineId);
if n<>-1 then
begin
for i:=0 to n-1do
begin
fillchar(s,sizeof(s),0);
GetData(s);
ListBox2.Items.add(s);
end;
end;
 
就是,你去问产商也比自己在这里摸来得快些啊
 
这个问题就用不着问厂商了,调用动态库常见的问题而已,string类型是Delphi才有的数据类型,改用PChar就没事了,不过是在调用前要先分配好内存罢了[:D][:D][:D]
 
我现在用:
ListBox2.Items.Clear;
n:=0;
S:='';
i:=0;
machineId:=ComboBox1.ItemIndex+1;
bunchId:=ComboBox2.ItemIndex+1;
n:=GetDataNum(bunchId,machineId);
if n<>-1 then
begin
for i:=0 to n-1do
begin
fillchar(s,sizeof(s),0);
GetData(s);
ListBox2.Items.Strings:=s;
ListBox2.Refresh;
end;
end;
谢谢各位大哥,现在数据是可以收集了,但只能收集一次,如要再收集就得关掉系统再重新打开。请那位大哥再指点一下。即收集数据后如何释放?
 

Similar threads

后退
顶部