/// <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));
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Unmarshals and deallocates a OPCBROWSEELEMENT structures.
        /// </summary>
        internal static TsCDaBrowseElement GetBrowseElement(IntPtr pInput, bool deallocate)
        {
            TsCDaBrowseElement output = null;

            if (pInput != IntPtr.Zero)
            {
                OpcRcw.Da.OPCBROWSEELEMENT element = (OpcRcw.Da.OPCBROWSEELEMENT)Marshal.PtrToStructure(pInput, typeof(OpcRcw.Da.OPCBROWSEELEMENT));

                output = new TsCDaBrowseElement();

                output.Name        = element.szName;
                output.ItemPath    = null;
                output.ItemName    = element.szItemID;
                output.IsItem      = ((element.dwFlagValue & OpcRcw.Da.Constants.OPC_BROWSE_ISITEM) != 0);
                output.HasChildren = ((element.dwFlagValue & OpcRcw.Da.Constants.OPC_BROWSE_HASCHILDREN) != 0);
                output.Properties  = GetItemProperties(ref element.ItemProperties, deallocate);

                if (deallocate)
                {
                    Marshal.DestroyStructure(pInput, typeof(OpcRcw.Da.OPCBROWSEELEMENT));
                }
            }

            return(output);
        }
        /// <summary>
        /// Adds the specified browse element into the tree.
        /// </summary>
        private void AddBrowseElement(TreeNode parent, TsCDaBrowseElement element)
        {
            // create the new node.
            TreeNode node = new TreeNode(element.Name);

            // select the icon.
            if (element.IsItem)
            {
                node.ImageIndex = node.SelectedImageIndex = Resources.IMAGE_GREEN_SCROLL;
            }
            else
            {
                node.ImageIndex = node.SelectedImageIndex = Resources.IMAGE_CLOSED_YELLOW_FOLDER;
            }

            node.Tag = element;

            // add a dummy node to force display of '+' symbol.
            if (element.HasChildren)
            {
                node.Nodes.Add(new TreeNode());
            }

            // add properties
            if (element.Properties != null)
            {
                foreach (TsCDaItemProperty property in element.Properties)
                {
                    AddItemProperty(node, property);
                }
            }

            // add to parent.
            parent.Nodes.Add(node);
        }
Esempio n. 4
0
        /// <summary>
        /// Unmarshals and deallocates an array of OPCBROWSEELEMENT structures.
        /// </summary>
        internal static TsCDaBrowseElement[] GetBrowseElements(ref IntPtr pInput, int count, bool deallocate)
        {
            TsCDaBrowseElement[] output = null;

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

                IntPtr pos = pInput;

                for (int ii = 0; ii < count; ii++)
                {
                    output[ii] = GetBrowseElement(pos, deallocate);
                    pos        = (IntPtr)(pos.ToInt64() + Marshal.SizeOf(typeof(OpcRcw.Da.OPCBROWSEELEMENT)));
                }

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

            return(output);
        }
Esempio n. 5
0
		public OpcDaTag(TsCDaBrowseElement element)
		{
			if (element.IsItem)
			{
				ElementName = element.ItemName;
				Path = element.ItemPath;
				
				var access = GetProperty(element, TsDaProperty.ACCESSRIGHTS).Value;
				if (Enum.IsDefined(typeof(TsDaAccessRights), access))
				{
					AccessRights = (TsDaAccessRights)Enum.Parse(typeof(TsDaAccessRights), access.ToString(), true);
				}
				else
				{
					throw new InvalidCastException(string.Format(
						"Невозможно приветсти {0} к типу TsDaAccessRights", access.ToString()));
				}

				ScanRate = Convert.ToSingle(GetProperty(element, TsDaProperty.SCANRATE).Value);
				TypeNameOfValue = ((Type)GetProperty(element, TsDaProperty.DATATYPE).Value).FullName;
			}
			else
			{
				throw new InvalidCastException("Невозможно создать тег на основе элемента типа группа");
			}
		}
        /// <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);
            }
        }
		public OpcTechnosoftwareTagValueBaseViewModel(TsCDaBrowseElement tag)
		{
			if (!tag.IsItem)
			{
				throw new ArgumentException("Элемент не является тегом", "tag");
			}
			Tag = tag;
		}
        /// <summary>
        /// Initializes the object from a browse element.
        /// </summary>
        private bool Init(TsCDaBrowseElement element)
        {
            // update the item id.
            ItemPath = element.ItemPath;
            ItemName = element.ItemName;
            Name     = element.Name;

            return(Init(element.Properties));
        }
		public OpcTechnosoftWriteTagsViewModel(TsCDaServer server, TsCDaBrowseElement[] tags)
		{
			Title = "Запись тегов";
			_opcDaServer = server;
			_tags = tags.Select(x => OpcTechnosoftwareTagValueBaseViewModel.Create(x))
				.Where(y => y.Accessibility == TsDaAccessRights.ReadWritable ||
					y.Accessibility == TsDaAccessRights.Writable)
				.ToArray();
			WriteTagsCommand = new RelayCommand(OnWriteTags, CanWriteTags);
		}
Esempio n. 10
0
        /// <summary>
        /// Returns the complex item for the specified item browse element.
        /// </summary>
        /// <param name="element">The item browse element.</param>
        public static TsCCpxComplexItem GetComplexItem(TsCDaBrowseElement element)
        {
            if (element == null)
            {
                return(null);
            }

            lock (typeof(TsCCpxComplexTypeCache))
            {
                return(GetComplexItem(new OpcItem(element.ItemPath, element.ItemName)));
            }
        }
Esempio n. 11
0
		public TsOpcElement(TsOpcTagsStructure owner, 
			TsCDaBrowseElement element)
		{
			if (owner == null)
			{
				throw new ArgumentNullException("owner");
			}
			if (element == null)
			{
				throw new ArgumentNullException("element");
			}
			_owner = owner;
			_element = element;
		}
		public static OpcTechnosoftwareTagValueBaseViewModel Create(TsCDaBrowseElement tag)
		{
			var property = tag.Properties.First(x => x.ID == TsDaProperty.DATATYPE);

			if ((Type)property.Value == typeof(Boolean))
			{
				return new OpcTechnosoftwareTagValueBoolViewModel(tag);
			}
			else
			{
				throw new NotSupportedException(
					string.Format("Неудалось создать объект. Таг с типом данных {0} не поддерживается",
					property.Value.ToString()));
			}
			throw new NotImplementedException();
		}
        /// <summary>
        /// Called when the browse filters have changed.
        /// </summary>
        private void OnBrowseFiltersChanged(TsCDaBrowseFilters filters)
        {
            m_filters = filters;

            if (IsBrowseElementNode(BrowseTV.SelectedNode))
            {
                TsCDaBrowseElement element = (TsCDaBrowseElement)BrowseTV.SelectedNode.Tag;

                if (!element.HasChildren)
                {
                    GetProperties(BrowseTV.SelectedNode);
                    return;
                }
            }

            Browse(BrowseTV.SelectedNode);
        }
Esempio n. 14
0
        /// <summary>
        /// Initializes the control with a set of identified results.
        /// </summary>
        public void Initialize(TsCDaBrowseElement element)
        {
            propertiesLv_.Items.Clear();

            // check if there is nothing to do.
            if (element == null || element.Properties == null)
            {
                return;
            }

            mElement_ = element;

            foreach (TsCDaItemProperty property in element.Properties)
            {
                AddProperty(property);
            }

            // adjust the list view columns to fit the data.
            AdjustColumns();
        }
Esempio n. 15
0
        /// <summary>
        /// Allocates and marshals an OPCBROWSEELEMENT structure.
        /// </summary>
        internal static OpcRcw.Da.OPCBROWSEELEMENT GetBrowseElement(TsCDaBrowseElement input, bool propertiesRequested)
        {
            OpcRcw.Da.OPCBROWSEELEMENT output = new OpcRcw.Da.OPCBROWSEELEMENT();

            if (input != null)
            {
                output.szName         = input.Name;
                output.szItemID       = input.ItemName;
                output.dwFlagValue    = 0;
                output.ItemProperties = GetItemProperties(input.Properties);

                if (input.IsItem)
                {
                    output.dwFlagValue |= OpcRcw.Da.Constants.OPC_BROWSE_ISITEM;
                }

                if (input.HasChildren)
                {
                    output.dwFlagValue |= OpcRcw.Da.Constants.OPC_BROWSE_HASCHILDREN;
                }
            }

            return(output);
        }
Esempio n. 16
0
 /// <summary>
 /// Called when a server is picked in the browse control.
 /// </summary>
 private void OnElementSelected(TsCDaBrowseElement element)
 {
     PropertiesCTRL.Initialize(element);
 }
Esempio n. 17
0
		/// <summary>
		/// Создаёт на основе указанного объетка, OpcDaTag или OpcDaGroup
		/// </summary>
		/// <param name="element"></param>
		/// <returns></returns>
		public static OpcDaElement Create(TsCDaBrowseElement element)
		{
			if (element.IsItem)
			{
				return new OpcDaTag(element);
			}
			else
			{
				return new OpcDaGroup { Path = element.ItemPath, ElementName = element.ItemName };
			}
		}
Esempio n. 18
0
		protected static TsCDaItemProperty GetProperty(TsCDaBrowseElement element, TsDaPropertyID propertyId)
		{
			return element.Properties.FirstOrDefault(x => x.ID == propertyId);
		}
 /// <summary>
 /// Called when a server is picked in the browse control.
 /// </summary>
 private void OnElementSelected(TsCDaBrowseElement element)
 {
     propertiesCtrl_.Initialize(element);
 }
        /// <summary>
        /// Browses for children of the element at the current node.
        /// </summary>
        private void Browse(TreeNode node)
        {
            try
            {
                // get the server for the current node.
                TsCDaServer server = FindServer(node);

                // get the current element to use for a browse.
                TsCDaBrowseElement parent = null;
                OpcItem            itemID = null;

                if (node.Tag != null && node.Tag.GetType() == typeof(TsCDaBrowseElement))
                {
                    parent = (TsCDaBrowseElement)node.Tag;
                    itemID = new OpcItem(parent.ItemPath, parent.ItemName);
                }

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

                // add properties
                if (parent != null && parent.Properties != null)
                {
                    foreach (TsCDaItemProperty property in parent.Properties)
                    {
                        AddItemProperty(node, property);
                    }
                }

                // begin a browse.
                OpcClientSdk.Da.TsCDaBrowsePosition position = null;
                TsCDaBrowseElement[] elements = server.Browse(itemID, m_filters, out position);

                // add children.
                if (elements != null)
                {
                    foreach (TsCDaBrowseElement element in elements)
                    {
                        AddBrowseElement(node, element);
                    }

                    node.Expand();
                }

                // loop until all elements have been fetched.
                while (position != null)
                {
                    DialogResult result = MessageBox.Show(
                        "More items meeting search criteria exist. Continue browse?",
                        "Browse Items",
                        MessageBoxButtons.YesNo);

                    if (result == DialogResult.No)
                    {
                        break;
                    }

                    // fetch next batch of elements,.
                    elements = server.BrowseNext(ref position);

                    // add children.
                    if (elements != null)
                    {
                        foreach (TsCDaBrowseElement element in elements)
                        {
                            AddBrowseElement(node, element);
                        }

                        node.Expand();
                    }
                }

                // send notification that property list changed.
                if (ElementSelected != null)
                {
                    if (node.Tag.GetType() == typeof(TsCDaBrowseElement))
                    {
                        ElementSelected((TsCDaBrowseElement)node.Tag);
                    }
                    else
                    {
                        ElementSelected(null);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
		internal OpcTechnosoftwareTagValueBoolViewModel(TsCDaBrowseElement tag) : base(tag) { }
Esempio n. 22
0
		string[] GetSegmentsOfPath(TsCDaBrowseElement element)
		{
			var result = element.ItemPath.Split(new string[] { SPLITTER }, StringSplitOptions.RemoveEmptyEntries);
			return result;
		}
Esempio n. 23
0
		public TsOpcTagsStructure(TsCDaBrowseElement[] elements)
		{
			var list = elements.Select(x => new TsOpcElement(this, x));
			_allItems = new List<TsOpcElement>(list);
		}