public OpcDaItemProperties[] GetProperties(IList <string> itemIds, bool returnPropertyValues,
                                                   IList <int> propertyIds)
        {
            var properties = new OpcDaItemProperties[itemIds.Count];

            var itemProperties = new IntPtr();

            if (propertyIds == null)
            {
                propertyIds = new int[0];
            }
            string[] pszItemIDs     = itemIds.ToArray();
            int[]    pdwPropertyIDs = propertyIds.ToArray();
            DoComCall(ComObject, "IOpcBrowser::GetProperties", () =>
                      ComObject.GetProperties(pszItemIDs.Length, pszItemIDs, returnPropertyValues, pdwPropertyIDs.Length,
                                              pdwPropertyIDs, out itemProperties), pszItemIDs.Length,
                      pszItemIDs, returnPropertyValues, pdwPropertyIDs.Length, pdwPropertyIDs);

            IntPtr current = itemProperties;

            for (int i = 0; i < itemIds.Count; i++)
            {
                var opcItemProperties = (OPCITEMPROPERTIES)Marshal.PtrToStructure(current, typeof(OPCITEMPROPERTIES));
                properties[i] = ReadItemProperties(ref opcItemProperties);
                Marshal.DestroyStructure(current, typeof(OPCITEMPROPERTIES));
                current += Marshal.SizeOf(typeof(OPCITEMPROPERTIES));
            }
            Marshal.FreeCoTaskMem(itemProperties);

            return(properties);
        }
 public static OpcDaItemProperties[] CreateEmptyItemProperties(int size)
 {
     var result = new OpcDaItemProperties[size];
     for (int i = 0; i < result.Length; i++)
     {
         result[i] = new OpcDaItemProperties {Properties = new OpcDaItemProperty[0]};
     }
     return result;
 }
        private static OpcDaItemProperties ReadItemProperties(ref OPCITEMPROPERTIES itemProperties)
        {
            var result = new OpcDaItemProperties
            {
                ErrorId    = itemProperties.hrErrorID,
                Properties = ReadItemProperties(ref itemProperties.pItemProperties, itemProperties.dwNumProperties)
            };

            return(result);
        }
        public List <String> BrowseChildren(IOpcDaBrowser browser, string itemId = null, int indent = 0)
        {
            List <string> result = new List <string>();

            // When itemId is null, root elements will be browsed.
            OpcDaBrowseElement[] elements = browser.GetElements(itemId);

            // Output elements.
            foreach (OpcDaBrowseElement element in elements)
            {
                if (!element.HasChildren)
                {
                    //Console.WriteLine(element);

                    OpcDaItemProperties[] ppts = browser.GetProperties(new [] { element.ItemId }, new OpcDaPropertiesQuery(true, new int[] { 1 }));
                    OpcDaItemProperties   ppt  = (OpcDaItemProperties)ppts.GetValue(0);

                    /*
                     * Console.WriteLine(element.ItemId);
                     * Console.WriteLine(ppt.Properties[0].DataType);
                     */
                    /*
                     *
                     * 1 Item Canonical DataType (ItemId: #MonitorACLFile, DataType System.Int16, Value: , ErrorId: S_OK: Success code)
                     * 2 Item Value (ItemId: #MonitorACLFile, DataType TitaniumAS.Opc.Client.Common.IllegalType, Value: , ErrorId: S_OK: Success code)
                     * 3 Item Quality (ItemId: #MonitorACLFile, DataType System.Int16, Value: , ErrorId: S_OK: Success code)
                     * 4 Item Timestamp (ItemId: #MonitorACLFile, DataType System.DateTime, Value: , ErrorId: S_OK: Success code)
                     * 5 Item Access Rights (ItemId: #MonitorACLFile, DataType System.Int32, Value: , ErrorId: S_OK: Success code)
                     * 6 this.server Scan Rate (ItemId: #MonitorACLFile, DataType System.Single, Value: , ErrorId: S_OK: Success code)
                     * 7 Item EU Type (ItemId: #MonitorACLFile, DataType System.Int32, Value: , ErrorId: S_OK: Success code)
                     * 8 Item EUInfo (ItemId: #MonitorACLFile, DataType System.String[], Value: , ErrorId: S_OK: Success code)
                     */
                    /*
                     * foreach(OpcDaItemProperty _prop in ppt.Properties)
                     * {
                     *  Console.WriteLine(_prop);
                     * }
                     */


                    //element.ItemProperties.Properties.DataType;   elemento mais tag datatype
                    result.Add(element.ItemId + "," + tagTypeConvert((Int16)ppt.Properties[0].Value));
                    continue;
                }

                // Output children of the element.
                if (element.ItemId != "_Hints")
                {
                    result.AddRange(BrowseChildren(browser, element.ItemId, indent + 2));
                }
            }

            return(result);
        }
        public static OpcDaItemProperties[] CreateEmptyItemProperties(int size)
        {
            var result = new OpcDaItemProperties[size];

            for (int i = 0; i < result.Length; i++)
            {
                result[i] = new OpcDaItemProperties {
                    Properties = new OpcDaItemProperty[0]
                };
            }
            return(result);
        }
        public static OpcDaItemProperties QueryAvailableProperties(this OpcItemProperties opcItemProperties,
            string itemId)
        {
            string[] ppDescriptions;
            VarEnum[] ppvtDataTypes;
            var pdwPropertyIDs = opcItemProperties.QueryAvailableProperties(itemId, out ppDescriptions,
                out ppvtDataTypes);

            var props = new OpcDaItemProperties {Properties = new OpcDaItemProperty[pdwPropertyIDs.Length]};
            for (var i = 0; i < pdwPropertyIDs.Length; i++)
            {
                var property = new OpcDaItemProperty
                {
                    PropertyId = pdwPropertyIDs[i],
                    Description = ppDescriptions[i],
                    DataType = TypeConverter.FromVarEnum(ppvtDataTypes[i])
                };
                props.Properties[i] = property;
            }
            return props;
        }
        /// <summary>
        /// Gets properties of items by specified item identifiers.
        /// </summary>
        /// <param name="itemIds">The item identifiers.</param>
        /// <param name="propertiesQuery">The properties query.</param>
        /// <returns>
        /// Array of properties of items.
        /// </returns>
        /// <exception cref="System.InvalidOperationException">Interface IOPCItemProperties not supported.</exception>
        public OpcDaItemProperties[] GetProperties(IList <string> itemIds, OpcDaPropertiesQuery propertiesQuery = null)
        {
            if (OpcItemProperties == null)
            {
                throw new InvalidOperationException("Interface IOPCItemProperties not supported.");
            }

            if (propertiesQuery == null)
            {
                propertiesQuery = new OpcDaPropertiesQuery();
            }

            var result = new OpcDaItemProperties[itemIds.Count];

            for (var i = 0; i < result.Length; i++)
            {
                var itemId = itemIds[i];
                try
                {
                    OpcDaItemProperties itemProperties = OpcItemProperties.QueryAvailableProperties(itemId);
                    if (!propertiesQuery.AllProperties) // filter properties
                    {
                        itemProperties.IntersectProperties(propertiesQuery.PropertyIds);
                    }
                    if (propertiesQuery.ReturnValues) // read property values
                    {
                        OpcItemProperties.GetItemProperties(itemId, itemProperties);
                    }
                    OpcItemProperties.LookupItemIDs(itemId, itemProperties);
                    result[i] = itemProperties;
                }
                catch (Exception ex)
                {
                    Log.ErrorFormat("Cannot get properties for item '{0}'.", ex, itemId);
                    result[i] = OpcDaItemProperties.CreateEmpty();
                }
            }

            return(result);
        }
        /// <summary>
        /// Browse the server using specified criteria.
        /// </summary>
        /// <param name="parentItemId">Indicates the item identifier from which browsing will begin. If the root branch is to be browsed then a null should be passed.</param>
        /// <param name="filter">The filtering context.</param>
        /// <param name="propertiesQuery">The properties query.</param>
        /// <returns>
        /// Array of browsed elements.
        /// </returns>
        /// <exception cref="System.InvalidOperationException">Interface IOPCBrowseServerAddressSpace not supported.</exception>
        virtual public OpcDaBrowseElement[] GetElements(string parentItemId, OpcDaElementFilter filter = null,
                                                        OpcDaPropertiesQuery propertiesQuery = null)
        {
            if (OpcBrowseServerAddressSpace == null)
            {
                throw new InvalidOperationException("Interface IOPCBrowseServerAddressSpace not supported.");
            }

            if (parentItemId == null)
            {
                parentItemId = string.Empty;
            }

            if (filter == null)
            {
                filter = new OpcDaElementFilter();
            }

            var elements = GetElementsImpl(parentItemId, filter);

            if (propertiesQuery != null)
            {
                var properties = GetProperties(elements.Select(e => e.ItemId).ToArray(), propertiesQuery);
                for (var i = 0; i < elements.Length; i++)
                {
                    elements[i].ItemProperties = properties[i];
                }
            }
            else
            {
                for (var i = 0; i < elements.Length; i++)
                {
                    elements[i].ItemProperties = OpcDaItemProperties.CreateEmpty();
                }
            }

            return(elements);
        }
        public static OpcDaItemProperties QueryAvailableProperties(this OpcItemProperties opcItemProperties,
                                                                   string itemId)
        {
            string[]  ppDescriptions;
            VarEnum[] ppvtDataTypes;
            var       pdwPropertyIDs = opcItemProperties.QueryAvailableProperties(itemId, out ppDescriptions,
                                                                                  out ppvtDataTypes);

            var props = new OpcDaItemProperties {
                Properties = new OpcDaItemProperty[pdwPropertyIDs.Length]
            };

            for (var i = 0; i < pdwPropertyIDs.Length; i++)
            {
                var property = new OpcDaItemProperty
                {
                    PropertyId  = pdwPropertyIDs[i],
                    Description = ppDescriptions[i],
                    DataType    = TypeConverter.FromVarEnum(ppvtDataTypes[i])
                };
                props.Properties[i] = property;
            }
            return(props);
        }
 public static OpcDaItemProperties GetItemProperties(this OpcItemProperties opcItemProperties, string itemId,
                                                     OpcDaItemProperties properties)
 {
     opcItemProperties.GetItemProperties(itemId, properties.Properties);
     return(properties);
 }
 public static OpcDaItemProperties LookupItemIDs(this OpcItemProperties opcItemProperties, string itemId,
                                                 OpcDaItemProperties properties)
 {
     opcItemProperties.LookupItemIDs(itemId, properties.Properties);
     return(properties);
 }
        /// <summary>
        /// Gets properties of items by specified item identifiers.
        /// </summary>
        /// <param name="itemIds">The item identifiers.</param>
        /// <param name="propertiesQuery">The properties query.</param>
        /// <returns>
        /// Array of properties of items.
        /// </returns>
        /// <exception cref="System.InvalidOperationException">Interface IOPCItemProperties not supported.</exception>
        public OpcDaItemProperties[] GetProperties(IList<string> itemIds, OpcDaPropertiesQuery propertiesQuery = null)
        {
            if (OpcItemProperties == null)
                throw new InvalidOperationException("Interface IOPCItemProperties not supported.");

            if (propertiesQuery == null)
                propertiesQuery = new OpcDaPropertiesQuery();

            var result = new OpcDaItemProperties[itemIds.Count];

            for (var i = 0; i < result.Length; i++)
            {
                var itemId = itemIds[i];
                try
                {
                    OpcDaItemProperties itemProperties = OpcItemProperties.QueryAvailableProperties(itemId);
                    if (!propertiesQuery.AllProperties) // filter properties
                    {
                        itemProperties.IntersectProperties(propertiesQuery.PropertyIds);
                    }
                    if (propertiesQuery.ReturnValues) // read property values
                    {
                        OpcItemProperties.GetItemProperties(itemId, itemProperties);
                    }
                    OpcItemProperties.LookupItemIDs(itemId, itemProperties);
                    result[i] = itemProperties;
                }
                catch (Exception ex)
                {
                    Log.ErrorFormat("Cannot get properties for item '{0}'.", ex, itemId);
                    result[i] = OpcDaItemProperties.CreateEmpty();
                }
            }

            return result;
        }
 public static OpcDaItemProperties GetItemProperties(this OpcItemProperties opcItemProperties, string itemId,
     OpcDaItemProperties properties)
 {
     opcItemProperties.GetItemProperties(itemId, properties.Properties);
     return properties;
 }
 public static OpcDaItemProperties LookupItemIDs(this OpcItemProperties opcItemProperties, string itemId,
     OpcDaItemProperties properties)
 {
     opcItemProperties.LookupItemIDs(itemId, properties.Properties);
     return properties;
 }
 private static OpcDaItemProperties ReadItemProperties(ref OPCITEMPROPERTIES itemProperties)
 {
     var result = new OpcDaItemProperties
     {
         ErrorId = itemProperties.hrErrorID,
         Properties = ReadItemProperties(ref itemProperties.pItemProperties, itemProperties.dwNumProperties)
     };
     return result;
 }
        public OpcDaItemProperties[] GetProperties(IList<string> itemIds, bool returnPropertyValues,
            IList<int> propertyIds)
        {
            var properties = new OpcDaItemProperties[itemIds.Count];

            var itemProperties = new IntPtr();
            if (propertyIds == null)
            {
                propertyIds = new int[0];
            }
            string[] pszItemIDs = itemIds.ToArray();
            int[] pdwPropertyIDs = propertyIds.ToArray();
            DoComCall(ComObject, "IOpcBrowser::GetProperties", () =>
                ComObject.GetProperties(pszItemIDs.Length, pszItemIDs, returnPropertyValues, pdwPropertyIDs.Length,
                    pdwPropertyIDs, out itemProperties), pszItemIDs.Length,
                pszItemIDs, returnPropertyValues, pdwPropertyIDs.Length, pdwPropertyIDs);

            IntPtr current = itemProperties;
            for (int i = 0; i < itemIds.Count; i++)
            {
                var opcItemProperties = (OPCITEMPROPERTIES) Marshal.PtrToStructure(current, typeof (OPCITEMPROPERTIES));
                properties[i] = ReadItemProperties(ref opcItemProperties);
                Marshal.DestroyStructure(current, typeof (OPCITEMPROPERTIES));
                current += Marshal.SizeOf(typeof (OPCITEMPROPERTIES));
            }
            Marshal.FreeCoTaskMem(itemProperties);

            return properties;
        }