I have prepared two examples
The first example obtains the data type through OPC property:
// This example shows how to obtain a data type of an OPC item.
using System;
using OpcLabs.EasyOpc;
using OpcLabs.EasyOpc.DataAccess;
.....
var easyDAClient = new EasyDAClient();
// Get the value of DataType property; it is a 16-bit signed integer
var dataType = (short)easyDAClient.GetPropertyValue("", "OPCLabs.KitServer.2", "Simulation.Random",
DAPropertyId.DataType);
// 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)
{
case VarType.R8:
Console.WriteLine("The data type is VarType.R8, as we expected.");
break;
// other cases may come here ...
default:
Console.WriteLine("The data type is not as we expected!");
break;
}
.....
The second example reads an item and interprets the data type of the item value:
// This example shows how to read a single item and obtains a type code of the received value.
using System;
using OpcLabs.EasyOpc.DataAccess;
.....
var easyDAClient = new EasyDAClient();
DAVtq vtq = easyDAClient.ReadItem("", "OPCLabs.KitServer.2", "Simulation.Random");
TypeCode typeCode = Type.GetTypeCode(vtq.Value.GetType());
Console.WriteLine("TypeCode: {0}", typeCode);
.....