PIStateSets Class
- Last UpdatedNov 18, 2025
- 9 minute read
- PI System
- AF SDK 2024 R2
- Developer
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
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
| Name | Description | |
|---|---|---|
| Count |
Gets the number of items actually contained in the collection.
| |
| ItemGuid |
Gets the item with the specified id.
| |
| ItemInt32 |
Gets or sets the item at the specified index.
| |
| ItemString |
Returns the specified object from the collection by name.
|
Methods
| Name | Description | |
|---|---|---|
| Add(String) |
Creates a new PI Digital State set with the passed in name.
| |
| Add(AFEnumerationSet) |
Adds the passed in AFEnumerationSet to the PI Digital State Sets collection.
| |
| Contains(Guid) |
This method determines whether the collection contains a specific item referenced by id.
| |
| Contains(String) |
This method determines whether the collection contains a specific item referenced by name.
| |
| Contains(AFEnumerationSet) |
This method determines whether the collection contains a specific state set.
| |
| Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
| GetEnumerator |
Returns an enumerator that iterates through the collection.
| |
| GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
| GetType | Gets the Type of the current instance. (Inherited from Object.) | |
| Refresh |
This method updates the PIStateSets collection by checking for updates
on the PIServer.
| |
| Remove(Guid) |
Removes a PI Digital State Set from the PI Data Archive by ID
| |
| Remove(String) |
Removes a PI Digital State Set from the PI Data Archive by name
| |
| Remove(AFEnumerationSet) |
Removes a PI Digital State Set from the PI Data Archive
| |
| ToString | Returns a string that represents the current object. (Inherited from Object.) |
Extension Methods
| Name | Description | |
|---|---|---|
| AggregateAFEnumerationSet |
Performs all requested aggregates on the specified items.
(Defined by AFAggregate.) | |
| AggregateAsyncAFEnumerationSet |
Performs all requested aggregates on the specified items asynchronously.
(Defined by AFAggregate.) | |
| BinnedSummaryAFEnumerationSet, TBin |
Generates a summary broken down by the specified bins for items matching the search criteria.
(Defined by AFAggregate.) | |
| BinnedSummaryAsyncAFEnumerationSet, TBin |
Generates a summary broken down by the specified bins for items matching the search criteria asynchronously.
(Defined by AFAggregate.) | |
| 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.) | |
| FrequencyDistributionAFEnumerationSet |
Generates a frequency distribution for the specified items.
(Defined by AFAggregate.) | |
| FrequencyDistributionAsyncAFEnumerationSet |
Generates a frequency distribution for the specified items asynchronously.
(Defined by AFAggregate.) | |
| GroupedSummaryAFEnumerationSet |
Generates a summary broken down by group for the specified items.
(Defined by AFAggregate.) | |
| GroupedSummaryAsyncAFEnumerationSet |
Generates a histogram for the specified items asynchronously.
(Defined by AFAggregate.) | |
| HistogramAFEnumerationSet, TBin |
Generates a histogram for the specified items with the specified weighting.
(Defined by AFAggregate.) | |
| HistogramAsyncAFEnumerationSet, TBin |
Generates a histogram for the specified items with the specified weighting asynchronously.
(Defined by AFAggregate.) | |
| SummaryAFEnumerationSet(String, AFSummaryTypes) | Overloaded.
Summarizes the specified items.
(Defined by AFAggregate.) | |
| SummaryAFEnumerationSet(String, AFSummaryTypes, String) | Overloaded.
Summarizes the specified items with the specified weighting.
(Defined by AFAggregate.) | |
| SummaryAsyncAFEnumerationSet(String, AFSummaryTypes, CancellationToken) | Overloaded.
Summarizes the specified items asynchronously.
(Defined by AFAggregate.) | |
| 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.