I have an OPC data collection program that reads tags from a PLC and logs the data.
The program uses the OPCDaAuto.dll. I having trouble figuring out how to read the quality codes that are returned from the SyncRead function.
When calling SyncRead, an empty object is passed to hold the quality codes. I'm not sure what to do with this object when it returns.
Here's the declaration of the object and the function call...
static object a; // For Quality Return
MyOPCGroup2.SyncRead((short)OPCAutomation.OPCDataSource.OPCDevice, 9, ref ItemServerHandles, out ItemServerValues, out ItemServerErrors, out a, out b);
I found this snippit of code and attempted to use it to gain some insight...
Type myType = a.GetType();
IList<PropertyInfo> props = new List<PropertyInfo>(myType.GetProperties());
foreach (PropertyInfo prop in props)
{
object propValue = prop.GetValue(a, null);
Console.WriteLine("Quality = " + propValue.ToString());
}
It produces the following output...
Quality = 9
Quality = 9
Quality = 1
Quality = System.Int16[*]
Quality = False
Quality = True
Quality = False
I'm expecting 9 elements to be returned (I'm reading 9 tags) and I expect their values to be 192 ( = good ). The SyncRead is working because I'm receiving the correct values in ItemServerValues. How can I get the quality codes for the object a?