登录
首页 PLC论坛 PLC论坛
回帖 发帖
正文

主题:[求助]谁有用VB访问PLC读取数据的完整的源程序?

点击:2738 回复:4

刚接触PLC,又有急用,请各们大人不吝赐教!~~~~~
谢谢
05-03-29 15:32
Private Sub Command4_Click()
   '单通道发送区代码
On Error GoTo PortError
If Shape1.FillColor = RGB(0, 255, 0) Then
MsgBox "PLC在运行状态不能修改"
Else
Timer1.Enabled = False
Dim Inputstr As String
Inputstr = Text2.Text           '输入通道地址及修改值
Data = Inputstr
outdata = "@00WD" + Data
L = Len(outdata)
fcs = 0
For i = 1 To L
fcs1 = fcs1 Xor Asc(Mid(outdata, i, 1))
Next i
fcs = Hex(fcs1)
Dim Instring As String
frmMain.MSComm1.CommPort = 2
frmMain.MSComm1.Settings = "9600,E,7,2"
frmMain.MSComm1.InputLen = 0
frmMain.MSComm1.PortOpen = True
frmMain.MSComm1.Output = outdata + fcs + "*" + Chr$(13)
Do
 DoEvents
 Loop Until frmMain.MSComm1.InBufferCount >= 10
 Instring = frmMain.MSComm1.Input
 frmMain.MSComm1.PortOpen = False
 If Mid(Instring, Len(Instring) - 1, 1) <> "*" Then
 MsgBox "通讯出错"
 Else
 fcs2 = 0
 For i = 1 To Len(Instring) - 4
 fcs2 = fcs2 Xor Asc(Mid(Instring, i, 1))
 Next i
 fcs3 = Hex(fcs2)
 If (fcs3) = Mid(Instring, Len(Instring) - 3, 2) Then
   MsgBox "·发送成功"
   Else
   MsgBox "通讯出错"
   End If
   End If
   Timer1.Enabled = True
  End If
PortError:                             '错误处理
   Select Case Err.Number
       Case 8005
           MsgBox ("该串口正在使用,请等待!!")
   End Select
End Sub
05-03-30 13:55
谢谢~~~~~~
要想学这类的编程应当看些什么样的书啊?
05-03-31 18:08
你的是omron的plc吗?
哈哈
05-03-31 20:37
用的是: 西门子PLC:选用西门子S7-400 PLC 控制系统,西门子STEP 7 编程软件
05-04-01 17:25

工控新闻

更多新闻资讯