Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AF SDK Reference

AFConnection Class

  • Last UpdatedNov 18, 2025
  • 8 minute read
AFConnection Class
The AFConnection represents a connection between the AFPort objects of two AFBaseElement objects in a model.

Inheritance Hierarchy

SystemObject
  OSIsoft.AFAFObject
    OSIsoft.AF.ModelingAFConnection

Namespace:  OSIsoft.AF.Modeling
Assembly:  OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182

Syntax

[SerializableAttribute]
public sealed class AFConnection : AFObject, 
	IComparable<AFConnection>, IEquatable<AFConnection>
<SerializableAttribute>
Public NotInheritable Class AFConnection
	Inherits AFObject
	Implements IComparable(Of AFConnection), IEquatable(Of AFConnection)

Dim instance As AFConnection
[SerializableAttribute]
public ref class AFConnection sealed : public AFObject, 
	IComparable<AFConnection^>, IEquatable<AFConnection^>
[<SealedAttribute>]
[<SerializableAttribute>]
type AFConnection =  
    class
        inherit AFObject
        interface IComparable<AFConnection>
        interface IEquatable<AFConnection>
    end

The AFConnection type exposes the following members.

Properties

  NameDescription
Public property
Database
This read-only property returns the AFDatabase where this object is defined.
Public property
Destination
This property returns the AFBaseElement object which is the connection's destination.
Public property
DestinationPort
This property returns the destination AFPort for the connection.
Public property
ID
Read-only property that provides a unique identifier for the object to be used for quick access that is not dependent upon the index.
(Inherited from AFObject.)
Public property
Identity
This read-only property contains identity of the object.
(Inherited from AFObject.)
Public property
IsDeleted
This read-only property indicates whether the object has been deleted.
(Inherited from AFObject.)
Public property
Model
This read-only property returns the model that owns this object.
Public property
PISystem
This read-only property allows access to the PISystem associated with this object.
(Inherited from AFObject.)
Public property
Source
This property returns the AFBaseElement object which is the connection's source.
Public property
SourcePort
This property returns the source AFPort for the connection.
Public property
UniqueID
Read-only property that provides the object's ID as a String.
(Inherited from AFObject.)

Methods

  NameDescription
Public method
CompareTo(Object)
Compares this instance with a specified Object.
(Overrides AFObjectCompareTo(Object).)
Public method
CompareTo(AFConnection)
Compares this instance with a specified AFConnection.
Public method
CompareTo(AFObject)
Compares this instance with a specified AFObject.
(Inherited from AFObject.)
Public method
Equals(Object)
Determines whether the specified Object is equal to the current object.
(Overrides AFObjectEquals(Object).)
Public method
Equals(AFConnection)
Indicates whether the current object is equal to another object of the same type.
Public method
Equals(AFObject)
Indicates whether the current object is equal to another object of the same type.
(Inherited from AFObject.)
Public method
GetHashCode
Gets the hash code for this instance of the object which is suitable for use in hashing algorithms and data structures like a hash table.
(Overrides AFObjectGetHashCode.)
Public method
GetPath
Returns the full path to the object, using just the names.
(Inherited from AFObject.)
Public method
GetPath(AFObject)
Returns the path to the object relative from another object.
(Inherited from AFObject.)
Public method
GetPath(AFEncodeType, AFObject)
Returns the path to the object relative from another object, using the name and/or id as specified by encodeType.
(Inherited from AFObject.)
Public method
GetType
Gets the Type of the current instance.
(Inherited from Object.)
Public method
Persist
This method returns the persistence string for the object.
(Inherited from AFObject.)
Public method
ToString
Returns a String that represents the current object.
(Overrides AFObjectToString.)

Operators

  NameDescription
Public operatorStatic member
Equality
The equality operator (==) compares its operands to determine if they are equal.
Public operatorStatic member
GreaterThan
The greater than relation operator (>) compares its operands to determine which one is greater than the other.
Public operatorStatic member
GreaterThanOrEqual
The greater than or equal relation operator (>=) compares its operands to determine which one is greater than or equal to the other.
Public operatorStatic member
Inequality
The inequality operator (!=) compares its operands to determine if they are not equal.
Public operatorStatic member
LessThan
The less than relation operator (<) compares its operands to determine which one is less than the other.
Public operatorStatic member
LessThanOrEqual
The less than or equal relation operator (<=) compares its operands to determine which one is less than or equal to the other.

Remarks

A connection is created by calling one of the AFConnections.Add Overload methods and specifying the elements and ports to be connected.

Examples

// This example demonstrates how to connect and disconnect elements.
// Note: This example assumes that there is a database called "Chocolate Milk Tutorial"
// containing elements named "MilkTank1" and "MilkTank2" each with input/output ports,
// as well as an ElementTemplate named "Flow"

// Get the Database
PISystems myPISystems = new PISystems();
AFDatabase myDB = myPISystems.DefaultPISystem.Databases["Chocolate Milk Tutorial"];

// Create a Model
AFElementTemplate modelTempl = myDB.ElementTemplates.Add("ModelTemplate");
modelTempl.InstanceType = typeof(AFModel);
AFModel myModel = myDB.Elements.Add("MyModel", modelTempl) as AFModel;
myModel.Description = "This Model represents a manufacturing facility";

// Get the Elements
AFElement srcElement = myDB.Elements["MilkTank1"];
AFElement destElement = myDB.Elements["MilkTank2"];
AFElement flowElement = myDB.Elements.Add("Flow", myDB.ElementTemplates["Flow"]);
myDB.ApplyChanges();

// Add Elements to Model
myModel.Elements.Add(srcElement);
myModel.Elements.Add(destElement);
myModel.Elements.Add(flowElement);

// Connect the Elements
AFConnection conn1 = myModel.Connections.Add(srcElement.DefaultOutputPort,
    flowElement.DefaultInputPort);
AFConnection conn2 = myModel.Connections.Add(flowElement.DefaultOutputPort,
    destElement.DefaultInputPort);

// Display Information about each Connection
Console.WriteLine("Connection Count = {0}", myModel.Connections.Count);
foreach (AFConnection CurConn in myModel.Connections)
{
    Console.WriteLine("Name of Model = {0}", CurConn.Model.Name);
    Console.WriteLine("Source = {0}", CurConn.Source);
    Console.WriteLine("Source Port = {0}", CurConn.SourcePort);
    Console.WriteLine("Destination = {0}", CurConn.Destination);
    Console.WriteLine("Destination Port = {0}", CurConn.DestinationPort);
}
' This example demonstrates how to connect and disconnect elements.
' Note: This example assumes that there Is a database called "Chocolate Milk Tutorial"
' containing elements named "MilkTank1" And "MilkTank2" each with input/output ports,
' as well as an ElementTemplate named "Flow"

' Get the Database
Dim myPISystems As New PISystems
Dim myDB As AFDatabase = myPISystems.DefaultPISystem.Databases("Chocolate Milk Tutorial")

' Create a Model
Dim modelTempl As AFElementTemplate = myDB.ElementTemplates.Add("ModelTemplate")
modelTempl.InstanceType = GetType(AFModel)
Dim myModel As AFModel = CType(myDB.Elements.Add("MyModel", modelTempl), AFModel)
myModel.Description = "This Model represents a manufacturing facility"

' Get the Elements
Dim srcElement As AFElement = myDB.Elements("MilkTank1")
Dim destElement As AFElement = myDB.Elements("MilkTank2")
Dim flowElement As AFElement = myDB.Elements.Add("Flow", myDB.ElementTemplates("Flow"))
myDB.ApplyChanges()

' Add Elements to Model
myModel.Elements.Add(srcElement)
myModel.Elements.Add(destElement)
myModel.Elements.Add(flowElement)

' Connect the Elements
Dim conn1 As AFConnection = myModel.Connections.Add(srcElement.DefaultOutputPort,
    flowElement.DefaultInputPort)
Dim conn2 As AFConnection = myModel.Connections.Add(flowElement.DefaultOutputPort,
    destElement.DefaultInputPort)

'Display Information about each Connection
Console.WriteLine("Connection Count = {0}", myModel.Connections.Count)
Dim CurConn As AFConnection
For Each CurConn In myModel.Connections
    Console.WriteLine("Name of Model = {0}", CurConn.Model.Name)
    Console.WriteLine("Source = {0}", CurConn.Source)
    Console.WriteLine("Source Port = {0}", CurConn.SourcePort)
    Console.WriteLine("Destination = {0}", CurConn.Destination)
    Console.WriteLine("Destination Port = {0}", CurConn.DestinationPort)
Next CurConn

No code example is currently available or this language may not be supported.

No code example is currently available or this language may not be supported.

Version Information

AFSDK


See Also

TitleResults for “How to create a CRG?”Also Available in