我用wincc读串口数据,仪表在收到我从wincc发出的指令后会发出25个字节的十六进制数,但是我用按钮做测试时,按下按钮时,得不到25个字节.我的mscomm1.inputlen=25.我的脚本如下:Sub OnComm(ByVal Item)
'On Error Resume Next
Dim text1
Dim text2
Dim text3
Dim text4
Set text4=ScreenItems("控件5")
Set text3=ScreenItems("控件4")
Set text1=ScreenItems("控件2")
Set text2=ScreenItems("控件3")
HMIRuntime.Trace "OnComm...." & CStr(Now())& vbCrLf
'If item.CommEvent=2 Then
Dim intInputLen
intInputLen = item.InBufferCount
If intInputLen<1 Then Exit Sub
'End If
Dim ADS
Set ADS = CreateObject("ADs.ArrayConvert")
Dim CharV
Dim OctV
Dim HexV
Dim tex
tex=""
CharV=Item.Input
' Do
' DoEvents
' Loop Until .InBufferCount = 25
'HMIRuntime.Trace "CharV is :" & CStr(CharV) & vbCrLf
OctV=ads.CvStr2vOctetStr(CharV)
'MsgBox("yes5")
text1.Text =CStr(OctV)
'MsgBox("yes6")
' HMIRuntime.Trace "OctV is :" & CStr(OctV) & vbCrLf
'MsgBox("yes7")
HexV=ads.CvOctetStr2vHexStr(OctV)
MsgBox("yes8")
tex=tex&CStr(HexV)
text2.Text =tex
MsgBox("yes9")
text4.Text =Len(HexV)
'HMIRuntime.Trace "HexV is :" & CStr(HexV) & vbCrLf
'End If
If Len(HexV)=10 Then
Dim str(4),strFloat
str(0)=Mid(HexV,7,2)
str(1)=Mid(HexV,5,2)
str(2)=Mid(HexV,3,2)
str(3)=Mid(HexV,1,2)
str(4)=Mid(HexV,9,2)
strFloat=str(0)&str(1)&str(2)&str(3)&"."&str(4)
HMIRuntime.Trace "strFloat is :" & CStr(strFloat) & vbCrLf
Dim vFloat
vFloat=CDbl(strFloat)
text3.Text =CStr(vFloat)
HMIRuntime.Trace "vFloat is :" & CStr(vFloat) & vbCrLf
End If
End Sub