打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
WinCC 通过VBS脚本进行串口通讯
PLC价格还要缺货多久?
电气人上哪儿接单靠谱?    

(一)打开端口

(1)代码图片

(2)VBS代码

Sub OnClick(Byval Item)     

       DimobjMSComm1, tagConnection

       SetobjMSComm1 = HMIRuntime.Screens("Main").ScreenItems("MSComm1")

       SettagConnection = HMIRuntime.Tags("Connection")

       IfobjMSComm1.PortOpen = False Then

              'Assign com port number

              objMSComm1.Commport= 1

              'Values: 9600 Baud, N - No Parity, 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("Portis already opened." & vbCrLf)

       EndIf

End Sub

(二)读Buffer

(1)代码图片

(2)VBS代码

Option Explicit

Function action

       DimstrBuffer, strTemp

       DimobjMSComm1, tagBuffer

       SetobjMsComm1 = HMIRuntime.Screens("Main").ScreenItems("MSComm1")

       SettagBuffer  =HMIRuntime.Tags("Buffer")

       strTemp= ""

       IfobjMSComm1.PortOpen = True Then

              'readthe buffer

              strTemp= CStr(objMSComm1.Input)

              IfstrTemp <> "" Then

                     'checkingfor the delimited character

                     IfInStr(strTemp, Chr(6)) Then

                            strBuffer= Left(strTemp,Len(strTemp)-1)

                     Else

                            strBuffer= strTemp

                     EndIf

                     tagBuffer.Value= strBuffer

                     tagBuffer.Write

              EndIf

       Else

              HMIRuntime.Trace("Noport is opened!" & vbCrLf)

       EndIf

End Function

(三)发送数据

(1)代码图片

(2)VBS代码

Sub OnClick(ByVal Item) 

       DimtagOutput, objMSComm1

       SettagOutput = HMIRuntime.Tags("Output")

       SetobjMSComm1 = HMIRuntime.Screens("Main").ScreenItems("MSComm1")

       IfobjMSComm1.PortOpen = True Then

              tagOutput.Read

              objMSComm1.Output= tagOutput.Value

              tagOutput.Write("")

       Else

              HMIRuntime.Trace("Noport is opened!" & vbCrLf)

       EndIf

End Sub

(四)关闭端口

(1)代码图片

 (2)VBS代码

Sub OnClick(Byval Item)  

       DimobjMSComm1, tagConnection

       SetobjMSComm1 = HMIRuntime.Screens("Main").ScreenItems("MSComm1")

       SettagConnection = HMIRuntime.Tags("Connection")

       IfobjMSComm1.PortOpen = True Then     

              objMSComm1.PortOpen= False

              tagConnection.Write(False)

              HMIRuntime.Trace("Portclose." & vbCrLf)

       EndIf

End Sub



大家都在看



【视频】德国工程师是如何制作PLC柜的?

【视频】德国威图电气柜是如何生产出的?

【视频】德国工程师的办公环境是怎样的?

【视频】PROFINET为何比PROFIBUS更牛?

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
博图WINCC 水流动画和电机风叶旋转
按键精灵 TXT文件用法大全 (源码) (免费!)
WinCC 使用VBS脚本读变量
VBS整人代码
VBS脚本病毒特点 原理分析以及如何防范
分享vbs脚本办事的乐趣
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服