wincc读串口(找万泉河版主)

已锁定

小仙女

  • 帖子

    23
  • 精华

    0
  • 被关注

    0

论坛等级:新手

注册时间:2008-10-06

普通 普通 如何晋级?

wincc读串口(找万泉河版主)

703

6

2008-10-21 09:07:46

我用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
wincc读串口(找万泉河版主) 已锁定
编辑推荐: 关闭

请填写推广理由:

本版热门话题

SIMATIC WinCC / Panel

共有32563条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

快扫描右侧二维码晒一晒吧!

再发帖或跟帖交流2条,就能晋升VIP啦!开启更多专属权限!

  • 分享

  • 只看
    楼主

top
您收到0封站内信:
×
×
信息提示
很抱歉!您所访问的页面不存在,或网址发生了变化,请稍后再试。