奔跑的迷鹿 发表于 2018-10-4 17:08:23

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

啊哈肆 发表于 2019-1-1 00:56:26

真是难得给力的帖子啊。

zyqcat 发表于 2019-4-18 13:33:38

我只是路过打酱油的。

198366809 发表于 2019-4-27 05:15:18

党的好公民,人民的好公仆。。。

497705263 发表于 2019-4-27 09:32:01

感谢{author}无私分享!

owen 发表于 2019-5-17 21:30:10

感谢分享,佩服佩服!

wx_N4Y1VtGh 发表于 2025-11-12 10:11:02

路过打卡,为优质内容疯狂打 call

198366809 发表于 2025-11-14 22:59:57

学到干货了,感谢分享,已火速收藏

xywwh 发表于 2025-11-15 02:55:30

理性围观,感觉大家说的都有道理~

wuxinwl 发表于 2025-11-15 03:15:31

这评论区卧虎藏龙,个个都是人才!
页: [1] 2
查看完整版本: PLC与PC机通讯的VB源程序