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