PIServer.UpdateValues Method (IList(AFValue), AFUpdateOption, AFBufferOption)
- Last UpdatedNov 18, 2025
- 8 minute read
- PI System
- AF SDK 2024 R2
- Developer
Namespace: OSIsoft.AF.PI
Assembly: OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182
Syntax
public AFErrors<AFValue> UpdateValues( IList<AFValue> values, AFUpdateOption option, AFBufferOption bufferOption )
Public Function UpdateValues ( values As IList(Of AFValue), option As AFUpdateOption, bufferOption As AFBufferOption ) As AFErrors(Of AFValue) Dim instance As PIServer Dim values As IList(Of AFValue) Dim option As AFUpdateOption Dim bufferOption As AFBufferOption Dim returnValue As AFErrors(Of AFValue) returnValue = instance.UpdateValues(values, option, bufferOption)
public: AFErrors<AFValue^>^ UpdateValues( IList<AFValue^>^ values, AFUpdateOption option, AFBufferOption bufferOption )
member UpdateValues : values : IList<AFValue> * option : AFUpdateOption * bufferOption : AFBufferOption -> AFErrors<AFValue>
Parameters
- values
- Type: System.Collections.GenericIListAFValue
The list of values with an associated PIPoint to be inserted, replaced, or removed to the PI Data Archive. - option
- Type: OSIsoft.AF.DataAFUpdateOption
An enumeration value that specifies how to treat duplicate values in the archive. It can also be used to specify that existing values should be removed. - bufferOption
- Type: OSIsoft.AF.DataAFBufferOption
An enumeration value that specifies buffering behavior.
Return Value
Type: AFErrorsAFValueIf there are no errors, then is returned. Otherwise an AFErrorsTKey instance containing error information is returned.
Remarks
This method will take the list of values with an associated PIPoint and update multiple values for multiple points. Multiple values for the same PIPoint can be in the list. The value's PIPoint must be set or its Attribute must be set to an AFAttribute associated with a PIPoint.
For successful data write through Buffer, this method requires that PI Buffer Subsystem (PIBufSS) needs to be correctly pre-configured with Buffering Manager. Currently, buffering data through PIBufSS has a limitation where error feedback from PI Data Archive cannot be returned to the caller.
Data write through Buffer will be fanned to Collective members.
| Exception reporting is not handled automatically by the AF SDK. Historically, exception reporting has been handled by the application writing data (i.e. Uniint-based interfaces). |
Examples
// This example demonstrates how to update values to attributes with PIPoint data reference through PIserver object. // Note: For successul write through Buffer, PI Buffer Subsystem needs to be correctly pre-configured with PI Buffer Manager. // Get the Database and UOMs PISystems myPISystems = new PISystems(); PISystem myPISystem = myPISystems.DefaultPISystem; AFDatabase myDB = myPISystem.Databases.DefaultDatabase; UOM uomFoot = myPISystem.UOMDatabase.UOMs["foot"]; UOM uomYard = myPISystem.UOMDatabase.UOMs["yard"]; // Create Attributes and their new values int attributeCount = 2; AFAttributeList attrList = new AFAttributeList(); AFTime newStartTime = new AFTime("T-1d", CultureInfo.CurrentCulture); List<AFValue> newValues = new List<AFValue>(); Random randomValues = new Random(); // Create Dynamic Attributes to a PIPoint to Update PIServer piServer = PIServers.GetPIServers().DefaultPIServer; int dataCount = 5; //Create 5 new values to update AFTime newTime = newStartTime; for (int j = 1; j <= attributeCount; j++) { newTime = newStartTime; PIPoint point; if (!PIPoint.TryFindPIPoint(piServer, "MyTestPoint#" + j, out point)) { point = piServer.CreatePIPoint("MyTestPoint#" + j); } AFAttribute myAttribute = new AFAttribute(String.Format(CultureInfo.InvariantCulture, @"\\{0}\{1}", piServer.Name, point.Name)); myAttribute.DefaultUOM = uomFoot; myAttribute.ConfigString += ";ReadOnly=False"; attrList.Add(myAttribute); for (int i = 0; i < dataCount; i++) { AFValue newValue = new AFValue(myAttribute, randomValues.NextDouble(), newTime, uomYard); newValues.Add(newValue); newTime = newTime.LocalTime.AddMinutes(10); } } AFTime newEndTime = newTime; // Get the Recorded Values for the Attributes int totalRecordedValuesCount = 0; foreach (AFAttribute myAttribute in attrList) { AFValues recordedValues = myAttribute.Data.RecordedValues(new AFTimeRange(newStartTime, newEndTime), AFBoundaryType.Inside, myAttribute.DefaultUOM, null, false); Console.WriteLine("Recorded Values:"); foreach (AFValue value in recordedValues) { Console.WriteLine(" {0}: '{1} {2}' at '{3}'", value.Attribute, value.Value, value.UOM, value.Timestamp); } totalRecordedValuesCount += recordedValues.Count; } // Get the Buffer Option // Note: If not specified in AFSDK.config, the buffer option is defaulted to "BufferIfPossible". Console.WriteLine("Current Buffer Option: {0}", AFData.BufferOption); // Set the Buffer Option to "Buffer" if it is not already, which will be valid throughout this client instance. if (AFData.BufferOption != AFBufferOption.Buffer) { AFData.BufferOption = AFBufferOption.Buffer; Console.WriteLine("Current Buffer Option for this instance has been changed to: {0}", AFData.BufferOption); } //1. Update the Attribute Values and Display any Errors AFErrors<AFValue> errorsWithBuffer = piServer.UpdateValues(newValues, AFUpdateOption.InsertNoCompression); //Insert or InsertNoCompression Thread.Sleep(1000); if (errorsWithBuffer != null && errorsWithBuffer.HasErrors) { Console.WriteLine("\nErrors returned from PIServer.UpdateValues:"); // Display Value errors if (errorsWithBuffer.Errors != null && errorsWithBuffer.Errors.Count > 0) { foreach (var item in errorsWithBuffer.Errors) { Console.WriteLine(" AFValue '{0}': {1}", item.Key, item.Value); } } // Display error from the PI Data Archive if (errorsWithBuffer.PIServerErrors != null && errorsWithBuffer.PIServerErrors.Count > 0) { foreach (var item in errorsWithBuffer.PIServerErrors) { Console.WriteLine(" AFValue '{0}': {1}", item.Key, item.Value); } } // Display PI System errors if (errorsWithBuffer.PISystemErrors != null && errorsWithBuffer.PISystemErrors.Count > 0) { foreach (var item in errorsWithBuffer.PISystemErrors) { Console.WriteLine(" AFValue '{0}': {1}", item.Key, item.Value); } } } //2. Alternatively, one can specify buffer option in the UpdateValues method AFErrors<AFValue> errorsWithBufferIfPossible = piServer.UpdateValues(newValues, AFUpdateOption.InsertNoCompression, AFBufferOption.BufferIfPossible); Thread.Sleep(1000); // Get the Updated Recorded Values for the Attributes int totalRecordedValuesCountUpdated = 0; foreach (AFAttribute myAttribute in attrList) { AFValues recordedValuesUpdated = myAttribute.Data.RecordedValues(new AFTimeRange(newStartTime, newEndTime), AFBoundaryType.Inside, myAttribute.DefaultUOM, null, false); Console.WriteLine("\nUpdated Recorded Values:"); foreach (AFValue value in recordedValuesUpdated) { Console.WriteLine(" {0}: '{1} {2}' at '{3}'", value.Attribute, value.Value, value.UOM, value.Timestamp); } totalRecordedValuesCountUpdated += recordedValuesUpdated.Count; }
' This example demonstrates how to update values to attributes with PIPoint data reference through PIserver object. ' Note: For successful write through Buffer, PI Buffer Subsystem needs to be correctly pre-configured with PI Buffer Manager. ' Get the Database and UOMs Dim myPISystems As PISystems = New PISystems Dim myPISystem As PISystem = myPISystems.DefaultPISystem Dim myDB As AFDatabase = myPISystem.Databases.DefaultDatabase Dim uomFoot As UOM = myPISystem.UOMDatabase.UOMs("foot") Dim uomYard As UOM = myPISystem.UOMDatabase.UOMs("yard") ' Create Attributes and their new values Dim attributeCount As Integer = 2 Dim attrList As AFAttributeList = New AFAttributeList Dim newStartTime As AFTime = New AFTime("T-1d", CultureInfo.CurrentCulture) Dim newValues As List(Of AFValue) = New List(Of AFValue) Dim randomValues As Random = New Random ' Create Dynamic Attributes to a PIPoint to Update Dim piServer As PIServer = PIServers.GetPIServers.DefaultPIServer Dim dataCount As Integer = 5 'Create 5 new values to update Dim newTime As AFTime = newStartTime For j As Integer = 1 To attributeCount newTime = newStartTime Dim point As PIPoint = Nothing If Not PIPoint.TryFindPIPoint(piServer, "MyTestPoint#" + j.ToString, point) Then point = piServer.CreatePIPoint("MyTestPoint#" + j.ToString) End If Dim myAttribute As AFAttribute = New AFAttribute(String.Format(CultureInfo.InvariantCulture, "\\{0}\{1}", piServer.Name, point.Name)) myAttribute.DefaultUOM = uomFoot myAttribute.ConfigString = (myAttribute.ConfigString + ";UOM=ft;ReadOnly=True") attrList.Add(myAttribute) For i As Integer = 1 To dataCount Dim newValue As AFValue = New AFValue(myAttribute, randomValues.NextDouble(), newTime, uomYard) newValues.Add(newValue) newTime = newTime.LocalTime.AddMinutes(10) Next Next Dim newEndTime As AFTime = newTime ' Get the Recorded Values for the Attributes Dim totalRecordedValuesCount As Integer = 0 For Each myAttribute As AFAttribute In attrList Dim recordedValues As AFValues = myAttribute.Data.RecordedValues(New AFTimeRange(newStartTime, newEndTime), AFBoundaryType.Inside, myAttribute.DefaultUOM, Nothing, False) Console.WriteLine("Recorded Values:") For Each value As AFValue In recordedValues Console.WriteLine(" {0}: '{1} {2}' at '{3}'", value.Attribute, value.Value, value.UOM, value.Timestamp) Next totalRecordedValuesCount += recordedValues.Count Next ' Get the Buffer Option ' Note: If not specified in AFSDK.config, the buffer option is defaulted to "BufferIfPossible". Console.WriteLine("Current Buffer Option: {0}", AFData.BufferOption) ' Set the Buffer Option to "Buffer" if it is not already, which will be valid throughout this client instance. If Not AFData.BufferOption.Equals(AFBufferOption.Buffer) Then AFData.BufferOption = AFBufferOption.Buffer Console.WriteLine("Current Buffer Option for this instance has been changed to: {0}", AFData.BufferOption) End If '1. Update the Attribute Values and Display any Errors Dim errorsWithBuffer As AFErrors(Of AFValue) = piServer.UpdateValues(newValues, AFUpdateOption.InsertNoCompression) 'Insert or InsertNoCompression Thread.Sleep(1000) If Not errorsWithBuffer Is Nothing AndAlso errorsWithBuffer.HasErrors Then Console.WriteLine("Errors returned from PIServer.UpdateValues:") ' Display Value errors If Not errorsWithBuffer.Errors Is Nothing AndAlso errorsWithBuffer.Errors.Count > 0 Then For Each item As KeyValuePair(Of AFValue, Exception) In errorsWithBuffer.Errors Console.WriteLine(" AFValue '{0}': {1}", item.Key, item.Value) Next End If ' Display PI Data Archive error If Not errorsWithBuffer.PIServerErrors Is Nothing AndAlso errorsWithBuffer.PIServerErrors.Count > 0 Then For Each item As KeyValuePair(Of PIServer, Exception) In errorsWithBuffer.PIServerErrors Console.WriteLine(" AFValue '{0}': {1}", item.Key, item.Value) Next End If ' Display PI System errors If Not errorsWithBuffer.PISystemErrors Is Nothing AndAlso errorsWithBuffer.PISystemErrors.Count > 0 Then For Each item As KeyValuePair(Of PISystem, Exception) In errorsWithBuffer.PISystemErrors Console.WriteLine(" AFValue '{0}': {1}", item.Key, item.Value) Next End If End If '2. Alternatively, one can specify buffer option in the UpdateValues method Dim errorsWithBufferIfPossible As AFErrors(Of AFValue) = piServer.UpdateValues(newValues, AFUpdateOption.InsertNoCompression, AFBufferOption.BufferIfPossible) Thread.Sleep(1000) ' Get the Updated Recorded Values for the Attributes Dim totalRecordedValuesCountUpdated As Integer = 0 For Each myAttribute As AFAttribute In attrList Dim recordedValuesUpdated As AFValues = myAttribute.Data.RecordedValues(New AFTimeRange(newStartTime, newEndTime), AFBoundaryType.Inside, myAttribute.DefaultUOM, Nothing, False) Console.WriteLine("Updated Recorded Values:") For Each value As AFValue In recordedValuesUpdated Console.WriteLine(" {0}: '{1} {2}' at '{3}'", value.Attribute, value.Value, value.UOM, value.Timestamp) Next totalRecordedValuesCountUpdated += recordedValuesUpdated.Count 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.