Пример #1
0
 /// <remarks/>
 public void Clone(out IEnumOPCItemAttributes ppEnumItemAttributes)
 {
     lock (m_lock)
     {
         try
         {
             ppEnumItemAttributes = new EnumOPCItemAttributes(m_items);
         }
         catch (Exception e)
         {
             throw ComUtils.CreateComException(e);
         }
     }
 }
Пример #2
0
		/// <remarks/>
		public void Clone(out IEnumOPCItemAttributes ppEnumItemAttributes)
		{			
			lock (m_lock)
			{
				try
				{
					ppEnumItemAttributes = new EnumOPCItemAttributes(m_items);
				}
				catch (Exception e)
				{
					throw ComUtils.CreateComException(e);
				}
			}
		}
Пример #3
0
        /// <summary>
        /// IOPCItemMgt::CreateEnumerator - Creates an enumerator for the items in the group.
        /// </summary>
		public void CreateEnumerator(ref Guid riid, out object ppUnk)
		{
			lock (m_lock)
			{
				if (m_subscription == null) throw ComUtils.CreateComException(ResultIds.E_FAIL);

				if (riid != typeof(OpcRcw.Da.IEnumOPCItemAttributes).GUID)
				{
					throw ComUtils.CreateComException(ResultIds.E_INVALIDARG);
				}

				try
				{			

                    List<EnumOPCItemAttributes.ItemAttributes> itemsToEnumerate = new List<EnumOPCItemAttributes.ItemAttributes>();

                    foreach (Item item in m_items.Values)
                    {
						EnumOPCItemAttributes.ItemAttributes attributes = new EnumOPCItemAttributes.ItemAttributes();

						attributes.ItemID            = item.ItemId;
						attributes.AccessPath        = String.Empty;
						attributes.ClientHandle      = item.ClientHandle;
						attributes.ServerHandle      = item.ServerHandle;
						attributes.Active            = item.Active;
						attributes.RequestedDataType = item.ReqType;
						attributes.AccessRights      = ComUtils.GetAccessRights(item.Variable.AccessLevel);
						attributes.CanonicalDataType = m_server.DataTypeToVarType(item.Variable.DataType, item.Variable.ValueRank);
						attributes.EuType            = OpcRcw.Da.OPCEUTYPE.OPC_NOENUM;
						attributes.MaxValue          = 0; 
						attributes.MinValue          = 0; 
						attributes.EuInfo            = null;

                        if (attributes.CanonicalDataType == VarEnum.VT_VARIANT)
                        {
                            attributes.CanonicalDataType = VarEnum.VT_EMPTY;
                        }

                        // find euRange.
                        VariableNode euRange = m_session.NodeCache.Find(
                            item.Variable.NodeId, 
                            ReferenceTypeIds.HasProperty, 
                            false, 
                            true, 
                            Opc.Ua.BrowseNames.EURange) as VariableNode;

                        if (euRange != null)
                        {						
                            attributes.EuType = OpcRcw.Da.OPCEUTYPE.OPC_ANALOG;

                            Range range = ExtensionObject.ToEncodeable(euRange.Value.Value as ExtensionObject) as Range;

                            if (range != null)
                            {
						        attributes.MaxValue = range.High; 
						        attributes.MinValue = range.Low; 
                            }
                        }
                        
                        // find enumStrings.
                        VariableNode enumStrings = m_session.NodeCache.Find(
                            item.Variable.NodeId, 
                            ReferenceTypeIds.HasProperty, 
                            false, 
                            true, 
                            Opc.Ua.BrowseNames.EnumStrings) as VariableNode;

                        if (enumStrings != null)
                        {						
                            attributes.EuType = OpcRcw.Da.OPCEUTYPE.OPC_ENUMERATED;

                            LocalizedText[] strings = enumStrings.Value.Value as LocalizedText[];

                            if (strings != null)
                            {
                                attributes.EuInfo = new string[strings.Length];

                                for (int ii = 0; ii < strings.Length; ii++)
                                {
                                    attributes.EuInfo[ii] = strings[ii].Text;
                                }
                            }
                        }

                        // add item
                        itemsToEnumerate.Add(attributes);
                    }

                    // create enumerator.
					ppUnk = new EnumOPCItemAttributes(itemsToEnumerate);
				}
				catch (Exception e)
				{
					throw ComUtils.CreateComException(e);
				}
			}
		}