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

AF SDK Reference

AFValue Class

  • Last UpdatedNov 18, 2025
  • 13 minute read
AFValue Class
The AFValue object is used to represent the value of an AFAttribute along with a timestamp, status, and unit of measure.

Inheritance Hierarchy

SystemObject
  OSIsoft.AF.AssetAFValue

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

Syntax

[SerializableAttribute]
public sealed class AFValue : ISerializable, 
	IPIPersist, IComparable, IComparable<AFValue>, IEquatable<AFValue>
<SerializableAttribute>
Public NotInheritable Class AFValue
	Implements ISerializable, IPIPersist, IComparable, IComparable(Of AFValue), 
	IEquatable(Of AFValue)

Dim instance As AFValue
[SerializableAttribute]
public ref class AFValue sealed : ISerializable, 
	IPIPersist, IComparable, IComparable<AFValue^>, IEquatable<AFValue^>
[<SealedAttribute>]
[<SerializableAttribute>]
type AFValue =  
    class
        interface ISerializable
        interface IPIPersist
        interface IComparable
        interface IComparable<AFValue>
        interface IEquatable<AFValue>
    end

The AFValue type exposes the following members.

Constructors

  NameDescription
Public method
AFValue
This is the default constructor which creates a new AFValue object with default values for its properties.
Public method
AFValue(Object)
This is the constructor for an AFValue object which specifies the value and uses defaults for all the other properties.
Public method
AFValue(AFValue)
This is the copy constructor which creates a new AFValue object with the same values as the specified AFValue object.
Public method
AFValue(Object, AFTime)
This is the constructor for an AFValue object which specifies the value and timestamp and uses defaults for all the other properties.
Public method
AFValue(Object, UOM)
This is the constructor for an AFValue object which specifies the value and unit of measure and uses defaults for all the other properties.
Public method
AFValue(Object, AFTime, UOM)
This is the constructor for an AFValue object which specifies the value, timestamp, and unit of measure and uses defaults for all the other properties.
Public method
AFValue(AFAttribute, Object, AFTime)
This is the constructor for an AFValue object which specifies the Attribute, the value, and timestamp and uses defaults for all the other properties.
Public method
AFValue(Object, AFTime, UOM, AFValueStatus)
This is the constructor for an AFValue object which specifies all the properties.
Public method
AFValue(AFAttribute, Object, AFTime, UOM)
This is the constructor for an AFValue object which specifies the Attribute, the value, timestamp, and unit of measure and uses defaults for all the other properties.
Public method
AFValue(AFAttribute, Object, AFTime, UOM, AFValueStatus)
This is the constructor for an AFValue object which specifies the Attribute for the value and all the properties of the value.

Properties

  NameDescription
Public property
AdditionalInfo
This property holds additional information associated with the value.
Public property
Annotated
Indicates whether the value contains an annotation.
Public property
Attribute
This property returns the AFAttribute associated with the value.
Public property
IsGood
Indicates whether the value is good or bad.
Public property
PIPoint
This property returns the PIPoint associated with the value.
Public property
Questionable
Indicates whether the value has been identified as irregular in some way by an application.
Public property
Status
Indicates the various conditions of the value.
Public property
Substituted
Indicates whether value has been replaced after it was originally written.
Public property
Timestamp
The timestamp associated with the value.
Public property
UOM
This property contains the unit of measure (UOM) of the value.
Public property
Value
This property contains the actual value.
Public property
ValueType
Returns the Type for the value held by this AFValue.
Public property
ValueTypeCode
Returns the TypeCode for the value held by this AFValue.

Methods

  NameDescription
Public method
CompareTo(Object)
Compares this instance with a specified Object.
Public method
CompareTo(AFValue)
Compares this instance with a specified AFValue.
Public method
Convert(UOM)
Returns a new AFValue in the specified UOM.
Public methodCode example
Convert(UOMGroup)
Returns a new AFValue in the UOM specified by the UOMGroup.
Public method
ConvertForAttribute
Converts the current value using the type and units of measure configured for the specified attribute.
Public methodStatic member
Create(AFAttribute, Double, AFTime, UOM, AFValueStatus, Object)
This method will create an AFValue object of Double type that is associated with an AFAttribute.
Public methodStatic member
Create(AFAttribute, Int32, AFTime, UOM, AFValueStatus, Object)
This method will create an AFValue object of Int32 type that is associated with an AFAttribute.
Public methodStatic member
Create(AFAttribute, Single, AFTime, UOM, AFValueStatus, Object)
This method will create an AFValue object of Single type that is associated with an AFAttribute.
Public methodStatic member
CreateSystemNoDataFound
This method will create an AFValue object with a system state of NoData as its AFEnumerationValue with a Bad status that is associated with an AFAttribute.
Public methodStatic member
CreateSystemStateValue(AFSystemStateCode, AFTime)
This method will create an AFValue object with a system AFEnumerationValue as its value with a Bad status that is not associated with an AFAttribute.
Public methodStatic member
CreateSystemStateValue(AFAttribute, AFSystemStateCode, AFTime)
This method will create an AFValue object with a system AFEnumerationValue as its value with a Bad status that is associated with an AFAttribute.
Public methodStatic member
DefaultValue
Gets the default value for the specified type.
Public methodStatic member
DisplayValue(Decimal, Int32, IFormatProvider)
Displays the Decimal value based upon the specified number of display digits.
Public methodStatic member
DisplayValue(Double, Int32, IFormatProvider)
Displays the Double value based upon the specified number of display digits.
Public method
DisplayValue(Int32, IFormatProvider, Boolean)
Displays the Value based upon the value's Type with the option to add the value's UOM abbreviation.
Public methodStatic member
DisplayValue(Object, Int32, IFormatProvider)
Displays the Object value based upon the specified number of display digits.
Public methodStatic member
DisplayValue(Single, Int32, IFormatProvider)
Displays the Single value based upon the specified number of display digits.
Public method
Equals(Object)
Determines whether the specified Object is equal to the current object.
(Overrides ObjectEquals(Object).)
Public method
Equals(AFValue)
Indicates whether the current object is equal to another object of the same type.
Public method
FromPIValue(Object) Obsolete.
This method sets the value of this AFValue object from a PISDK.PIValue object.
Public method
FromPIValue(Boolean, Object) Obsolete.
This method sets the value of this AFValue object from a PISDK.PIValue object.
Public method
FromPIValue(Object, Type, Object, AFEnumerationSet, UOM) Obsolete.
This method sets the value of this AFValue object from a PISDK.PIValue object, converting to the appropriate type as necessary.
Public methodCode example
GetAnnotation
Gets the annotation associated with this AF value.
Public methodStatic member
GetAnnotations
Gets the annotation associated for each AF value in the specified list.
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 ObjectGetHashCode.)
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.
Public methodCode example
SetAnnotation
Associates an annotation with this AF value.
Public method
ToPIValue Obsolete.
This method returns the value of this object as a new PISDK.PIValue object.
Public method
ToPIValue(Object) Obsolete.
This method sets the value of the passed in PISDK.PIValue object to the value of this AFValue object.
Public method
ToString
Returns a String that represents the current object.
(Overrides ObjectToString.)
Public method
ValueAsDouble
Returns the value held by this AFValue as a Double. The value will be converted if possible. If the value cannot be converted an exception will be throw. The value can be checked before performing the conversion using the Type or TypeCode property.
Public method
ValueAsInt32
Returns the value held by this AFValue as a Int32. The value will be converted if possible. If the value cannot be converted an exception will be throw. The value can be checked before performing the conversion using the Type or TypeCode property.
Public method
ValueAsSingle
Returns the value held by this AFValue as a Single. The value will be converted if possible. If the value cannot be converted an exception will be throw. The value can be checked before performing the conversion using the Type or TypeCode property.

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

The AFValue object contains properties for the actual value (Value), the value's timestamp (Timestamp), status (Status, IsGood, Substituted, Questionable), and unit of measure (UOM). The actual value may be of any type, however, in order for a value to be saved, it must either be a .NET base type, a .NET serializable type, or support the PI SDK's IPIPersist interface. This means it is possible to save values such as arrays, System.Data.DataSet's, PI SDK objects, and references to other AF SDK objects.

If the type is an Exception, then it will be persisted to the PI AF Server as a string so that the error message can be viewed by older clients that may not have the exception type defined. The Status of the value will not be modified. This means that the value could initially be an exception, but change to a string when reloaded from the PI AF Server.

Examples

// This example shows how to create a dynamic attribute and obtain
// the values of an attribute over a specified time range.

// Get the Database
PISystems myPISystems = new PISystems();
PISystem myPISystem = myPISystems.DefaultPISystem;
AFDatabase myDB = myPISystem.Databases.DefaultDatabase;

// Create the Attribute
AFAttribute myAttribute = new AFAttribute(myDB);
myAttribute.Name = "Sinusoid";
myAttribute.Type = typeof(float);
myAttribute.DefaultUOM = myPISystem.UOMDatabase.UOMs["m"];
myAttribute.DataReferencePlugIn = AFDataReference.GetPIPointDataReference(myPISystem);
myAttribute.ConfigString = @"\\%Server%\Sinusoid";

// Set the Time Range
AFTimeRange myTimeRange = new AFTimeRange();
myTimeRange.StartTime = new AFTime(DateTime.UtcNow.AddHours(-1));
myTimeRange.EndTime = AFTime.Now;

// Display each Value of the Attribute during the Time Range
AFValues myValues = myAttribute.GetValues(myTimeRange, 0, null);
Console.WriteLine("Number of values = {0}", myValues.Count);
foreach (AFValue myValue in myValues)
{
    Console.WriteLine("Annotated = {0}", myValue.Annotated);
    Console.WriteLine("IsGood = {0}", myValue.IsGood);
    Console.WriteLine("Questionable = {0}", myValue.Questionable);
    Console.WriteLine("Substituted = {0}", myValue.Substituted);
    Console.WriteLine("TimeStamp = {0}", myValue.Timestamp.LocalTime);
    Console.WriteLine("UOM = {0}", myValue.UOM);
    Console.WriteLine("Value = {0}", myValue.Value);
}
' This example shows how to create a dynamic attribute and obtain
' the values of an attribute over a specified time range.

' Get the Database
Dim myPISystems As New PISystems
Dim myPISystem As PISystem = myPISystems.DefaultPISystem
Dim myDB As AFDatabase = myPISystem.Databases.DefaultDatabase

' Create the Attribute
Dim myAttribute As New AFAttribute(myDB)
myAttribute.Name = "Sinusoid"
myAttribute.Type = GetType(Double)
myAttribute.DefaultUOM = myPISystem.UOMDatabase.UOMs("m")
myAttribute.DataReferencePlugIn = AFDataReference.GetPIPointDataReference(myPISystem)
myAttribute.ConfigString = "\\%Server%\Sinusoid"

' Set the Time Range
Dim myTimeRange As New AFTimeRange()
myTimeRange.StartTime = New AFTime(DateTime.UtcNow.AddHours(-1))
myTimeRange.EndTime = AFTime.Now

' Display each Value of the Attribute during the Time Range
Dim myValues As AFValues = myAttribute.GetValues(myTimeRange, 0, Nothing)
Console.WriteLine("Number of values = {0}", myValues.Count)
Dim myValue As AFValue
For Each myValue In myValues
    Console.WriteLine("Annotated = {0}", myValue.Annotated)
    Console.WriteLine("IsGood = {0}", myValue.IsGood)
    Console.WriteLine("Questionable = {0}", myValue.Questionable)
    Console.WriteLine("Substituted = {0}", myValue.Substituted)
    Console.WriteLine("TimeStamp = {0}", myValue.Timestamp.LocalTime)
    Console.WriteLine("UOM = {0}", myValue.UOM)
    Console.WriteLine("Value = {0}", myValue.Value)
Next myValue

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