发表于:2008/1/14 17:59:00
#0楼
我的程序代码如下,显示时有时数据为空。
Private Sub Timer1_Timer()
Label1.Caption = Word_Read(MSComm1, FindAddrWord("D130"))
Label2.Caption = Word_Read(MSComm1, FindAddrWord("D131"))
Label3.Caption= Word_Read(MSComm1, FindAddrWord("D132"))
Label4.Caption = Word_Read(MSComm1, FindAddrWord("D133"))
Label5.Caption = Word_Read(MSComm1, FindAddrWord("D134"))
End Sub
Public Function FindAddrWord(sName As String) As String
Dim strTagType As String
Dim strTmp As String
strTagType = Left$(sName, 1)
strTmp = Right$(sName, Len(sName) - 1)
Select Case UCase(strTagType)
Case "C"
FindAddrWord = "0" + Hex(Val(strTmp) * 2 + 2560)
Case "T"
FindAddrWord = "0" + Hex(Val(strTmp) * 2 + 2048)
Case "D"
FindAddrWord = Hex(Val(strTmp) * 2 + 4096)
End Select
Exit Function
End Function
Private Sub Timer1_Timer()
Label1.Caption = Word_Read(MSComm1, FindAddrWord("D130"))
Label2.Caption = Word_Read(MSComm1, FindAddrWord("D131"))
Label3.Caption= Word_Read(MSComm1, FindAddrWord("D132"))
Label4.Caption = Word_Read(MSComm1, FindAddrWord("D133"))
Label5.Caption = Word_Read(MSComm1, FindAddrWord("D134"))
End Sub
Public Function FindAddrWord(sName As String) As String
Dim strTagType As String
Dim strTmp As String
strTagType = Left$(sName, 1)
strTmp = Right$(sName, Len(sName) - 1)
Select Case UCase(strTagType)
Case "C"
FindAddrWord = "0" + Hex(Val(strTmp) * 2 + 2560)
Case "T"
FindAddrWord = "0" + Hex(Val(strTmp) * 2 + 2048)
Case "D"
FindAddrWord = Hex(Val(strTmp) * 2 + 4096)
End Select
Exit Function
End Function
[此贴子已经被作者于2008-1-14 18:13:42编辑过]