您现在所在的是:

PLC论坛

回帖:3个,阅读:4754 [上一页] [1] [下一页]
905
jackyliu9025
文章数:1
年度积分:50
历史总积分:905
注册时间:2003/11/8
发站内信
发表于:2003/11/26 18:37:00
#0楼
我这里与一段读和写的部分代码(哪位老兄帮我看看有什么问题?)
Public Function read_db(ByVal pntNumber As String, _
ByVal Order As String, ByVal startAddress As String, _
ByVal Lengh As Integer, ByRef value() As Single, ByVal Gdlength As Integer)
Dim outstring As String
MSComm1.InBufferCount = 0 'clear off  inbuffer
Order = UCase(Order)      '命令大写
keyorder = startAddress   '首地址
If Lengh > Gdlength Then
   Lengh = Gdlength
End If
outstring = "@" + pntNumber + Order + keyorder + "00" + Trim(Str(Lengh))
fcdd$ = XORR(outstring)
outstring = outstring + fcdd$ + "*" + Chr$(13)
MSComm1.Output = outstring
Time_out = Timer

'判断通讯错误
Do
   If Timer > (Time_out + 1) Then
       ERROR_COM = True
   Else
       ERROR_COM = False
   End If
   DoEvents
Loop Until ((MSComm1.InBufferCount >= 11 + 4 * Lengh) Or (ERROR_COM = True))
Instring = MSComm1.Input
order1 = Mid(Instring, 6, 2)  '结束码
Call ErrMessage(order1)

For i = 0 To Lengh - 1
   zhancun = Mid(Instring, 8 + i * 4, 4)   '取出数据位
'    value(I) = Revert(zhancun)
   value(i) = Val(zhancun)
Next
End Function


Public Sub Write_dbserver(ByVal pntNumber As String, _
ByVal Order As String, ByVal startAddress As String, _
ByVal Lengh As Integer, ByRef value As Single)

CmdEnable False
MSComm1.InBufferCount = 0
If Lengh > 8 Then
Lengh = 8
End If
Order = UCase(Order)
outstring = "@" + pntNumber + Order + "0" + startAddress


outstring = outstring + four_bit(value)

fcdd$ = XORR(outstring)
outstring = outstring + fcdd$ + "*" + Chr$(13)
MSComm1.Output = outstring
Time_out = Timer
Do
If Timer > (Time_out + 1) Then
ERROR_COM = True
Else
ERROR_COM = False
End If
DoEvents
Loop Until ((MSComm1.InBufferCount >= 11) Or (ERROR_COM = True))
Instring = MSComm1.Input
endcode = Mid(Instring, 6, 2)
Call ErrMessage(endcode)
CmdEnable True
End Sub

我主要是想问这两个函数实时监控时有时候会出现问题(不正确的数据).
哪位帮帮忙,帮忙改一下。
4061
利昌機電 版主
文章数:2023
年度积分:50
历史总积分:4061
注册时间:2003/10/26
发站内信
发表于:2003/11/26 20:26:00
#1楼
图
969
CuZn
文章数:23
年度积分:50
历史总积分:969
注册时间:2003/9/23
发站内信
发表于:2003/11/27 13:58:00
#2楼
原来是这里,谢谢!
1271
sea_horse2000
文章数:192
年度积分:50
历史总积分:1271
注册时间:2002/11/8
发站内信
发表于:2003/11/28 10:47:00
#3楼
OK!顶!

关于我们 | 联系我们 | 广告服务 | 本站动态 | 友情链接 | 法律声明 | 非法和不良信息举报

工控网客服热线:0755-86369299
版权所有 工控网 Copyright©2024 Gkong.com, All Rights Reserved

62.4004