《電子技術(shù)應(yīng)用》
您所在的位置:首頁 > 模擬設(shè)計(jì) > 設(shè)計(jì)應(yīng)用 > PLC與PC機(jī)通訊的VB源程序
PLC與PC機(jī)通訊的VB源程序
摘要: PLC與PC機(jī)通訊的VB源程序大體如下:我采用的是FX232BD通訊模塊,協(xié)議就是FX通訊協(xié)議。
關(guān)鍵詞: 接口IC PLC VB 通訊
Abstract:
Key words :

PLC與PC機(jī)通訊VB源程序

PLC與PC機(jī)通訊的VB源程序大體如下:我采用的是FX232BD通訊模塊,協(xié)議就是FX通訊協(xié)議。

強(qiáng)制PLC為RUN

Private Sub command1_Click()
   Dim dat As String
   commli.OutBufferCount = 0
    commli.InBufferCount = 0
           dat = "01FFRR0"
    commli.Output = Chr$(5) + dat + SumChk(dat)
   
End Sub

強(qiáng)制PLC為STOP

Private Sub command2_Click()
   Dim dat As String
   commli.OutBufferCount = 0
   commli.InBufferCount = 0
   dat = "01FFRS0"
   commli.Output = Chr$(5) + dat + SumChk(dat)
   
End Sub

強(qiáng)制Y0為1

 

Private Sub command3_Click()
   Dim dat As String
   commli.OutBufferCount = 0
   commli.InBufferCount = 0
   commli.Output = “01FFBW0Y001011”
   
End Sub

強(qiáng)制Y0為0

Private Sub command3_Click()
   Dim dat As String
   commli.OutBufferCount = 0
   commli.InBufferCount = 0
   commli.Output = “01FFBW0Y001010”
   
End Sub

設(shè)置電腦通信參數(shù)

Private Sub Commlis()
  
    If commli.PortOpen = True Then
        commli.PortOpen = False
    End If
    If Not commli.PortOpen Then
        commli.CommPort = 1 ''通信口
        commli.Settings = "9600,N,8,1"
        commli.Handshaking = 0
        commli.InputLen = 0
        commli.OutBufferCount = 0
        commli.InBufferCount = 0
        commli.PortOpen = True
    End If
    Exit Sub

   
End Sub
Private Function SumChk(Dats$) As String
    Dim i&
    Dim CHK&
    For i = 1 To Len(Dats)
        CHK = CHK + Asc(Mid(Dats, i, 1))
    Next i
 
    SumChk = Right(Hex$(CHK), 2)
End Function

此內(nèi)容為AET網(wǎng)站原創(chuàng),未經(jīng)授權(quán)禁止轉(zhuǎn)載。