请哪位有时间的同仁测试一下该段程序,我总查不出问题出在何处。其中有两个VB编的外部函数。
unit readunit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls;
type
Treaddataform = class(TForm)
Label1: TLabel;
Panel5: TPanel;
Label15: TLabel;
Button1: TButton;
Timer1: TTimer;
Memo1: TMemo;
Button2: TButton;
LCEdt: TEdit;
Label3: TLabel;
Label5: TLabel;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
procedure zy;
//调整力值增益
procedure zy1;
//调整部分位移增益
procedure zy2;
public
end;
procedure delay(delaytime:longint);
function ad2118(channel:integer):integer;
procedure out_byte(port,dat:word);external 'vbdll.dll';
function in_byte(port:word):integer;external 'vbdll.dll';
var
readdataform: Treaddataform;
SaveFileName:string;
qflz,dqpower:real;
lc:integer;
zyxs,zyxs1,zyxs2:integer;
z1,z2,z3:integer;
z,bz,ysz:real;
//力值、部分位移值、引伸机值
dat1,dat2,dat3:integer;
const
baseadd=$100;
implementation
{$R *.DFM}
procedure Treaddataform.Button1Click(Sender: TObject);
begin
self.close;
end;
procedure Treaddataform.Timer1Timer(Sender: TObject);
var temp:string;
begin
Case z1 of //力值
0: dat1:= ad2118(0);
32: dat1:= ad2118(32);
64: dat1:= ad2118(64);
96: dat1:= ad2118(96);
128:dat1:= ad2118(128);
End ;
if zyxs>0 then
z:= 10*dat1/4096/zyxs
else
z:=0;
dqpower:=z*lc/10;
temp:=format('%5.3f',[dqpower]);
memo1.Lines.Add(temp);
panel5.Caption:=temp;
zy;
Case z2 of //位移值
1: dat2:= ad2118(1);
33: dat2:= ad2118(33);
65: dat2:= ad2118(65);
97: dat2:= ad2118(97);
129:dat2:= ad2118(129);
End ;
bz:= 10*dat2/4096;
if zyxs1>0 then
bz:= strtofloat(Format('%1.5f',[bz/zyxs1]));
zy1;
Case z3 of //引伸机值
2: dat3:= ad2118(2);
34: dat3:= ad2118(34);
66: dat3:= ad2118(66);
98: dat3:= ad2118(98);
130:dat3:= ad2118(130);
End ;
ysz:= 10*dat3/4096;
if zyxs2>0 then
ysz:= strtofloat(Format('%1.5f',[ysz/zyxs2]));
zy2;
end;
procedure Treaddataform.zy;
begin
if abs(z)<0.62 then
begin
delay(100);
z1:=128;
zyxs:=16;
end;
if (abs(z)>=0.62) and (abs(z)<1.248) then
begin
delay(100);
z1:=96;
zyxs:=8;
end;
if (abs(z)>=1.248) and (abs(z)<2.48) then
begin
delay(100);
z1:=64;
zyxs:=4;
end;
if (abs(z)>=2.48) and (abs(z)<4.98) then
begin
delay(100);
z1:=32;
zyxs:=2;
end;
if (abs(z)>=4.98) and (abs(z)<=9.98) then
begin
delay(100);
z1:=0;
zyxs:=1;
end;
end;
procedure Treaddataform.zy1;//调整部分位移增益
begin
if abs(bz)<0.6249 then
begin
delay(100);
z2:=129;
zyxs1:=16;
end;
if (abs(bz)>=0.6249) and (abs(bz)<1.249) then
begin
delay(100);
z2:=97;
zyxs1:=8;
end;
if (abs(bz)>=1.249) and (abs(bz)<2.499) then
begin
delay(100);
z2:=65;
zyxs1:=4;
end;
if (abs(bz)>=2.499) and (abs(bz)<4.99) then
begin
delay(100);
z2:=33;
zyxs1:=2;
end;
if (abs(bz)>=4.99) and (abs(bz)<=9.99) then
begin
delay(100);
z2:=1;
zyxs1:=1;
end;
end;
procedure Treaddataform.zy2;//调整引伸机增益
begin
if abs(ysz)<0.31249 then
begin
delay(100);
z3:=130;
zyxs2:=16;
end;
if (abs(ysz)>=0.31249) and (abs(ysz)<0.6249) then
begin
delay(100);
z3:=98;
zyxs2:=8;
end;
if (abs(ysz)>=0.6249) and (abs(ysz)<1.249) then
begin
delay(100);
z3:=66;
zyxs2:=4;
end;
if (abs(ysz)>=1.249) and (abs(ysz)<2.499) then
begin
delay(100);
z3:=34;
zyxs2:=2;
end;
if (abs(ysz)>=2.499) and (abs(ysz)<=4.999) then
begin
delay(100);
z3:=2;
zyxs2:=1;
end;
end;
Function ad2118(channel:Integer):integer;
var h,l:integer;
da:integer;
begin
out_byte(baseadd, channel);
delay(100);
out_byte(baseadd+1, 1);
delay(500);
h:= in_byte(baseadd + 2);
delay(50);
l:= trunc(in_byte(baseadd+3)/16);
// h:=255;
// l:=15;
da:= h*16+l ;
result:= da ;
end;
procedure delay(delaytime:longint);
var first,now:longint;
begin
first:=gettickcount;
repeat
now:=gettickcount
until ((now-first)>=delaytime)
end;
procedure Treaddataform.Button2Click(Sender: TObject);
begin
lc:=strtoint(lcedt.text);
timer1.Enabled:=true;
end;
procedure Treaddataform.Button3Click(Sender: TObject);
begin
timer1.Enabled:=false;
end;
end.