VB上位组态与ABPLC通过RSlinx之间通信

时间:2022-11-21 05:07:58 作者:壹号 字数:2864字

VB上位组态与ABPLC通过RSlinx之间通信

OPC是一个工业标准,它是由一些世界上著名的自动化系统和硬件、软件公司和Microsoft(微软)紧密合作而建立的。O代表OLE(对象链接和嵌入),P (process过程),C (control控制)。OLE已从面向对象重新定义为基于对象并更名为Active X。OPC的使用是作为一个DCOM在使用,所以OPC客户端可以网络上任一计算机运行,但你必须配置DCOM的访问权限,如果你不想费神,把服务器与客户端都用相同的用户名与密码登录就成了。如果想配置DCOM,请参看DCOM的配置。RSlinx集成的OPC(OLE for process control)服务器使得过程数据可由其它应用程序(OPC客户机)访问。在安装RSlinx时提供了OPC的客户端控件: Rockwell Software OPC Automation(C:\Program Files\Common Files\Rockwell\RsiOPCAuto.dll)本例就是用VB通过对这个控件进行操作,来实现对RSLogix 5000内存标签的读写访问。

第一部分:PLC部分的设置

1, RSlogix Emulate 5000

在第二槽中添加Emulate 5000的仿真CPU。

2, RSLogix 5000 程序的建立

a:I/O配置

b.程序编写

3, RSlinx 的设置

在rslinx中建立OPC服务器,名字为“qin”,如图所示。

4:OPC的结构

第二部分

VB的设置

1,OPC与VB的连接方式

2,在VB中引用OPC Automation

3,OPC的连接,定义全局变量

4,连接OPCSERVER和OPC GROUPS Private Sub OPCServerConnect() Dim ConnectedServerName As String Dim ConnectedNodeName As Variant Dim opcserverName As String Dim OPCNodename As String

opcserverName = OPCNodename =

' Test to see if the User has entered or selected an OPC server name yet if not post a message

If InStr(opcserverName, 'Set error handling for OPC Function 'Create a new OPC Server object

…… 此处隐藏0字 ……

Set ConnectedOPCServer = New OPCServer

'Load the selected server name to start the interface ConnectedServerName = opcserverName

'Load the node name of the connected server. The node name should be entered 'without the use of forward slashes \\. ConnectedNodeName = OPCNodename 'Attempt to connect with the server

ConnectedOPCServer.Connect ConnectedServerName, ConnectedNodeName

' Throughout this example you will see a lot of code that simply enables ' and disables the various controls on the form. The purpose of these ' actions is to demonstrate and insure the proper sequence of events when ' making an OPC connection.

' If we successfully connect to a server allow the user to disconnect

'*********************************************************** '*********************************************************** 'Prepare to add a group to the current OPC Server