/// <summary>
        /// Build DaBrowse
        /// </summary>
        /// <param name="daSession"></param>
        public void BuildDaBrowseTree(DaSession daSession, DaSubscription subsciption)
        {
            daSubscription = subsciption;
            ShowProperContextMenu(browseTreeView.SelectedNode);
            if (browseTreeView.Nodes.Count > 0)
            {
                if (browseTreeView.Nodes[0].Text.Equals(daSession.Url))
                {
                    return;
                }
            }
            browseTreeView.Nodes.Clear();
            TreeNode treeRootNode = new TreeNode(daSession.Url, BROWSE_INDEX, BROWSE_INDEX);

            treeRootNode.Name = daSession.Url;
            DaAddressSpaceElement daAddressSpaceElement = new DaAddressSpaceElement();

            daAddressSpaceElement.Session = daSession;
            daRootSpaceElem = daAddressSpaceElement;
            browseTreeView.Nodes.Add(treeRootNode);
            treeRootNode.Nodes.Add(new TreeNode(""));
            treeRootNode.Tag = daSession;
            if (Options.SortDa)
            {
                browseTreeView.Sort();
            }
            else
            {
                browseTreeView.Sorted = false;
            }
        }
Exemple #2
0
        }           //	end CreateDaAddressSpaceRoot

        public override DaRequest CreateRequest(
            EnumTransactionType aTransactionType,
            uint aSessionHandle,
            DaAddressSpaceElement anElement,
            int aPropertyId,
            uint aRequestHandle)
        {
            return(new MyRequest(
                       aTransactionType,
                       aSessionHandle,
                       anElement,
                       aPropertyId,
                       aRequestHandle));
        }           //	end CreateRequest
        //-----------------

        public MyRequest(
            EnumTransactionType transactionType,
            uint sessionHandle,
            DaAddressSpaceElement aDaAddressSpaceElement,
            int propertyID,
            uint requestHandle)
            :
            base(
                transactionType,
                sessionHandle,
                aDaAddressSpaceElement,
                propertyID,
                requestHandle)
        {
        }           //	end constructor
Exemple #4
0
        }           //	end QueryAddressSpaceElementChildren

        public override int QueryAddressSpaceElementProperties(string anElementID, out ArrayList aPropertyList)
        {
            aPropertyList = null;
            Hashtable elements = Hashtable.Synchronized(this.m_elements);

            foreach (object element in elements.Values)
            {
                DaAddressSpaceElement daElement = element as DaAddressSpaceElement;
                if (daElement.ItemId == anElementID)
                {
                    daElement.QueryProperties(out aPropertyList);
                    return((int)EnumResultCode.S_OK);
                }           //	end if
            }               //	end foreach

            return((int)EnumResultCode.E_NOTIMPL);
        }         // end QueryAddressSpaceElementProperties
Exemple #5
0
        public override int QueryAddressSpaceElementChildren(string anElementId, ArrayList aChildrenList)
        {
            aChildrenList = null;
            Hashtable elements = Hashtable.Synchronized(this.m_elements);

            foreach (object element in elements.Values)
            {
                DaAddressSpaceElement daElement = element as DaAddressSpaceElement;
                if (daElement.ItemId == anElementId)
                {
                    aChildrenList.InsertRange(0, daElement.GetChildren());
                    return((int)EnumResultCode.S_OK);
                }           //	end if
            }               //	end foreach

            return((int)EnumResultCode.E_NOTIMPL);
        }           //	end QueryAddressSpaceElementChildren
Exemple #6
0
        public override int QueryAddressSpaceElementData(string anElementId, out AddressSpaceElement anElement)
        {
            anElement = null;
            Hashtable elements = Hashtable.Synchronized(this.m_elements);

            foreach (object element in elements.Values)
            {
                DaAddressSpaceElement daElement = element as DaAddressSpaceElement;
                if (daElement.ItemId == anElementId)
                {
                    anElement = daElement;
                    return((int)EnumResultCode.S_OK);
                }           //	end if
            }               //	end foreach

            return((int)EnumResultCode.E_NOTIMPL);
        }
 /// <summary>
 /// Get Properties
 /// </summary>
 /// <param name="session"></param>
 /// <param name="itemId"></param>
 /// <param name="node"></param>
 private void AddProperties(DaAddressSpaceElement addSpaceElem, DaGetPropertiesOptions propertyGetOptions, TreeNode node)
 {
     //get properties
     DaProperty[] properties = null;
     if (ResultCode.SUCCEEDED(addSpaceElem.GetDaProperties(new DaGetPropertiesOptions(),
                                                           out properties,
                                                           executionOptions)))
     {
         if (properties == null)
         {
             return;
         }
         for (int j = 0; j < properties.Length; j++)
         {
             if (properties[j].Id > 99)
             {
                 TreeNode proNode = new TreeNode(properties[j].Description, PROP_INDEX, PROP_INDEX);
                 proNode.Name = properties[j].Description;
                 proNode.Tag  = properties[j];
                 node.Nodes.Add(proNode);
             }
         }
     }
 }
        /// <summary>
        /// Get Da_Items or Leafs, according to the browse options
        /// </summary>
        /// <param name="browseOptions"></param>
        /// <param name="addrSpaceElem"></param>
        /// <param name="node"></param>
        /// <param name="session"></param>
        private void GetTagNode(DaAddressSpaceElementBrowseOptions browseOptions, DaAddressSpaceElement addrSpaceElem, TreeNode node)
        {
            DaGetPropertiesOptions propertyGetOptions = new DaGetPropertiesOptions();

            propertyGetOptions.WhatPropertyData = EnumPropertyData.ALL;

            DaAddressSpaceElement[] addressSpaceElements = null;
            if (ResultCode.SUCCEEDED(addrSpaceElem.Browse(browseOptions,
                                                          out addressSpaceElements,
                                                          executionOptions)))
            {
                for (int i = 0; i < addressSpaceElements.Length; i++)
                {
                    TreeNode newNode = new TreeNode(addressSpaceElements[i].Name, TAG_INDEX, TAG_INDEX);
                    newNode.Name = addressSpaceElements[i].Name;
                    newNode.Tag  = addressSpaceElements[i];
                    node.Nodes.Add(newNode);

                    //get properties
                    AddProperties(addressSpaceElements[i], propertyGetOptions, newNode);
                }
                AddProperties(addrSpaceElem, propertyGetOptions, node);
            }
        }
        public EnumResultCode CreateItems(ValueQT valueQT)
        {
            //lock (m_lock)
            {
                try
                {
                    // Retreive parent folder
                    AddressSpaceElement parentFolder = GetParent();
                    ArrayList           children     = GetChildren();

                    uint    itemCount              = 0;
                    VarType itemType               = VarType.Unknown;
                    string  itemSet                = String.Empty;
                    bool    isAnalogItem           = false;
                    DaAddressSpaceElement outParam = null;

                    // get parameter values
                    foreach (DaAddressSpaceElement param in children)
                    {
                        if (param == null)
                        {
                            continue;
                        }

                        ValueQT paramValue = null;
                        param.GetCacheValue(ref paramValue);

                        if (param.Name == ItemCountParam)
                        {
                            itemCount = (uint)paramValue.Data;
                        }
                        else if (param.Name == ItemTypeParam)
                        {
                            itemType = (VarType)((uint)paramValue.Data);
                        }
                        else if (param.Name == ItemSetIdParam)
                        {
                            outParam = param;
                        }
                        else if (param.Name == ItemIsAnalogParam)
                        {
                            isAnalogItem = (bool)paramValue.Data;
                        }
                    }

                    // Check if all parameters are set
                    if (itemCount != 0 && itemType != VarType.Unknown && outParam != null)
                    {
                        Type varType;

                        switch (itemType)
                        {
                        case VarType.Uint8:
                            varType = typeof(Byte);
                            break;

                        case VarType.Int8:
                            varType = typeof(SByte);
                            break;

                        case VarType.Uint16:
                            varType = typeof(UInt16);
                            break;

                        case VarType.Int16:
                            varType = typeof(Int16);
                            break;

                        case VarType.Uint32:
                            varType = typeof(UInt32);
                            break;

                        case VarType.Int32:
                            varType = typeof(Int32);
                            break;

                        case VarType.Uint64:
                            varType = typeof(UInt64);
                            break;

                        case VarType.Int64:
                            varType = typeof(Int64);
                            break;

                        case VarType.Float:
                            varType = typeof(Single);
                            break;

                        case VarType.Double:
                            varType = typeof(Double);
                            break;

                        default:
                            varType = typeof(Byte);
                            break;
                        }

                        // Create the item set
                        CreateItems(parentFolder, outParam, itemCount, varType, false, valueQT.Data.ToString(), isAnalogItem);
                    }

                    else
                    {
                        // Parameters not set correctly
                        return(EnumResultCode.E_FAIL);
                    }

                    return(EnumResultCode.S_OK);
                }
                catch
                {
                    return(EnumResultCode.E_FAIL);
                }
            }
        }
        /// <summary>
        /// Create a list o items in the AddressSpace
        /// </summary>
        /// <param name="parentFolder"></param>
        /// <param name="itemCount"></param>
        /// <param name="itemType"></param>
        /// <param name="itemSetName"></param>
        private EnumResultCode CreateItems(
            AddressSpaceElement parentFolder,
            DaAddressSpaceElement resultItem,
            uint itemCount,
            Type itemType,
            bool generateRandomValues,
            string guid,
            bool isAnalogItem)
        {
            // Create item folder
            MyDaAddressSpaceElement itemFolder = new MyDaAddressSpaceElement();

            itemFolder.Name         = String.Format("TestItems_{0}", m_createdFolders);
            itemFolder.HasChildren  = true;
            itemFolder.AccessRights = EnumAccessRights.READABLE;
            if (!parentFolder.AddChild(itemFolder))
            {
                return(EnumResultCode.E_FAIL);
            }

            m_createdFolders++;

            //add guid to ItemSetId node
            ValueQT cacheValue = null;

            resultItem.GetCacheValue(ref cacheValue);
            string[] currentValue = cacheValue.Data as string[];
            string[] newValue     = new string[currentValue.Length + 1];
            currentValue.CopyTo(newValue, 0);
            newValue[currentValue.Length] = itemFolder.ItemId + "#" + guid;
            resultItem.ValueChanged(new ValueQT(newValue, EnumQuality.GOOD, DateTime.Now));


            // Add Start/Stop simulation command
            DaStartStopSimulationCommand simulationCmd = new DaStartStopSimulationCommand();

            simulationCmd.Name        = "StartStopSimulationCommand";
            simulationCmd.HasChildren = true;
            if (!itemFolder.AddChild(simulationCmd))
            {
                return(EnumResultCode.E_FAIL);
            }
            simulationCmd.ValueChanged(new ValueQT(false, EnumQuality.GOOD, DateTime.Now));

            MyDaAddressSpaceElement param;

            // Add command parameters

            // item count parameter
            param = new MyDaAddressSpaceElement(DaStartStopSimulationCommand.ChangeIntervalParam, DaStartStopSimulationCommand.ChangeIntervalParamType);
            if (!simulationCmd.AddChild(param))
            {
                return(EnumResultCode.E_FAIL);
            }
            param.ValueChanged(new ValueQT((uint)0, EnumQuality.GOOD, DateTime.Now));

            // repeat count parameter
            param = new MyDaAddressSpaceElement(DaStartStopSimulationCommand.RepeatCountParam, DaStartStopSimulationCommand.RepeatCountParamType);
            if (!simulationCmd.AddChild(param))
            {
                return(EnumResultCode.E_FAIL);
            }
            param.ValueChanged(new ValueQT((uint)0, EnumQuality.GOOD, DateTime.Now));

            // incrementt parameter
            param = new MyDaAddressSpaceElement(DaStartStopSimulationCommand.IncrementParam, DaStartStopSimulationCommand.IncrementParamType);
            if (!simulationCmd.AddChild(param))
            {
                return(EnumResultCode.E_FAIL);
            }
            param.ValueChanged(new ValueQT((uint)0, EnumQuality.GOOD, DateTime.Now));

            // Add Delete Items command
            DaDeleteItemsCommand deleteItemsCmd = new DaDeleteItemsCommand();

            deleteItemsCmd.Name        = "DeleteItemsCommand";
            deleteItemsCmd.HasChildren = true;
            if (!itemFolder.AddChild(deleteItemsCmd))
            {
                return(EnumResultCode.E_FAIL);
            }
            deleteItemsCmd.ValueChanged(new ValueQT(false, EnumQuality.GOOD, DateTime.Now));

            // Add items to list
            for (uint i = 0; i < itemCount; i++)
            {
                MyDaAddressSpaceElement item = new MyDaAddressSpaceElement(String.Format("TV_{0}", i), itemType);
                if (!itemFolder.AddChild(item))
                {
                    return(EnumResultCode.E_FAIL);
                }

                if (isAnalogItem)
                {
                    DaConstantProperty euType = new DaConstantProperty(
                        (int)EnumPropertyId.ITEM_EU_TYPE,
                        "EUType",
                        "7",
                        new ValueQT(EnumEUType.ANALOG, EnumQuality.GOOD, DateTime.Now));
                    euType.AccessRights = EnumAccessRights.READABLE;
                    item.AddProperty(euType);

                    DaProperty euHigh = new DaProperty();
                    euHigh.Id           = (int)EnumPropertyId.HIGH_EU;
                    euHigh.Name         = "High EU";
                    euHigh.Description  = "High EU";
                    euHigh.ItemId       = euHigh.Id.ToString();
                    euHigh.Datatype     = typeof(System.Double);
                    euHigh.AccessRights = EnumAccessRights.READABLE;
                    item.AddProperty(euHigh);

                    DaProperty euLow = new DaProperty();
                    euLow.Id           = (int)EnumPropertyId.LOW_EU;
                    euLow.Name         = "Low EU";
                    euLow.Description  = "Low EU";
                    euLow.ItemId       = euLow.Id.ToString();
                    euLow.Datatype     = typeof(System.Double);
                    euLow.AccessRights = EnumAccessRights.READABLE;
                    item.AddProperty(euLow);
                }

                if (generateRandomValues)
                {
                    // item.ValueChanged(m_generator.GetRandomValueQT(item.Datatype));
                }
                else
                {
                    item.ValueChanged(new ValueQT(0, EnumQuality.GOOD, DateTime.Now));
                }
            }



            return(EnumResultCode.S_OK);
        }
        public OpcForm(OutProc anOutProc)
        {
            InitializeComponent();

            try
            {
                m_outProc = anOutProc;

                m_opcClient = m_outProc.OpcClient;

                m_session = m_opcClient.GetSession();

                m_executionOptions = m_opcClient.GetExecutionOptions();

                //create the browse tree root element
                TreeNode treeRoot = new TreeNode(m_session.Url, 0, 0);
                DaAddressSpaceElement rootDaAddressSpaceElement = new DaAddressSpaceElement(EnumAddressSpaceElementType.BRANCH, String.Empty, string.Empty, string.Empty, 0, null);
                rootDaAddressSpaceElement.Session = m_session;
                treeRoot.Tag = rootDaAddressSpaceElement;
                itemsTreeView.Nodes.Add(treeRoot);

                DaAddressSpaceElement[] addressSpaceElements = null;

                #region Browse branches
                //---------------------
                DaAddressSpaceElementBrowseOptions browseOptions = new DaAddressSpaceElementBrowseOptions();
                browseOptions.ElementTypeFilter = EnumAddressSpaceElementType.BRANCH;

                //get the root's children
                if (ResultCode.SUCCEEDED(m_session.Browse(
                                             ((DaAddressSpaceElement)treeRoot.Tag).ItemId,
                                             ((DaAddressSpaceElement)treeRoot.Tag).ItemPath,
                                             browseOptions,
                                             out addressSpaceElements,
                                             m_executionOptions)))
                {
                    if (addressSpaceElements != null)
                    {
                        for (int i = 0; i < addressSpaceElements.Length; i++)
                        {
                            TreeNode node = new TreeNode(addressSpaceElements[i].Name, 1, 1);
                            node.Tag = addressSpaceElements[i];
                            treeRoot.Nodes.Add(node);
                        }        //end for
                    }
                }                //end if

                //-
                #endregion

                addressSpaceElements = null;

                #region Browse Leaves
                //-------------------
                browseOptions.ElementTypeFilter = EnumAddressSpaceElementType.LEAF;

                //get the root's children
                if (ResultCode.SUCCEEDED(m_session.Browse(
                                             ((DaAddressSpaceElement)treeRoot.Tag).ItemId,
                                             ((DaAddressSpaceElement)treeRoot.Tag).ItemPath,
                                             browseOptions,
                                             out addressSpaceElements,
                                             m_executionOptions)))
                {
                    if (addressSpaceElements != null)
                    {
                        for (int i = 0; i < addressSpaceElements.Length; i++)
                        {
                            TreeNode node = new TreeNode(addressSpaceElements[i].Name, 2, 2);
                            node.Tag = addressSpaceElements[i];
                            treeRoot.Nodes.Add(node);
                        }        //end for
                    }            //  end if
                }                //end if
                                 //-
                #endregion

                #region GetDaProperties
                //---------------------

                DaProperty[] daProperties = null;
                m_propertyGetOptions.WhatPropertyData = EnumPropertyData.ALL;

                if (ResultCode.SUCCEEDED(rootDaAddressSpaceElement.GetDaProperties(
                                             m_propertyGetOptions,
                                             out daProperties,
                                             m_executionOptions)))
                {
                    if (daProperties != null)
                    {
                        for (int i = 0; i < daProperties.Length; i++)
                        {
                            TreeNode node = new TreeNode(daProperties[i].Name, 3, 3);
                            //add all properties except OPC-specific properties
                            if (daProperties[i].Id >= 100)
                            {
                                treeRoot.Nodes.Add(node);
                            }
                        }           //end for
                    }
                }                   //  end if

                //-
                #endregion
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.ToString());
            }       //	end try...catch
        }           //	end constructor
        }           //	end Main

        private void TreeViewBeforeExpand(object sender, System.Windows.Forms.TreeViewCancelEventArgs e)
        {
            try
            {
                itemsTreeView.Cursor = System.Windows.Forms.Cursors.WaitCursor;

                foreach (TreeNode node in e.Node.Nodes)
                {
                    m_propertyGetOptions.WhatPropertyData = EnumPropertyData.ALL;
                    DaAddressSpaceElement[] addressSpaceElements = null;

                    node.Nodes.Clear();

                    if (node.Tag is DaAddressSpaceElement)
                    {
                        DaAddressSpaceElement element = node.Tag as DaAddressSpaceElement;
                        DaAddressSpaceElementBrowseOptions browseOptions = new DaAddressSpaceElementBrowseOptions();

                        #region Branches
                        //-----------
                        if (m_session.isConnected())
                        {
                            browseOptions.ElementTypeFilter = EnumAddressSpaceElementType.BRANCH;

                            if (ResultCode.SUCCEEDED(m_session.Browse(
                                                         element.ItemId,
                                                         element.ItemPath,
                                                         browseOptions,
                                                         out addressSpaceElements,
                                                         m_executionOptions)))
                            {
                                if (addressSpaceElements != null)
                                {
                                    for (int i = 0; i < addressSpaceElements.Length; i++)
                                    {
                                        TreeNode newNode = new TreeNode(addressSpaceElements[i].Name, 1, 1);
                                        newNode.Tag = addressSpaceElements[i];
                                        node.Nodes.Add(newNode);
                                    }            //end for
                                }
                            }                    //end if
                        }                        //end if
                                                 //-
                        #endregion

                        addressSpaceElements = null;

                        #region Leaves
                        //-----------
                        if (m_session.isConnected())
                        {
                            browseOptions.ElementTypeFilter = EnumAddressSpaceElementType.LEAF;

                            if (ResultCode.SUCCEEDED(m_session.Browse(
                                                         element.ItemId,
                                                         element.ItemPath,
                                                         browseOptions,
                                                         out addressSpaceElements,
                                                         m_executionOptions)))
                            {
                                if (addressSpaceElements != null)
                                {
                                    for (int i = 0; i < addressSpaceElements.Length; i++)
                                    {
                                        TreeNode newNode = new TreeNode(addressSpaceElements[i].Name, 2, 2);
                                        newNode.Tag = addressSpaceElements[i];
                                        node.Nodes.Add(newNode);
                                    }            //end for
                                }
                            }                    //end if
                        }                        //end if
                                                 //-
                        #endregion

                        DaProperty[] daProperties = null;

                        #region Properties
                        //----------------
                        if (m_session.isConnected())
                        {
                            if (ResultCode.SUCCEEDED(element.GetDaProperties(
                                                         m_propertyGetOptions,
                                                         out daProperties,
                                                         m_executionOptions)))
                            {
                                if (daProperties != null)
                                {
                                    for (int i = 0; i < daProperties.Length; i++)
                                    {
                                        //add all properties except OPC-specific properties
                                        if (daProperties[i].Id >= 100)
                                        {
                                            TreeNode newNode = new TreeNode(daProperties[i].Description, 3, 3);
                                            node.Nodes.Add(newNode);
                                        }
                                    }    //end for
                                }
                            }            //  end if
                        }                //end if
                                         //-
                        #endregion
                    }                    // end if

                    node.Collapse();
                }                   //  end if
                itemsTreeView.Cursor = System.Windows.Forms.Cursors.Default;
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.ToString());
            }
        } //	end treeview_beforeexpand
        /// <summary>
        /// ReadItemProperties
        /// </summary>
        private void ReadProperties()
        {
            TreeNode selectedNode = browseTreeView.SelectedNode;

            if (selectedNode == null)
            {
                return;
            }
            if (selectedNode.Tag == null)
            {
                return;
            }

            //get the session
            if (browseTreeView.Nodes.Count == 0)
            {
                return;
            }
            TreeNode rootNode = browseTreeView.Nodes[0];

            if (rootNode == null)
            {
                return;
            }
            if (rootNode.Tag == null)
            {
                return;
            }
            if (Type.ReferenceEquals(rootNode.Tag.GetType(), typeof(DaSession)))
            {
                DaSession session = rootNode.Tag as DaSession;
                if (session == null)
                {
                    return;
                }

                if (serviceWindow == null)
                {
                    return;
                }

                if (Type.ReferenceEquals(selectedNode.Tag.GetType(), typeof(DaAddressSpaceElement)))
                {
                    //get AddressSpaceElement Properties List
                    DaAddressSpaceElement addressSpaceElem = selectedNode.Tag as DaAddressSpaceElement;
                    if (addressSpaceElem == null)
                    {
                        return;
                    }
                    propertyWindow.ReadAddressSpaceElemProperties(session, addressSpaceElem.ItemId);
                    propertyWindow.Show(dockPanel);
                }
                else if (Type.ReferenceEquals(selectedNode.Tag.GetType(), typeof(DaProperty)))
                {
                    //get DaProperty Properties
                    DaProperty property = selectedNode.Tag as DaProperty;
                    if (property == null)
                    {
                        return;
                    }
                    propertyWindow.DaProperty(property);
                    propertyWindow.Show(dockPanel);
                }
            }
        }
        /// <summary>
        /// Write Da Value
        /// </summary>
        /// <param name="strValue"></param>
        private void WriteValue(string strValue)
        {
            TreeNode selectedNode = browseTreeView.SelectedNode;

            if (selectedNode == null)
            {
                return;
            }
            if (selectedNode.Tag == null)
            {
                return;
            }

            //get the session
            if (browseTreeView.Nodes.Count == 0)
            {
                return;
            }
            TreeNode rootNode = browseTreeView.Nodes[0];

            if (rootNode == null)
            {
                return;
            }
            if (rootNode.Tag == null)
            {
                return;
            }
            if (Type.ReferenceEquals(rootNode.Tag.GetType(), typeof(DaSession)))
            {
                DaSession session = rootNode.Tag as DaSession;
                if (session == null)
                {
                    return;
                }

                //get the itemId
                string itemId     = null;
                Type   dataType   = typeof(System.Byte);
                int    startIndex = 0;
                if (Type.ReferenceEquals(selectedNode.Tag.GetType(), typeof(DaAddressSpaceElement)))
                {
                    itemId = (selectedNode.Tag as DaAddressSpaceElement).ItemId;
                    DaAddressSpaceElement addSpaceElem = selectedNode.Tag as DaAddressSpaceElement;
                    //Get Data Type
                    DaProperty[]           properties         = null;
                    DaGetPropertiesOptions propertyGetOptions = new DaGetPropertiesOptions();
                    propertyGetOptions.WhatPropertyData = EnumPropertyData.ALL;
                    if (ResultCode.SUCCEEDED(session.GetDaProperties(itemId,
                                                                     null,
                                                                     propertyGetOptions,
                                                                     out properties,
                                                                     null)))
                    {
                        if (properties == null)
                        {
                            dataType = typeof(System.Byte);
                        }
                        if (properties.Length < 5)
                        {
                            dataType = typeof(System.Byte);
                        }
                        dataType = DataTypeConverter.GetSysType((short)properties[0].ValueQT.Data);
                        if (dataType.IsArray)
                        {
                            startIndex = ((properties[1].ValueQT.Data) as Array).GetLowerBound(0);
                        }
                    }
                }
                else if (Type.ReferenceEquals(selectedNode.Tag.GetType(), typeof(DaProperty)))
                {
                    itemId   = (selectedNode.Tag as DaProperty).Id.ToString();
                    dataType = (selectedNode.Tag as DaProperty).DataType;
                    if (dataType.IsArray)
                    {
                        startIndex = (((selectedNode.Tag as DaProperty).ValueQT.Data) as Array).GetLowerBound(0);
                    }
                }
                if (String.IsNullOrEmpty(itemId))
                {
                    return;
                }
                if (dataType == null)
                {
                    return;
                }

                ValueQT itemValue = new ValueQT();

                if (!dataType.IsArray)
                {
                    //data type is not array
                    object objData = null;
                    ConvertToType(dataType, out objData, strValue);
                    itemValue.SetData(objData, EnumQuality.GOOD, DateTime.Now);
                }
                else
                {
                    //data type is array
                    string   typeStr   = dataType.FullName;
                    Type     arrayType = System.Type.GetType(typeStr.Substring(0, typeStr.IndexOf('[')));
                    string[] objDatas  = strValue.Trim().Split(';');
                    if (objDatas == null)
                    {
                        return;
                    }
                    Array array = null;
                    if (startIndex > 0)
                    {
                        //non-zero bound array
                        array = Array.CreateInstance(arrayType, new int[] { objDatas.Length }, new int[] { startIndex });
                    }
                    else
                    {
                        //zero boud array
                        array = Array.CreateInstance(arrayType, objDatas.Length);
                    }
                    int strIndex = 0;
                    for (int index = array.GetLowerBound(0);
                         index <= array.GetUpperBound(0);
                         index++)
                    {
                        object objData = null;
                        ConvertToType(arrayType, out objData, objDatas[strIndex]);
                        array.SetValue(objData, index);
                        strIndex++;
                    }
                    itemValue.SetData(array, EnumQuality.GOOD, DateTime.Now);
                }

                //Write DaItem Values
                ExecutionOptions executionOptions = new ExecutionOptions();
                executionOptions.ExecutionType    = EnumExecutionType.ASYNCHRONOUS;
                executionOptions.ExecutionContext = 0;


                ValueQT[] itemValues = new ValueQT[] { itemValue };
                int[]     results;
                session.Write(new string[] { itemId }, null, itemValues, out results, executionOptions);
            }
        }
        /// <summary>
        /// Get Da BrowseData
        /// </summary>
        private void GetDaData(TreeNode node, TreeNode rootNode, object daSessionObject)
        {
            if (node.ImageIndex == TAG_INDEX)
            {
                return;
            }
            DaSession session = daSessionObject as DaSession;

            if (session == null)
            {
                return;
            }
            if (daRootSpaceElem == null)
            {
                return;
            }

            DaAddressSpaceElement[] addressSpaceElements = null;

            //get branches
            DaAddressSpaceElementBrowseOptions browseOptions = new DaAddressSpaceElementBrowseOptions();

            browseOptions.RetrieveItemId = true;

            DaAddressSpaceElement currentAddSpaceElem = null;

            if (node.Tag == null)
            {
                return;
            }
            if (node.Tag is DaSession)
            {
                currentAddSpaceElem = daRootSpaceElem;
            }
            if (node.Tag is DaAddressSpaceElement)
            {
                currentAddSpaceElem = node.Tag as DaAddressSpaceElement;
            }
            if (currentAddSpaceElem != null)
            {
                browseOptions.ElementTypeFilter = EnumAddressSpaceElementType.BRANCH;
                if (ResultCode.SUCCEEDED(currentAddSpaceElem.Browse(browseOptions,
                                                                    out addressSpaceElements,
                                                                    executionOptions)))
                {
                    node.Nodes.Clear();
                    for (int i = 0; i < addressSpaceElements.Length; i++)
                    {
                        TreeNode newNode = new TreeNode(addressSpaceElements[i].Name, NODE_INDEX, NODE_INDEX);
                        newNode.Name = addressSpaceElements[i].Name;
                        newNode.Tag  = addressSpaceElements[i];
                        node.Nodes.Add(newNode);
                        newNode.Nodes.Add(new TreeNode(""));
                    }
                }
                //get the items
                //browseOptions.ElementTypeFilter = EnumAddressSpaceElementType.DA_ITEM;
                //GetTagNode(browseOptions, currentAddSpaceElem, node);

                //get leaves
                browseOptions.ElementTypeFilter = EnumAddressSpaceElementType.LEAF;
                GetTagNode(browseOptions, currentAddSpaceElem, node);
            }
        }
        public override int QueryAddressSpaceElementData(string anElementID, out AddressSpaceElement anElement)
        {
            DaAddressSpaceElement element = new DaAddressSpaceElement();

            if (anElementID.StartsWith("stringBased"))
            {
                if (anElementID == "stringBased")
                {
                    element.Name        = anElementID;
                    element.IoMode      = EnumIoMode.NONE;
                    element.HasChildren = true;
                }
                else if (anElementID == "stringBased.N1" ||
                         anElementID == "stringBased.N2")
                {
                    element.Name         = anElementID.Substring(anElementID.LastIndexOf(".") + 1);
                    element.AccessRights = EnumAccessRights.READWRITEABLE;
                    element.Datatype     = typeof(byte);
                    element.HasChildren  = true;
                    element.IoMode       = EnumIoMode.REPORT;
                }
                else if (anElementID == "stringBased.T1")
                {
                    element.Name         = anElementID.Substring(anElementID.LastIndexOf(".") + 1);
                    element.AccessRights = EnumAccessRights.READWRITEABLE;
                    element.Datatype     = typeof(byte);
                    element.HasChildren  = false;
                    element.IoMode       = EnumIoMode.REPORT;
                }
                else if (anElementID.LastIndexOf("N1") > 0)
                {
                    if (anElementID.Substring(anElementID.LastIndexOf("N1")).EndsWith("T1"))
                    {
                        element.Name         = anElementID.Substring(anElementID.LastIndexOf(".") + 1);
                        element.AccessRights = EnumAccessRights.READWRITEABLE;
                        element.Datatype     = typeof(byte);
                        element.HasChildren  = false;
                        element.IoMode       = EnumIoMode.REPORT;
                    }
                }
                else if (anElementID.LastIndexOf("N2") > 0)
                {
                    if (anElementID.Substring(anElementID.LastIndexOf("N2")).EndsWith("T1") ||
                        anElementID.Substring(anElementID.LastIndexOf("N2")).EndsWith("T2"))
                    {
                        element.Name         = anElementID.Substring(anElementID.LastIndexOf(".") + 1);
                        element.AccessRights = EnumAccessRights.READWRITEABLE;
                        element.Datatype     = typeof(byte);
                        element.HasChildren  = false;
                        element.IoMode       = EnumIoMode.REPORT;
                    }
                }
            }
            else if (anElementID.StartsWith("syntaxBased"))
            {
                if (anElementID == "syntaxBased")
                {
                    element.Name        = anElementID;
                    element.IoMode      = EnumIoMode.NONE;
                    element.HasChildren = true;
                }

                Int32 index = anElementID.LastIndexOf(".T");
                if (index > 0)
                {
                    element.Name = anElementID.Substring(index + 1);
                    if (element.Name.Length == 2)
                    {
                        element.HasChildren  = false;
                        element.IoMode       = EnumIoMode.POLL;
                        element.AccessRights = EnumAccessRights.READWRITEABLE;
                        element.Datatype     = typeof(Int32);
                    }
                    else
                    {
                        element.Name = string.Empty;
                    }
                }
                else
                {
                    index = anElementID.LastIndexOf(".N");
                    if (index > 0)
                    {
                        element.Name = anElementID.Substring(index + 1);
                        if (element.Name.Length == 2)
                        {
                            element.HasChildren = true;
                            element.IoMode      = EnumIoMode.NONE;
                        }
                        else
                        {
                            element.Name = string.Empty;
                        }
                    }
                }
            }

            //	check if an element was succeeded
            if (element.Name == string.Empty)
            {
                anElement = null;
                return((int)EnumResultCode.E_BADTYPE);
            }               //	end if

            anElement = element;
            return((int)EnumResultCode.S_OK);
        }           //	end QueryAddressSpaceElementData