}           //	end ProcessCommandLine

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

            m_daSubscription.RemoveDaItem(m_daItem1);
            m_daSubscription.RemoveDaItem(m_daItem2);
            m_daSubscription.RemoveDaItem(m_daItem3);
            m_daSubscription.RemoveDaItem(m_daItem4);
            m_daSubscription.RemoveDaItem(m_daItem5);
            m_daSubscription.RemoveDaItem(m_daItem6);

            m_daSession.RemoveDaSubscription(m_daSubscription);

            GetApplication().RemoveDaSession(m_daSession);

            GetApplication().Terminate();
            m_daSession      = null;
            m_daSubscription = null;
            m_daItem1        = null;
            m_daItem2        = null;
            m_daItem3        = null;
            m_daItem4        = null;
            m_daItem5        = null;
            m_daItem6        = null;
        }           //	end Terminate
Exemplo n.º 2
0
		//-----------------

		public MyDaItem(string itemId, MyDaSubscription parentSubscription) : base(itemId, parentSubscription)
		{
			ValueChanged += new ValueChangedEventHandler(HandleValueChanged);
			StateChangeCompleted += new StateChangeEventHandler(HandleStateChanged);
			PerformStateTransitionCompleted += new PerformStateTransitionEventHandler(HandlePerformStateTransition);
		}
        }           //	end Terminate

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

            m_executionOptions = new ExecutionOptions();
            m_executionOptions.ExecutionType    = EnumExecutionType.ASYNCHRONOUS;
            m_executionOptions.ExecutionContext = 0;

            m_itemList = new MyDaItem[6];
            m_itemIds  = new string[] { "maths.sin", "time.local.second", "increment.UI1 array", "increment.BSTR", "secure.I2", "IOP.static.I1 array" };

            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);

                if (!m_daSession.Valid)
                {
                    return(connectResult);
                }

                m_daSubscription = new MyDaSubscription(1000, m_daSession);

                if (!m_daSubscription.Valid)
                {
                    return(connectResult);
                }

                m_daItem1 = new MyDaItem("maths.sin", m_daSubscription);

                if (!m_daItem1.Valid)
                {
                    return(connectResult);
                }
                m_itemList[0] = m_daItem1;

                m_daItem2 = new MyDaItem("time.local.second", m_daSubscription);

                if (!m_daItem2.Valid)
                {
                    return(connectResult);
                }
                m_itemList[1] = m_daItem2;

                m_daItem3 = new MyDaItem("increment.UI1 array", m_daSubscription);
                if (!m_daItem3.Valid)
                {
                    return(connectResult);
                }
                m_itemList[2] = m_daItem3;

                m_daItem4 = new MyDaItem("increment.BSTR", m_daSubscription);
                if (!m_daItem4.Valid)
                {
                    return(connectResult);
                }

                m_itemList[3] = m_daItem4;

                m_daItem5 = new MyDaItem("secure.I2", m_daSubscription);
                if (!m_daItem5.Valid)
                {
                    return(connectResult);
                }

                m_itemList[4] = m_daItem5;

                m_daItem6 = new MyDaItem("IOP.static.I1 array", m_daSubscription);
                if (!m_daItem6.Valid)
                {
                    return(connectResult);
                }

                m_itemList[5] = m_daItem6;



                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