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

AF SDK Reference

PIStateSets Class

  • Last UpdatedNov 18, 2025
  • 9 minute read
PIStateSets Class
The PIStateSets collection represents the available State Sets on a particular PIServer. The State Sets are represented as a collection of AFEnumerationSet objects.

Inheritance Hierarchy

SystemObject
  OSIsoft.AF.PIPIStateSets

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

Syntax

public sealed class PIStateSets : IEnumerable<AFEnumerationSet>, 
	IEnumerable, IAFList, IList, ICollection, IList<AFEnumerationSet>, 
	ICollection<AFEnumerationSet>
Public NotInheritable Class PIStateSets
	Implements IEnumerable(Of AFEnumerationSet), IEnumerable, 
	IAFList, IList, ICollection, IList(Of AFEnumerationSet), 
	ICollection(Of AFEnumerationSet)

Dim instance As PIStateSets
public ref class PIStateSets sealed : IEnumerable<AFEnumerationSet^>, 
	IEnumerable, IAFList, IList, ICollection, IList<AFEnumerationSet^>, 
	ICollection<AFEnumerationSet^>
[<SealedAttribute>]
type PIStateSets =  
    class
        interface IEnumerable<AFEnumerationSet>
        interface IEnumerable
        interface IAFList
        interface IList
        interface ICollection
        interface IList<AFEnumerationSet>
        interface ICollection<AFEnumerationSet>
    end

The PIStateSets type exposes the following members.

Properties

Methods

  NameDescription
Public method
Add(String)
Creates a new PI Digital State set with the passed in name.
Public method
Add(AFEnumerationSet)
Adds the passed in AFEnumerationSet to the PI Digital State Sets collection.
Public method
Contains(Guid)
This method determines whether the collection contains a specific item referenced by id.
Public method
Contains(String)
This method determines whether the collection contains a specific item referenced by name.
Public method
Contains(AFEnumerationSet)
This method determines whether the collection contains a specific state set.
Public method
Equals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public method
GetEnumerator
Returns an enumerator that iterates through the collection.
Public method
GetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public method
GetType
Gets the Type of the current instance.
(Inherited from Object.)
Public method
Refresh
This method updates the PIStateSets collection by checking for updates on the PIServer.
Public method
Remove(Guid)
Removes a PI Digital State Set from the PI Data Archive by ID
Public method
Remove(String)
Removes a PI Digital State Set from the PI Data Archive by name
Public method
Remove(AFEnumerationSet)
Removes a PI Digital State Set from the PI Data Archive
Public method
ToString
Returns a string that represents the current object.
(Inherited from Object.)

Extension Methods

  NameDescription
Public Extension Method
AggregateAFEnumerationSet
Performs all requested aggregates on the specified items.
(Defined by AFAggregate.)
Public Extension Method
AggregateAsyncAFEnumerationSet
Performs all requested aggregates on the specified items asynchronously.
(Defined by AFAggregate.)
Public Extension Method
BinnedSummaryAFEnumerationSet, TBin
Generates a summary broken down by the specified bins for items matching the search criteria.
(Defined by AFAggregate.)
Public Extension Method
BinnedSummaryAsyncAFEnumerationSet, TBin
Generates a summary broken down by the specified bins for items matching the search criteria asynchronously.
(Defined by AFAggregate.)
Public Extension MethodCode example
ChunkedByAFEnumerationSet
This extension method breaks up search results into chunks to make it easier to page through and process IEnumerableT collections in chunks.
(Defined by AFSDKExtension.)
Public Extension Method
FrequencyDistributionAFEnumerationSet
Generates a frequency distribution for the specified items.
(Defined by AFAggregate.)
Public Extension Method
FrequencyDistributionAsyncAFEnumerationSet
Generates a frequency distribution for the specified items asynchronously.
(Defined by AFAggregate.)
Public Extension Method
GroupedSummaryAFEnumerationSet
Generates a summary broken down by group for the specified items.
(Defined by AFAggregate.)
Public Extension Method
GroupedSummaryAsyncAFEnumerationSet
Generates a histogram for the specified items asynchronously.
(Defined by AFAggregate.)
Public Extension Method
HistogramAFEnumerationSet, TBin
Generates a histogram for the specified items with the specified weighting.
(Defined by AFAggregate.)
Public Extension Method
HistogramAsyncAFEnumerationSet, TBin
Generates a histogram for the specified items with the specified weighting asynchronously.
(Defined by AFAggregate.)
Public Extension Method
SummaryAFEnumerationSet(String, AFSummaryTypes)Overloaded.
Summarizes the specified items.
(Defined by AFAggregate.)
Public Extension Method
SummaryAFEnumerationSet(String, AFSummaryTypes, String)Overloaded.
Summarizes the specified items with the specified weighting.
(Defined by AFAggregate.)
Public Extension Method
SummaryAsyncAFEnumerationSet(String, AFSummaryTypes, CancellationToken)Overloaded.
Summarizes the specified items asynchronously.
(Defined by AFAggregate.)
Public Extension Method
SummaryAsyncAFEnumerationSet(String, AFSummaryTypes, String, CancellationToken)Overloaded.
Summarizes the specified items with the specified weighting asynchronously.
(Defined by AFAggregate.)

Examples

// Get the PIServers collection for the current user and default PIServer.
myPIServer = new PIServers().DefaultPIServer;

// Create a new state set
AFEnumerationSet myColorsSet = myPIServer.StateSets.Add("myColors");

// Add values to the new set
myColorsSet.Add("Red", 0);
myColorsSet.Add("Blue", 1);
myColorsSet.Add("Green", 2);

// Commit the new state set to the PI Data Archive
myColorsSet.CheckIn();

// Print set values out
PrintStateSetValues(myColorsSet);

// Create a new PI Point with this digital state set
Dictionary<string, object> pointAttributes = new Dictionary<string, object>();
pointAttributes[PICommonPointAttributes.PointType] = PIPointType.Digital;
pointAttributes[PICommonPointAttributes.DigitalSetName] = "myColors";

PIPoint myColorPoint = myPIServer.CreatePIPoint("myColorPoint", pointAttributes);

// Write three color values to the points using different techniques
AFValue redValue = new AFValue(myColorsSet["Red"], new AFTime("t"));
myColorPoint.UpdateValue(redValue, AFUpdateOption.Insert);

AFValue blueValue = new AFValue(new AFEnumerationValue("Blue", 1), new AFTime("t+5s"));
myColorPoint.UpdateValue(blueValue, AFUpdateOption.Insert);

AFValue greenValue = new AFValue(2, new AFTime("t+10s"));
myColorPoint.UpdateValue(greenValue, AFUpdateOption.Insert);

// Write system state set values using different techniques
AFValue ioTimeoutValue = new AFValue(
    AFEnumerationSet.GetBySystemStateCode(AFSystemStateCode.IOTimeout),
    new AFTime("t+15s"));

myColorPoint.UpdateValue(ioTimeoutValue, AFUpdateOption.Insert);

AFValue sampleBadValue = new AFValue(
    AFEnumerationSet.SystemStateSet["Sample Bad"],
    new AFTime("t+20s"));

myColorPoint.UpdateValue(sampleBadValue, AFUpdateOption.Insert);

// Use system state specific to this PI Data Archive
AFValue noLabDataValue = new AFValue(
    myPIServer.StateSets["SYSTEM"]["No Lab Data"],
    new AFTime("t+25s"));

myColorPoint.UpdateValue(noLabDataValue, AFUpdateOption.Insert);

// Read the values
AFValues colorValues = myColorPoint.RecordedValues(
    new AFTimeRange("t", "t+25s"), AFBoundaryType.Inside, null, false);

// Print them out
foreach (AFValue colorValue in colorValues)
{
    AFEnumerationValue setValue = colorValue.Value as AFEnumerationValue;

    if (!ReferenceEquals(setValue, null))
    {
        Console.WriteLine("Set Name: {0} Value Name: {1} Value Code: {2}",
            setValue.EnumerationSet.Name, setValue.Name, setValue.Value);
    }
}
' Get the PIServers collection for the current user and default PIServer.
myPIServer = New PIServers().DefaultPIServer

' Create a new state set
Dim myColorsSet As AFEnumerationSet = myPIServer.StateSets.Add("myColors")

' Add values to the new set
myColorsSet.Add("Red", 0)
myColorsSet.Add("Blue", 1)
myColorsSet.Add("Green", 2)

' Commit the new state set to the PI Data Archive
myColorsSet.CheckIn()

' Print out set values
PrintStateSetValues(myColorsSet)

' Create a new PI Point with this digital state set
Dim pointAttributes As Dictionary(Of String, Object) = New Dictionary(Of String, Object)
pointAttributes(PICommonPointAttributes.PointType) = PIPointType.Digital
pointAttributes(PICommonPointAttributes.DigitalSetName) = "myColors"

Dim myColorPoint As PIPoint = myPIServer.CreatePIPoint("myColorPoint", pointAttributes)

' Write three color values to the points using different techniques
Dim redValue As AFValue = New AFValue(myColorsSet("Red"), New AFTime("t"))
myColorPoint.UpdateValue(redValue, AFUpdateOption.Insert)

Dim blueValue As AFValue = New AFValue(New AFEnumerationValue("Blue", 1), New AFTime("t+5s"))
myColorPoint.UpdateValue(blueValue, AFUpdateOption.Insert)

Dim greenValue As AFValue = New AFValue(2, New AFTime("t+10s"))
myColorPoint.UpdateValue(greenValue, AFUpdateOption.Insert)

' Write system state set values using different techniques
Dim ioTimeoutValue As AFValue = New AFValue(
    AFEnumerationSet.GetBySystemStateCode(AFSystemStateCode.IOTimeout),
    New AFTime("t+15s"))

myColorPoint.UpdateValue(ioTimeoutValue, AFUpdateOption.Insert)

Dim sampleBadValue As AFValue = New AFValue(
    AFEnumerationSet.SystemStateSet("Sample Bad"),
    New AFTime("t+20s"))

myColorPoint.UpdateValue(sampleBadValue, AFUpdateOption.Insert)

' Use system state specific to this PI Data Archive
Dim noLabDataValue As AFValue = New AFValue(
    myPIServer.StateSets("SYSTEM")("No Lab Data"),
    New AFTime("t+25s"))

myColorPoint.UpdateValue(noLabDataValue, AFUpdateOption.Insert)

' Read the values
Dim colorValues As AFValues = myColorPoint.RecordedValues(
    New AFTimeRange("t", "t+25s"), AFBoundaryType.Inside, Nothing, False)

' Print them out
For Each colorValue As AFValue In colorValues
    Dim setValue As AFEnumerationValue = TryCast(colorValue.Value, AFEnumerationValue)

    If Not setValue Is Nothing Then
        Console.WriteLine("Set Name: {0} Value Name: {1} Value Code: {2}",
            setValue.EnumerationSet.Name, setValue.Name, setValue.Value)
    End If

Next

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

Supported in: 3.1.1, 3.1.0, 3.0.2, 3.0.1, 3.0.0, 2.10.11, 2.10.5, 2.10.0, 2.10, 2.9.5, 2.9, 2.8.5, 2.8, 2.7.5, 2.7, 2.6

See Also

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