回复:请问Wincc中采用VBS调用Mscomm控件实现COM端口通讯,Mscomm的Oncomm触发事件应该如何写入?

szy868

  • 帖子

    101
  • 精华

    6
  • 被关注

    18

论坛等级:侠客

注册时间:2006-10-24

普通 普通 如何晋级?

发布于 2007-01-18 11:49:35

0楼

楼主的意思是不是说ONComm事件的处理代码写在何处?
选择MSCOMM控件->属性->事件->对象事件->ONCOMM->"VBS动作"
代码如下:
Sub OnComm(Byval Item)

'此处写入事件处理代码

End Sub

至于书定规则,按VBS语法要求就可以了。

网上的例子确实很少,我提供一段代码供你参考,这是一段处理CDT规约的代码。如果你不懂CDT规约,也不用去管它了,只注意语法就行了。
Sub OnComm(Byval Item)

InitMod()

Dim cnvt
Dim obj_Com
Dim obj_textInput
Dim strInput
Dim strForCheck
Dim byForCheck
Dim bParseResult

Set cnvt = CreateObject("ADs.ArrayConvert")
Set obj_Com = ScreenItems("m_Com")
Set obj_textInput = ScreenItems("txt_Input")

If obj_Com.CommEvent = 2 Then
If obj_Com.InBufferCount > 0 Then
obj_Com.InputLen = obj_Com.InBufferCount
strInput = cnvt.CvOctetStr2vHexStr(obj_Com.Input)
strHInputAll = strHInputAll & strInput
obj_textInput.Text = strHInputAll
End If
If intHFirstSyn = 0 Then
If InStr(1,strHInputAll,strSyn,vbTextCompare) > 0 Then
strHInputAll = Right(strHInputAll , Len(strHInputAll) - InStr(1,strHInputAll,strSyn,vbTextCompare) + 1)
intHFirstSyn = 1
End If
End If

intHSecondSyn = Len(strHInputAll) + 1

If intHFirstSyn = 1 Then
If InStr(2,strHInputAll,strSyn,vbTextCompare) > 0 Then
intHSecondSyn = InStr(2,strHInputAll,strSyn,vbTextCompare)
End If
If intHP = 0 And intHSecondSyn > 24 Then intHP = 24
End If

If intHP >= 24 Then
If intHSecondSyn > intHP + 12 Then
strForCheck = Mid(strHInputAll,intHP + 1,((intHSecondSyn - intHP - 1)\12)*12)
byForCheck = cnvt.CvHexStr2vOctetStr(strForCheck)

bParseResult = CDTHParse(byForCheck)
Select Case bParseResult
Case 1
' HMIRuntime.Trace "OK!" &vbCrLf
Case 0
HMIRuntime.Trace "Length is Error!" &vbCrLf
Case -1
HMIRuntime.Trace "CRC is Error!" &vbCrLf
End Select
intHP = ((intHSecondSyn - 1)\12) * 12
End If
End If

If Len(strHInputAll) > intHSecondSyn Then
strHInputAll = Right(strHInputAll,Len(strHInputAll) - intHSecondSyn +1)
intHP = 0
intHFirstSyn = 0
End If
End If
End Sub
评论
编辑推荐: 关闭

请填写推广理由:

本版热门话题

SIMATIC WinCC / Panel

共有32566条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

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

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

  • 分享

  • 只看
    楼主

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