Exemple #1
0
 // method that handles the completion of getting the server status
 public static void HandleGetStatusCompleted(ObjectSpaceElement obj, uint executionContext, ServerStatus serverStatus, int result)
 {
     if (ResultCode.FAILED(result))
     {
         System.Console.WriteLine(obj.ToString() + "Asynchronous GetServerStatus Failed");
     }
     if (ResultCode.SUCCEEDED(result))
     {
         System.Console.WriteLine("Asynchronous GetServerStatus Succeeded");
         System.Console.WriteLine("Server Status");
         System.Console.WriteLine("	Vendor info: "+ serverStatus.VendorInfo);
         System.Console.WriteLine("	Product version: "+ serverStatus.ProductVersion);
         System.Console.WriteLine("	State: "+ serverStatus.State);
         System.Console.WriteLine("	Start time: "+ serverStatus.StartTime);
         System.Console.WriteLine("	Last update time: "+ serverStatus.LastUpdateTime);
         System.Console.WriteLine("	Current time: "+ serverStatus.CurrentTime);
         System.Console.WriteLine("	GroupCount: "+ serverStatus.GroupCount);
         System.Console.WriteLine("	Bandwidth: "+ serverStatus.Bandwidth);
         for (int i = 0; i < serverStatus.SupportedLcIds.Length; i++)
         {
             System.Console.WriteLine("	Supported LCID: "+ serverStatus.SupportedLcIds[i]);
         }
         System.Console.WriteLine("	Status info: "+ serverStatus.StatusInfo);
     }
 }
Exemple #2
0
		} //	end GetProperties


		/// <summary>
		/// Retrieves the element`s property list.
		/// </summary>
		/// <param name="someDaProperties">A list with the property data for the current element.</param>
		/// <param name="executionOptions">Specifies the modality of execution for getting the element's properties.</param>
		///<returns>The result of retrieving the element's properties.</returns>
		/// <include
		///  file='TBNC.doc.xml'
		///  path='//class[@name="DaAddressSpaceElement"]/method[@name="GetDaProperties_2"]/doc/*'
		/// />
		public virtual int GetDaProperties(out DaProperty[] someDaProperties, ExecutionOptions executionOptions)
		{
			int res = (int) EnumResultCode.E_FAIL;
			try
			{
				res = this.Session.GetDaProperties(
					this,
					this.ItemId,
					this.ItemPath,
					null,
					out someDaProperties,
					executionOptions);

				if (ResultCode.FAILED(res))
				{
					Application.Instance.Trace(
						EnumTraceLevel.ERR,
						EnumTraceGroup.CLIENT,
						"DaAddressSpaceElement.GetDaProperties",
						"Getting properties failed! Result: " + res);
				}
			}
			catch (Exception exc)
			{
				Application.Instance.Trace(
					EnumTraceLevel.ERR,
					EnumTraceGroup.CLIENT,
					"DaAddressSpaceElement.GetDaProperties",
					exc.ToString());

				someDaProperties = null;
			}
			return res;
		} //	end GetDaProperties
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(Session))
            {
                return(TestResult.ParameterMissing("Session"));
            }

            DaSession session = GetProperty(Session) as DaSession;

            if (session == null)
            {
                return(TestResult.ParameterInvalid("Session"));
            }

            try
            {
                DaSubscription subscription = new DaSubscription(UpdateRate, session);

                if (!subscription.Valid)
                {
                    return(TestResult.Failed("DaSubscription not Valid"));
                }

                if (RequestedKeepAliveTime.HasValue)
                {
                    subscription.RequestedKeepAliveTime = RequestedKeepAliveTime.Value;
                }

                // set the global property anyhow.
                SetProperty(Property, subscription);

                if (Connect)
                {
                    int result = subscription.Connect(Deep, Active, null);

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

                if (Deadband.HasValue)
                {
                    subscription.Deadband = Deadband.Value;
                }
            }
            catch (Exception ex)
            {
                if (ExpectedSuccess)
                {
                    return(new TestResult(ex));
                }
            }

            return(TestResult.Success());
        }
        }           //	end HandleReadRequests

        public override int HandleWriteRequests()
        {
            int result = ValuesChanged();

            if (ResultCode.FAILED(result))
            {
                return(result);
            }               //	end if

            return(CompleteRequests());
        } //	end HandleWriteRequests
        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());
        }
        }         // end ConnectSession

        public void DisconnectSession(bool sync)
        {
            System.Console.WriteLine();
            if (sync)
            {
                int result = m_daSession.Disconnect(new ExecutionOptions());
                if (ResultCode.FAILED(result))
                {
                    System.Console.WriteLine(" Session disconnect failed!");
                }
            }             // end if
            else
            {
                m_daSession.Disconnect(m_executionOptions);
                m_executionOptions.ExecutionContext++;
            }     // end else
        }         //end DisconnectSession
        }           //	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
		//-
		#endregion

		#region //Public Methods
		//------------------------

		/// <summary>
		/// Acknowledges the current condition.
		/// </summary>
		/// <param name="ackId">An identifier for the client who last acknowledged the condition.</param>
		/// <param name="ackComment">A comment string passed in by the client who acknowledged the condition.</param>
		/// <param name="executionOptions">Specifies the modality of execution for acknowledging the condition.</param>
		/// <returns>The result of acknowledging the condition.</returns>
		/// <include
		///  file='TBNC.doc.xml'
		///  path='//class[@name="AeCondition"]/method[@name="Acknowledge"]/doc/*'
		/// />
		public virtual int Acknowledge(string ackId, string ackComment, ExecutionOptions executionOptions)
		{
			int[] results = new int[] {-1};
			int res = (int) EnumResultCode.E_FAIL;

			if (this.AeSession == null)
			{
				Application.Instance.Trace(
					EnumTraceLevel.ERR,
					EnumTraceGroup.CLIENT,
					"AeCondition.Acknowledge",
					"The Session property of the Condition cannot be null! Set the property to a value before calling Acknowledge!");
				return res;
			}
			try
			{
				res = this.AeSession.AcknowledgeAeConditions(
					ackId,
					ackComment,
					new AeCondition[] {this},
					out results,
					executionOptions);

				if (ResultCode.FAILED(res))
				{
					Application.Instance.Trace(
						EnumTraceLevel.ERR,
						EnumTraceGroup.CLIENT,
						"AeCondition.Acknowledge",
						"Acknowledging condition failed! Result: " + res);
				}
			}
			catch (Exception exc)
			{
				Application.Instance.Trace(
					EnumTraceLevel.ERR,
					EnumTraceGroup.CLIENT,
					"AeCondition.Acknowledge",
					exc.ToString());
			}
			return res;
		}
        }         // end ConnectSession

        public void DisconnectSession(bool sync)
        {
            FileStream   fs           = new FileStream("C:\\ClientService.txt", FileMode.OpenOrCreate, FileAccess.Write);
            StreamWriter streamWriter = new StreamWriter(fs);

            streamWriter.BaseStream.Seek(0, SeekOrigin.End);
            streamWriter.WriteLine();
            if (sync)
            {
                int result = m_daSession.Disconnect(new ExecutionOptions());
                if (ResultCode.FAILED(result))
                {
                    streamWriter.WriteLine(" Session disconnect failed!");
                }
            }             // end if
            else
            {
                m_daSession.Disconnect(m_executionOptions);
                m_executionOptions.ExecutionContext++;
            }             // end else
            streamWriter.Flush();
            streamWriter.Close();
        }         //end DisconnectSession
Exemple #10
0
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(Session))
            {
                return(TestResult.ParameterMissing("Session"));
            }

            DaSession session = GetProperty(Session) as DaSession;

            if (session == null)
            {
                return(TestResult.ParameterInvalid("Session"));
            }

            ValueQT[] values;

            if (Values.Count == 0)
            {
                if (!string.IsNullOrEmpty(ValuesProperty))
                {
                    values = GetProperty(ValuesProperty) as ValueQT[];
                    if (values == null)
                    {
                        return(TestResult.ParameterInvalid("ValuesProperty"));
                    }
                }
                else
                {
                    return(TestResult.ParameterMissing("Values"));
                }
            }
            else
            {
                //if the quality was not set ; set it to the value QUALITY_NOT_SET
                for (int i = 0; i < Values.Count; i++)
                {
                    if (Values[i].Wrapped.Quality == Softing.OPCToolbox.EnumQuality.BAD_WAITING_FOR_INITIAL_DATA)
                    {
                        Values[i].Wrapped.SetData(Values[i].Wrapped.Data, Softing.OPCToolbox.EnumQuality.QUALITY_NOT_SET, Values[i].Wrapped.TimeStamp);
                    }
                }
                values = Value.CreateSDKCollection(Values);
            }

            try
            {
                int   result = (int)EnumResultCode.S_FALSE;
                int[] results;

                string[] itemIDs   = ItemIds.ToArray();
                string[] itemPaths = ItemPaths.Count > 0 ? ItemPaths.ToArray() : null;

                if (ExecutionType == EnumExecutionType.SYNCHRONOUS)
                {
                    result = session.Write(itemIDs, itemPaths, values, out results, null);
                }
                else
                {
                    m_asyncExecutionContext = DaExecutionContext.Next;
                    ExecutionOptions executionOptions = new ExecutionOptions(EnumExecutionType.ASYNCHRONOUS, m_asyncExecutionContext);

                    m_waitHandle = new System.Threading.AutoResetEvent(false);

                    SessionWriteEventHandler asyncHandler = new SessionWriteEventHandler(session_WriteCompleted);
                    session.WriteCompleted += asyncHandler;

                    result = session.Write(itemIDs, itemPaths, values, out results, executionOptions);

                    if (m_waitHandle.WaitOne(30000))
                    {
                        result  = m_asyncResult;
                        results = m_asyncResults;
                    }

                    session.WriteCompleted -= asyncHandler;
                }

                if (ResultCode.SUCCEEDED(result))
                {
                    if (!string.IsNullOrEmpty(ResultsProperty))
                    {
                        SetProperty(ResultsProperty, results);
                    }

                    if (ValidateAllResults)
                    {
                        for (int i = 0; i < results.Length; i++)
                        {
                            if (ResultCode.FAILED(results[i]))
                            {
                                EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), results[i].ToString());

                                return(TestResult.Failed(string.Format("Result {0} failed with the code: {1}  ({2})", i, resCode.ToString(), results[i])));
                            }
                        }
                    }
                    else if (ExpectedResults.Count > 0)
                    {
                        //validate with expected values
                        if (ExpectedResults.Count != results.Length)
                        {
                            return(new DaWriteTestResult(result, results, "Unexpected number of results"));
                        }

                        for (int i = 0; i < results.Length; i++)
                        {
                            if (results[i] != ExpectedResults[i])
                            {
                                EnumResultCode resCode         = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), results[i].ToString());
                                EnumResultCode resExpectedCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), ExpectedResults[i].ToString());

                                return(new DaWriteTestResult(result, results, string.Format("Unexpected result code for item {0}: received {1}  ({2}) instead of {3}  ({4})", i, resCode.ToString(), results[i], resExpectedCode.ToString(), ExpectedResults[i])));
                            }
                        }
                    }

                    return(new DaWriteTestResult(result, results));
                }
                else
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());
                    if (!string.IsNullOrEmpty(ExpectedServiceResult))
                    {
                        EnumResultCode expectedResCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), ExpectedServiceResult.ToString());
                        if (expectedResCode != resCode)
                        {
                            return(TestResult.Failed(string.Format("Unexpected service result: expected {0}, actual {1}", resCode, expectedResCode)));
                        }
                        return(TestResult.Success());
                    }

                    return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                }
            }
            catch (Exception ex)
            {
                return(new TestResult(ex));
            }
        }
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(ItemsProperty))
            {
                return(TestResult.ParameterMissing("ItemsProperty"));
            }

            DaItem[] items = GetProperty(ItemsProperty) as DaItem[];
            if (items == null)
            {
                return(TestResult.ParameterInvalid("ItemsProperty"));
            }

            ValueQT[] values;

            if (Values.Count == 0)
            {
                if (!string.IsNullOrEmpty(ValuesProperty))
                {
                    values = GetProperty(ValuesProperty) as ValueQT[];
                    if (values == null)
                    {
                        return(TestResult.ParameterInvalid("ValuesProperty"));
                    }
                }
                else
                {
                    return(TestResult.ParameterMissing("Values"));
                }
            }
            else
            {
                values = Value.CreateSDKCollection(Values);
            }

            try
            {
                int[] results = new int[items.Length];

                for (int i = 0; i < items.Length; i++)
                {
                    DaItem  item  = items[i];
                    ValueQT value = values[i];
                    int     writeResult;

                    int result = item.Write(value, out writeResult, new ExecutionOptions());

                    if (ResultCode.SUCCEEDED(result))
                    {
                        results[i] = writeResult;

                        if (ValidateAllResults)
                        {
                            if (ResultCode.FAILED(results[i]))
                            {
                                EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), results[i].ToString());

                                return(TestResult.Failed(string.Format("Result {0} failed with the code: {1}  ({2})", i, resCode.ToString(), results[i])));
                            }
                        }
                        else if (ExpectedResults.Count > i)
                        {
                            //validate with expected values

                            if (results[i] != ExpectedResults[i])
                            {
                                EnumResultCode resCode         = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), results[i].ToString());
                                EnumResultCode resExpectedCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), ExpectedResults[i].ToString());

                                return(new DaWriteTestResult(result, results, string.Format("Unexpected result code for item {0}: received {1}  ({2}) instead of {3}  ({4})", i, resCode.ToString(), results[i], resExpectedCode.ToString(), ExpectedResults[i])));
                            }
                        }
                    }
                    else
                    {
                        EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                        return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                    }
                }

                if (!string.IsNullOrEmpty(ResultsProperty))
                {
                    SetProperty(ResultsProperty, results);
                }

                return(TestResult.Success());
            }
            catch (Exception ex)
            {
                return(new TestResult(ex));
            }
        }
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(Session))
            {
                return(TestResult.ParameterMissing("Session"));
            }
            if (string.IsNullOrEmpty(RootID))
            {
                return(TestResult.ParameterMissing("RootID"));
            }
            //	if (string.IsNullOrEmpty(RootPath))
            //	return TestResult.ParameterMissing("RootPath");


            Softing.OPCToolbox.Client.DaSession session = GetProperty(Session) as DaSession;
            if (session == null)
            {
                return(TestResult.Failed("Session non existent"));
            }

            try
            {
                ExecutionOptions executionOptions = new ExecutionOptions(EnumExecutionType.SYNCHRONOUS, 0);
                session.Connect(false, false, executionOptions);

                Softing.OPCToolbox.Client.DaAddressSpaceElement[] elements;

                Softing.OPCToolbox.Client.DaAddressSpaceElement rootDaAddressSpaceElement = new Softing.OPCToolbox.Client.DaAddressSpaceElement(
                    EnumAddressSpaceElementType.BRANCH, String.Empty, string.Empty, string.Empty, 0, null);
                rootDaAddressSpaceElement.Session = session;


                int result = rootDaAddressSpaceElement.Browse(new Softing.OPCToolbox.Client.DaAddressSpaceElementBrowseOptions(), out elements, new ExecutionOptions(EnumExecutionType.SYNCHRONOUS, m_asyncExecutionContext));

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

                    return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                }

                Softing.OPCToolbox.Client.DaAddressSpaceElement addressSpaceElement = null;
                for (int i = 0; i < elements.Length; i++)
                {
                    if (elements[i].ItemId == RootID)
                    {
                        addressSpaceElement = elements[i];
                        break;
                    }
                }

                if (addressSpaceElement == null)
                {
                    return(TestResult.Failed(string.Format("Address space element {0} not found!", RootID)));
                }

                if (BrowseOptions == null)
                {
                    BrowseOptions = new DaAddressSpaceElementBrowseOptions();
                }



                if (ResultCode.SUCCEEDED(addressSpaceElement.Browse(BrowseOptions.Wrapped, out elements, new ExecutionOptions(EnumExecutionType.SYNCHRONOUS, 0))))
                {
                    //Softing.OPCToolbox.Client.DaAddressSpaceElement daElement;
                    Softing.OPCToolbox.Client.DaSubscription workerSubscription = new Softing.OPCToolbox.Client.DaSubscription(updateRate, session);

                    foreach (Softing.OPCToolbox.Client.DaAddressSpaceElement daElement in elements)
                    {
                        DaItem newItem = new DaItem(daElement.ItemId, workerSubscription);
                        //	result =  Connect(true, true, executionOptions);
                    }

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

                        return(TestResult.Failed(string.Format("Subscribe Call returned: {0}  ({1})", resCode.ToString(), result)));
                    }

                    SetProperty(Property, workerSubscription);
                }//end if
                else
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

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

            return(TestResult.Success());
        }
Exemple #13
0
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(ItemsProperty))
            {
                return(TestResult.ParameterMissing("ItemsProperty"));
            }

            DaItem[] items = GetProperty(ItemsProperty) as DaItem[];
            if (items == null)
            {
                return(TestResult.ParameterInvalid("ItemsProperty"));
            }

            DaSubscription subscription = items[0].DaSubscription;

            ValueQT[] values;

            if (Values.Count == 0)
            {
                if (!string.IsNullOrEmpty(ValuesProperty))
                {
                    values = GetProperty(ValuesProperty) as ValueQT[];
                    if (values == null)
                    {
                        return(TestResult.ParameterInvalid("ValuesProperty"));
                    }
                }
                else
                {
                    return(TestResult.ParameterMissing("Values"));
                }
            }
            else
            {
                values = Value.CreateSDKCollection(Values);
            }

            try
            {
                int   result  = (int)EnumResultCode.S_FALSE;
                int[] results = null;

                if (ExecutionType == EnumExecutionType.SYNCHRONOUS)
                {
                    result = subscription.Write(items, values, out results, null);
                }
                else
                {
                    m_asyncExecutionContext = DaExecutionContext.Next;
                    ExecutionOptions executionOptions = new ExecutionOptions(EnumExecutionType.ASYNCHRONOUS, m_asyncExecutionContext);

                    m_waitHandle = new System.Threading.AutoResetEvent(false);

                    SubscriptionWriteEventHandler asyncHandler = new SubscriptionWriteEventHandler(subscription_WriteCompleted);
                    subscription.WriteCompleted += asyncHandler;

                    result = subscription.Write(items, values, out results, executionOptions);

                    if (m_waitHandle.WaitOne(30000))
                    {
                        result  = m_asyncResult;
                        results = m_asyncResults;
                    }

                    subscription.WriteCompleted -= asyncHandler;
                }

                if (ResultCode.SUCCEEDED(result))
                {
                    if (!string.IsNullOrEmpty(ResultsProperty))
                    {
                        SetProperty(ResultsProperty, results);
                    }

                    if (ValidateAllResults)
                    {
                        for (int i = 0; i < results.Length; i++)
                        {
                            if (ResultCode.FAILED(results[i]))
                            {
                                EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), results[i].ToString());

                                return(TestResult.Failed(string.Format("Result {0} failed with the code: {1}  ({2})", i, resCode.ToString(), results[i])));
                            }
                        }
                    }
                    else if (ExpectedResults.Count > 0)
                    {
                        //validate with expected values
                        if (ExpectedResults.Count != results.Length)
                        {
                            return(new DaWriteTestResult(result, results, "Unexpected number of results"));
                        }

                        for (int i = 0; i < results.Length; i++)
                        {
                            if (results[i] != ExpectedResults[i])
                            {
                                EnumResultCode resCode         = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), results[i].ToString());
                                EnumResultCode resExpectedCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), ExpectedResults[i].ToString());

                                return(new DaWriteTestResult(result, results, string.Format("Unexpected result code for item {0}: received {1}  ({2}) instead of {3}  ({4})", i, resCode.ToString(), results[i], resExpectedCode.ToString(), ExpectedResults[i])));
                            }
                        }
                    }

                    return(new DaWriteTestResult(result, results));
                }
                else
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                    return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                }
            }
            catch (Exception ex)
            {
                return(new TestResult(ex));
            }
        }
Exemple #14
0
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(Subscription))
            {
                return(TestResult.ParameterMissing("Subscription"));
            }

            DaSubscription subscription = GetProperty(Subscription) as DaSubscription;

            if (subscription == null)
            {
                return(TestResult.ParameterInvalid("Subscription"));
            }

            try
            {
                ExecutionOptions executionOptions = new ExecutionOptions(EnumExecutionType.SYNCHRONOUS, 0);
                int           result;
                List <DaItem> items = new List <DaItem>(ItemIds.Count);

                foreach (string itemId in ItemIds)
                {
                    DaItem item = new DaItem(itemId, subscription);

                    if (!item.Valid)
                    {
                        return(TestResult.Failed("Item not Valid"));
                    }

                    if (Deadband.HasValue)
                    {
                        item.Deadband = Deadband.Value;
                    }

                    if (Connect)
                    {
                        result = item.Connect(false, 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)));
                        }
                    }

                    items.Add(item);
                }

                SetProperty(Property, items.ToArray());
            }
            catch (Exception ex)
            {
                if (ExpectedSuccess)
                {
                    return(new TestResult(ex));
                }
            }

            return(TestResult.Success());
        }
Exemple #15
0
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(Session))
            {
                return(TestResult.ParameterMissing("Session"));
            }
            if (string.IsNullOrEmpty(RootID))
            {
                return(TestResult.ParameterMissing("RootID"));
            }
            //	if (string.IsNullOrEmpty(RootPath))
            //	return TestResult.ParameterMissing("RootPath");


            Softing.OPCToolbox.Client.DaSession session = GetProperty(Session) as DaSession;
            if (session == null)
            {
                return(TestResult.Failed("Session non existent"));
            }

            try
            {
                ExecutionOptions executionOptions = new ExecutionOptions(EnumExecutionType.SYNCHRONOUS, 0);
                session.Connect(false, false, executionOptions);
                int result = 1;

                Softing.OPCToolbox.Client.DaAddressSpaceElementBrowseOptions browseOptions = new Softing.OPCToolbox.Client.DaAddressSpaceElementBrowseOptions();
                browseOptions.ElementTypeFilter = EnumAddressSpaceElementType.LEAF;

                Softing.OPCToolbox.Client.DaAddressSpaceElement[] DaElements;

                //get the nodes children
                if (ResultCode.SUCCEEDED(session.Browse(RootID, RootPath, browseOptions, out DaElements, executionOptions)))
                {
                    //Softing.OPCToolbox.Client.DaAddressSpaceElement daElement;
                    Softing.OPCToolbox.Client.DaSubscription workerSubscription = new Softing.OPCToolbox.Client.DaSubscription(updateRate, session);

                    foreach (Softing.OPCToolbox.Client.DaAddressSpaceElement daElement in DaElements)
                    {
                        DaItem newItem = new DaItem(daElement.ItemId, workerSubscription);
                        //	result =  Connect(true, true, executionOptions);
                    }
                    result = workerSubscription.Connect(true, true, executionOptions);
                    if (ResultCode.FAILED(result))
                    {
                        EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                        return(TestResult.Failed(string.Format("Subscribe Call returned: {0}  ({1})", resCode.ToString(), result)));
                    }
                }                //end if
                else
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

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

            return(TestResult.Success());
        }
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(ItemsProperty))
            {
                return(TestResult.ParameterMissing("ItemsProperty"));
            }

            DaItem[] items = GetProperty(ItemsProperty) as DaItem[];
            if (items == null)
            {
                return(TestResult.ParameterInvalid("ItemsProperty"));
            }

            try
            {
                ValueQT[] values  = new ValueQT[items.Length];
                int[]     results = new int[items.Length];

                for (int i = 0; i < items.Length; i++)
                {
                    DaItem  item = items[i];
                    ValueQT value;
                    int     readResult;

                    int result = item.Read(MaxAge, out value, out readResult, new ExecutionOptions());
                    values[i]  = value;
                    results[i] = result;

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

                if (!string.IsNullOrEmpty(ValuesProperty))
                {
                    SetProperty(ValuesProperty, values);
                }

                if (!string.IsNullOrEmpty(ResultsProperty))
                {
                    SetProperty(ResultsProperty, results);
                }

                //validate with expected values
                if (ExpectedValues.Count != 0 && ExpectedValues.Count != values.Length)
                {
                    return(new DaReadTestResult((int)EnumResultCode.S_OK, values, results, "Unexpected number of results"));
                }

                for (int i = 0; i < ExpectedValues.Count; i++)
                {
                    Softing.OPCToolbox.ValueQT receivedValue = values[i];
                    Value expectedValue = ExpectedValues[i];

                    if (expectedValue.Data != null)
                    {
                        if (!expectedValue.Data.Equals(receivedValue.Data))
                        {
                            return(new DaReadTestResult((int)EnumResultCode.S_OK, values, results, string.Format("Unexpected result Value for item #{0}", i)));
                        }
                    }
                    else if (expectedValue.DataArray != null)
                    {
                        IList receivedList = receivedValue.Data as IList;

                        if (receivedList != null)
                        {
                            if (expectedValue.DataArray.Count != receivedList.Count)
                            {
                                return(new DaReadTestResult((int)EnumResultCode.S_OK, values, results, string.Format("Result Value array is of different size then expected for item #{0}", i)));
                            }

                            for (int j = 0; j < receivedList.Count; j++)
                            {
                                if (!expectedValue.DataArray[j].Equals(receivedList[j]))
                                {
                                    return(new DaReadTestResult((int)EnumResultCode.S_OK, values, results, string.Format("Unexpected result Array Item Value for item #{0}", i)));
                                }
                            }
                        }
                    }

                    if (expectedValue.Quality != null && expectedValue.Quality != receivedValue.Quality)
                    {
                        return(new DaReadTestResult((int)EnumResultCode.S_OK, values, results, string.Format("Unexpected result Quality for item #{0}", i)));
                    }

                    //BUG in TB 4.0
                    //if( expectedValue.TimeStamp != null && expectedValue.TimeStamp != receivedValue.TimeStamp )
                    //	return new DaReadTestResult( (int) EnumResultCode.S_OK, values, results, string.Format( "Unexpected result Timestamp for item #{0}", i ) );
                }

                return(new DaReadTestResult((int)EnumResultCode.S_OK, values, results));
            }
            catch (Exception ex)
            {
                return(new TestResult(ex));
            }
        }
Exemple #17
0
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(Session))
            {
                return(TestResult.ParameterMissing("Session"));
            }

            DaSession session = GetProperty(Session) as DaSession;

            if (session == null)
            {
                return(TestResult.ParameterInvalid("Session"));
            }

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

            string nodeSetId = GetProperty(NodeSetId) as string;

            if (nodeSetId == null)
            {
                return(TestResult.ParameterInvalid("NodeSetId"));
            }

            try
            {
                DaSubscription subscription = new DaSubscription(UpdateRate, session);

                if (!subscription.Valid)
                {
                    return(TestResult.Failed("DaSubscription not Valid"));
                }

                int result = subscription.Connect(true, true, null);

                if (ResultCode.SUCCEEDED(result))
                {
                    // subscription created
                    ExecutionOptions executionOptions = new ExecutionOptions(EnumExecutionType.SYNCHRONOUS, 0);
                    List <DaItem>    items            = new List <DaItem>();

                    // create items
                    for (uint i = 0; i < Count; i++)
                    {
                        string itemId = String.Format("{0}, {1}, {2}", nodeSetId, m_variableNodeIdPrefix, i);

                        DaItem item = new DaItem(itemId, subscription);

                        if (!item.Valid)
                        {
                            return(TestResult.Failed("Item not Valid"));
                        }

                        result = item.Connect(false, true, 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)));
                        }

                        items.Add(item);
                    }

                    SetProperty(Property, items.ToArray());
                    SetProperty(SubscriptionProperty, subscription);

                    return(TestResult.Success());
                }
                else
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

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