コード例 #1
0
        /// <summary>
        /// Fetches the type dictionary for the item.
        /// </summary>
        /// <param name="itemID">The item id.</param>
        public static string GetTypeDictionary(OpcItem itemID)
        {
            if (itemID == null)
            {
                return(null);
            }

            lock (typeof(TsCCpxComplexTypeCache))
            {
                string dictionary = (string)_dictionaries[itemID.Key];

                if (dictionary != null)
                {
                    return(dictionary);
                }

                TsCCpxComplexItem item = GetComplexItem(itemID);

                if (item != null)
                {
                    dictionary = item.GetTypeDictionary(_server);
                }

                return(dictionary);
            }
        }
コード例 #2
0
        /// <summary>
        /// Fetches the type description for the item.
        /// </summary>
        /// <param name="itemID">The item id.</param>
        public static string GetTypeDescription(OpcItem itemID)
        {
            if (itemID == null)
            {
                return(null);
            }

            lock (typeof(TsCCpxComplexTypeCache))
            {
                string description = null;

                TsCCpxComplexItem item = GetComplexItem(itemID);

                if (item != null)
                {
                    description = (string)_descriptions[item.TypeItemID.Key];

                    if (description != null)
                    {
                        return(description);
                    }

                    _descriptions[item.TypeItemID.Key] = description = item.GetTypeDescription(_server);
                }

                return(description);
            }
        }
コード例 #3
0
        ///////////////////////////////////////////////////////////////////////
        #region Public Methods

        /// <summary>
        /// Returns the complex item for the specified item id.
        /// </summary>
        /// <param name="itemID">The item id.</param>
        public static TsCCpxComplexItem GetComplexItem(OpcItem itemID)
        {
            if (itemID == null)
            {
                return(null);
            }

            lock (typeof(TsCCpxComplexTypeCache))
            {
                TsCCpxComplexItem item = new TsCCpxComplexItem(itemID);

                try
                {
                    item.Update(_server);
                }
                catch
                {
                    // item is not a valid complex data item.
                    item = null;
                }

                _items[itemID.Key] = item;
                return(item);
            }
        }
        /// <summary>
        /// Fetches the set of data filters from the server.
        /// </summary>
        /// <param name="server">The server object</param>
        public TsCCpxComplexItem[] GetDataFilters(TsCDaServer server)
        {
            // not a valid operation for data filter items.
            if (_unfilteredItemID != null)
            {
                return(null);
            }

            // data filters not supported by the item.
            if (_filterItem == null)
            {
                return(null);
            }

            TsCDaBrowsePosition position = null;

            try
            {
                // browse any existing filter instances.
                TsCDaBrowseFilters filters = new TsCDaBrowseFilters {
                    ElementNameFilter = null, BrowseFilter = TsCDaBrowseFilter.Item, ReturnAllProperties = false, PropertyIDs = CPX_PROPERTIES, ReturnPropertyValues = true
                };

                TsCDaBrowseElement[] elements = server.Browse(_filterItem, filters, out position);

                // nothing found.
                if (elements == null || elements.Length == 0)
                {
                    return(new TsCCpxComplexItem[0]);
                }

                // contruct an array of complex data items for each available data filter.
                ArrayList dataFilters = new ArrayList(elements.Length);

                Array.ForEach(elements, element =>
                {
                    TsCCpxComplexItem item = new TsCCpxComplexItem();
                    if (item.Init(element))
                    {
                        dataFilters.Add(item);
                    }
                });

                // return the set of available data filters.
                return((TsCCpxComplexItem[])dataFilters.ToArray(typeof(TsCCpxComplexItem)));
            }
            finally
            {
                if (position != null)
                {
                    position.Dispose();
                    position = null;
                }
            }
        }
        /// <summary>
        /// Initializes the control with information specified to a complex item.
        /// </summary>
        private void SetComplexItem(OpcItem itemId)
        {
            mItem_ = TsCCpxComplexTypeCache.GetComplexItem(itemId);

            // do nothing for items that are not complex.
            if (mItem_ == null)
            {
                reqTypePn_.Visible     = true;
                complexItemPn_.Visible = false;
                return;
            }

            // display complex item controls.
            reqTypePn_.Visible     = false;
            complexItemPn_.Visible = true;

            // initialize controls.
            typeConversionCb_.Items.Clear();
            typeConversionCb_.Text             = null;
            typeConversionSpecifiedCb_.Checked = false;

            dataFilterTb_.Text             = null;
            dataFilterSpecifiedCb_.Checked = false;

            // fetch the available type conversions.
            Technosoftware.DaAeHdaClient.Cpx.TsCCpxComplexItem[] conversions = mItem_.GetRootItem().GetTypeConversions(TsCCpxComplexTypeCache.Server);

            // no conversions available.
            if (conversions == null || conversions.Length == 0)
            {
                typeConversionSpecifiedCb_.Enabled = false;
            }

            // populate conversions drop down menu.
            else
            {
                Technosoftware.DaAeHdaClient.Cpx.TsCCpxComplexItem item = mItem_;

                if (item.UnfilteredItemID != null)
                {
                    item = TsCCpxComplexTypeCache.GetComplexItem(item.UnfilteredItemID);
                }

                foreach (TsCCpxComplexItem conversion in conversions)
                {
                    typeConversionCb_.Items.Add(conversion);

                    if (conversion.Key == item.Key)
                    {
                        typeConversionCb_.SelectedItem     = conversion;
                        typeConversionSpecifiedCb_.Checked = true;
                    }
                }

                if (typeConversionCb_.SelectedItem == null)
                {
                    typeConversionCb_.SelectedIndex = 0;
                }
            }

            // display the active data filter.
            if (mItem_.UnfilteredItemID != null)
            {
                dataFilterTb_.Text             = mItem_.DataFilterValue;
                dataFilterSpecifiedCb_.Checked = true;
            }
        }
        /// <summary>
        /// Creates a new data filter.
        /// </summary>
        /// <param name="server">The server object</param>
        /// <param name="filterName">The name of the filter</param>
        /// <param name="filterValue">The value of the filter</param>
        public TsCCpxComplexItem CreateDataFilter(TsCDaServer server, string filterName, string filterValue)
        {
            // not a valid operation for data filter items.
            if (_unfilteredItemID != null)
            {
                return(null);
            }

            // data filters not supported by the item.
            if (_filterItem == null)
            {
                return(null);
            }

            TsCDaBrowsePosition position = null;

            try
            {
                // write the desired filter to the server.
                TsCDaItemValue item = new TsCDaItemValue(_filterItem);

                // create the filter parameters document.
                using (StringWriter ostrm = new StringWriter())
                {
                    using (XmlTextWriter writer = new XmlTextWriter(ostrm))
                    {
                        writer.WriteStartElement("DataFilters");
                        writer.WriteAttributeString("Name", filterName);
                        writer.WriteString(filterValue);
                        writer.WriteEndElement();
                        writer.Close();
                    }
                    // create the value to write.
                    item.Value = ostrm.ToString();
                }
                item.Quality            = TsCDaQuality.Bad;
                item.QualitySpecified   = false;
                item.Timestamp          = DateTime.MinValue;
                item.TimestampSpecified = false;

                // write the value.
                OpcItemResult[] result = server.Write(new TsCDaItemValue[] { item });

                if (result == null || result.Length == 0)
                {
                    throw new OpcResultException(new OpcResult((int)OpcResult.E_FAIL.Code, OpcResult.FuncCallType.SysFuncCall, null), "Unexpected results returned from server.");
                }

                if (result[0].Result.Failed())
                {
                    throw new OpcResultException(new OpcResult((int)OpcResult.Cpx.E_FILTER_ERROR.Code, OpcResult.FuncCallType.SysFuncCall, null), "Could not create new data filter.");
                }

                // browse for new data filter item.
                TsCDaBrowseFilters filters = new TsCDaBrowseFilters {
                    ElementNameFilter = filterName, BrowseFilter = TsCDaBrowseFilter.Item, ReturnAllProperties = false, PropertyIDs = CPX_PROPERTIES, ReturnPropertyValues = true
                };

                TsCDaBrowseElement[] elements = server.Browse(_filterItem, filters, out position);

                // nothing found.
                if (elements == null || elements.Length == 0)
                {
                    throw new OpcResultException(new OpcResult((int)OpcResult.Cpx.E_FILTER_ERROR.Code, OpcResult.FuncCallType.SysFuncCall, null), "Could not browse to new data filter.");
                }

                TsCCpxComplexItem filterItem = new TsCCpxComplexItem();

                if (!filterItem.Init(elements[0]))
                {
                    throw new OpcResultException(new OpcResult((int)OpcResult.Cpx.E_FILTER_ERROR.Code, OpcResult.FuncCallType.SysFuncCall, null), "Could not initialize to new data filter.");
                }

                // return the new data filter.
                return(filterItem);
            }
            finally
            {
                if (position != null)
                {
                    position.Dispose();
                    position = null;
                }
            }
        }
        /// <summary>
        /// Fetches the set of type conversions from the server.
        /// </summary>
        /// <param name="server">The server object</param>
        public TsCCpxComplexItem[] GetTypeConversions(TsCDaServer server)
        {
            // only the root item can have type conversions.
            if (_unconvertedItemID != null || _unfilteredItemID != null)
            {
                return(null);
            }

            TsCDaBrowsePosition position = null;

            try
            {
                // look for the 'CPX' branch.
                TsCDaBrowseFilters filters = new TsCDaBrowseFilters {
                    ElementNameFilter = CPX_BRANCH, BrowseFilter = TsCDaBrowseFilter.Branch, ReturnAllProperties = false, PropertyIDs = null, ReturnPropertyValues = false
                };

                TsCDaBrowseElement[] elements = server.Browse(this, filters, out position);

                // nothing found.
                if (elements == null || elements.Length == 0)
                {
                    return(null);
                }

                // release the browse position object.
                if (position != null)
                {
                    position.Dispose();
                    position = null;
                }

                // browse for type conversions.
                OpcItem itemID = new OpcItem(elements[0].ItemPath, elements[0].ItemName);

                filters.ElementNameFilter    = null;
                filters.BrowseFilter         = TsCDaBrowseFilter.Item;
                filters.ReturnAllProperties  = false;
                filters.PropertyIDs          = CPX_PROPERTIES;
                filters.ReturnPropertyValues = true;

                elements = server.Browse(itemID, filters, out position);

                // nothing found.
                if (elements == null || elements.Length == 0)
                {
                    return(new TsCCpxComplexItem[0]);
                }

                // contruct an array of complex data items for each available conversion.
                ArrayList conversions = new ArrayList(elements.Length);

                Array.ForEach(elements, element =>
                {
                    if (element.Name != CPX_DATA_FILTERS)
                    {
                        TsCCpxComplexItem item = new TsCCpxComplexItem();
                        if (item.Init(element))
                        {
                            // check if data filters supported for type conversion.
                            item.GetDataFilterItem(server);
                            conversions.Add(item);
                        }
                    }
                });

                // return the set of available conversions.
                return((TsCCpxComplexItem[])conversions.ToArray(typeof(TsCCpxComplexItem)));
            }
            finally
            {
                if (position != null)
                {
                    position.Dispose();
                    position = null;
                }
            }
        }