![](https://csdnimg.cn/release/download_crawler_static/86592686/bg1.jpg)
提供一个类似的例子,VB 编程应差不多, 不过抱歉 1.)是英文的 2.)是 Rockwell
RSLinx OPC -VB 的例子
Within the VB Development enviroment add a reference to the RSLinx OPC
automation DLL. For
RsLinx Versions lower than 2.30 it is called RsLinxOPCAuto.DLL otherwise it is
called RsiOPCAuto.DLL. This DLL exposes the RSLinx OPC Server automation
interfaces to the client application .
Within your program or class module declare the following objects :
[Dim or Private] WithEvents oServer As OPCServer
[Dim or Private] WithEvents oGroup As OPCGroup
[Dim or Private] oItems As OPCItems
** The WithEvents keyword is used if you want to utilize the Event sink attributes
of the OPCServer and OPCGroup Objects.
The following code illustrates how to connect to the OPC server and create an OPC
group:
set oServer = new OPCServer
oServer.Connect "RSLinx OPC Server"
Set oGroup = oServer.OPCGroups.Add(mvaropcGroup)
oGroup.OPCItems.DefaultAccessPath = mDAccessPath
Set oItems = oGroup.OPCItems
oGroup.IsActive = False
oGroup.IsSubscribed = True
oGroup.UpdateRate = 250
** The Default access path is a string that contains the name of a valid DDE/OPC
topic that has been created in RSLinx and points to appropriate controller (Softlogix or
ControlLogix). This access path applies to all
items within a specific group. To specify individual paths per item use the following
syntax: [Path]Tag Name for each item.
** to see the Interfaces/objects exposed by the RSLinx OPC Automation DLL use
the VB Object browser.
Next you need to add OPC items to the created OPCGroup.
These items represent PLC tags and should follow the Allen-Bradley naming
conventions eg. PLC-5 N7:0 or N7:0,L10 (specifies an array of ten contigious elements).
This is accomplished by utilizing the "oGroup.OpcItems.AddItems" function. It is