// This example for OPC DA type-less mapping shows how to define mappings of various kinds, and perform subscribe and
// unsubscribe operations.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
using System;
using System.Threading;
using OpcLabs.BaseLib.ComponentModel.Linking;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.DataAccess.Generic;
using OpcLabs.EasyOpc.DataAccess.LiveMapping;
namespace DocExamples.DataAccess._DAClientMapper
{
partial class DefineMapping
{
class MyClassMappingKinds
{
public Double CurrentValue
{
set
{
// Display the incoming value
Console.WriteLine("Value: {0}", value);
}
}
public DAVtq<Double> CurrentVtq
{
set
{
// Display the incoming Vtq
Console.WriteLine("Vtq: {0}", value);
}
}
public Exception CurrentException
{
set
{
// Display the incoming exception
Console.WriteLine("Exception: {0}", value);
}
}
public DAVtqResult<Double> CurrentResult
{
set
{
// Display the incoming result
Console.WriteLine("Result: {0}", value);
}
}
}
public static void MappingKinds()
{
// Instantiate the client mapper object.
var mapper = new DAClientMapper();
var target = new MyClassMappingKinds();
// Define several type-less mappings for the same source, with different mapping kinds.
Type targetType = target.GetType();
var source = new DAClientItemSource("OPCLabs.KitServer.2", "Demo.Ramp", 1000, DADataSource.Cache);
mapper.DefineMapping(
source,
new DAClientItemMapping(typeof(Double)),
new ObjectMemberLinkingTarget(targetType, target, "CurrentValue"));
mapper.DefineMapping(
source,
new DAClientItemMapping(typeof(Double), DAItemMappingKind.Vtq),
new ObjectMemberLinkingTarget(targetType, target, "CurrentVtq"));
mapper.DefineMapping(
source,
new DAClientItemMapping(typeof(Double), DAItemMappingKind.Exception),
new ObjectMemberLinkingTarget(targetType, target, "CurrentException"));
mapper.DefineMapping(
source,
new DAClientItemMapping(typeof(Double), DAItemMappingKind.Result),
new ObjectMemberLinkingTarget(targetType, target, "CurrentResult"));
// Perform a subscribe operation.
mapper.Subscribe(true);
Thread.Sleep(30 * 1000);
// Perform an unsubscribe operation.
mapper.Subscribe(false);
}
}
}
' This example for OPC DA type-less mapping shows how to define mappings of various kinds, and perform subscribe and
' unsubscribe operations.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
Imports OpcLabs.BaseLib.ComponentModel.Linking
Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.DataAccess.Generic
Imports OpcLabs.EasyOpc.DataAccess.LiveMapping
Namespace _DAClientMapper
Partial Friend Class DefineMapping
Class MyClassMappingKinds
Public WriteOnly Property CurrentValue As Double
Set(value As Double)
' Display the incoming value
Console.WriteLine("Value: {0}", value)
End Set
End Property
Public WriteOnly Property CurrentVtq As DAVtq(Of Double)
Set(value As DAVtq(Of Double))
' Display the incoming Vtq
Console.WriteLine("Vtq: {0}", value)
End Set
End Property
Public WriteOnly Property CurrentException As Exception
Set(value As Exception)
' Display the incoming exception
Console.WriteLine("Exception: {0}", value)
End Set
End Property
Public WriteOnly Property CurrentResult As DAVtqResult(Of Double)
Set(value As DAVtqResult(Of Double))
' Display the incoming result
Console.WriteLine("Result: {0}", value)
End Set
End Property
End Class
Public Shared Sub MappingKinds()
Dim mapper = New DAClientMapper()
Dim target = New MyClassMappingKinds()
' Define several type-less mappings for the same source, with different mapping kinds.
Dim targetType = target.GetType()
Dim source = New DAClientItemSource("OPCLabs.KitServer.2", "Demo.Ramp", 1000, DADataSource.Cache)
mapper.DefineMapping(
source,
New DAClientItemMapping(GetType(Double)),
New ObjectMemberLinkingTarget(targetType, target, "CurrentValue"))
mapper.DefineMapping(
source,
New DAClientItemMapping(GetType(Double), DAItemMappingKind.Vtq),
New ObjectMemberLinkingTarget(targetType, target, "CurrentVtq"))
mapper.DefineMapping(
source,
New DAClientItemMapping(GetType(Double), DAItemMappingKind.Exception),
New ObjectMemberLinkingTarget(targetType, target, "CurrentException"))
mapper.DefineMapping(
source,
New DAClientItemMapping(GetType(Double), DAItemMappingKind.Result),
New ObjectMemberLinkingTarget(targetType, target, "CurrentResult"))
' Perform a subscribe operation.
mapper.Subscribe(True)
Threading.Thread.Sleep(30 * 1000)
' Perform an unsubscribe operation.
mapper.Subscribe(False)
End Sub
End Class
End Namespace