Online Forums
Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.
Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.
Do not use the Contact page for technical issues.
How to get the OPC data type of the returned value (tag)?
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
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);
.....
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
If you have read the value already and want to figure out what it is, there are multiple ways how to do that. You can e.g. do .GetType() on the value and then compare it to a specific type, such as typeof(int), or do Type.GetTypeCode(value.GetType()), and then compare it to one of the TypeCode enumeration members (ms-help://MS.MSDNQTR.v90.en/fxref_mscorlib/html/ec83d2c5-2704-dbbc-4fdb-ac5759b7940e.htm ). You can also use the 'as' operator to try cast the value to what your code actually needs.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.