/// <summary> /// Moves the current browse position to the specified item. /// </summary> public void BrowseTo(string itemId) { Session session = Session; if (session == null) { throw ComUtils.CreateComException(ResultIds.E_FAIL); } m_browseManager.BrowseTo(session, itemId); }
/// <summary> /// Moves the current browse position up. /// </summary> public void BrowseUp() { Session session = Session; if (session == null) { throw ComUtils.CreateComException(ResultIds.E_FAIL); } m_browseManager.BrowseUp(session); }
/// <summary> /// Gets the item id for the specified browse element. /// </summary> /// <param name="browseName">The name of the browse element.</param> /// <returns></returns> public string GetItemId(string browseName) { Session session = m_server.Session; if (session == null) { throw ComUtils.CreateComException(ResultIds.E_FAIL); } return(m_browseManager.GetItemId(session, browseName)); }
/// <summary> /// Gets the properties. /// </summary> /// <param name="requests">The requests.</param> /// <param name="propertyIds">The property ids.</param> /// <returns>The list of properities.</returns> public IList <DaProperty> GetProperties(ComDaReadPropertiesRequest[] requests, params int[] propertyIds) { Session session = Session; if (session == null) { throw ComUtils.CreateComException(ResultIds.E_FAIL); } return(m_browseManager.GetPropertyValues(session, requests, propertyIds)); }
/// <summary> /// Gets the properties. /// </summary> /// <param name="session">The session.</param> /// <param name="itemId">The item id.</param> /// <returns>The list of properities.</returns> public IList <DaProperty> GetAvailableProperties(Session session, string itemId) { IList <DaProperty> properties = m_cache.GetAvailableProperties(session, itemId); if (properties == null) { throw ComUtils.CreateComException(ResultIds.E_UNKNOWNITEMID); } return(properties); }
/// <summary> /// Gets the item ids for the properties. /// </summary> /// <param name="itemId">The item id.</param> /// <param name="propertyIds">The property ids.</param> /// <param name="itemIds">The item ids.</param> /// <returns>Any errors.</returns> public IList <int> GetItemIds(string itemId, int[] propertyIds, out string[] itemIds) { Session session = Session; if (session == null) { throw ComUtils.CreateComException(ResultIds.E_FAIL); } return(m_browseManager.GetItemIds(session, itemId, propertyIds, out itemIds)); }
/// <summary> /// Gets the property values. /// </summary> /// <param name="itemId">The item id.</param> /// <param name="propertyIds">The property ids.</param> /// <returns>The property values.</returns> public DaValue[] GetPropertyValues(string itemId, int[] propertyIds) { Session session = Session; if (session == null) { throw ComUtils.CreateComException(ResultIds.E_FAIL); } return(m_browseManager.GetPropertyValues(session, itemId, propertyIds)); }
/// <summary> /// Moves the current browse position down. /// </summary> public void BrowseDown(string targetName) { Session session = Session; if (session == null) { throw ComUtils.CreateComException(ResultIds.E_FAIL); } m_browseManager.BrowseDown(session, targetName); }
/// <summary> /// Gets the properties. /// </summary> /// <param name="itemId">The item id.</param> /// <returns>The list of properities.</returns> public IList <DaProperty> GetProperties(string itemId) { Session session = Session; if (session == null) { throw ComUtils.CreateComException(ResultIds.E_FAIL); } return(m_browseManager.GetAvailableProperties(session, itemId)); }
/// <summary> /// Provides a mechanism to assemble a fully qualified Area name in a hierarchical space. /// </summary> /// <param name="szAreaName">The name of an Area at the current level, obtained from the string enumerator returned by BrowseOPCAreas with a BrowseFilterType of OPC_AREA</param> /// <param name="pszQualifiedAreaName">Where to return the resulting fully qualified area name.</param> public void GetQualifiedAreaName(string szAreaName, out string pszQualifiedAreaName) { pszQualifiedAreaName = String.Empty; try { pszQualifiedAreaName = szAreaName; // Make sure the stack is not null INode parent = m_browseStack.Peek(); if (parent == null) { throw ComUtils.CreateComException(ResultIds.E_FAIL); } // And make sure this is avalid Area name at the level INode child = FindChildByName(parent.NodeId, szAreaName); if (child == null) { throw ComUtils.CreateComException(ResultIds.E_INVALIDARG); } pszQualifiedAreaName = ""; INode[] stack = m_browseStack.ToArray(); for (int i = stack.Length - 2; i >= 0; i--) { // Translate the server namespace index in browsename to the corresponding client namespace index QualifiedName QName = stack[i].BrowseName; QualifiedName translatedName = new QualifiedName(QName.Name, (ushort)m_server.ServerMappingTable[QName.NamespaceIndex]); if (pszQualifiedAreaName.Length != 0) { pszQualifiedAreaName = pszQualifiedAreaName + "/" + translatedName.ToString(); } else { pszQualifiedAreaName = translatedName.ToString(); } } //Also translate the areaname QualifiedName QualifiedAreaName = QualifiedName.Parse(szAreaName); QualifiedName TranslatedAreaName = new QualifiedName(QualifiedAreaName.Name, (ushort)m_server.ServerMappingTable[QualifiedAreaName.NamespaceIndex]); pszQualifiedAreaName = pszQualifiedAreaName + "/" + TranslatedAreaName.ToString(); } catch (COMException e) { throw ComUtils.CreateComException(e); } catch (Exception e) { Utils.Trace(e, "Unexpected error in GetQualifiedAreaName"); throw ComUtils.CreateComException(e); } }
/// <remarks/> public void GetConnectionPointContainer(out OpcRcw.Comn.IConnectionPointContainer ppCPC) { lock (m_lock) { try { ppCPC = m_container; } catch (Exception e) { throw ComUtils.CreateComException(e); } } }
/// <remarks/> public void Clone(out IEnumOPCItemAttributes ppEnumItemAttributes) { lock (m_lock) { try { ppEnumItemAttributes = new EnumOPCItemAttributes(m_items); } catch (Exception e) { throw ComUtils.CreateComException(e); } } }
/// <remarks/> public void GetConnectionInterface(out Guid pIID) { lock (m_lock) { try { pIID = m_interface; } catch (Exception e) { throw ComUtils.CreateComException(e); } } }
/// <remarks/> public void Clone(out OpcRcw.Comn.IEnumString ppenum) { lock (m_lock) { try { ppenum = new EnumString(m_strings); } catch (Exception e) { throw ComUtils.CreateComException(e); } } }
/// <remarks/> public void Reset() { lock (m_lock) { try { m_index = 0; } catch (Exception e) { throw ComUtils.CreateComException(e); } } }
/// <summary> /// Throws if disposed or not connected. /// </summary> protected Session ThrowIfNotConnected() { if (m_disposed) { throw new ObjectDisposedException(GetType().Name); } if (m_session == null || !m_session.Connected) { throw ComUtils.CreateComException(ResultIds.E_FAIL); } return(m_session); }
/// <remarks/> public void Clone(out OpcRcw.Comn.IEnumConnectionPoints ppenum) { lock (m_lock) { try { ppenum = new EnumConnectionPoints(m_connectionPoints); } catch (Exception e) { throw ComUtils.CreateComException(e); } } }
/// <summary> /// Selects the attributes for the event category. /// </summary> public void SelectAttributes( uint categoryId, uint[] attributeIds) { ThrowIfDisposed(); lock (m_lock) { if (!m_filter.SelectAttributes(categoryId, attributeIds)) { throw ComUtils.CreateComException(ResultIds.E_INVALIDARG); } } }
/// <remarks/> public void Clone(out IEnumUnknown ppenum) { lock (m_lock) { try { ppenum = new EnumUnknown(m_unknowns); } catch (Exception e) { throw ComUtils.CreateComException(e); } } }
/// <summary> /// Gets the item ids for the properties. /// </summary> /// <param name="session">The session.</param> /// <param name="itemId">The item id.</param> /// <param name="propertyIds">The property ids.</param> /// <param name="itemIds">The item ids.</param> /// <returns>Any errors.</returns> public IList <int> GetItemIds(Session session, string itemId, int[] propertyIds, out string[] itemIds) { TraceState("GetItemId", itemId); // no properties for the root. if (String.IsNullOrEmpty(itemId)) { throw ComUtils.CreateComException(ResultIds.E_INVALIDITEMID); } // select all available properties if none provided. IList <DaProperty> properties = GetAvailableProperties(session, itemId); if (propertyIds == null || propertyIds.Length == 0) { propertyIds = new int[properties.Count]; for (int ii = 0; ii < propertyIds.Length; ii++) { propertyIds[ii] = properties[ii].PropertyId; } } itemIds = new string[propertyIds.Length]; int[] results = new int[propertyIds.Length]; for (int ii = 0; ii < propertyIds.Length; ii++) { results[ii] = ResultIds.E_INVALID_PID; // must return E_INVALID_PID for standard properties. if (propertyIds[ii] <= PropertyIds.EuInfo) { continue; } // supported properties must return E_FAIL. for (int jj = 0; jj < properties.Count; jj++) { if (properties[jj].PropertyId == propertyIds[ii]) { results[ii] = ResultIds.E_FAIL; break; } } } return(results); }
/// <summary> /// Force a refresh for all active conditions and inactive, unacknowledged conditions whose event notifications match the filter of the event subscription. /// </summary> /// <param name="dwConnection">The OLE Connection number returned from IConnectionPoint::Advise. This is passed to help the server determine which OPC event sink to call when the request completes.</param> public void Refresh(int dwConnection) { try { if (m_RefreshID != 0 || m_RefreshQ.Count != 0) { throw ComUtils.CreateComException("Refresh", ResultIds.E_BUSY); } m_RefreshID = dwConnection; // Foe each source walk through all associated conditions. If the condition is "refreshable", i.e. Active or // inactive/unacknowledged, then create an event and push it on to the subscription's refresh queue SourceMap sourceMap = SourceMap.TheSourceMap; foreach (KeyValuePair <string, ConditionMap> kvp in sourceMap) { string sourceName = kvp.Key; ConditionMap conditionMap = kvp.Value; foreach (KeyValuePair <string, OPCCondition> kvpCond in conditionMap) { string conditionName = kvpCond.Key; OPCCondition cond = kvpCond.Value; if (cond.IsEnabled() && (cond.IsActive() || !cond.IsAcked())) { OnEventClass OEClass = new OnEventClass(sourceName, conditionName, cond); if (MatchesFilter(OEClass)) { m_RefreshQ.Enqueue(OEClass); } } } } if (m_RefreshQ.Count > 0) { ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadWork), null); } else { CancelRefresh(dwConnection); } } catch (Exception e) { Utils.Trace(e, "Unexpected error in Refresh"); throw ComUtils.CreateComException(e); } }
/// <summary> /// Sets the attributes to be returned with event notifications in the IOPCEventSink::OnEvent callback. /// </summary> /// <param name="dwEventCategory">The specific event category for which the list of attributes applies.</param> /// <param name="dwCount">The size of the attribute IDs array.</param> /// <param name="dwAttributeIDs">The list IDs of the attributes to return with event notifications for the event type and event category specified.</param> public void SelectReturnedAttributes(int dwEventCategory, int dwCount, int[] dwAttributeIDs) { try { if (dwCount < 0) { throw ComUtils.CreateComException("SelectReturnedAttributes", ResultIds.E_INVALIDARG); } // Make sure we are passed a valid dwEventCategory NodeId catNodeId = m_server.FindEventCatNodeId(dwEventCategory); if (catNodeId == null) { throw ComUtils.CreateComException("SelectReturnedAttributes", ResultIds.E_INVALIDARG); } // Check for valid attributeIds List <EventAttribute> attrs = m_server.GetEventAttributes(dwEventCategory); for (int i = 0; i < dwCount; i++) { if (!CompareAttribID(attrs, dwAttributeIDs[i])) { throw ComUtils.CreateComException("SelectReturnedAttributes", ResultIds.E_INVALIDARG); } ; } lock (m_csData) { ReturnedAttributeList ras = new ReturnedAttributeList(); for (int i = 0; i < dwCount; i++) { ras.AddUnique(dwAttributeIDs[i]); } m_ReturnedAttributes[dwEventCategory] = ras; } } catch (COMException e) { throw ComUtils.CreateComException(e); } catch (Exception e) { Utils.Trace(e, "Unexpected error in SelectReturnedAttributes"); throw ComUtils.CreateComException(e); } }
/// <summary> /// Browse for all items below the current branch. /// </summary> /// <param name="filter">The filter.</param> /// <param name="dataTypeFilter">The data type filter.</param> /// <param name="accessRightsFilter">The access rights filter.</param> /// <returns> /// The list of item ids that meet the criteria. /// </returns> public IList <string> BrowseForItems(string filter, short dataTypeFilter, int accessRightsFilter) { Session session = Session; if (session == null) { throw ComUtils.CreateComException(ResultIds.E_FAIL); } return(m_browseManager.BrowseFlat( session, filter, dataTypeFilter, accessRightsFilter)); }
/// <summary> /// Returns the currently active keep-alive time for the subscription. /// </summary> public void GetKeepAlive(out int pdwKeepAliveTime) { pdwKeepAliveTime = 0; lock (m_csData) { try { pdwKeepAliveTime = m_KeepAliveTime; } catch (Exception e) { throw ComUtils.CreateComException(e); } } }
/// <summary> /// Cancels a refresh in progress for the event subscription. /// </summary> /// <param name="dwConnection">The OLE Connection number returned from IConnectionPoint::Advise. This is passed to help the server determine which OPC event sink to call when the request completes.</param> public void CancelRefresh(int dwConnection) { if (dwConnection == 0) { throw ComUtils.CreateComException("CancelRefresh", ResultIds.E_INVALIDARG); } if (dwConnection != m_RefreshID) { throw ComUtils.CreateComException("CancelRefresh", ResultIds.E_FAIL); } m_bCancelRefresh = true; ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadWork), null); }
/// <summary> /// Recovers the session context. /// </summary> /// <param name="group">The group.</param> public void RecoverSessionContext(ComDaGroup group) { // create a new subscription and copy existing one. Subscription discardSubscription = group.Subscription; Subscription subscription = new Subscription(); subscription.DisplayName = discardSubscription.DisplayName; subscription.PublishingInterval = discardSubscription.PublishingInterval; subscription.KeepAliveCount = discardSubscription.KeepAliveCount; subscription.LifetimeCount = discardSubscription.LifetimeCount; subscription.MaxNotificationsPerPublish = discardSubscription.MaxNotificationsPerPublish; subscription.Priority = discardSubscription.Priority; subscription.PublishingEnabled = discardSubscription.PublishingEnabled; subscription.DisableMonitoredItemCache = discardSubscription.DisableMonitoredItemCache; try { discardSubscription.Dispose(); } catch (Exception) { } m_session.AddSubscription(subscription); try { // create the initial subscription. subscription.Create(); // set the keep alive interval to 30 seconds and the the lifetime interval to 5 minutes. subscription.KeepAliveCount = (uint)((30000 / (int)subscription.CurrentPublishingInterval) + 1); subscription.LifetimeCount = (uint)((600000 / (int)subscription.CurrentPublishingInterval) + 1); // update the subscription. subscription.Modify(); } catch (Exception e) { m_session.RemoveSubscription(subscription); throw ComUtils.CreateComException(e, ResultIds.E_FAIL); } // update the group. group.ActualUpdateRate = (int)(subscription.CurrentPublishingInterval * 2); group.Subscription = subscription; group.RecreateItems(); }
/// <summary> /// Browses the current branch. /// </summary> /// <param name="isBranch">if set to <c>true</c> the return branches.</param> /// <param name="filter">The filter.</param> /// <param name="dataTypeFilter">The data type filter.</param> /// <param name="accessRightsFilter">The access rights filter.</param> /// <returns>The list of names that meet the criteria.</returns> public IList <string> BrowseForNames(bool isBranch, string filter, short dataTypeFilter, int accessRightsFilter) { Session session = Session; if (session == null) { throw ComUtils.CreateComException(ResultIds.E_FAIL); } return(m_browseManager.BrowseForNames( session, (isBranch)?BrowseElementFilter.Branch:BrowseElementFilter.Item, filter, dataTypeFilter, accessRightsFilter)); }
/// <summary> /// Client can set various properties of the event subscription. /// </summary> /// <param name="pbActive">TRUE (non-zero) to activate the subscription. FALSE (0) to deactivate the subscription.</param> /// <param name="pdwBufferTime">New buffer time requested for the subscription by the client.</param> /// <param name="pdwMaxSize">New maximum number of event notifications to send with a single IOPCEventSink::OnEvent callback.</param> /// <param name="hClientSubscription">Client supplied handle for the subscription.</param> /// <param name="pdwRevisedBufferTime">The buffer time that the server is actually providing, which may differ from dwBufferTime.</param> /// <param name="pdwRevisedMaxSize">The maximum number of events that the server will actually be sending in a single IOPCEventSink::OnEvent callback, which may differ from dwMaxSize.</param> public void SetState( IntPtr pbActive, IntPtr pdwBufferTime, IntPtr pdwMaxSize, int hClientSubscription, out int pdwRevisedBufferTime, out int pdwRevisedMaxSize) { pdwRevisedBufferTime = m_dwBufferTime; pdwRevisedMaxSize = m_dwMaxSize; try { int dwBufferTime = 0; int dwMaxSize = 0; if (pbActive != IntPtr.Zero) { m_bActive = Marshal.ReadInt32(pbActive) == 0 ? false : true; } m_hClientSubscription = hClientSubscription; // Set revised max size to the smaller of (1)requested size or (2)default max if (pdwMaxSize != IntPtr.Zero) { dwMaxSize = Marshal.ReadInt32(pdwMaxSize); dwMaxSize = dwMaxSize > 0 ? dwMaxSize : DefaultMaxCallbackSize; m_dwMaxSize = (dwMaxSize < DefaultMaxCallbackSize ? dwMaxSize : DefaultMaxCallbackSize); pdwRevisedMaxSize = m_dwMaxSize; } // Set revised buffer time to the larger of (1)requested time or (2) default time if (pdwBufferTime != IntPtr.Zero) { dwBufferTime = Marshal.ReadInt32(pdwBufferTime); dwBufferTime = dwBufferTime > 0 ? dwBufferTime : DefaultBufferTime; m_dwBufferTime = (dwBufferTime > DefaultBufferTime ? dwBufferTime : DefaultBufferTime); pdwRevisedBufferTime = m_dwBufferTime; } } catch (Exception e) { Utils.Trace(e, "Unexpected error in SetState"); throw ComUtils.CreateComException(e); } }
/// <summary> /// Browse for all items below the current branch. /// </summary> /// <returns> /// The list of item ids that meet the criteria. /// </returns> public IList <string> BrowseForItems() { Session session = m_server.Session; if (session == null) { throw ComUtils.CreateComException(ResultIds.E_FAIL); } ComDaBrowseElement position = m_browseManager.GetBrowsePosition(session); List <ComDaBrowseElement> elements = new List <ComDaBrowseElement>(); BrowseForItems(session, position, elements); return(ApplyFilters(elements, (int)OPCHDA_BROWSETYPE.OPCHDA_FLAT)); }
/// <summary> /// Gets the qualified name. /// </summary> public string GetQualifiedName(string targetName, bool isArea) { Session session = m_server.Session; if (session == null) { throw ComUtils.CreateComException(ResultIds.E_FAIL); } lock (m_lock) { List <AeBrowseElement> elements = null; // check if this is the first access. if (isArea) { if (m_position.Areas == null) { Browse(true, String.Empty); } elements = m_position.Areas; } else { if (m_position.Sources == null) { Browse(false, String.Empty); } elements = m_position.Sources; } // find the target. for (int ii = 0; ii < elements.Count; ii++) { if (elements[ii].BrowseText == targetName) { return(elements[ii].ItemId); } } throw ComUtils.CreateComException(ResultIds.E_INVALIDARG); } }