/// <summary>
 /// Gets the elements.
 /// </summary>
 /// <param name="parentItemId">The parent item identifier.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="propertiesQuery">The properties query.</param>
 /// <returns></returns>
 public override OpcDaBrowseElement[] GetElements(string parentItemId, OpcDaElementFilter filter = null,
     OpcDaPropertiesQuery propertiesQuery = null)
 {
     OpcDaBrowseElement[] elements = base.GetElements(parentItemId, filter, propertiesQuery);
     SavePathes(elements);
     return elements;
 }
 /// <summary>
 /// Gets the elements.
 /// </summary>
 /// <param name="parentItemId">The parent item identifier.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="propertiesQuery">The properties query.</param>
 /// <returns></returns>
 public override OpcDaBrowseElement[] GetElements(string parentItemId, OpcDaElementFilter filter = null,
                                                  OpcDaPropertiesQuery propertiesQuery = null)
 {
     OpcDaBrowseElement[] elements = base.GetElements(parentItemId, filter, propertiesQuery);
     SavePathes(elements);
     return(elements);
 }
Example #3
0
 /// <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.AggregateException"></exception>
 public OpcDaBrowseElement[] GetElements(string parentItemId, OpcDaElementFilter filter = null,
                                         OpcDaPropertiesQuery propertiesQuery = null)
 {
     try
     {
         return(_browser3.GetElements(parentItemId, filter, propertiesQuery));
     }
     catch (Exception ex1)
     {
         Log.Warn("Failed to browse address space using IOPCBrowse (OPC DA 3.x).", ex1);
         try
         {
             return(_browser2.GetElements(parentItemId, filter, propertiesQuery));
         }
         catch (Exception ex2)
         {
             Log.Warn("Failed to browse address space using IOPCBrowseServerAddressSpace (OPC DA 2.x).", ex2);
             try
             {
                 return(_browser1.GetElements(parentItemId, filter, propertiesQuery));
             }
             catch (Exception ex3)
             {
                 Log.Warn("Failed to browse address space using IOPCBrowseServerAddressSpace (OPC DA 1.x).", ex2);
                 throw new AggregateException(ex3, ex2, ex1);
             }
         }
     }
 }
        /// <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;
        }
 /// <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.AggregateException"></exception>
 public OpcDaBrowseElement[] GetElements(string parentItemId, OpcDaElementFilter filter = null,
     OpcDaPropertiesQuery propertiesQuery = null)
 {
     try
     {
         return _browser3.GetElements(parentItemId, filter, propertiesQuery);
     }
     catch (Exception ex1)
     {
         Log.Warn("Failed to browse address space using IOPCBrowse (OPC DA 3.x).", ex1);
         try
         {
             return _browser2.GetElements(parentItemId, filter, propertiesQuery);
         }
         catch (Exception ex2)
         {
             Log.Warn("Failed to browse address space using IOPCBrowseServerAddressSpace (OPC DA 2.x).", ex2);
             try
             {
                 return _browser1.GetElements(parentItemId, filter, propertiesQuery);
             }
             catch (Exception ex3)
             {
                 Log.Warn("Failed to browse address space using IOPCBrowseServerAddressSpace (OPC DA 1.x).", ex2);
                 throw new AggregateException(ex3, ex2, ex1);
             }
         }
     }
 }
        /// <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">Browser isn't attached to com object.</exception>
        public OpcDaBrowseElement[] GetElements(string parentItemId, OpcDaElementFilter filter = null,
                                                OpcDaPropertiesQuery propertiesQuery = null)
        {
            if (OpcBrowse == null)
            {
                throw new InvalidOperationException("Browser isn't attached to com object.");
            }

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

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

            bool        returnAllProperties;
            bool        returnPropertyValues;
            IList <int> propertyIds;

            if (propertiesQuery != null)
            {
                returnAllProperties  = propertiesQuery.AllProperties;
                returnPropertyValues = propertiesQuery.ReturnValues;
                propertyIds          = propertiesQuery.PropertyIds;
            }
            else
            {
                returnAllProperties  = false;
                returnPropertyValues = false;
                propertyIds          = new int[0];
            }

            var opcBrowseElements = OpcBrowse.Browse(parentItemId, filter.ElementType, filter.Name,
                                                     filter.VendorSpecific,
                                                     returnAllProperties, returnPropertyValues, propertyIds);

            if (OpcConfiguration.EnableQuirks && opcBrowseElements.Length > 0 && returnAllProperties &&
                NoPropertiesReturned(opcBrowseElements))
            {
                // bad server implementation of Browse. For example some versions of Matrikon simulation server
                // all properties was requested but returned nothing.
                // Requery properties with GetProperties
                var properties = GetProperties(opcBrowseElements.Select(e => e.ItemId).ToArray(), propertiesQuery);
                for (var i = 0; i < opcBrowseElements.Length; i++)
                {
                    opcBrowseElements[i].ItemProperties = properties[i];
                }
            }

            return(opcBrowseElements);
        }
Example #7
0
        //Reads Data from OPC. Fills the Nodelist from PLC
        internal IEnumerable <OpcDaBrowseElement> ReadDataToNodeList(string _subStringFromTagName) //e.g. "_CAP - for Capacity tag"
        {
            //Читаем список переменных из OCP-сервера. Фильтруем переменные-ветви и отбираем те, в именах которых содержится _subStringFromTagName (например "_CAP")
            var opcDaElementFilter = new OpcDaElementFilter()
            {
                ElementType = OpcDaBrowseFilter.Branches
            };
            var browser = new OpcDaBrowserAuto(_opcServer);

            var items = from s in browser.GetElements(_parentNodeDescriptor, opcDaElementFilter)
                        where s.Name.Contains(_subStringFromTagName)
                        select s;

            return(items);
        }
        /// <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">Browser isn't attached to com object.</exception>
        public OpcDaBrowseElement[] GetElements(string parentItemId, OpcDaElementFilter filter = null,
            OpcDaPropertiesQuery propertiesQuery = null)
        {
            if (OpcBrowse == null)
                throw new InvalidOperationException("Browser isn't attached to com object.");

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

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

            bool returnAllProperties;
            bool returnPropertyValues;
            IList<int> propertyIds;
            if (propertiesQuery != null)
            {
                returnAllProperties = propertiesQuery.AllProperties;
                returnPropertyValues = propertiesQuery.ReturnValues;
                propertyIds = propertiesQuery.PropertyIds;
            }
            else
            {
                returnAllProperties = false;
                returnPropertyValues = false;
                propertyIds = new int[0];
            }

            var opcBrowseElements = OpcBrowse.Browse(parentItemId, filter.ElementType, filter.Name,
                filter.VendorSpecific,
                returnAllProperties, returnPropertyValues, propertyIds);

            if (OpcConfiguration.EnableQuirks && opcBrowseElements.Length > 0 && returnAllProperties &&
                NoPropertiesReturned(opcBrowseElements))
            {
                // bad server implementation of Browse. For example some versions of Matrikon simulation server
                // all properties was requested but returned nothing.
                // Requery properties with GetProperties
                var properties = GetProperties(opcBrowseElements.Select(e => e.ItemId).ToArray(), propertiesQuery);
                for (var i = 0; i < opcBrowseElements.Length; i++)
                {
                    opcBrowseElements[i].ItemProperties = properties[i];
                }
            }

            return opcBrowseElements;
        }
        /// <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);
        }
        private OpcDaBrowseElement[] GetElementsImpl(string itemId, OpcDaElementFilter filter)
        {
            IEnumerable <OpcDaBrowseElement> elements;
            var     namespaceType  = OpcBrowseServerAddressSpace.Organization;
            VarEnum dataTypeFilter = TypeConverter.ToVarEnum(filter.DataType);

            switch (namespaceType)
            {
            case OpcDaNamespaceType.Hierarchial:
                ChangeBrowsePositionTo(itemId);

                switch (filter.ElementType)
                {
                case OpcDaBrowseFilter.All:
                    var branches = OpcBrowseServerAddressSpace.BrowseOpcItemIds(OpcDaBrowseType.Branch,
                                                                                filter.Name, dataTypeFilter,
                                                                                filter.AccessRights)
                                   .Select(CreateBranchBrowseElement);
                    var leafs = OpcBrowseServerAddressSpace.BrowseOpcItemIds(OpcDaBrowseType.Leaf, filter.Name,
                                                                             dataTypeFilter,
                                                                             filter.AccessRights)
                                .Select(CreateLeafBrowseElement);
                    elements = branches.Union(leafs);
                    break;

                case OpcDaBrowseFilter.Branches:
                    elements = OpcBrowseServerAddressSpace.BrowseOpcItemIds(OpcDaBrowseType.Branch, filter.Name,
                                                                            dataTypeFilter,
                                                                            filter.AccessRights)
                               .Select(CreateBranchBrowseElement);
                    break;

                case OpcDaBrowseFilter.Items:
                    elements = OpcBrowseServerAddressSpace.BrowseOpcItemIds(OpcDaBrowseType.Leaf, filter.Name,
                                                                            dataTypeFilter,
                                                                            filter.AccessRights)
                               .Select(CreateLeafBrowseElement);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                break;

            case OpcDaNamespaceType.Flat:
                if (filter.ElementType == OpcDaBrowseFilter.Branches)     // no branches in flat namespace
                {
                    elements = Enumerable.Empty <OpcDaBrowseElement>();
                }
                else
                {
                    elements = OpcBrowseServerAddressSpace.BrowseOpcItemIds(OpcDaBrowseType.Flat, filter.Name,
                                                                            dataTypeFilter,
                                                                            filter.AccessRights)
                               .Select(CreateLeafBrowseElement);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(elements.ToArray());
        }
        private OpcDaBrowseElement[] GetElementsImpl(string itemId, OpcDaElementFilter filter)
        {
            IEnumerable<OpcDaBrowseElement> elements;
            var namespaceType = OpcBrowseServerAddressSpace.Organization;
            VarEnum dataTypeFilter = TypeConverter.ToVarEnum(filter.DataType);
            switch (namespaceType)
            {
                case OpcDaNamespaceType.Hierarchial:
                    ChangeBrowsePositionTo(itemId);

                    switch (filter.ElementType)
                    {
                        case OpcDaBrowseFilter.All:
                            var branches = OpcBrowseServerAddressSpace.BrowseOpcItemIds(OpcDaBrowseType.Branch,
                                filter.Name, dataTypeFilter,
                                filter.AccessRights)
                                .Select(CreateBranchBrowseElement);
                            var leafs = OpcBrowseServerAddressSpace.BrowseOpcItemIds(OpcDaBrowseType.Leaf, filter.Name,
                                dataTypeFilter,
                                filter.AccessRights)
                                .Select(CreateLeafBrowseElement);
                            elements = branches.Union(leafs);
                            break;
                        case OpcDaBrowseFilter.Branches:
                            elements = OpcBrowseServerAddressSpace.BrowseOpcItemIds(OpcDaBrowseType.Branch, filter.Name,
                                dataTypeFilter,
                                filter.AccessRights)
                                .Select(CreateBranchBrowseElement);
                            break;
                        case OpcDaBrowseFilter.Items:
                            elements = OpcBrowseServerAddressSpace.BrowseOpcItemIds(OpcDaBrowseType.Leaf, filter.Name,
                                dataTypeFilter,
                                filter.AccessRights)
                                .Select(CreateLeafBrowseElement);
                            break;
                        default:
                            throw new ArgumentOutOfRangeException();
                    }
                    break;
                case OpcDaNamespaceType.Flat:
                    if (filter.ElementType == OpcDaBrowseFilter.Branches) // no branches in flat namespace
                    {
                        elements = Enumerable.Empty<OpcDaBrowseElement>();
                    }
                    else
                    {
                        elements = OpcBrowseServerAddressSpace.BrowseOpcItemIds(OpcDaBrowseType.Flat, filter.Name,
                            dataTypeFilter,
                            filter.AccessRights)
                            .Select(CreateLeafBrowseElement);
                    }
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
            return elements.ToArray();
        }