各位看看这段程序(100分)

  • 主题发起人 主题发起人 JOJO813
  • 开始时间 开始时间
J

JOJO813

Unregistered / Unconfirmed
GUEST, unregistred user!
这是VB写的,100大洋:帮我翻译成DELPHI语言,且能用CPORT控制。
Public Function senddata(lockadr As Integer, lockcmd As Integer, lockdata() As Byte)
Dim bv(18) As Byte
Dim av, checksum, i As Byte
On Error GoTo err1
'ReDim lockdata(9)
receivenum = 0
bv(0) = "&hfe" '头
bv(1) = "&hfa"
bv(2) = "&hfa"
bv(3) = "&hff"
bv(4) = "&h" & lockadr '地址
lockaddress = bv(4)
bv(5) = "&h" & lockcmd '命令
lockcommand = lockcmd
For i = 6 To 15 ' 传送的数据
bv(i) = lockdata(i - 6)
Next
bv(16) = "&hfb" '尾
bv(17) = "&hfb"
checksum = 0
For i = 1 To 17
checksum = checksum + bv(i)
Next i
bv(18) = "&h" & Right(Hex(checksum), 2) '校验位
If MSComm.PortOpen = True Then
MSComm.RTSEnable = False
MSComm.Output = bv
Else
MsgBox "端口未打开", vbInformation, "警告!"
End If
Call delay(0.02)
MSComm.InBufferCount = 0
MSComm.RTSEnable = True
Exit Function
err1: MsgBox "command error"
End Function
 
自己做吧。
 
你在DELPHI下装上mscomm就可以了,代码机会不用怎么改,不要太懒了
 
接受答案了。
 
后退
顶部