请求翻译以下程序! (50分)

  • 主题发起人 主题发起人 ahhlian
  • 开始时间 开始时间
A

ahhlian

Unregistered / Unconfirmed
GUEST, unregistred user!
我有一程序(VB版)需要改写为Delphi版,请大家帮忙。谢谢!
Private Declare Sub out_byte Lib "vbdll.dll" (ByVal port%, ByVal da%)//写一个byte
Private Declare Sub out_word Lib "vbdll.dll" (ByVal port%, ByVal da%)//写一个word
Private Declare Function in_byte Lib "vbdll.dll" (ByVal port%) As Integer//读一个byte
Private Declare Function in_word Lib "vbdll.dll" (ByVal port%) As Integer//读一个word
Const baseadd = &H100
Private Sub Timer1_Timer() '采样、调整增益,投点z1代表力值通道的端口地址,z2代表部分位移通道,z3代表引伸机通道的端口地址,zyxs,zyxs1,zyx2代表各自的增益,采几点平均投点自定。z代表力值,bz代表部分位移值,ysz代表引伸机值
Select Case z1
Case 0
dat1 = ad2118(0)
Case 32
dat1 = ad2118(32)
Case 64
dat1 = ad2118(64)
Case 96
dat1 = ad2118(96)
Case 128
dat1 = ad2118(128)
End Select
z = 10 * dat1 / 4096
z = Format(z / zyxs, "0.#####")
Call zy

Select Case z2
Case 1
dat2 = ad2118(1)
Case 33
dat2 = ad2118(33)
Case 65
dat2 = ad2118(65)
Case 97
dat2 = ad2118(97)
Case 129
dat2 = ad2118(129)
End Select
bz = 10 * dat2 / 4096
bz = Format(bz / zyxs1, "0.#####")
Call zy1

Select Case z3
Case 2
dat3 = ad2118(2)
Case 34
dat3 = ad2118(34)
Case 66
dat3 = ad2118(66)
Case 98
dat3 = ad2118(98)
Case 130
dat3 = ad2118(130)
End Select
ysz = 10 * dat3 / 4096
ysz = Format(ysz / zyxs2, "0.#####")
Call zy2

End Sub
Private Sub zy() '调整力值增益
If Abs(z) < 0.62 then
delay (100)
z1 = 128
zyxs = 16
End If
If Abs(z) >= 0.62 And Abs(z) < 1.248 then
delay (100)
z1 = 96
zyxs = 8
End If
If Abs(z) >= 1.248 And Abs(z) < 2.48 then
delay (100)
z1 = 64
zyxs = 4
End If
If Abs(z) >= 2.48 And Abs(z) < 4.98 then
delay (100)
z1 = 32
zyxs = 2
End If
If Abs(z) >= 4.98 And Abs(z) <= 9.98 then
delay (100)
z1 = 0
zyxs = 1
End If
End Sub
Private Sub zy1() '调整部分位移增益
If Abs(bz) < 0.6249 then
delay (100)
z2 = 129
zyxs1 = 16
End If
If Abs(bz) >= 0.6249 And Abs(bz) < 1.249 then
delay (100)
z2 = 97
zyxs1 = 8
End If
If Abs(bz) >= 1.249 And Abs(bz) < 2.499 then
delay (100)
z2 = 65
zyxs1 = 4
End If
If Abs(bz) >= 2.499 And Abs(bz) < 4.99 then
delay (100)
z2 = 33
zyxs1 = 2
End If
If Abs(bz) >= 4.99 And Abs(bz) <= 9.99 then
delay (100)
z2 = 1
zyxs1 = 1
End If
End Sub
Private Sub zy2()
If Abs(ysz) < 0.31249 then
delay (100)
z3 = 130
zyxs2 = 16
End If
If Abs(ysz) >= 0.31249 And Abs(bz) < 0.6249 then
delay (100)
z3 = 98
zyxs2 = 8
End If
If Abs(ysz) >= 0.6249 And Abs(ysz) < 1.249 then
delay (100)
z3 = 66
zyxs2 = 4
End If
If Abs(ysz) >= 1.249 And Abs(ysz) < 2.499 then
delay (100)
z3 = 34
zyxs2 = 2
End If
If Abs(ysz) >= 2.499 And Abs(ysz) <= 4.999 then
delay (100)
z3 = 2
zyxs2 = 1
End If
End Sub
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
Function delay(dalay_time As Integer)
For nn = 0 To dalay_time
Next nn
End Function
可电邮至以下油箱:denglg@263.net,ahlain@sina.com
 
周末我来翻。现在受管制。
 
ahhlian:对不起,不一定正确,还要你自己查端口资料
procedure Timer1_Timer(Sender: TObject) ;'采样、调整增益,投点z1代表力值通道的端口地址,z2代表部分位移通道,z3代表引伸机通道的端口地址,zyxs,zyxs1,zyx2代表各自的增益,采几点平均投点自定。z代表力值,bz代表部分位移值,ysz代表引伸机值
Case z1 of
0:
dat1:= ad2118(0);
32:
dat1:= ad2118(32);
64:
dat1:= ad2118(64);
96:
dat1: = ad2118(96);
128:
dat1: = ad2118(128);
end;
z: = 10 * dat1 / 4096;
// z: = Format(z / zyxs, "0.#####") 此处格式化输出不太了解。自己查吧。
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;
// 同上 bz := Format(bz / zyxs1, "0.#####");
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;
ysz = Format(ysz / zyxs2, "0.#####")
zy2;

end;

procedure zy();// '调整力值增益
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 zy1();// '调整部分位移增益
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 zy2();
If Abs(ysz) < 0.31249 then
begin
delay (100);
z3: = 130;
zyxs2 := 16;
end;
If Abs(ysz) >= 0.31249 And Abs(bz) < 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 As Integer) : Integer
var h, m, l, da : Integer;
begin
//对端口操作,请查资料
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 delay(dalay_time : Integer)
For nn := 0 To dalay_timedo
Next nn;
End ;
 
安达,谢谢你的“翻译”,但问题仍然存在。我想可能是函数AD2118有问题,
特别是DA:=H*16+L这一行,你可以试着运行一下。调试时可以计算出H*16+L等于4095,
但DA值总是无法与其对应,应该是数据类型问题,可不知道该如何来改写。你有什么建议吗?
 
函数ad2118的函数头中参数是如何定义的,另外,把ad2118:=da 换成result:=da行吗?
 
两种写法好象效果相同,还有什么建议吗?
 
数据采集吗?搞请原理流程后,这不难翻译吧。
不过是dll而已
 
后退
顶部