Reputation: 429
For the life of me I can't find out the answer to what I thought would have been a simple question - how to find the data typeof an OPC Node.
I'm writing a UA OPC library which involves creating a subscription and the monitoring/updating of tags within this subscription.
The request to write to a tag comes from an external application and consists of Subscription and tag ID together with an object value. The issue is that this object is invariably a string (don't ask), which needs to be converted to an appropriate data type for the tag. So, I need to find out what data type is associated with the tag. At the moment, the writing fails with a type mismatch exception.
Here's my update code:
//
// Extension methods
public bool Write<T>(long groupID, long tagID, T item)
{
var sub = FindSubscription(groupID);
try
{
if (sub != null)
{
var node = sub.MonitoredItems.FirstOrDefault(m => (long)m.Handle == tagID);
if (node != null)
{
bool result = false;
var nodesToWrite = BuildWriteValueCollection(node.DisplayName, Attributes.Value, item);
StatusCodeCollection results;
DiagnosticInfoCollection diag;
try
{
_session.Write(
requestHeader: null,
nodesToWrite: nodesToWrite,
results: out results,
diagnosticInfos: out diag);
result = CheckReturnValue(results[0]);
}
catch (Exception ex)
{
}
}
}
}
catch (Exception ex)
{
LogMessage(String.Format("Write GroupID {0}, Tag {1}, Value {2}", groupID, tagID, item.ToString()), ex);
}
return false;
}
I've searched for ages to find out how to determine the data type of the node, but without success. So, for a MonitoredItem, how would one go about finding the data type so that I can convert the string to a compatible type?
Thanks
Steve
Upvotes: 0
Views: 1816