Reading OPC quality code returned from Group.SyncRead using OPCDaAuto.dll

StackOverflow https://stackoverflow.com/questions/22546239

  •  18-06-2023
  •  | 
  •  

Frage

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?

War es hilfreich?

Lösung

Your first code snippet (SyncRead) appear basically correct. The second snippet not listing the qualities, it is listing the values of .NET properties of the 'a' object.

You need to typecast or convert the returned 'a' to Int16[9], and then access its elements by indexing it.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top