Opc.Ua.Com.Client.ComAeClient.GetEventAttributes C# (CSharp) Méthode

GetEventAttributes() public méthode

Gets the event attributes.
public GetEventAttributes ( int categoryId, int &attributeIds, string &descriptions, short &datatypes ) : bool
categoryId int The category id.
attributeIds int The attribute ids.
descriptions string The descriptions.
datatypes short The datatypes.
Résultat bool
        public bool GetEventAttributes(
            int categoryId, 
            out int[] attributeIds,
            out string[] descriptions,
            out short[] datatypes)
        {
            string methodName = "IOPCEventServer.QueryEventAttributes";

            int count = 0;
            IntPtr pAttributeIds = IntPtr.Zero;
            IntPtr pDescriptions = IntPtr.Zero;
            IntPtr pDataTypes = IntPtr.Zero;

            try
            {
                IOPCEventServer server = BeginComCall<IOPCEventServer>(methodName, true);

                server.QueryEventAttributes(
                    categoryId,
                    out count,
                    out pAttributeIds,
                    out pDescriptions,
                    out pDataTypes);
            }
            catch (Exception e)
            {
                ComCallError(methodName, e);
            }
            finally
            {
                EndComCall(methodName);
            }

            // unmarshal results.
            attributeIds = ComUtils.GetInt32s(ref pAttributeIds, count, true);
            descriptions = ComUtils.GetUnicodeStrings(ref pDescriptions, count, true);
            datatypes = ComUtils.GetInt16s(ref pDataTypes, count, true);

            // remove the AREAS attribute which is never exposed.
            for (int ii = 0; ii < count; ii++)
            {
                if (String.Compare(descriptions[ii], "AREAS", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    int[] attributeIds2 = new int[count-1];
                    string[] descriptions2 = new string[count-1];
                    short[] datatypes2 = new short[count-1];

                    if (ii > 0)
                    {
                        Array.Copy(attributeIds, attributeIds2, ii);
                        Array.Copy(descriptions, descriptions2, ii);
                        Array.Copy(datatypes, datatypes2, ii);
                    }

                    if (ii < count-1)
                    {
                        Array.Copy(attributeIds, ii+1, attributeIds2, ii, count-ii-1);
                        Array.Copy(descriptions, ii+1, descriptions2, ii, count-ii-1);
                        Array.Copy(datatypes, ii+1, datatypes2, ii, count-ii-1);
                    }

                    attributeIds = attributeIds2;
                    descriptions = descriptions2;
                    datatypes = datatypes2;
                    break;
                }
            }

            return count > 0;
        }
        #endregion

Usage Example

        /// <summary>
        /// Fetches the attributes for the category from the AE server.
        /// </summary>
        private List <EventAttribute> LoadEventAttributes(ComAeClient client, int eventTypeId, int categoryId)
        {
            List <EventAttribute> attributes = new List <EventAttribute>();

            int[]    ids          = null;
            string[] descriptions = null;
            short[]  dataTypes    = null;

            try
            {
                client.GetEventAttributes(categoryId, out ids, out descriptions, out dataTypes);
            }
            catch (Exception e)
            {
                Utils.Trace(e, "Unexpected error fetching event attributes.");
                ids = null;
            }

            if (ids != null)
            {
                for (int ii = 0; ii < ids.Length; ii++)
                {
                    EventAttribute attribute = new EventAttribute();
                    attribute.Id          = ids[ii];
                    attribute.Description = descriptions[ii];
                    attribute.VarType     = dataTypes[ii];
                    attributes.Add(attribute);
                }
            }

            return(attributes);
        }
All Usage Examples Of Opc.Ua.Com.Client.ComAeClient::GetEventAttributes