Пример #1
0
        /// <summary>
        /// Shows a detailed view for array values.
        /// </summary>
        private void ViewMI_Click(object sender, System.EventArgs e)
        {
            if (propertiesLv_.SelectedItems.Count > 0)
            {
                object tag = propertiesLv_.SelectedItems[0].Tag;

                if (tag != null && tag.GetType() == typeof(TsCDaItemProperty))
                {
                    TsCDaItemProperty property = (TsCDaItemProperty)tag;

                    if (property.Value != null)
                    {
                        if (property.ID == TsDaProperty.VALUE)
                        {
                            TsCCpxComplexItem complexItem = TsCCpxComplexTypeCache.GetComplexItem(mElement_);

                            if (complexItem != null)
                            {
                                new EditComplexValueDlg().ShowDialog(complexItem, property.Value, true, true);
                            }
                        }
                        else if (property.Value.GetType().IsArray)
                        {
                            new EditArrayDlg().ShowDialog(property.Value, true);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Sends a server or item pciked depending on the node.
        /// </summary>
        private void PickNode(TreeNode node)
        {
            if (IsServerNode(node))
            {
                if (ServerPicked != null)
                {
                    ServerPicked((TsCDaServer)node.Tag);
                }
            }

            else if (IsBrowseElementNode(node))
            {
                TsCDaBrowseElement element = (TsCDaBrowseElement)node.Tag;

                if (element.IsItem && ItemPicked != null)
                {
                    ItemPicked(new OpcItem(element.ItemPath, element.ItemName));
                }
            }

            else if (IsItemPropertyNode(node))
            {
                TsCDaItemProperty property = (TsCDaItemProperty)node.Tag;

                if (property.ItemName != null && ItemPicked != null)
                {
                    ItemPicked(new OpcItem(property.ItemPath, property.ItemName));
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Unmarshals and deallocates a OPCITEMPROPERTIES structures.
        /// </summary>
        internal static TsCDaItemProperty[] GetItemProperties(ref OpcRcw.Da.OPCITEMPROPERTIES input, bool deallocate)
        {
            TsCDaItemProperty[] output = null;

            if (input.dwNumProperties > 0)
            {
                output = new TsCDaItemProperty[input.dwNumProperties];

                IntPtr pos = input.pItemProperties;

                for (int ii = 0; ii < output.Length; ii++)
                {
                    try
                    {
                        output[ii] = GetItemProperty(pos, deallocate);
                    }
                    catch (Exception e)
                    {
                        output[ii]             = new TsCDaItemProperty();
                        output[ii].Description = e.Message;
                        output[ii].Result      = OpcResult.E_FAIL;
                    }

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

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

            return(output);
        }
Пример #4
0
        /// <summary>
        /// Allocates and marshals an arary of OPCITEMPROPERTY structures.
        /// </summary>
        internal static OpcRcw.Da.OPCITEMPROPERTY GetItemProperty(TsCDaItemProperty input)
        {
            OpcRcw.Da.OPCITEMPROPERTY output = new OpcRcw.Da.OPCITEMPROPERTY();

            if (input != null)
            {
                output.dwPropertyID  = input.ID.Code;
                output.szDescription = input.Description;
                output.vtDataType    = (short)Technosoftware.DaAeHdaClient.Com.Interop.GetType(input.DataType);
                output.vValue        = MarshalPropertyValue(input.ID, input.Value);
                output.wReserved     = 0;
                output.hrErrorID     = Technosoftware.DaAeHdaClient.Com.Interop.GetResultID(input.Result);

                // set the property data type.
                TsDaPropertyDescription description = TsDaPropertyDescription.Find(input.ID);

                if (description != null)
                {
                    output.vtDataType = (short)Technosoftware.DaAeHdaClient.Com.Interop.GetType(description.Type);
                }

                // convert unified DA code to COM DA code.
                if (input.Result == OpcResult.Da.E_WRITEONLY)
                {
                    output.hrErrorID = Result.E_BADRIGHTS;
                }
            }

            return(output);
        }
Пример #5
0
        /// <summary>
        /// Adds an item to the list view.
        /// </summary>
        private void AddProperty(TsCDaItemProperty property)
        {
            // create list view item.
            ListViewItem listItem = new ListViewItem((string)GetFieldValue(property, Id), Resources.IMAGE_EXPLODING_BOX);

            // add appropriate sub-items.
            listItem.SubItems.Add(Technosoftware.DaAeHdaClient.OpcConvert.ToString(GetFieldValue(property, Description)));
            listItem.SubItems.Add(Technosoftware.DaAeHdaClient.OpcConvert.ToString(GetFieldValue(property, Value)));
            listItem.SubItems.Add(Technosoftware.DaAeHdaClient.OpcConvert.ToString(GetFieldValue(property, DataType)));
            listItem.SubItems.Add(Technosoftware.DaAeHdaClient.OpcConvert.ToString(GetFieldValue(property, ItemPath)));
            listItem.SubItems.Add(Technosoftware.DaAeHdaClient.OpcConvert.ToString(GetFieldValue(property, ItemName)));
            listItem.SubItems.Add(Technosoftware.DaAeHdaClient.OpcConvert.ToString(GetFieldValue(property, Error)));

            // save item object as list view item tag.
            listItem.Tag = property;

            // add to list view.
            propertiesLv_.Items.Add(listItem);
        }
        /// <summary>
        /// Adds an item to the list view.
        /// </summary>
        private void AddProperty(TsCDaItemProperty property)
        {
            // create list view item.
            ListViewItem listItem = new ListViewItem((string)GetFieldValue(property, ID), Resources.IMAGE_PROPERTY);

            // add appropriate sub-items.
            listItem.SubItems.Add(OpcClientSdk.OpcConvert.ToString(GetFieldValue(property, DESCRIPTION)));
            listItem.SubItems.Add(OpcClientSdk.OpcConvert.ToString(GetFieldValue(property, VALUE)));
            listItem.SubItems.Add(OpcClientSdk.OpcConvert.ToString(GetFieldValue(property, DATA_TYPE)));
            listItem.SubItems.Add(OpcClientSdk.OpcConvert.ToString(GetFieldValue(property, ITEM_PATH)));
            listItem.SubItems.Add(OpcClientSdk.OpcConvert.ToString(GetFieldValue(property, ITEM_NAME)));
            listItem.SubItems.Add(OpcClientSdk.OpcConvert.ToString(GetFieldValue(property, ERROR)));

            // save item object as list view item tag.
            listItem.Tag = property;

            // add to list view.
            PropertiesLV.Items.Add(listItem);
        }
        /// <summary>
        /// Adds the specified item property into the tree.
        /// </summary>
        private void AddItemProperty(TreeNode parent, TsCDaItemProperty property)
        {
            if (property != null && property.Result.Succeeded())
            {
                // create the new node.
                TreeNode node = new TreeNode(property.Description);

                // select the icon.
                if (property.ItemName != null && property.ItemName != "")
                {
                    node.ImageIndex = node.SelectedImageIndex = Resources.IMAGE_GREEN_SCROLL;
                }
                else
                {
                    node.ImageIndex = node.SelectedImageIndex = Resources.IMAGE_EXPLODING_BOX;
                }

                node.Tag = property;

                if (property.Value != null)
                {
                    TreeNode child = new TreeNode(OpcClientSdk.OpcConvert.ToString(property.Value));
                    child.ImageIndex = child.SelectedImageIndex = Resources.IMAGE_LIST_BOX;
                    child.Tag        = property.Value;
                    node.Nodes.Add(child);

                    if (property.Value.GetType().IsArray)
                    {
                        foreach (object element in (Array)property.Value)
                        {
                            TreeNode arrayChild = new TreeNode(OpcClientSdk.OpcConvert.ToString(element));
                            arrayChild.ImageIndex = arrayChild.SelectedImageIndex = Resources.IMAGE_LIST_BOX;
                            arrayChild.Tag        = element;
                            child.Nodes.Add(arrayChild);
                        }
                    }
                }

                // add to parent.
                parent.Nodes.Add(node);
            }
        }
Пример #8
0
        /// <summary>
        /// Returns the value of the specified field.
        /// </summary>
        private object GetFieldValue(TsCDaItemProperty property, int fieldId)
        {
            switch (fieldId)
            {
            case Id:          { return(property.ID.ToString()); }

            case Description: { return(property.Description); }

            case Value:       { return(property.Value); }

            case DataType:   { return((property.Value != null)?property.Value.GetType():null); }

            case ItemPath:   { return(property.ItemPath); }

            case ItemName:   { return(property.ItemName); }

            case Error:       { return(property.Result); }
            }

            return(null);
        }
        /// <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);
        }
		/// <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>
        /// Returns the value of the specified field.
        /// </summary>
        private object GetFieldValue(TsCDaItemProperty property, int fieldID)
        {
            switch (fieldID)
            {
            case ID:          { return(property.ID.ToString()); }

            case DESCRIPTION: { return(property.Description); }

            case VALUE:       { return(property.Value); }

            case DATA_TYPE:   { return((property.Value != null)?property.Value.GetType():null); }

            case ITEM_PATH:   { return(property.ItemPath); }

            case ITEM_NAME:   { return(property.ItemName); }

            case ERROR:       { return(property.Result); }
            }

            return(null);
        }
Пример #12
0
        /// <summary>
        /// Unmarshals and deallocates a OPCITEMPROPERTY structures.
        /// </summary>
        internal static TsCDaItemProperty GetItemProperty(IntPtr pInput, bool deallocate)
        {
            TsCDaItemProperty output = null;

            if (pInput != IntPtr.Zero)
            {
                try
                {
                    OpcRcw.Da.OPCITEMPROPERTY property = (OpcRcw.Da.OPCITEMPROPERTY)Marshal.PtrToStructure(pInput, typeof(OpcRcw.Da.OPCITEMPROPERTY));

                    output = new TsCDaItemProperty();

                    output.ID          = GetPropertyID(property.dwPropertyID);
                    output.Description = property.szDescription;
                    output.DataType    = Technosoftware.DaAeHdaClient.Com.Interop.GetType((VarEnum)property.vtDataType);
                    output.ItemPath    = null;
                    output.ItemName    = property.szItemID;
                    output.Value       = UnmarshalPropertyValue(output.ID, property.vValue);
                    output.Result      = Technosoftware.DaAeHdaClient.Com.Interop.GetResultID(property.hrErrorID);

                    // convert COM DA code to unified DA code.
                    if (property.hrErrorID == Result.E_BADRIGHTS)
                    {
                        output.Result = new OpcResult(OpcResult.Da.E_WRITEONLY, Result.E_BADRIGHTS);
                    }
                }
                catch (Exception)
                {
                }
                if (deallocate)
                {
                    Marshal.DestroyStructure(pInput, typeof(OpcRcw.Da.OPCITEMPROPERTY));
                }
            }

            return(output);
        }