Ejemplo n.º 1
0
        }           //	end Trace

        public void ActivateSession(bool sync)
        {
            System.Console.WriteLine();
            if (sync)
            {
                int result = this.m_daSession.Connect(true, true, new ExecutionOptions());
                if (ResultCode.FAILED(result))
                {
                    System.Console.WriteLine(" Session activate failed!");
                }
            }            // end if
            else
            {
                m_daSession.Connect(true, true, m_executionOptions);
                m_executionOptions.ExecutionContext++;
            }     // end else
        }         // end ActivateSession
Ejemplo n.º 2
0
        }           //	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