小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

WinCC 通過VBS腳本進行串口通訊

 工控庫吧 2021-12-08
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

(三)發(fā)送數(shù)據(jù)

(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

(四)關(guān)閉端口

(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柜的?

【視頻】德國威圖電氣柜是如何生產(chǎn)出的?

【視頻】德國工程師的辦公環(huán)境是怎樣的?

【視頻】PROFINET為何比PROFIBUS更牛?

    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多