/// <summary>
        /// Reads the current complex data item properties from the server.
        /// </summary>
        /// <param name="server">The server object</param>
        public void Update(TsCDaServer server)
        {
            // clear the existing state.
            Clear();

            // check if the item supports any of the complex data properties.
            TsCDaItemPropertyCollection[] results = server.GetProperties(
                new OpcItem[] { this },
                CPX_PROPERTIES,
                true);

            // unexpected return value.
            if (results == null || results.Length != 1)
            {
                throw new OpcResultException(new OpcResult((int)OpcResult.E_FAIL.Code, OpcResult.FuncCallType.SysFuncCall, null), "Unexpected results returned from server.");
            }

            // update object.
            if (!Init((TsCDaItemProperty[])results[0].ToArray(typeof(TsCDaItemProperty))))
            {
                throw new OpcResultException(new OpcResult((int)OpcResult.E_INVALIDARG.Code, OpcResult.FuncCallType.SysFuncCall, null), "Not a valid complex item.");
            }

            // check if data filters are suppported for the item.
            GetDataFilterItem(server);
        }
コード例 #2
0
        /// <summary>
        /// Browses for children of the element at the current node.
        /// </summary>
        private void GetProperties(TreeNode node)
        {
            try
            {
                // get the server for the current node.
                TsCDaServer server = FindServer(node);

                // get the current element to use for a get properties.
                TsCDaBrowseElement element = null;

                if (node.Tag != null && node.Tag.GetType() == typeof(TsCDaBrowseElement))
                {
                    element = (TsCDaBrowseElement)node.Tag;
                }

                // can only get properties for an item.
                if (!element.IsItem)
                {
                    return;
                }

                // clear the node children.
                node.Nodes.Clear();

                // begin a browse.
                OpcItem itemID = new OpcItem(element.ItemPath, element.ItemName);

                TsCDaItemPropertyCollection[] propertyLists = server.GetProperties(
                    new OpcItem[] { itemID },
                    m_filters.PropertyIDs,
                    m_filters.ReturnPropertyValues);

                if (propertyLists != null)
                {
                    foreach (TsCDaItemPropertyCollection propertyList in propertyLists)
                    {
                        foreach (TsCDaItemProperty property in propertyList)
                        {
                            AddItemProperty(node, property);
                        }

                        // update element properties.
                        element.Properties = (TsCDaItemProperty[])propertyList.ToArray(typeof(TsCDaItemProperty));
                    }
                }

                node.Expand();

                // send notification that property list changed.
                if (ElementSelected != null)
                {
                    ElementSelected(element);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
        /// <summary>
        /// Fetches the type description for the item.
        /// </summary>
        /// <param name="server">The server object</param>
        public string GetTypeDescription(TsCDaServer server)
        {
            TsCDaItemPropertyCollection[] results = server.GetProperties(
                new OpcItem[] { _typeItemID },
                new TsDaPropertyID[] { TsDaProperty.TYPE_DESCRIPTION },
                true);

            if (results == null || results.Length == 0 || results[0].Count == 0)
            {
                return(null);
            }

            TsCDaItemProperty property = results[0][0];

            if (!property.Result.Succeeded())
            {
                return(null);
            }

            return((string)property.Value);
        }
コード例 #4
0
		/// <summary>
		/// Fetches the type dictionary for the item.
		/// </summary>
		/// <param name="server">The server object</param>
		public string GetTypeDictionary(TsCDaServer server)
		{
			TsCDaItemPropertyCollection[] results = server.GetProperties(
				new OpcItem[] { _dictionaryItemID },
				new TsDaPropertyID[] { TsDaProperty.DICTIONARY },
				true);

			if (results == null || results.Length == 0 || results[0].Count == 0)
			{
				return null;
			}

			TsCDaItemProperty property = results[0][0];

			if (!property.Result.Succeeded())
			{
				return null;
			}

			return (string)property.Value;
		}
        /// <summary>
        /// Initializes an item value object with the item properties.
        /// </summary>
        private void GetDefaultValues(TsCDaItemValue[] items, bool valuesOnly)
        {
            try
            {
                // get item value properties.
                TsCDaItemPropertyCollection[] propertyLists = mServer_.GetProperties(
                    items,
                    new TsDaPropertyID[] { TsDaProperty.DATATYPE, TsDaProperty.QUALITY, TsDaProperty.TIMESTAMP, TsDaProperty.VALUE },
                    true);

                // update item values.
                for (int ii = 0; ii < items.Length; ii++)
                {
                    // ignore errors for failures for individual items.
                    if (propertyLists[ii].Result.Failed())
                    {
                        continue;
                    }

                    // set a default value based on the data type.
                    object defaultValue = propertyLists[ii][3].Value;

                    if (defaultValue == null)
                    {
                        System.Type type     = (System.Type)propertyLists[ii][0].Value;
                        System.Type baseType = (type.IsArray)?type.GetElementType():type;

                        if (baseType == typeof(string))
                        {
                            defaultValue = "";
                        }
                        if (baseType == typeof(DateTime))
                        {
                            defaultValue = DateTime.Now;
                        }
                        if (baseType == typeof(object))
                        {
                            defaultValue = "";
                        }

                        defaultValue = Technosoftware.DaAeHdaClient.OpcConvert.ChangeType(defaultValue, baseType);

                        // convert to a three element array.
                        if (type.IsArray)
                        {
                            defaultValue = new object[] { defaultValue, defaultValue, defaultValue };
                            defaultValue = Technosoftware.DaAeHdaClient.OpcConvert.ChangeType(defaultValue, type);
                        }
                    }

                    // update the object.
                    items[ii].Value     = defaultValue;
                    items[ii].Quality   = (TsCDaQuality)propertyLists[ii][1].Value;
                    items[ii].Timestamp = (DateTime)propertyLists[ii][2].Value;

                    // set the quality/timestamp exists flags.
                    items[ii].QualitySpecified   = !valuesOnly;
                    items[ii].TimestampSpecified = !valuesOnly;
                }
            }
            catch
            {
                // ignore errors.
            }
        }