예제 #1
0
        public void ReadAddressSpaceElemProperties(DaSession session, string itemId)
        {
            panelBottom.Visible = false;

            DaGetPropertiesOptions propertyGetOptions = new DaGetPropertiesOptions();

            propertyGetOptions.WhatPropertyData = EnumPropertyData.ALL;

            DaProperty[] properties = null;
            if (ResultCode.SUCCEEDED(session.GetDaProperties(itemId,
                                                             null,
                                                             propertyGetOptions,
                                                             out properties,
                                                             null)))
            {
                if (properties == null)
                {
                    return;
                }

                Helper.CustomProperties propertiesColl = new DemoClient.Helper.CustomProperties();

                for (int i = 0; i < properties.Length; i++)
                {
                    SetPropertyData(ref propertiesColl, properties[i], String.Format("{0} - {1}", properties[i].Id, properties[i].Description));
                }
                propertyGrid.PropertySort   = PropertySort.Categorized;
                propertyGrid.SelectedObject = propertiesColl;
            }
        }
예제 #2
0
        }           //	end Trace

        public void GetPropertiesAsync()
        {
            m_executionOptions.ExecutionType = EnumExecutionType.ASYNCHRONOUS;

            DaProperty[]           properties = null;
            DaGetPropertiesOptions getAllPropertiesOptions = new DaGetPropertiesOptions();

            getAllPropertiesOptions.WhatPropertyData = EnumPropertyData.ALL;

            System.Console.WriteLine("Get all properties of address space element: " + m_addressSpaceElementId);

            m_operationResult = m_daSession.GetDaProperties(
                m_addressSpaceElementId,
                m_addressSpaceElementPath,
                getAllPropertiesOptions,
                out properties,
                m_executionOptions);

            m_executionOptions.ExecutionContext++;

            System.Console.WriteLine("Get properties 1 and 5 of address space element: " + m_addressSpaceElementId);

            DaProperty[]           someProperties       = null;
            DaGetPropertiesOptions getPropertiesOptions = new DaGetPropertiesOptions();

            getPropertiesOptions.WhatPropertyData = EnumPropertyData.ALL;
            getPropertiesOptions.PropertyIds      = new int[] { 1, 5 };

            m_operationResult = m_daSession.GetDaProperties(
                m_addressSpaceElementId,
                m_addressSpaceElementPath,
                getPropertiesOptions,
                out someProperties,
                m_executionOptions);

            m_executionOptions.ExecutionContext++;
        }        // end GetPropertiesAsync
 /// <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);
            }
        }
        /// <summary>
        /// Write Address Space Element
        /// </summary>
        /// <param name="session"></param>
        /// <param name="itemId"></param>
        public void WriteAddresSpaceItem(DaSession session, string itemId, object selectedObject, bool isAddSpaceElem)
        {
            Helper.DataTypes dataTypeHelper = new DataTypes();
            this.panelBottom.Visible = true;

            isDaItem     = false;
            this.session = session;

            ValueQT[] itemValues;
            int[]     itemResults;
            int       result = session.Read(MAX_AGE_DEVICE, new string[] { itemId }, null, out itemValues, out itemResults, null);

            if (itemResults.Length == 0)
            {
                return;
            }
            if (itemValues.Length == 0)
            {
                return;
            }

            Type             itemDataType    = typeof(short);
            EnumAccessRights itemAccessRighs = EnumAccessRights.READWRITEABLE;
            bool             hasWriteAccess  = true;

            if (ResultCode.SUCCEEDED(result) && ResultCode.SUCCEEDED(itemResults[0]))
            {
                DaGetPropertiesOptions propertyGetOptions = new DaGetPropertiesOptions();
                propertyGetOptions.WhatPropertyData = EnumPropertyData.ALL;

                DaProperty[] properties = null;
                if (isAddSpaceElem)
                {
                    if (ResultCode.SUCCEEDED(session.GetDaProperties(itemId,
                                                                     null,
                                                                     propertyGetOptions,
                                                                     out properties,
                                                                     null)))
                    {
                        if (properties == null)
                        {
                            this.propertyGrid.SelectedObject = FillEmptyValueQT(itemId, null);
                            return;
                        }
                        if (properties.Length < 5)
                        {
                            this.propertyGrid.SelectedObject = FillEmptyValueQT(itemId, null);
                            return;
                        }
                        itemDataType    = DataTypeConverter.GetSysType((short)properties[0].ValueQT.Data);
                        itemAccessRighs = ObjToAccesssRights(properties[4].ValueQT.Data);
                    }
                }
                else
                {
                    itemDataType = (selectedObject as DaProperty).DataType;
                }

                //the item value is null
                if (itemValues[0] == null)
                {
                    this.propertyGrid.SelectedObject = FillEmptyValueQT(itemId, itemDataType);
                    return;
                }

                if (itemAccessRighs == EnumAccessRights.READABLE)
                {
                    hasWriteAccess = false;
                }
            }
            this.propertyGrid.SelectedObject = FillWriteService(itemId, itemDataType, hasWriteAccess, itemValues[0]);
        }
예제 #6
0
        }        // end GetPropertiesAsync

        public void GetPropertiesSync()
        {
            m_executionOptions.ExecutionType = EnumExecutionType.SYNCHRONOUS;
            DaProperty[]           properties = null;
            DaGetPropertiesOptions getAllPropertiesOptions = new DaGetPropertiesOptions();

            getAllPropertiesOptions.WhatPropertyData = EnumPropertyData.ALL;

            System.Console.WriteLine("Get all properties of address space element: " + m_addressSpaceElementId);
            m_operationResult = m_daSession.GetDaProperties(
                m_addressSpaceElementId,
                m_addressSpaceElementPath,
                getAllPropertiesOptions,
                out properties,
                m_executionOptions);

            if (ResultCode.SUCCEEDED(m_operationResult))
            {
                System.Console.WriteLine("Get properties of address space element:  " + m_addressSpaceElementId);
                for (int i = 0; i < properties.Length; i++)
                {
                    System.Console.WriteLine("	Property Name: "+ properties[i].Name);
                    System.Console.WriteLine("	Property Id: "+ properties[i].Id);
                    System.Console.WriteLine("	Property Item Id: "+ properties[i].ItemId);
                    System.Console.WriteLine("	Property DataType: "+ properties[i].DataType);
                    System.Console.WriteLine("	Property description: "+ properties[i].Description);
                    System.Console.WriteLine("	Property value: "+ properties[i].ValueQT.Data.ToString() + "	");
                    System.Console.WriteLine(" ");
                }
            }             //end if
            else
            {
                System.Console.WriteLine("Failed to synchronously get properties of address space element: " + m_addressSpaceElementId + " - 0x" + m_operationResult.ToString("X8"));
            }

            System.Console.WriteLine("Get properties 1 and 5 of address space element: " + m_addressSpaceElementId);
            DaProperty[]           someProperties       = null;
            DaGetPropertiesOptions getPropertiesOptions = new DaGetPropertiesOptions();

            getPropertiesOptions.PropertyIds      = new int[] { 1, 5 };
            getPropertiesOptions.WhatPropertyData = EnumPropertyData.ALL;

            m_operationResult = m_daSession.GetDaProperties(
                m_addressSpaceElementId,
                m_addressSpaceElementPath,
                getPropertiesOptions,
                out someProperties,
                m_executionOptions);

            if (ResultCode.SUCCEEDED(m_operationResult))
            {
                for (int i = 0; i < someProperties.Length; i++)
                {
                    System.Console.WriteLine("	Property Name: "+ someProperties[i].Name);
                    System.Console.WriteLine("	Property Id: "+ someProperties[i].Id);
                    System.Console.WriteLine("	Property Item Id: "+ someProperties[i].ItemId);
                    System.Console.WriteLine("	Property DataType: "+ someProperties[i].DataType);
                    System.Console.WriteLine("	Property description: "+ someProperties[i].Description);
                    System.Console.WriteLine("	Property value: "+ someProperties[i].ValueQT.Data.ToString() + "	");
                    System.Console.WriteLine(" ");
                }
            }
            else
            {
                System.Console.WriteLine("Failed to synchronously get 1 and 5 properties of address space element: " + m_addressSpaceElementId + " - 0x" + m_operationResult.ToString("X8"));
            }
        }        // end GetPropertiesSync
        /// <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);
            }
        }