A
ahhlian
Unregistered / Unconfirmed
GUEST, unregistred user!
VB中:
Private Declare Sub out_byte Lib "vbdll.dll" (ByVal port%, ByVal da%) '写一个byte
Private Declare Function in_byte Lib "vbdll.dll" (ByVal port%) As Integer '读一个byte
Function ad2118(channel As Integer) As Integer
Dim h, m, l, da As Integer
out_byte baseadd, channel
delay (100)
out_byte baseadd + 1, 1
delay (500)
h = in_byte(baseadd + 2)
delay (50)
l = Int(in_byte(baseadd + 3) / 16)
da = h * 16 + l
ad2118 = da
End Function
DELPHI中:
procedure out_byte(port,dat:integer);external 'vbdll.dll';
function in_byte(port:integer):integer;external 'vbdll.dll';
Function ad2118(channel:Integer):integer;
var h,l,da:integer;
begin
out_byte(baseadd, channel);
//start
delay(100);
out_byte(baseadd+1, 1);
delay(500);
h:= in_byte(baseadd + 2);
//高位
delay(50);
l:= trunc(in_byte(baseadd+3)/16);
//低位 //end
da:= h*16 +l ;
ad2118:= da ;
end;
这是两段程序,其中BASEADD为常量=H100。该程序在VB中运行正常,但在DELPHI中函数
AD2118无法返回值。我想问题应该在DA:=H*16+L行,但该如何纠正却不知道。奇怪的是,
我屏蔽掉START..END之间的语句即不调用OUT_BYTE和IN_BYTE函数,而直接给H、L赋值,
则运行正常。我想函数声明应该没问题,但问题在哪呢?
Private Declare Sub out_byte Lib "vbdll.dll" (ByVal port%, ByVal da%) '写一个byte
Private Declare Function in_byte Lib "vbdll.dll" (ByVal port%) As Integer '读一个byte
Function ad2118(channel As Integer) As Integer
Dim h, m, l, da As Integer
out_byte baseadd, channel
delay (100)
out_byte baseadd + 1, 1
delay (500)
h = in_byte(baseadd + 2)
delay (50)
l = Int(in_byte(baseadd + 3) / 16)
da = h * 16 + l
ad2118 = da
End Function
DELPHI中:
procedure out_byte(port,dat:integer);external 'vbdll.dll';
function in_byte(port:integer):integer;external 'vbdll.dll';
Function ad2118(channel:Integer):integer;
var h,l,da:integer;
begin
out_byte(baseadd, channel);
//start
delay(100);
out_byte(baseadd+1, 1);
delay(500);
h:= in_byte(baseadd + 2);
//高位
delay(50);
l:= trunc(in_byte(baseadd+3)/16);
//低位 //end
da:= h*16 +l ;
ad2118:= da ;
end;
这是两段程序,其中BASEADD为常量=H100。该程序在VB中运行正常,但在DELPHI中函数
AD2118无法返回值。我想问题应该在DA:=H*16+L行,但该如何纠正却不知道。奇怪的是,
我屏蔽掉START..END之间的语句即不调用OUT_BYTE和IN_BYTE函数,而直接给H、L赋值,
则运行正常。我想函数声明应该没问题,但问题在哪呢?