// This example shows how to obtain a data type of an OPC item.
using System;
using OpcLabs.BaseLib.ComInterop;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.OperationModel;
namespace DocExamples.DataAccess._EasyDAClient
{
partial class GetPropertyValue
{
public static void DataType()
{
// Instantiate the client object.
var client = new EasyDAClient();
// Get the value of DataType property; it is a 16-bit signed integer
short dataType;
try
{
dataType = (short)client.GetPropertyValue("", "OPCLabs.KitServer.2", "Simulation.Random",
DAPropertyIds.DataType);
}
catch (OpcException opcException)
{
Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message);
return;
}
// Convert the data type to VarType
var varType = (VarType)dataType;
// Display the obtained data type
Console.WriteLine("DataType: {0}", dataType); // Display data type as numerical value
Console.WriteLine("VarType: {0}", varType); // Display data type symbolically
// Code below illustrates how decisions can be made based on type
switch (varType.InternalValue)
{
case VarTypes.R8:
Console.WriteLine("The data type is VarTypes.R8, as we expected.");
break;
// other cases may come here ...
default:
Console.WriteLine("The data type is not as we expected!");
break;
}
}
}
}
' This example shows how to obtain a data type of an OPC item.
Imports OpcLabs.BaseLib.ComInterop
Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.OperationModel
Namespace DocExamples.DataAccess._EasyDAClient
Partial Friend Class GetPropertyValue
Public Shared Sub DataType()
Dim client = New EasyDAClient()
' Get the value of DataType property; it is a 16-bit signed integer
Dim aDataType As Short
Try
aDataType = CShort(Fix(client.GetPropertyValue("", "OPCLabs.KitServer.2", "Simulation.Random", DAPropertyIds.DataType)))
Catch opcException As OpcException
Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message)
Exit Sub
End Try
' Convert the data type to VarType
Dim varType = CType(aDataType, VarType)
' Display the obtained data type
Console.WriteLine("DataType: {0}", aDataType) ' Display data type as numerical value
Console.WriteLine("VarType: {0}", varType) ' Display data type symbolically
' Code below illustrates how decisions can be made based on type
Select Case varType
Case VarTypes.R8
Console.WriteLine("The data type is VarTypes.R8, as we expected.")
' other cases may come here ...
Case Else
Console.WriteLine("The data type is not as we expected!")
End Select
End Sub
End Class
End Namespace