コード例 #1
0
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(Url))
            {
                return(TestResult.ParameterMissing("Url"));
            }
            try
            {
                ExecutionOptions executionOptions = new ExecutionOptions(EnumExecutionType.SYNCHRONOUS, 0);
                for (uint sessionCnt = 0; sessionCnt < SessionsCount; sessionCnt++)
                {
                    DaSession session = new DaSession(ExpandProperty(Url));

                    for (uint subscriptionCnt = 0; subscriptionCnt < SubscriptionsCount; subscriptionCnt++)
                    {
                        DaSubscription subscription = new DaSubscription(SubscriptionRate, session);

                        for (uint itemCnt = 0; itemCnt < ItemsCount; itemCnt++)
                        {
                            string itemID = "Test Folder.TestItems_0.TV_" + itemCnt.ToString();
                            DaItem item   = new DaItem("item", subscription);
                        }
                    }
                    session.Connect(true, true, executionOptions);
                }
            }
            catch (Exception ex)
            {
                if (ExpectedSuccess)
                {
                    return(new TestResult(ex));
                }
            }
            return(TestResult.Success());
        }
コード例 #2
0
        }               //	end InitializeAeObjects

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

            try{
                m_daSession      = new DaSession("opcda:///Softing.OPCToolboxDemo_ServerDA.1/{2E565242-B238-11D3-842D-0008C779D775}");
                m_daSubscription = new DaSubscription(1000, m_daSession);
                m_daItem         = new DaItem("maths.sin", m_daSubscription);

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

            return(connectResult);
        }               //	end InitializeDaObjects
コード例 #3
0
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(Url))
            {
                return(TestResult.ParameterMissing("Url"));
            }

            try
            {
                ExecutionOptions executionOptions = new ExecutionOptions(EnumExecutionType.SYNCHRONOUS, 0);
                DaSession        session          = new DaSession(ExpandProperty(Url));

                if (!session.Valid)
                {
                    return(TestResult.Failed("DaSession not Valid"));
                }

                // set the global prioperty no matter what
                SetProperty(Property, session);

                if (ForcedOpcSpecification != EnumOPCSpecification.DEFAULT)
                {
                    session.ForcedOpcSpecification = ForcedOpcSpecification;
                }

                if (Connect)
                {
                    int result = session.Connect(Deep, Active, executionOptions);

                    if (ResultCode.FAILED(result))
                    {
                        EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                        return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                    }
                }
            }
            catch (Exception ex)
            {
                if (ExpectedSuccess)
                {
                    return(new TestResult(ex));
                }
            }

            return(TestResult.Success());
        }
コード例 #4
0
        public override TestResult Execute()
        {
            CountDataChanges.s_counts = 0;

            ExecutionOptions executionOptions = new ExecutionOptions(EnumExecutionType.SYNCHRONOUS, 0);

            if (TimeInterval == 0)
            {
                return(TestResult.ParameterMissing("TimeInterval"));
            }

            if (string.IsNullOrEmpty(Url))
            {
                return(TestResult.ParameterMissing("Session"));
            }


            if (string.IsNullOrEmpty(ParentNode))
            {
                ParentNode = "Test Folder.TestItems_0";
            }
            try
            {
                int              res;
                DaSession        session      = new DaSession(ExpandProperty(Url));
                DaSubscription[] subscription = new MyDaSubscription[SubscriptionCount];
                CountDataChanges.s_dataChangesPerSubscription = new long[SubscriptionCount];

                uint             itemCount = 0;
                MyDaSubscription currentSubscription;
                for (uint subCount = 0; subCount < SubscriptionCount; ++subCount)
                {
                    currentSubscription    = new MyDaSubscription(subCount, SubscriptionRate, session);
                    subscription[subCount] = currentSubscription;
                    CountDataChanges.s_dataChangesPerSubscription[subCount] = 0;
                    for (uint i = 0; i < ItemsCountPerSubscription; ++i)
                    {
                        string itemID = ParentNode + ".TV_" + itemCount.ToString();
                        DaItem item   = new DaItem(itemID, currentSubscription);
                        ++itemCount;
                    }
                }

                for (uint i = 0; i < SubscriptionCount; ++i)
                {
                    subscription[i].DataChanged += new DataChangedEventHandler(HandleDataChanged);
                }

                res = session.Connect(true, true, executionOptions);

                System.Threading.Thread.Sleep(TimeInterval);

                session.Disconnect(executionOptions);

                string datachangesPerSubscription = "";
                for (uint i = 0; i < SubscriptionCount; ++i)
                {
                    datachangesPerSubscription += " | Sub#" + i.ToString() + ": " + CountDataChanges.s_dataChangesPerSubscription[i].ToString();
                }
                datachangesPerSubscription = "Total: " + CountDataChanges.s_counts.ToString() + datachangesPerSubscription;
                return(TestResult.Failed(datachangesPerSubscription));
            }
            catch (Exception ex)
            {
                return(new TestResult(ex));
            }
        }