Connectivity Software User's Guide and Reference
SparkplugMetricData Constructor(Object,DateTime)
Example 



OpcLabs.EasySparkplug Assembly > OpcLabs.EasySparkplug Namespace > SparkplugMetricData Class > SparkplugMetricData Constructor : SparkplugMetricData Constructor(Object,DateTime)
The value of the Sparkplug data.

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

Timestamp associated with data acquisition time. In UTC.
Initializes a new instance of the class, with given value and timestamp.
Syntax
'Declaration
 
Public Function New( _
   ByVal value As Object, _
   ByVal timestamp As Date _
)
'Usage
 
Dim value As Object
Dim timestamp As Date
 
Dim instance As New SparkplugMetricData(value, timestamp)
public SparkplugMetricData( 
   object value,
   DateTime timestamp
)
public:
SparkplugMetricData( 
   Object^ value,
   DateTime timestamp
)

Parameters

value
The value of the Sparkplug data.

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

timestamp
Timestamp associated with data acquisition time. In UTC.
Exceptions
ExceptionDescription

One of the arguments provided to a method is not valid.

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

 

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.

Example
// This example shows how to publish a command with single metric for a given edge node, including timestamp.
//
// In order to publish or observe messages for this example, start the SparkplugEdgeNodeConsoleDemo program first.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-ConnectivityStudio/Latest/examples.html .
// Sparkplug examples in C# on GitHub: https://github.com/OPCLabs/Examples-ConnectivityStudio-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

using System;
using OpcLabs.EasySparkplug;
using OpcLabs.EasySparkplug.OperationModel;

namespace SparkplugDocExamples.Consumer._EasySparkplugConsumer
{
    partial class PublishEdgeNodeMetric
    {
        public static void Timestamp()
        {
            // Note that the default port for the "mqtt" scheme is 1883.
            var hostDescriptor = new SparkplugHostDescriptor("mqtt://localhost");

            // Instantiate the consumer object.
            var consumer = new EasySparkplugConsumer();

            Console.WriteLine("Publishing...");
            try
            {
                // Create the command metric data: value and timestamp.
                var metricData = new SparkplugMetricData(42, DateTime.UtcNow.AddMinutes(-10));
                
                consumer.PublishEdgeNodeMetric(hostDescriptor, 
                    "easyGroup", "easySparkplugDemo", "Simple",
                    metricData);
            }
            catch (SparkplugException sparkplugException)
            {
                Console.WriteLine($"*** Failure: {sparkplugException.GetBaseException().Message}");
                return;
            }

            Console.WriteLine("Finished.");
        }
    }
}
' This example shows how to publish a command with single metric for a given edge node, including timestamp.
'
' In order to publish or observe messages for this example, start the SparkplugEdgeNodeConsoleDemo program first.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-ConnectivityStudio/Latest/examples.html .
' Sparkplug examples in C# on GitHub: https://github.com/OPCLabs/Examples-ConnectivityStudio-CSharp .
' Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
' a commercial license in order to use Online Forums, and we reply to every post.

Imports OpcLabs.EasySparkplug
Imports OpcLabs.EasySparkplug.OperationModel

Namespace Global.SparkplugDocExamples.Consumer._EasySparkplugConsumer
    Partial Class PublishEdgeNodeMetric
        Public Shared Sub Timestamp()
            ' Note that the default port for the "mqtt" scheme is 1883.
            Dim hostDescriptor = New SparkplugHostDescriptor("mqtt://localhost")

            ' Instantiate the consumer object.
            Dim consumer = New EasySparkplugConsumer()

            Console.WriteLine("Publishing...")
            Try
                ' Create the command metric data: value and timestamp.
                Dim metricData = New SparkplugMetricData(42, DateTime.UtcNow.AddMinutes(-10))

                consumer.PublishEdgeNodeMetric(hostDescriptor,
                    "easyGroup", "easySparkplugDemo", "Simple",
                    metricData)
            Catch sparkplugException As SparkplugException
                Console.WriteLine($"*** Failure: {sparkplugException.GetBaseException().Message}")
                Return
            End Try

            Console.WriteLine("Finished.")
        End Sub
    End Class
End Namespace
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