Exemplo n.º 1
0
        }           //	end Terminate

        public int InitializeDaObjects()
        {
            int connectResult = (int)EnumResultCode.E_FAIL;

            m_executionOptions = new ExecutionOptions();

            try
            {
                //	TODO add your server URL here
                //	this is the server url for Softing OPCToolbox Demo Server
                //	first choice is COM-DA
                string url = "opcda:///Softing.OPCToolboxDemo_ServerDA.1/{2E565242-B238-11D3-842D-0008C779D775}";

                //uncomment if you need an XML-DA access
                //string url ="http://localhost:8079/OPC/DA";

                m_daSession = new MyDaSession(url);

                connectResult = m_daSession.Connect(true, false, m_executionOptions);
            }
            catch (Exception exc)
            {
                GetApplication().Trace(
                    EnumTraceLevel.ERR,
                    EnumTraceGroup.USER,
                    "OpcClient::InitializaDaObjects",
                    exc.ToString());
            }               //	end try...catch

            return(connectResult);
        }           //	end InitializeDaObjects
Exemplo n.º 2
0
        }           //	end ProcessCommandLine

        public void Terminate()
        {
            if (m_daSession.CurrentState != EnumObjectState.DISCONNECTED)
            {
                m_daSession.Disconnect(new ExecutionOptions());
            }
            GetApplication().RemoveDaSession(m_daSession);

            GetApplication().Terminate();
            m_daSession        = null;
            m_executionOptions = null;
        }           //	end Terminate
Exemplo n.º 3
0
        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