Beispiel #1
0
        public override TestResult Execute()
        {
            Softing.OPCToolbox.Client.DaSession session = GetProperty(Session) as DaSession;
            if (session == null)
            {
                //	session = new Softing.OPCToolbox.Client.DaSession("opcda:///Softing.COM TestServer.DA.1/{E4D228D9-1442-4DC9-BFB6-026215D5D302}");
                session = new Softing.OPCToolbox.Client.DaSession("opcda:///OpcTestLab.OpcAnalyzer.1/{B8AADBA5-382F-45DA-AA0A-D7BB21E4AE97}");
            }
            try
            {
                if (string.IsNullOrEmpty(Session))
                {
                    return(TestResult.ParameterMissing("Session"));
                }
                if (string.IsNullOrEmpty(RootID))
                {
                    return(TestResult.ParameterMissing("RootID"));
                }

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

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

                Softing.OPCToolbox.Client.DaAddressSpaceElement[] DaElements;
                ValueQT[] values;
                int[]     results;
                Softing.OPCToolbox.Client.DaSubscription workerSubscription = new Softing.OPCToolbox.Client.DaSubscription(1000, session);

                if (ResultCode.SUCCEEDED(session.Browse(RootID, RootPath, browseOptions, out DaElements, executionOptions)))
                {
                    foreach (Softing.OPCToolbox.Client.DaAddressSpaceElement daElement in DaElements)
                    {
                        if (daElement.ItemId.Contains("TV"))
                        {
                            Softing.OPCToolbox.Client.DaItem myItem = new DaItem(daElement.ItemId, workerSubscription);
                        }
                    }
                    workerSubscription.Connect(true, true, new ExecutionOptions());
                    result = workerSubscription.Read(1000, workerSubscription.ItemList, out values, out results, new ExecutionOptions());
                }
            }
            catch (System.Exception ex)
            {
                if (ExpectedSuccess)
                {
                    return(new TestResult(ex));
                }
            }


            return(TestResult.Success());
        }
Beispiel #2
0
		//-
		#endregion

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

		/// <summary>
		/// Browses the Data Access Server`s address space starting from the element`s position in the address space.
		/// </summary>
		/// <param name="browseOptions">Specifies the options of the browsing.</param>
		/// <param name="addressSpaceElements">A list with the element`s children.</param>
		/// <param name="executionOptions">Specifies the modality of execution for browsing the server's address space.</param>
		/// <returns>The result of browsing the address space.</returns>
		/// <include
		///  file='TBNC.doc.xml'
		///  path='//class[@name="DaAddressSpaceElement"]/method[@name="Browse"]/doc/*'
		/// />
		public int Browse(
			DaAddressSpaceElementBrowseOptions browseOptions,
			out DaAddressSpaceElement[] addressSpaceElements,
			ExecutionOptions executionOptions)
		{
			addressSpaceElements = null;
			OTCAddressSpaceBrowseOptions OTCBrowseOptions = new OTCAddressSpaceBrowseOptions();
			OTCBrowseOptions.m_accessRightsFilter = 0;
			int res = (int) EnumResultCode.E_FAIL;

			if (this.Session == null)
			{
				Application.Instance.Trace(
					EnumTraceLevel.ERR,
					EnumTraceGroup.CLIENT,
					"DaAddressSpaceElement.Browse",
					"The Session property of the AddressSpaceElement cannot be null! Set the property to a value before calling Browse!");
				return res;
			}
			try
			{
				OTCExecutionOptions options = new OTCExecutionOptions();

				if (executionOptions != null)
				{
					options.m_executionType = (byte) executionOptions.ExecutionType;
					options.m_executionContext = (uint) executionOptions.ExecutionContext;
				}
				else
				{
					options.m_executionType = (byte) EnumExecutionType.SYNCHRONOUS;
					options.m_executionContext = 0;
				}

				IntPtr pOTCaddressSpaceElements = new IntPtr();
				uint addressSpaceElementDataCount = 0;

				OTCBrowseOptions.m_type = (byte) browseOptions.ElementTypeFilter;
				OTCBrowseOptions.m_elementNameFilter = Marshal.StringToCoTaskMemUni(browseOptions.ElementNameFilter);
				OTCBrowseOptions.m_vendorFilter = Marshal.StringToCoTaskMemUni(browseOptions.VendorFilter);
				OTCBrowseOptions.m_accessRightsFilter = (uint) browseOptions.AccessRightsFilter;
				OTCBrowseOptions.m_dataTypeFilter = ValueQT.GetVartype(browseOptions.DataTypeFilter);
				OTCBrowseOptions.m_maxElements = browseOptions.MaxElements;
				OTCBrowseOptions.m_retrieveItemID = (byte) (browseOptions.RetrieveItemId ? 1 : 0);
				OTCBrowseOptions.m_retrieveProperties = (byte) (browseOptions.ReturnProperties ? 1 : 0);
				OTCBrowseOptions.m_retrievePropertyValues = (byte) (browseOptions.ReturnPropertyValues ? 1 : 0);
				OTCBrowseOptions.m_forceBrowseUp = (byte) (browseOptions.ForceBrowseUp ? 1 : 0);
				OTCBrowseOptions.m_continuationPoint = OTBFunctions.AllocateOTBString(browseOptions.ContinuationPoint);

				res = OTBFunctions.OTCBrowseAddressSpace(
					this.Session.Handle,
					this.m_objectElementHandle,
					this.ItemId,
					this.m_itemPath,
					ref OTCBrowseOptions,
					ref addressSpaceElementDataCount,
					out pOTCaddressSpaceElements,
					ref options);

				addressSpaceElements = new DaAddressSpaceElement[addressSpaceElementDataCount];

				if (options.m_executionType == (byte) EnumExecutionType.SYNCHRONOUS)
				{
					if (ResultCode.SUCCEEDED(res))
					{
						OTCAddressSpaceElementData typeOfAddressSpaceElement = new OTCAddressSpaceElementData();
						for (int i = 0; i < addressSpaceElementDataCount; i++)
						{
							int structSize = Marshal.SizeOf(typeOfAddressSpaceElement);
							OTCAddressSpaceElementData myData =
								(OTCAddressSpaceElementData)
								Marshal.PtrToStructure(OTBFunctions.GetIntPtrOffset(pOTCaddressSpaceElements, structSize*i),
								                       typeof (OTCAddressSpaceElementData));
							addressSpaceElements[i] = new DaAddressSpaceElement(
								(EnumAddressSpaceElementType) myData.m_type,
								Marshal.PtrToStringUni(myData.m_name),
								Marshal.PtrToStringUni(myData.m_itemID),
								Marshal.PtrToStringUni(myData.m_itemPath),
								myData.m_objectHandle,
								this.Session);
							OTBFunctions.OTFreeMemory(myData.m_itemID);
							OTBFunctions.OTFreeMemory(myData.m_name);
							OTBFunctions.OTFreeMemory(myData.m_itemPath);
						}
						if (pOTCaddressSpaceElements != IntPtr.Zero)
						{
							OTBFunctions.OTFreeMemory(pOTCaddressSpaceElements);
						}
						browseOptions.ContinuationPoint = Marshal.PtrToStringUni(OTCBrowseOptions.m_continuationPoint);
					}
					else
					{
						Application.Instance.Trace(
							EnumTraceLevel.ERR,
							EnumTraceGroup.CLIENT,
							"DaAddressSpaceElement.Browse",
							"Browsing failed! Result: " + res);
					}
				} //	if executionOptions Synchronous
				Marshal.FreeCoTaskMem(OTCBrowseOptions.m_elementNameFilter);
				Marshal.FreeCoTaskMem(OTCBrowseOptions.m_vendorFilter);
				OTBFunctions.OTFreeMemory(OTCBrowseOptions.m_continuationPoint);
			}
			catch (Exception exc)
			{
				Application.Instance.Trace(
					EnumTraceLevel.ERR,
					EnumTraceGroup.CLIENT,
					"DaAddressSpaceElement.Browse",
					exc.ToString());
			}
			return res;
		}
Beispiel #3
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());
        }