Visavi Visual OPC .NET  

OpcConnection Class

Represents a connection to an OPC Server. The OPC Connection implements the IOpcConnection interface.

For a list of all members of this type, see  OpcConnection Members.

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         Visavi.Opc.Client.OpcConnection

[Visual Basic]
 Public Class OpcConnection
   Inherits Component
   Implements IOpcConnection
[C#]
 public class OpcConnection: Component, IOpcConnection
[C++]
 public __gc class OpcConnection : public Component,
   IOpcConnection
[JScript]
public class OpcConnection extends Component implements IOpcConnection

Thread Safety

Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.

Remarks

The OpcConnection class allows you to connnect to OPC servers. The OpcConnection class is typically added to forms to connect to one or more items of an OPC Server . For example, you could add the OpcConnection component to a form, specify the OPC Server and ItemID you wish to bind with and implement the ItemRuntimeChange event to fill in a TextBox of the items's current value. In addition to reading and updating items on the form, you may use the OpcConnection class to write out values to those same items.

The OpcConnection class provides properties that specify to which OPC Server to connect, when to connect to that server, and the OPC groups to add to the server after the connection is made. The ServerIdentifier property identifies the server to which the connection will be made. Using the designer's property grid, you may browse your network for the server, or you may type in a URI type string that identifies the server. The ConnectionScheme property determines when the client connects to the server (i.e. Runtime only, Design-time only, Manually, etc.). The Groups property is the collection of groups that will be added after the OPC connection is made. These groups represent OPC Server groups and contain the ItemIDs to which the OpcConnection object will subscribe.

The OpcConnection class can be used in any container. To specify a specific container to use the  OpcConnection class within, use the OpcConnection constructor.

Example

[Visual Basic, C#]
The following example creates a connection to the PV, SP, and CO of Loop 2 in Visavi's OPC Simulation Server.

[C#] 
public OpcConnection CreateOpcConnection()
{
    OpcConnection myOpcConnection = new OpcConnection();
    myOpcConnection.ServerIdentifier = new Visavi.ResourceIdentifier("dcom://localhost:0/Visavi.OpcSimulation.1");
    myOpcConnection.Groups.Add("myGroupName");
    myOpcConnection.Groups[0].Items.Add("Process Loops.Loop 2.SP");
    myOpcConnection.Groups[0].Items.Add("Process Loops.Loop 2.PV");
    myOpcConnection.Groups[0].Items.Add("Process Loops.Loop 2.CO");
    myOpcConnection.ItemRuntimeChange += new ItemRuntimeChangeDelegate(OnMyOpcConnectionChange);
	
    return myOpcConnection;
}

private void OnMyOpcConnectionChange(object source, ItemArgs args)
{
    // handle OPC Item data changes here
}

[Visual Basic] 
Friend WithEvents myOpcConnection As Visavi.Opc.Client.OpcConnection
			
Public Sub CreateOpcConnection()
    OpcConnection myOpcConnection = New OpcConnection();
    myOpcConnection.ServerIdentifier = New Visavi.ResourceIdentifier("dcom://localhost:0/Visavi.OpcSimulation.1");
    myOpcConnection.Groups.Add("myGroupName");
    myOpcConnection.Groups[0].Items.Add("Process Loops.Loop 2.SP");
    myOpcConnection.Groups[0].Items.Add("Process Loops.Loop 2.PV");
    myOpcConnection.Groups[0].Items.Add("Process Loops.Loop 2.CO");
End Sub

Private Sub myOpcConnection_ItemRuntimeChange(ByVal source As Object, ByVal args As Visavi.Opc.Client.ItemArgs) Handles myOpcConnection.ItemRuntimeChange
    ' handle OPC Item data changes here
End Sub

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: Visavi.Opc.Client

Platforms:  Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows .NET Server family

Assembly: Visavi.Opc.Client

See Also

OpcConnection Members | Visavi.Opc.Client Namespace