PLC与PC机通讯的VB源程序
分类:创业故事 热度:

PLC与PC机通讯的VB源程序

PLC与PC机通讯的VB源程序大体如下:我采用的是FX232BD通讯模块,协议就是FX通讯协议。

强制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

强制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

强制Y0为1

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

End Sub

强制Y0为0

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

End Sub

设置电脑通信参数

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

上一篇:ABB将为重庆页岩气提供数据采集与监控系统 下一篇:没有了
猜你喜欢
热门排行
精彩图文