kaiyun官方注册
您所在的位置: 首页> 模拟设计> 设计应用> PLC与PC机通讯的VB源程序
PLC与PC机通讯的VB源程序
摘要:PLC与PC机通讯的VB源程序大体如下:我采用的是FX232BD通讯模块,协议就是FX通讯协议。
关键词: 接口IC PLC VB 通讯
Abstract:
Key words :

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

此内容为AET网站原创,未经授权禁止转载。
Baidu
map