AFConnection Class
- Last UpdatedNov 18, 2025
- 8 minute read
- PI System
- AF SDK 2024 R2
- Developer
The AFConnection represents a connection between the
AFPort objects of two AFBaseElement objects
in a model.

Inheritance Hierarchy
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
| Name | Description | |
|---|---|---|
| Database |
This read-only property returns the AFDatabase where this object is defined.
| |
| Destination |
This property returns the AFBaseElement object which is the connection's destination.
| |
| DestinationPort |
This property returns the destination AFPort for the connection.
| |
| 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.) | |
| Identity |
This read-only property contains identity of the object.
(Inherited from AFObject.) | |
| IsDeleted |
This read-only property indicates whether the object has been deleted.
(Inherited from AFObject.) | |
| Model |
This read-only property returns the model that owns this object.
| |
| PISystem |
This read-only property allows access to the PISystem associated with this
object.
(Inherited from AFObject.) | |
| Source |
This property returns the AFBaseElement object which is the connection's source.
| |
| SourcePort |
This property returns the source AFPort for the connection.
| |
| UniqueID |
Read-only property that provides the object's ID as a String.
(Inherited from AFObject.) |
Methods
| Name | Description | |
|---|---|---|
| CompareTo(Object) |
Compares this instance with a specified Object.
(Overrides AFObjectCompareTo(Object).) | |
| CompareTo(AFConnection) |
Compares this instance with a specified AFConnection.
| |
| CompareTo(AFObject) |
Compares this instance with a specified AFObject.
(Inherited from AFObject.) | |
| Equals(Object) |
Determines whether the specified Object is equal to the current object.
(Overrides AFObjectEquals(Object).) | |
| Equals(AFConnection) |
Indicates whether the current object is equal to another object of the same type.
| |
| Equals(AFObject) |
Indicates whether the current object is equal to another object of the same type.
(Inherited from AFObject.) | |
| 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.) | |
| GetPath |
Returns the full path to the object, using just the names.
(Inherited from AFObject.) | |
| GetPath(AFObject) |
Returns the path to the object relative from another object.
(Inherited from AFObject.) | |
| 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.) | |
| GetType | Gets the Type of the current instance. (Inherited from Object.) | |
| Persist |
This method returns the persistence string for the object.
(Inherited from AFObject.) | |
| ToString |
Returns a String that represents the current object.
(Overrides AFObjectToString.) |
Operators
| Name | Description | |
|---|---|---|
| Equality |
The equality operator (==) compares its operands to determine if they are equal.
| |
| GreaterThan |
The greater than relation operator (>) compares its operands to determine
which one is greater than the other.
| |
| GreaterThanOrEqual |
The greater than or equal relation operator (>=) compares its operands to determine
which one is greater than or equal to the other.
| |
| Inequality |
The inequality operator (!=) compares its operands to determine if they are not equal.
| |
| LessThan |
The less than relation operator (<) compares its operands to determine
which one is less than the other.
| |
| 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.