预览加载中,请您耐心等待几秒...
1/3
2/3
3/3

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

WinCC通过VBS脚本进行串口通讯 一、打开端口 SubOnClick(ByvalItem) DimobjMSComm1,tagConnection SetobjMSComm1=HMIRuntime.Screens("Main").ScreenItems("MSComm1") SettagConnection=HMIRuntime.Tags("Connection") IfobjMSComm1.PortOpen=FalseThen 'Assigncomportnumber objMSComm1.Commport=1 'Values:9600Baud,N-NoParity,8-Databit,1-Stopbit objMSComm1.Settings="9600,N,8,1" objMSComm1.RThreshold=1 objMSComm1.SThreshold=1 objMSComm1.InputLen=0 objMSComm1.PortOpen=True tagConnection.Write(True) HMIRuntime.Trace("Portopen."&vbCrLf) Else HMIRuntime.Trace("Portisalreadyopened."&vbCrLf) EndIf EndSub 二、读Buffer OptionExplicit Functionaction DimstrBuffer,strTemp DimobjMSComm1,tagBuffer SetobjMsComm1=HMIRuntime.Screens("Main").ScreenItems("MSComm1") SettagBuffer=HMIRuntime.Tags("Buffer") strTemp="" IfobjMSComm1.PortOpen=TrueThen 'readthebuffer strTemp=CStr(objMSComm1.Input) IfstrTemp<>""Then 'checkingforthedelimitedcharacter IfInStr(strTemp,Chr(6))Then strBuffer=Left(strTemp,Len(strTemp)-1) Else strBuffer=strTemp EndIf tagBuffer.Value=strBuffer tagBuffer.Write EndIf Else HMIRuntime.Trace("Noportisopened!"&vbCrLf) EndIf EndFunction 三、发送数据 SubOnClick(ByValItem) DimtagOutput,objMSComm1 SettagOutput=HMIRuntime.Tags("Output") SetobjMSComm1=HMIRuntime.Screens("Main").ScreenItems("MSComm1") IfobjMSComm1.PortOpen=TrueThen tagOutput.Read objMSComm1.Output=tagOutput.Value tagOutput.Write("") Else HMIRuntime.Trace("Noportisopened!"&vbCrLf) EndIf EndSub 四、关闭端口 SubOnClick(ByvalItem) DimobjMSComm1,tagConnection SetobjMSComm1=HMIRuntime.Screens("Main").ScreenItems("MSComm1") SettagConnection=HMIRuntime.Tags("Connection") IfobjMSComm1.PortOpen=TrueThen objMSComm1.PortOpen=False tagConnection.Write(False) HMIRuntime.Trace("Portclose."&vbCrLf) EndIf EndSub