// This example shows different ways of constructing generic data.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
using System;
using System.Collections;
using OpcLabs.BaseLib.DataTypeModel;
namespace UADocExamples.ComplexData._GenericData
{
class _Construction
{
public static void Main1()
{
// Create enumeration data with value of 1.
var enumerationData = new EnumerationData(1);
Console.WriteLine(enumerationData);
// Create opaque data from an array of 2 bytes, specifying its size as 15 bits.
var opaqueData1 = new OpaqueData(new byte[] {0xAA, 0x55}, sizeInBits:15);
Console.WriteLine(opaqueData1);
// Create opaque data from a bit array.
var opaqueData2 = new OpaqueData(new BitArray(new[] { false, true, false, true, false }));
Console.WriteLine(opaqueData2);
// Create primitive data with System.Double value of 180.0.
var primitiveData1 = new PrimitiveData(180.0d);
Console.WriteLine(primitiveData1);
// Create primitive data with System.String value.
var primitiveData2 = new PrimitiveData("Temperature is too high!");
Console.WriteLine(primitiveData2);
// Create sequence data with two elements, using collection initializer syntax.
var sequenceData1 = new SequenceData
{
opaqueData1,
opaqueData2
};
Console.WriteLine(sequenceData1);
// Create the same sequence data, using the Add method.
var sequenceData2 = new SequenceData();
sequenceData2.Elements.Add(opaqueData1);
sequenceData2.Elements.Add(opaqueData2);
Console.WriteLine(sequenceData2);
// Create the same sequence data, using an array (an enumerable) of its elements.
var sequenceData3 = new SequenceData(
new GenericDataCollection(new[] {opaqueData1, opaqueData2}));
Console.WriteLine(sequenceData3);
// Create structured data with two members, using collection initializer syntax.
var structuredData1 = new StructuredData
{
{"Message", primitiveData2},
{"Status", enumerationData}
};
Console.WriteLine(structuredData1);
// Create the same structured data using the Add method.
var structuredData2 = new StructuredData();
structuredData2.Add("Message", primitiveData2);
structuredData2.Add("Status", enumerationData);
Console.WriteLine(structuredData2);
// Create union data.
var unionData1 = new UnionData("DoubleField", primitiveData1);
Console.WriteLine(unionData1);
}
}
}
# This example shows different ways of constructing generic data.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc
# Import .NET namespaces.
from System import *
from System.Collections import *
from OpcLabs.BaseLib.DataTypeModel import *
# Create enumeration data with value of 1.
enumerationData = EnumerationData(1)
print(enumerationData)
# Create opaque data from an array of 2 bytes, specifying its size as 15 bits.
opaqueData1 = OpaqueData(
[0xAA, 0x55],
15) # sizeInBits
print(opaqueData1)
# Create opaque data from a bit array.
bitArray = BitArray(5)
bitArray[0] = False
bitArray[1] = True
bitArray[2] = False
bitArray[3] = True
bitArray[4] = False
opaqueData2 = OpaqueData(bitArray)
print(opaqueData2)
# Create primitive data with System.Double value of 180.0.
primitiveData1 = PrimitiveData(180.0)
print(primitiveData1)
# Create primitive data with System.String value.
primitiveData2 = PrimitiveData('Temperature is too high!')
print(primitiveData2)
# Create sequence data with two elements, using the Add method.
sequenceData2 = SequenceData()
sequenceData2.Elements.Add(opaqueData1)
sequenceData2.Elements.Add(opaqueData2)
print(sequenceData2)
# Create structured data with two members, using the Add method.
structuredData2 = StructuredData()
structuredData2.Add('Message', primitiveData2)
structuredData2.Add('Status', enumerationData)
print(structuredData2)
# Create union data.
unionData1 = UnionData('DoubleField', primitiveData1)
print(unionData1)
print()
print('Finished.')
' This example shows different ways of constructing generic data.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
Imports System
Imports System.Collections
Imports OpcLabs.BaseLib.DataTypeModel
Namespace ComplexData._GenericData
Friend Class _Construction
Public Shared Sub Main1()
' Create enumeration data with value of 1.
Dim enumerationData = New EnumerationData(1)
Console.WriteLine(enumerationData)
' Create opaque data from an array of 2 bytes, specifying its size as 15 bits.
Dim opaqueData1 = New OpaqueData(New Byte() {170, 85}, sizeInBits:=15)
Console.WriteLine(opaqueData1)
' Create opaque data from a bit array.
Dim opaqueData2 = New OpaqueData(New BitArray(New Boolean() {False, True, False, True, False}))
Console.WriteLine(opaqueData2)
' Create primitive data with System.Double value of 180.0.
Dim primitiveData1 = New PrimitiveData(180)
Console.WriteLine(primitiveData1)
' Create primitive data with System.String value.
Dim primitiveData2 = New PrimitiveData("Temperature is too high!")
Console.WriteLine(primitiveData2)
' Create sequence data with two elements, using collection initializer syntax.
Dim sequenceData1 = New SequenceData() From {opaqueData1, opaqueData2}
Console.WriteLine(sequenceData1)
' Create the same sequence data, using the Add method.
Dim sequenceData2 = New SequenceData
sequenceData2.Elements.Add(opaqueData1)
sequenceData2.Elements.Add(opaqueData2)
Console.WriteLine(sequenceData2)
' Create the same sequence data, using an array (an enumerable) of its elements.
Dim sequenceData3 = New SequenceData(New GenericDataCollection(New OpaqueData() {opaqueData1, opaqueData2}))
Console.WriteLine(sequenceData3)
' Create structured data with two members, using collection initializer syntax.
Dim structuredData1 = New StructuredData() From { _
{"Message", primitiveData2}, _
{"Status", enumerationData}}
Console.WriteLine(structuredData1)
' Create the same structured data using the Add method.
Dim structuredData2 = New StructuredData()
structuredData2.Add("Message", primitiveData2)
structuredData2.Add("Status", enumerationData)
Console.WriteLine(structuredData2)
End Sub
End Class
End Namespace