示例#1
0
        /// <summary>
        /// Adds an link and an item with the same id to the address space.
        /// </summary>
        private bool AddItemAndLink(string browsePath, ushort itemIndex, IDeviceIndexed device)
        {
            lock (this)
            {
                // validate browse path.
                if (browsePath == null || browsePath.Length == 0)
                {
                    return(false);
                }

                // check if item does not exists.
                if (m_items.Contains(browsePath))
                {
                    return(false);
                }

                // create the browse element.
                BrowseElement element = m_addressSpace.Insert(browsePath);

                if (element == null)
                {
                    return(false);
                }

                // create new item and index by item id.
                m_items[element.ItemID] = new CacheItem(browsePath, itemIndex, device);
                return(true);
            }
        }
示例#2
0
 /// <summary>
 /// Adds the address space for the device to the cache.
 /// </summary>
 private void BuildAddressSpace(IDeviceIndexed device, ItemDsc[] browsePath)
 {
     lock (this)
         foreach (ItemDsc item in browsePath)
         {
             AddItemAndLink(item.itemID, item.itemIdx, device);
         }
 }
示例#3
0
        internal static object ReadProperty(PropertyID propertyID, IDeviceIndexed device, ushort ItemIndex)
        {
            ItemValueResult result = device.Read(ItemIndex, propertyID);

            if (result == null || result.ResultID.Failed())
            {
                return(null);
            }
            return(result.Value);
        }
示例#4
0
        /// <summary>
        /// Initializes the object with its item id and device.
        /// </summary>
        internal CacheItem(string itemID, ushort itemIndex, IDeviceIndexed device)
        {
            if (itemID == null)
            {
                throw new ArgumentNullException("itemID");
            }
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }

            m_settings = new CacheItemSettings(itemID, itemIndex, device);
        }
示例#5
0
 public void GetIndexedAddressSpaceTestMethod()
 {
     using (Device _device = new Device())
     {
         IDeviceIndexed _iDeviceIndexed = _device as IDeviceIndexed;
         Assert.IsNotNull(_iDeviceIndexed);
         ItemDsc[] _itemsDsc = _iDeviceIndexed.GetIndexedAddressSpace;
         Assert.IsNotNull(_itemsDsc);
         Assert.AreEqual <int>(UnitTestAssemblyInitialize.NotSortedAddressSpace.Count, _itemsDsc.Length);
         string[] _addressSpace = _itemsDsc.Select <ItemDsc, string>(x => x.itemID).ToArray <string>();
         CollectionAssert.AreEqual(UnitTestAssemblyInitialize.NotSortedAddressSpace.Select <UnitTestAssemblyInitialize.TestTagInDevice, string>(x => x.ItemID).ToList <string>(), _addressSpace,
                                   $"{string.Join(",", UnitTestAssemblyInitialize.NotSortedAddressSpace.Select<UnitTestAssemblyInitialize.TestTagInDevice, string>(x => x.ItemID))} # {string.Join(",", _addressSpace)}");
     };
 }
示例#6
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}");
     };
 }
示例#7
0
            internal CacheItemSettings(string itemID, ushort ItemIndex, IDeviceIndexed Device)
            {
                lock (this)
                {
                    m_itemID    = itemID;
                    m_ItemIndex = ItemIndex;
                    m_device    = Device;

                    m_datatype = (System.Type)CacheItem.ReadProperty(Property.DATATYPE, m_device, m_ItemIndex);
                    m_euType   = (euType)CacheItem.ReadProperty(Property.EUTYPE, m_device, m_ItemIndex);

                    if (m_euType == euType.enumerated)
                    {
                        m_euInfo = (string[])CacheItem.ReadProperty(Property.EUINFO, m_device, m_ItemIndex);
                    }
                }
            }