Connectivity Software User's Guide and Reference
WriteFunction(SparkplugMetric,Type,Func<SparkplugData,Boolean>) Method



OpcLabs.EasySparkplug Assembly > OpcLabs.EasySparkplug Namespace > SparkplugMetricExtension Class > WriteFunction Method : WriteFunction(SparkplugMetric,Type,Func<SparkplugData,Boolean>) Method
The Sparkplug metric that will perform the operation.

The value of this parameter cannot be null (Nothing in Visual Basic).

The type of the Sparkplug metric, expressed as .NET System.Type.

The value of this parameter cannot be null (Nothing in Visual Basic).

The write function, i.e. the function that accepts the Sparkplug data to be written, performs the write operation, and returns a boolean success indication.

The value of this parameter cannot be null (Nothing in Visual Basic).

Modifies the metric for consuming Sparkplug data by a specified function, for the push data consumption model.

This method always makes the metric writable, including its timestamp, i.e. Sparkplug host applications will be able to modify them. If you need a different behavior, call the Writable(SparkplugMetric,Boolean) method subsequently, with desired parameter, or modify the WritableTimestamp accordingly (set it to true).

This method does not change the readability access of the metric. By default, metrics are readable. If you need a metric that is writable but non-readable, combine this method with calling Readable(SparkplugMetric,Boolean) method with the 'readable' parameter set to false.

The write function returns a boolean value that indicates the outcome of the Sparkplug write operation. The WriteFunction(SparkplugMetric,Type,Func<SparkplugData,Boolean>) method overloads are the most generic extensions methods for writing. If you only need to deal with the metric value (and not its timestamp), consider using one of the WriteValueFunction<TValue>(SparkplugMetric,Type,Func<TValue,Boolean>) or WriteValueAction<TValue>(SparkplugMetric,Type,Action<TValue>) method overloads, for shorter code and easier programming.

Makes a metric that consumes the Sparkplug data using the write function. Specify the value type.
Syntax
'Declaration
 
<ExtensionAttribute()>
<JetBrains.Annotations.NotNullAttribute()>
Public Overloads Shared Function WriteFunction( _
   ByVal metric As SparkplugMetric, _
   ByVal valueType As Type, _
   ByVal writeFunction As Func(Of SparkplugData,Boolean) _
) As SparkplugMetric
'Usage
 
Dim metric As SparkplugMetric
Dim valueType As Type
Dim writeFunction As Func(Of SparkplugData,Boolean)
Dim value As SparkplugMetric
 
value = SparkplugMetricExtension.WriteFunction(metric, valueType, writeFunction)
[Extension()]
[JetBrains.Annotations.NotNull()]
public static SparkplugMetric WriteFunction( 
   SparkplugMetric metric,
   Type valueType,
   Func<SparkplugData,bool> writeFunction
)
[Extension()]
[JetBrains.Annotations.NotNull()]
public:
static SparkplugMetric^ WriteFunction( 
   SparkplugMetric^ metric,
   Type^ valueType,
   Func<SparkplugData^,bool>^ writeFunction
) 

Parameters

metric
The Sparkplug metric that will perform the operation.

The value of this parameter cannot be null (Nothing in Visual Basic).

valueType
The type of the Sparkplug metric, expressed as .NET System.Type.

The value of this parameter cannot be null (Nothing in Visual Basic).

writeFunction
The write function, i.e. the function that accepts the Sparkplug data to be written, performs the write operation, and returns a boolean success indication.

The value of this parameter cannot be null (Nothing in Visual Basic).

Return Value

Returns the metric, internally modified as defined by the method.

This method never returns null (Nothing in Visual Basic).

Exceptions
ExceptionDescription

A null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.

This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception.

Remarks

This method always makes the metric writable, including its timestamp, i.e. Sparkplug host applications will be able to modify them. If you need a different behavior, call the Writable(SparkplugMetric,Boolean) method subsequently, with desired parameter, or modify the WritableTimestamp accordingly (set it to true).

This method does not change the readability access of the metric. By default, metrics are readable. If you need a metric that is writable but non-readable, combine this method with calling Readable(SparkplugMetric,Boolean) method with the 'readable' parameter set to false.

The write function returns a boolean value that indicates the outcome of the Sparkplug write operation. The WriteFunction(SparkplugMetric,Type,Func<SparkplugData,Boolean>) method overloads are the most generic extensions methods for writing. If you only need to deal with the metric value (and not its timestamp), consider using one of the WriteValueFunction<TValue>(SparkplugMetric,Type,Func<TValue,Boolean>) or WriteValueAction<TValue>(SparkplugMetric,Type,Action<TValue>) method overloads, for shorter code and easier programming.

This is an extension method (info: C#, VB.NET). In languages that have support for extensions methods (such as C# and VB.NET), you can use the extension method as if it were a regular method on the object that is its first parameter. In other languages (such as with Python.NET), you will call the extension as a static method, and pass it the object on which it acts as its first parameter.

 

Sparkplug is a trademark of Eclipse Foundation, Inc. "MQTT" is a trademark of the OASIS Open standards consortium. Other related terms are trademarks of their respective owners. Any use of these terms on this site is for descriptive purposes only and does not imply any sponsorship, endorsement or affiliation.

Requirements

Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2016, Windows Server 2022; .NET: Linux, macOS, Microsoft Windows

See Also