Esempio n. 1
0
        //======================================================================
        // GetProperties

        /// <summary>
        /// Returns the item properties for a set of items.
        /// </summary>
        /// <param name="itemIDs">A list of item identifiers.</param>
        /// <param name="propertyIDs">A list of properties to fetch for each item.</param>
        /// <param name="returnValues">Whether the property values should be returned with the properties.</param>
        /// <returns>A list of properties for each item.</returns>
        public ItemPropertyCollection[] GetProperties(
            ItemIdentifier[] itemIDs,
            PropertyID[] propertyIDs,
            bool returnValues)
        {
            if (itemIDs == null)
            {
                throw new ArgumentNullException("itemIDs");
            }

            lock (this)
            {
                ArrayList items = new ArrayList();

                foreach (ItemIdentifier itemID in itemIDs)
                {
                    ItemPropertyCollection properties = m_cache.GetProperties(itemID, propertyIDs, returnValues);

                    if (properties != null)
                    {
                        items.Add(properties);
                    }
                }

                return((ItemPropertyCollection[])items.ToArray(typeof(ItemPropertyCollection)));
            }
        }
Esempio n. 2
0
 internal static ItemPropertyCollection[] GetItemPropertyCollections(ref IntPtr pInput, int count, bool deallocate)
 {
     ItemPropertyCollection[] propertysArray = null;
     if ((pInput != IntPtr.Zero) && (count > 0))
     {
         propertysArray = new ItemPropertyCollection[count];
         IntPtr ptr = pInput;
         for (int i = 0; i < count; i++)
         {
             OPCITEMPROPERTIES input = (OPCITEMPROPERTIES)Marshal.PtrToStructure(ptr, typeof(OPCITEMPROPERTIES));
             propertysArray[i]          = new ItemPropertyCollection();
             propertysArray[i].ItemPath = null;
             propertysArray[i].ItemName = null;
             propertysArray[i].ResultID = OpcCom.Interop.GetResultID(input.hrErrorID);
             ItemProperty[] itemProperties = GetItemProperties(ref input, deallocate);
             if (itemProperties != null)
             {
                 propertysArray[i].AddRange(itemProperties);
             }
             if (deallocate)
             {
                 Marshal.DestroyStructure(ptr, typeof(OPCITEMPROPERTIES));
             }
             ptr = (IntPtr)(ptr.ToInt32() + Marshal.SizeOf(typeof(OPCITEMPROPERTIES)));
         }
         if (deallocate)
         {
             Marshal.FreeCoTaskMem(pInput);
             pInput = IntPtr.Zero;
         }
     }
     return(propertysArray);
 }
Esempio n. 3
0
        public void GetAvailablePropertiesTestMethod()
        {
            using (Device _device = new Device())
            {
                IDevice _iDevice = _device as IDevice;
                Assert.IsFalse(_iDevice.IsKnownItem("bleble"));
                Assert.IsTrue(_iDevice.IsKnownItem("TestTagInDevice6"));

                ItemPropertyCollection _properties = _iDevice.GetAvailableProperties("TestTagInDevice6", true);
                Assert.IsNotNull(_properties);
                Assert.AreEqual <int>(8, _properties.Count);
                Assert.AreEqual <string>(null, _properties.DiagnosticInfo, $"DiagnosticInfo: {_properties.DiagnosticInfo}");
                Assert.AreEqual <string>("TestTagInDevice6", _properties.ItemName, $"ItemName: {_properties.ItemName}");
                Assert.AreEqual <string>(null, _properties.ItemPath, $"ItemPath: {_properties.ItemPath}");
                Assert.AreEqual <ResultID>(ResultID.S_OK, _properties.ResultID, $"ResultID: {_properties.ItemPath}");

                Dictionary <PropertyID, ItemProperty> _sortedProperties = _properties.Cast <ItemProperty>().ToDictionary <ItemProperty, PropertyID>(x => x.ID);
                Assert.IsTrue(_sortedProperties.ContainsKey(Property.VALUE));

                int _valueIndex = _properties.IndexOf(_sortedProperties[Property.VALUE]);
                Assert.IsTrue(_valueIndex >= 0 && _valueIndex < _properties.Count, $"IndexOf: {Property.VALUE} is {_valueIndex}");
                Assert.AreSame(typeof(object), _properties[_valueIndex].DataType, $"DataType: {_properties[1].DataType}");
                Assert.AreEqual <string>("value", (string)_properties[1].Value, $"Current value: {_properties[1].Value}");
                Assert.AreEqual <PropertyID>(Property.VALUE, _properties[_valueIndex].ID, $"ID: {_properties[1].DataType}");
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Fetches the specified properties for an item.
        /// </summary>
        private Opc.Da.ItemProperty[] GetProperties(
            CacheItem item,
            PropertyID[] propertyIDs,
            bool returnValues)
        {
            // check for trivial case.
            if (item == null)
            {
                return(null);
            }

            // fetch properties.
            ItemPropertyCollection properties = null;

            if (propertyIDs == null)
            {
                properties = item.GetAvailableProperties(returnValues);
            }
            else
            {
                properties = item.GetAvailableProperties(propertyIDs, returnValues);
            }

            // convert collection to array.
            return((Opc.Da.ItemProperty[])properties.ToArray(typeof(Opc.Da.ItemProperty)));
        }
Esempio n. 5
0
        /// <summary>
        /// static function that read item property collection for selected item
        /// </summary>
        /// <param name="ItemName">item name to be read</param>
        /// <param name="ds">data set with settings</param>
        /// <returns>collection of properties</returns>
        public static ItemPropertyCollection GetItemPropertiesCollection(string ItemName, ItemDecriberDataSet ds)
        {
            ItemPropertyCollection _ret = null;

            if (ds != null)
            {
                _ret = new ItemPropertyCollection();
                foreach (ItemDecriberDataSet.ItemsRow _row in ds.Items.Rows)
                {
                    if (_row.ItemName == ItemName)
                    {
                        foreach (ItemDecriberDataSet.ItemPropertyRow row_property in _row.GetItemPropertyRows())
                        {
                            PropertyDescription prop_dsc = PropertyDescription.Find(new PropertyID(row_property.PropertyCode));
                            ItemProperty        itemprop = new ItemProperty
                            {
                                ID    = prop_dsc.ID,
                                Value = row_property.Value
                            };
                            _ret.Add(itemprop);
                        }
                        break;
                    }
                }
            }
            return(_ret);
        }
Esempio n. 6
0
        /// <summary>
        /// Returns the specified properties for the specified item.
        /// </summary>
        public Opc.Da.ItemPropertyCollection GetAvailableProperties(
            string itemID,
            PropertyID[] propertyIDs,
            bool returnValues)
        {
            lock (this)
            {
                // initialize result.
                ItemPropertyCollection properties = new ItemPropertyCollection();

                properties.ItemName       = itemID;
                properties.ItemPath       = null;
                properties.ResultID       = ResultID.S_OK;
                properties.DiagnosticInfo = null;

                // lookup item.
                DeviceItem item = (DeviceItem)m_items[itemID];

                if (item == null)
                {
                    properties.ResultID = ResultID.Da.E_UNKNOWN_ITEM_NAME;
                    return(properties);
                }

                // fetch properties.
                return(item.GetAvailableProperties(propertyIDs, returnValues));
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Fetches the specified properties for an item.
        /// </summary>
        public ItemPropertyCollection GetProperties(
            ItemIdentifier itemID,
            PropertyID[]   propertyIDs,
            bool returnValues)
        {
            if (itemID == null)
            {
                throw new ArgumentNullException("itemID");
            }

            lock (this)
            {
                if (m_disposed)
                {
                    throw new ObjectDisposedException("Opc.Da.Cache");
                }

                ItemPropertyCollection properties = new ItemPropertyCollection();

                properties.ItemName       = itemID.ItemName;
                properties.ItemPath       = itemID.ItemPath;
                properties.ResultID       = ResultID.S_OK;
                properties.DiagnosticInfo = null;

                if (itemID.ItemName == null || itemID.ItemName.Length == 0)
                {
                    properties.ResultID = ResultID.Da.E_INVALID_ITEM_NAME;
                    return(properties);
                }

                // find the item.
                CacheItem item = (CacheItem)m_items[itemID.ItemName];

                if (item == null)
                {
                    properties.ResultID = ResultID.Da.E_UNKNOWN_ITEM_NAME;
                    return(properties);
                }

                // get the properties.
                if (propertyIDs == null)
                {
                    properties = item.GetAvailableProperties(returnValues);
                }
                else
                {
                    properties = item.GetAvailableProperties(propertyIDs, returnValues);
                }

                // return result.
                return(properties);
            }
        }
        public ItemPropertiesDescriptor( ItemContent content )
        {
            myOwner = content;

            if ( content.Properties != null )
            {
                myProperties = content.Properties;
            }
            else
            {
                myProperties = new ItemPropertyCollection();
            }
        }
Esempio n. 9
0
 public void IDeviceIndexedGetAvailablePropertiesTest()
 {
     using (Device _device = new Device())
     {
         IDeviceIndexed _iDeviceIndexed = _device as IDeviceIndexed;
         Assert.IsNotNull(_iDeviceIndexed);
         ItemPropertyCollection _properties = _iDeviceIndexed.GetAvailableProperties(0, true);
         Assert.IsNotNull(_properties);
         Assert.AreEqual <int>(8, _properties.Count);
         Assert.AreEqual <string>(null, _properties.DiagnosticInfo, $"DiagnosticInfo: {_properties.DiagnosticInfo}");
         Assert.AreEqual <string>("TestTagInDevice0", _properties.ItemName, $"ItemName: {_properties.ItemName}");
         Assert.AreEqual <string>(null, _properties.ItemPath, $"ItemPath: {_properties.ItemPath}");
         Assert.AreEqual <ResultID>(ResultID.S_OK, _properties.ResultID, $"ResultID: {_properties.ItemPath}");
     };
 }
Esempio n. 10
0
        public override ItemPropertyCollection[] GetProperties(ItemIdentifier[] itemIDs, PropertyID[] propertyIDs, bool returnValues)
        {
            if (itemIDs == null)
            {
                throw new ArgumentNullException("itemIDs");
            }

            if (itemIDs.Length == 0)
            {
                return(new ItemPropertyCollection[0]);
            }

            lock (this)
            {
                if (m_server == null)
                {
                    throw new NotConnectedException();
                }

                ItemPropertyCollection[] array = new ItemPropertyCollection[itemIDs.Length];
                for (int i = 0; i < itemIDs.Length; i++)
                {
                    array[i]          = new ItemPropertyCollection();
                    array[i].ItemName = itemIDs[i].ItemName;
                    array[i].ItemPath = itemIDs[i].ItemPath;
                    try
                    {
                        ItemProperty[] properties = GetProperties(itemIDs[i].ItemName, propertyIDs, returnValues);
                        if (properties != null)
                        {
                            array[i].AddRange(properties);
                        }

                        array[i].ResultID = ResultID.S_OK;
                    }
                    catch (ResultIDException ex)
                    {
                        array[i].ResultID = ex.Result;
                    }
                    catch (Exception e)
                    {
                        array[i].ResultID = new ResultID(Marshal.GetHRForException(e));
                    }
                }

                return(array);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Unmarshals and deallocates an array of OPCITEMPROPERTIES structures.
        /// </summary>
        internal static ItemPropertyCollection[] GetItemPropertyCollections(ref IntPtr pInput, int count, bool deallocate)
        {
            ItemPropertyCollection[] output = null;

            if (pInput != IntPtr.Zero && count > 0)
            {
                output = new ItemPropertyCollection[count];

                IntPtr pos = pInput;

                for (int ii = 0; ii < count; ii++)
                {
                    OpcRcw.Da.OPCITEMPROPERTIES list = (OpcRcw.Da.OPCITEMPROPERTIES)Marshal.PtrToStructure(pos, typeof(OpcRcw.Da.OPCITEMPROPERTIES));

                    output[ii]          = new ItemPropertyCollection();
                    output[ii].ItemPath = null;
                    output[ii].ItemName = null;
                    output[ii].ResultID = OpcCom.Interop.GetResultID(list.hrErrorID);

                    ItemProperty[] properties = GetItemProperties(ref list, deallocate);

                    if (properties != null)
                    {
                        output[ii].AddRange(properties);
                    }

                    if (deallocate)
                    {
                        Marshal.DestroyStructure(pos, typeof(OpcRcw.Da.OPCITEMPROPERTIES));
                    }

                    pos = (IntPtr)(pos.ToInt64() + Marshal.SizeOf(typeof(OpcRcw.Da.OPCITEMPROPERTIES)));
                }

                if (deallocate)
                {
                    Marshal.FreeCoTaskMem(pInput);
                    pInput = IntPtr.Zero;
                }
            }

            return(output);
        }
Esempio n. 12
0
 private void GetProperties(System.Windows.Forms.TreeNode node)
 {
     try
     {
         Opc.Da.Server server        = this.FindServer(node);
         BrowseElement browseElement = null;
         if (node.Tag != null && node.Tag.GetType() == typeof(BrowseElement))
         {
             browseElement = (BrowseElement)node.Tag;
         }
         if (browseElement.IsItem)
         {
             node.Nodes.Clear();
             ItemIdentifier           itemIdentifier = new ItemIdentifier(browseElement.ItemPath, browseElement.ItemName);
             ItemPropertyCollection[] properties     = server.GetProperties(new ItemIdentifier[]
             {
                 itemIdentifier
             }, this.m_filters.PropertyIDs, this.m_filters.ReturnPropertyValues);
             if (properties != null)
             {
                 ItemPropertyCollection[] array = properties;
                 for (int i = 0; i < array.Length; i++)
                 {
                     ItemPropertyCollection itemPropertyCollection = array[i];
                     foreach (ItemProperty property in itemPropertyCollection)
                     {
                         this.AddItemProperty(node, property);
                     }
                     browseElement.Properties = (ItemProperty[])itemPropertyCollection.ToArray(typeof(ItemProperty));
                 }
             }
             node.Expand();
             if (this.ElementSelected != null)
             {
                 this.ElementSelected(browseElement);
             }
         }
     }
     catch (System.Exception ex)
     {
         System.Windows.Forms.MessageBox.Show(ex.Message);
     }
 }
Esempio n. 13
0
        /// <summary>
        /// Returns the specified properties for the specified item.
        /// </summary>
        ItemPropertyCollection IDevice.GetAvailableProperties(string itemID, PropertyID[] propertyIDs, bool returnValues)
        {
            // initialize result.
            ItemPropertyCollection properties = new ItemPropertyCollection
            {
                ItemName       = itemID,
                ItemPath       = null,
                ResultID       = Opc.ResultID.S_OK,
                DiagnosticInfo = null
            };
            // lookup item.
            DeviceItem item = GetItemFromItemsByItemID(itemID);

            if (item == null)
            {
                properties.ResultID = ResultID.Da.E_UNKNOWN_ITEM_NAME;
                return(properties);
            }
            // fetch properties.
            return(item.GetAvailableProperties(propertyIDs, returnValues));
        }
      /// <summary>
      /// Tag constructor
      /// </summary>
      /// <param name="myDSC">parameters from Tags table</param>
      /// <param name="myStation">pointer to interface that allow to change priority of the station</param>
      internal Tag(ComunicationNet.TagsRow myDSC, IStationState myStation)
          : base(myDSC.Name, null, qualityBits.badNotConnected, (ItemAccessRights)myDSC.AccessRights, GetDataTypeFromConfig(myDSC))
      {
        switch ((StateTrigger)myDSC.StateTrigger)
        {
          case StateTrigger.StateHigh:
            stateHihgTriger = true;
            break;

          case StateTrigger.StateLow:
            stateLowTriger = true;
            break;

          default:
            break;
        }
        stateMask = (int)myDSC.StateMask;
        this.myStation = myStation;
        this.EuType = Opc.Da.euType.noEnum;
        ItemPropertyCollection itemPropertyCollection = new ItemPropertyCollection();
        foreach (ComunicationNet.ItemPropertiesTableRow row_property in myDSC.GetItemPropertiesTableRows())
        {
          try
          {
            PropertyDescription prop_dsc =
                PropertyDescription.Find(
                new PropertyID(
                    new XmlQualifiedName(row_property.ID_Name_Name, row_property.ID_Name_Namespace)
                    ));
            ItemProperty _itemProperty = new ItemProperty
            {
              ID = prop_dsc.ID,
              Value = row_property.Value
            };
            if (prop_dsc.ID != Opc.Da.Property.DATATYPE) //this property is managed differently
                                                         // as GetDataTypeFromConfig( myDSC )
                                                         // at the constructor
            {
              if (prop_dsc.ID == Opc.Da.Property.HI_LIMIT ||
                 prop_dsc.ID == Opc.Da.Property.LO_LIMIT ||
                  prop_dsc.ID == Opc.Da.Property.HIHI_LIMIT ||
                 prop_dsc.ID == Opc.Da.Property.LOLO_LIMIT ||
                 prop_dsc.ID == Opc.Da.Property.LOWEU ||
                  prop_dsc.ID == Opc.Da.Property.HIGHEU ||
                 prop_dsc.ID == Opc.Da.Property.SCANRATE
                )
              {
                // this property contains double value
                if (double.TryParse(row_property.Value, out double prop_value))
                  _itemProperty.Value = prop_value;
              }
              if (prop_dsc.ID == Opc.Da.Property.EUTYPE)
              {
                _itemProperty.Value = Opc.Da.euType.noEnum;
                // this property contains vale from enum: Opc.Da.euType
                foreach (Opc.Da.euType NEWeuType in Enum.GetValues(typeof(Opc.Da.euType)))
                {
                  if (NEWeuType.ToString() == row_property.Value)
                    _itemProperty.Value = NEWeuType;
                }
              }
              if (prop_dsc.ID == Opc.Da.Property.EUINFO)
              {
                //I assume that this is table of strings spited by ;
                _itemProperty.Value = row_property.Value.Split(';');
              }
              itemPropertyCollection.Add(_itemProperty);
            }
          }
          catch (Exception ex)
          {
            CommServerComponent.Tracer.TraceInformation(290, "DataBlock.Tag",
            "Problem with property for item : " + myDSC.Name + ": " +
              TraceEvent.GetMessageWithExceptionNameFromExceptionIncludingInnerException(ex));
          }
        }
        try
        {
          this.AddProperties(itemPropertyCollection);
        }
        catch (Exception ex)
        {
          CommServerComponent.Tracer.TraceInformation(290, "DataBlock.Tag",
          "Problem with many properties for item : " + myDSC.Name + ": " +
            TraceEvent.GetMessageWithExceptionNameFromExceptionIncludingInnerException(ex));
        }
      }
Esempio n. 15
0
        /// <summary>
        /// Returns the specified properties for the specified item.
        /// </summary>
        public Opc.Da.ItemPropertyCollection GetAvailableProperties(
            PropertyID[] propertyIDs,
            bool returnValues)
        {
            // initialize property collection.
            ItemPropertyCollection properties = new ItemPropertyCollection();

            properties.ItemName       = m_itemID;
            properties.ItemPath       = null;
            properties.ResultID       = ResultID.S_OK;
            properties.DiagnosticInfo = null;

            // fetch information for each requested property.
            foreach (PropertyID propertyID in propertyIDs)
            {
                ItemProperty property = new ItemProperty();

                property.ID = propertyID;

                // read the property value.
                if (returnValues)
                {
                    ItemValueResult result = Read(propertyID);

                    if (result.ResultID.Succeeded())
                    {
                        property.Value = result.Value;
                    }

                    property.ResultID       = result.ResultID;
                    property.DiagnosticInfo = result.DiagnosticInfo;
                }

                // just validate the property id.
                else
                {
                    property.ResultID = ValidatePropertyID(propertyID, accessRights.readWritable);
                }

                // set status if one or more errors occur.
                if (property.ResultID.Failed())
                {
                    properties.ResultID = ResultID.S_FALSE;
                }

                else
                {
                    // set property description.
                    PropertyDescription description = PropertyDescription.Find(propertyID);

                    if (description != null)
                    {
                        property.Description = description.Name;
                        property.DataType    = description.Type;
                    }

                    // set property item id.
                    if (propertyID.Code >= ENGINEERINGUINTS && propertyID.Code <= TIMEZONE)
                    {
                        property.ItemName = m_itemID + ":" + propertyID.Code.ToString();
                        property.ItemPath = null;
                    }
                }

                // add to collection.
                properties.Add(property);
            }

            // return collection.
            return(properties);
        }
Esempio n. 16
0
        /// <summary>
        /// Fetches the specified properties for an item.
        /// </summary>
        public ItemPropertyCollection GetProperties(
            ItemIdentifier itemID,
            PropertyID[]   propertyIDs,
            bool           returnValues)
        {
            if (itemID == null) throw new ArgumentNullException("itemID");

            lock (this)
            {
                if (m_disposed) throw new ObjectDisposedException("Opc.Da.Cache");

                ItemPropertyCollection properties = new ItemPropertyCollection();

                properties.ItemName       = itemID.ItemName;
                properties.ItemPath       = itemID.ItemPath;
                properties.ResultID       = ResultID.S_OK;
                properties.DiagnosticInfo = null;

                if (itemID.ItemName == null || itemID.ItemName.Length == 0)
                {
                    properties.ResultID = ResultID.Da.E_INVALID_ITEM_NAME;
                    return properties;
                }

                // find the item.
                CacheItem item = (CacheItem)m_items[itemID.ItemName];

                if (item == null)
                {
                    properties.ResultID = ResultID.Da.E_UNKNOWN_ITEM_NAME;
                    return properties;
                }

                // get the properties.
                if (propertyIDs == null)
                {
                    properties = item.GetAvailableProperties(returnValues);
                }
                else
                {
                    properties = item.GetAvailableProperties(propertyIDs, returnValues);
                }

                // return result.
                return properties;
            }
        }
        /// <summary>
        /// Returns the specified properties for the specified item.
        /// </summary>
        public Opc.Da.ItemPropertyCollection GetAvailableProperties(
            PropertyID[] propertyIDs,
            bool         returnValues)
        {
            // initialize property collection.
            ItemPropertyCollection properties = new ItemPropertyCollection();

            properties.ItemName       = m_itemID;
            properties.ItemPath       = null;
            properties.ResultID       = ResultID.S_OK;
            properties.DiagnosticInfo = null;

            // fetch information for each requested property.
            foreach (PropertyID propertyID in propertyIDs)
            {
                ItemProperty property = new ItemProperty();

                property.ID = propertyID;

                // read the property value.
                if (returnValues)
                {
                    ItemValueResult result = Read(propertyID);

                    if (result.ResultID.Succeeded())
                    {
                        property.Value = result.Value;
                    }

                    property.ResultID       = result.ResultID;
                    property.DiagnosticInfo = result.DiagnosticInfo;
                }

                // just validate the property id.
                else
                {
                    property.ResultID = ValidatePropertyID(propertyID, accessRights.readWritable);
                }

                // set status if one or more errors occur.
                if (property.ResultID.Failed())
                {
                    properties.ResultID = ResultID.S_FALSE;
                }

                else
                {
                    // set property description.
                    PropertyDescription description = PropertyDescription.Find(propertyID);

                    if (description != null)
                    {
                        property.Description = description.Name;
                        property.DataType    = description.Type;
                    }

                    // set property item id.
                    if (propertyID.Code >= ENGINEERINGUINTS && propertyID.Code <= TIMEZONE)
                    {
                        property.ItemName = m_itemID + ":" + propertyID.Code.ToString();
                        property.ItemPath = null;
                    }
                }

                // add to collection.
                properties.Add(property);
            }

            // return collection.
            return properties;
        }