/// <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> /// 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> /// 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.AggregateException"></exception> public OpcDaItemProperties[] GetProperties(IList <string> itemIds, OpcDaPropertiesQuery propertiesQuery = null) { try { return(_browser3.GetProperties(itemIds, propertiesQuery)); } catch (Exception ex1) { Log.Warn("Failed to get properties using IOPCBrowse (OPC DA 3.x).", ex1); try { return(_browser2.GetProperties(itemIds, propertiesQuery)); } catch (Exception ex2) { Log.Warn("Failed to get properties using IOPCItemProperties (OPC DA 2.x).", ex2); try { return(_browser1.GetProperties(itemIds, propertiesQuery)); } catch (Exception ex3) { Log.Warn("Failed to get properties using IOPCItemProperties (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> /// 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> /// 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); }
/// <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> public OpcDaItemProperties[] GetProperties(IList <string> itemIds, OpcDaPropertiesQuery propertiesQuery = null) { if (propertiesQuery == null) { propertiesQuery = new OpcDaPropertiesQuery(); } var properties = OpcBrowse.GetProperties(itemIds, propertiesQuery.ReturnValues, propertiesQuery.PropertyIds); if (OpcConfiguration.EnableQuirks && properties.Length > 0 && propertiesQuery.AllProperties && NoPropertiesReturned(properties)) { // TODO: fallback to IOPCItemProperties } return(properties); }
/// <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> /// 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); }
/// <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> public OpcDaItemProperties[] GetProperties(IList<string> itemIds, OpcDaPropertiesQuery propertiesQuery = null) { if (propertiesQuery == null) propertiesQuery = new OpcDaPropertiesQuery(); var properties = OpcBrowse.GetProperties(itemIds, propertiesQuery.ReturnValues, propertiesQuery.PropertyIds); if (OpcConfiguration.EnableQuirks && properties.Length > 0 && propertiesQuery.AllProperties && NoPropertiesReturned(properties)) { // TODO: fallback to IOPCItemProperties } 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; }
/// <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.AggregateException"></exception> public OpcDaItemProperties[] GetProperties(IList<string> itemIds, OpcDaPropertiesQuery propertiesQuery = null) { try { return _browser3.GetProperties(itemIds, propertiesQuery); } catch (Exception ex1) { Log.Warn("Failed to get properties using IOPCBrowse (OPC DA 3.x).", ex1); try { return _browser2.GetProperties(itemIds, propertiesQuery); } catch (Exception ex2) { Log.Warn("Failed to get properties using IOPCItemProperties (OPC DA 2.x).", ex2); try { return _browser1.GetProperties(itemIds, propertiesQuery); } catch (Exception ex3) { Log.Warn("Failed to get properties using IOPCItemProperties (OPC DA 1.x).", ex2); throw new AggregateException(ex3, ex2, ex1); } } } }