发表于: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
我主要是想问这两个函数实时监控时有时候会出现问题(不正确的数据).
哪位帮帮忙,帮忙改一下。
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
我主要是想问这两个函数实时监控时有时候会出现问题(不正确的数据).
哪位帮帮忙,帮忙改一下。