STEP1:
安装MX Component V4.16S
STEP2:
利用软件自身的向导连接到PLC。此处用LO6的CPU,设置PLC的IP地址为192.168.1.100,设置电脑的IP地址为192.168.1.99。
如图:
Logic Station Number设置为1,注意稍后在VB..net中也要设置为与此相同的逻辑站号。
STEP3;
测试链接。
STEP4:
新建VB.NET项目,添加MX Components的组件。
STEP5:
在工具箱中拖动ActUtlType、AcuSupportMsg两个控件到设计视图。注意将ActLogicalStationNumber设置为1.
STEP6:
双击【读取D 设置Y】按纽,编写如下测试程序。
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Const LOK As Integer = 0
Dim iReturnValue(10) As Integer
Dim iReturnCode As Integer
Dim i As Integer
'打开链接,并判断是否出错
iReturnCode = AxActUtlType1.Open()
If (iReturnCode <> LOK) Then
ACTErr(iReturnCode)
End If
'读取D0至D10的内容到ListBox
iReturnCode = AxActUtlType1.ReadDeviceBlock("D0", 10, iReturnValue(0))
For Each i In iReturnValue
Me.ListBox1.Items.Add(i.ToString)
Next
'置位Y0
iReturnCode = AxActUtlType1.SetDevice("Y0", 0)
'关闭链接,
iReturnCode = AxActUtlType1.Close()
'AxActUtlType1 = Nothing
End Sub
Private Sub ACTErr(ByVal iErrorCode As Long)
Dim iReturnCode As Integer
Dim strMessage As String
iReturnCode = AxActSupportMsg1.GetErrorMessage(iErrorCode, strMessage)
If iReturnCode = 0 Then
'显示出错信息
MsgBox(strMessage, vbExclamation, “MX Components Error")
Else
MsgBox("Errorcode = " & Hex(iReturnCode) & "[Hex]")
End If
End Sub
End Class
STEP7:
事先往PLC的D0至D9填入“111、222”等数据,运行程序,结果如下图。
如果把网线拔掉,则会弹出“连接超时报警”。
附件为各个步骤的截图、源程序、MX Component中文手册。
楼主最近还看过