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
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