目的:通过MSComm控件实现WINCC串口通讯(C脚本和VB脚本两种方式)
测试环境:操作系统 win7
WINCC版本:V7.2
辅助工具:串口调试工具
ASPD虚拟串口工具
测试WINCC组态画面:

测试实验过程画面:

1、通过VB实现串口通讯
画面对象“打开画面”VB事件脚本:
Sub OnOpen()
Dim objMSComm, tagConnection
Set objMSComm = hmiRuntime.Screens("串口通讯VB版").ScreenItems("COM")
Set tagConnection = HMIRuntime.Tags("tagConnection1")
If objMSComm.PortOpen = False Then
' Assign com port number
objMSComm.Commport = 4
' Values: 9600 Baud, N - No Parity, 8 - Databit, 1 - Stopbit
objMSComm.Settings = "9600,N,8,1"
objMSComm.RThreshold = 1
objMSComm.SThreshold = 0
objMSComm.InBufferCount = 0
objMSComm.InputLen = 0
objMSComm.PortOpen = True
tagConnection.Write (True)
HMIRuntime.Trace("Port open."