/// <summary> /// Build DaBrowse /// </summary> /// <param name="daSession"></param> public void BuildDaBrowseTree(DaSession daSession, DaSubscription subsciption) { daSubscription = subsciption; ShowProperContextMenu(browseTreeView.SelectedNode); if (browseTreeView.Nodes.Count > 0) { if (browseTreeView.Nodes[0].Text.Equals(daSession.Url)) { return; } } browseTreeView.Nodes.Clear(); TreeNode treeRootNode = new TreeNode(daSession.Url, BROWSE_INDEX, BROWSE_INDEX); treeRootNode.Name = daSession.Url; DaAddressSpaceElement daAddressSpaceElement = new DaAddressSpaceElement(); daAddressSpaceElement.Session = daSession; daRootSpaceElem = daAddressSpaceElement; browseTreeView.Nodes.Add(treeRootNode); treeRootNode.Nodes.Add(new TreeNode("")); treeRootNode.Tag = daSession; if (Options.SortDa) { browseTreeView.Sort(); } else { browseTreeView.Sorted = false; } }
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 { int result = session.Disconnect(new ExecutionOptions()); TestClient.ApplicationInstance.RemoveDaSession(session); } catch (Exception ex) { return(new TestResult(ex)); } UnsetProperty(Session); return(TestResult.Success()); }
} // end HandleServerShutdown public static void HandleSessionReadCompleted( DaSession daSession, uint executionContext, string[] itemIds, string[] itemPaths, ValueQT[] values, int[] results, int result) { FileStream fs = new FileStream("C:\\ClientService.txt", FileMode.OpenOrCreate, FileAccess.Write); StreamWriter streamWriter = new StreamWriter(fs); streamWriter.BaseStream.Seek(0, SeekOrigin.End); if (ResultCode.SUCCEEDED(result)) { streamWriter.WriteLine(daSession + " asynchronous read succeeded! "); for (int i = 0; i < itemIds.Length; i++) { if (ResultCode.SUCCEEDED(results[i])) { streamWriter.WriteLine(String.Format("{0,-19} {1} {2,-50} ", itemIds[i], "-", values[i].ToString())); } else { streamWriter.WriteLine(" Session asynchronous read failed for item " + " Item: " + itemIds[i] + " [ResultID: " + results[i] + " ]"); } } } else { streamWriter.WriteLine(" Session asynchronous read failed! Result: " + result); } streamWriter.Flush(); streamWriter.Close(); } // end HandleSessionReadCompleted
//-- #endregion #region Private Members //--------------------- #region Private Attributes //------------------------ //-- #endregion //-- #endregion #region Public Methods //--------------------- //-- #endregion #region Public Properties //----------------------- //-- #endregion #region Handles //--------------------- public static void HandleGetDaPropertiesCompleted( DaSession aDaSession, uint executionContext, uint addressSpaceElementHandle, string addressSpaceElementId, string addressSpaceElementPath, DaProperty[] properties, int result) { if (ResultCode.SUCCEEDED(result)) { System.Console.WriteLine("Get properties of address space element: " + addressSpaceElementId); for (int i = 0; i < properties.Length; i++) { System.Console.WriteLine(" Property Name: "+ properties[i].Name); System.Console.WriteLine(" Property Id: "+ properties[i].Id); System.Console.WriteLine(" Property Item Id: "+ properties[i].ItemId); System.Console.WriteLine(" Property DataType: "+ properties[i].DataType); System.Console.WriteLine(" Property description: "+ properties[i].Description); System.Console.WriteLine(" Property value: "+ properties[i].ValueQT.Data.ToString() + " "); System.Console.WriteLine(" "); } } //end if else { System.Console.WriteLine("Failed to asynchronously get properties of address space element: " + addressSpaceElementId + " - 0x" + result.ToString("X8")); } } // end HandleGetDaPropertiesCompleted
} // 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
} // end HandleServerShutdown public static void HandleSessionReadCompleted( DaSession daSession, uint executionContext, string[] itemIds, string[] itemPaths, ValueQT[] values, int[] results, int result) { if (ResultCode.SUCCEEDED(result)) { System.Console.WriteLine(daSession + " asynchronous read succeeded! "); for (int i = 0; i < itemIds.Length; i++) { if (ResultCode.SUCCEEDED(results[i])) { System.Console.WriteLine(String.Format("{0,-19} {1} {2,-50} ", itemIds[i], "-", values[i].ToString())); } else { System.Console.WriteLine(" Session asynchronous read failed for item " + " Item: " + itemIds[i] + " [ResultID: " + results[i] + " ]"); } } } else { System.Console.WriteLine(" Session asynchronous read failed! Result: " + result); } } // end HandleSessionReadCompleted
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()); }
public void ReadAddressSpaceElemProperties(DaSession session, string itemId) { panelBottom.Visible = false; DaGetPropertiesOptions propertyGetOptions = new DaGetPropertiesOptions(); propertyGetOptions.WhatPropertyData = EnumPropertyData.ALL; DaProperty[] properties = null; if (ResultCode.SUCCEEDED(session.GetDaProperties(itemId, null, propertyGetOptions, out properties, null))) { if (properties == null) { return; } Helper.CustomProperties propertiesColl = new DemoClient.Helper.CustomProperties(); for (int i = 0; i < properties.Length; i++) { SetPropertyData(ref propertiesColl, properties[i], String.Format("{0} - {1}", properties[i].Id, properties[i].Description)); } propertyGrid.PropertySort = PropertySort.Categorized; propertyGrid.SelectedObject = propertiesColl; } }
/// <summary> /// Read the Address Space ValueQT's /// </summary> /// <param name="session"></param> /// <param name="itemId"></param> /// <param name="itemValues"></param> /// <returns></returns> public bool ReadAddresSpaceItem(DaSession session, string itemId, out ValueQT[] itemValues) { //read the item values this.panelBottom.Visible = false; isDaItem = false; int[] itemResults; int result = session.Read(MAX_AGE_DEVICE, new string[] { itemId }, null, out itemValues, out itemResults, null); if (itemResults.Length == 0) { return(false); } if (ResultCode.SUCCEEDED(result) && ResultCode.SUCCEEDED(itemResults[0])) { if (itemValues == null) { return(false); } if (itemValues.Length == 0) { return(false); } this.propertyGrid.SelectedObject = FillReadService(itemId, true, itemValues[0]); return(true); } return(false); }
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 ProcessCommandLine public void Terminate() { GetApplication().Terminate(); m_daSession = null; m_daSubscription = null; m_daItem = null; m_aeSession = null; m_aeSubscription = null; } // end Terminate
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 { int result = (int)EnumResultCode.S_FALSE; int[] results; string[] itemIDs; ValueQT[] values; // set stop simulation params itemIDs = new string[] { nodeSetId + m_deleteVariablesCommand }; values = new ValueQT[] { new ValueQT(true, EnumQuality.GOOD, DateTime.Now) }; // send write request result = session.Write(itemIDs, null, values, out results, null); if (ResultCode.SUCCEEDED(result)) { 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)); } }
void session_WriteCompleted(DaSession aDaSession, uint executionContext, string[] itemIDs, string[] itemPaths, ValueQT[] values, int[] results, int result) { if (executionContext == m_asyncExecutionContext) { m_asyncResults = results; m_asyncResult = result; m_waitHandle.Set(); } }
void session_GetDaPropertiesCompleted(DaSession aDaSession, uint executionContext, uint addressSpaceElementHandle, string addressSpaceElementID, string addressSpaceElementPath, DaProperty[] aDaProperty, int result) { if (executionContext == m_asyncExecutionContext) { m_browseAsyncResults = aDaProperty; m_browseAsyncResult = result; m_waitHandle.Set(); } }
void session_BrowseCompleted(DaSession aDaSession, uint executionContext, uint addressSpaceElementHandle, string addressSpaceElementID, string addressSpaceElementPath, Softing.OPCToolbox.Client.DaAddressSpaceElement[] addressSpaceElements, int result) { if (executionContext == m_asyncExecutionContext) { m_browseAsyncResults = addressSpaceElements; m_browseAsyncResult = result; m_waitHandle.Set(); } }
} // end InitializeDaObjects public void PrintDaSession(DaSession session) { System.Console.WriteLine("Session's Attributes:"); System.Console.WriteLine(" URL: "+ session.Url); System.Console.WriteLine(" ClientName: "+ session.ClientName); System.Console.WriteLine(" LocaleID: "+ session.LocaleId); System.Console.WriteLine(" SupportedOPCSpecification: "+ session.SupportedOpcSpecification); System.Console.WriteLine(" Forced OPC Specification: "+ session.ForcedOpcSpecification); System.Console.WriteLine(" Class context: "+ session.ClassContext); System.Console.WriteLine(); } // end PrintDaSession
//- #endregion #region // Public Constructors //----------------------------- /// <summary> /// Initializes a new instance of the <see cref="DaAddressSpaceElement"/> class with /// the values specified. /// </summary> /// <param name="aType">The type of the address space element</param> /// <param name="aName">The name of the address space element</param> /// <param name="anItemId">The ItemId of the address space element</param> /// <param name="anItemPath">The ItemPath for the address space element.</param> /// <param name="anObjectHandle">A handle for the address space element.</param> /// <param name="aSession">The owner session for this element</param> /// <include /// file='TBNC.doc.xml' /// path='//class[@name="DaAddressSpaceElement"]/constructor[@name="DaAddressSpaceElement"]/doc/*' /// /> public DaAddressSpaceElement( EnumAddressSpaceElementType aType, string aName, string anItemId, string anItemPath, uint anObjectHandle, DaSession aSession) : base(aType, aName, anItemId, anObjectHandle) { m_itemPath = anItemPath; m_session = aSession; }
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 { Softing.OPCToolbox.Client.DaAddressSpaceElement[] elements; int result = Int16.MaxValue; if (BrowseOptions == null) { BrowseOptions = new DaAddressSpaceElementBrowseOptions(); } if (ExecutionType == EnumExecutionType.SYNCHRONOUS) { result = session.Browse(RootID, RootPath, BrowseOptions.Wrapped, out elements, new ExecutionOptions(EnumExecutionType.SYNCHRONOUS, m_asyncExecutionContext)); } else { m_asyncExecutionContext = DaExecutionContext.Next; session.BrowseCompleted += session_BrowseCompleted; m_waitHandle = new System.Threading.AutoResetEvent(false); result = session.Browse(RootID, RootPath, BrowseOptions.Wrapped, out elements, new ExecutionOptions(EnumExecutionType.ASYNCHRONOUS, m_asyncExecutionContext)); if (m_waitHandle.WaitOne(3000)) { result = m_browseAsyncResult; elements = m_browseAsyncResults; } session.BrowseCompleted -= session_BrowseCompleted; } return(ValidateBrowsedElements(elements, result)); } catch (Exception ex) { return(new TestResult(ex)); } }
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()); }
/// <summary> /// AeSubscription Properties /// </summary> /// <param name="subscription"></param> internal bool AeSubscription(AeSubscription subscription) { panelBottom.Visible = true; this.daItem = null; aeSubscription = subscription; daSession = null; daSubscription = null; aeSession = null; Helper.DataTypes dataTypeHelper = new DataTypes(); this.panelBottom.Visible = true; //AeSubscription Buffer Time Helper.CustomProperties propServiceColl = new DemoClient.Helper.CustomProperties(); Helper.CustomProperty customProperty = new DemoClient.Helper.CustomProperty("Buffer Time", "System.String", "General", null, aeSubscription.RequestedBufferTime); propServiceColl.Properties.Add(customProperty); //AeSubscription Revised Buffer Time customProperty = new DemoClient.Helper.CustomProperty("Revised Buffer Time", "System.String", "General", null, aeSubscription.RevisedBufferTime); customProperty.Attributes = new Attribute[] { ReadOnlyAttribute.Yes }; propServiceColl.Properties.Add(customProperty); //AeSubscription Max Size customProperty = new DemoClient.Helper.CustomProperty("Max Size", "System.String", "General", null, aeSubscription.RequestedMaxSize); propServiceColl.Properties.Add(customProperty); //AeSubscription Revised Max Size customProperty = new DemoClient.Helper.CustomProperty("Revised Max Size", "System.String", "General", null, aeSubscription.RevisedMaxSize); customProperty.Attributes = new Attribute[] { ReadOnlyAttribute.Yes }; propServiceColl.Properties.Add(customProperty); this.propertyGrid.PropertySort = PropertySort.Categorized; this.propertyGrid.SelectedObject = propServiceColl; return(true); }
} // end AddProperty public override int QueryCacheValue(DaSession aSession, ref ValueQT aCacheValue) { if (IoMode == EnumIoMode.POLL_OWNCACHE) { MySession session = aSession as MySession; if (session != null) { return(session.GetCacheValue(ref aCacheValue)); } else { return((int)EnumResultCode.E_FAIL); } // end if ... else } else { return(base.GetCacheValue(ref aCacheValue)); } // end if } // end QueryCacheValue
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() { 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)); } }
/// <summary> /// AeSession Properties /// </summary> /// <param name="session"></param> internal bool AeSession(AeSession session) { panelBottom.Visible = true; this.daItem = null; daSubscription = null; daSession = null; aeSubscription = null; aeSession = session; Helper.DataTypes dataTypeHelper = new DataTypes(); this.panelBottom.Visible = true; //AeSession URL Helper.CustomProperties propServiceColl = new DemoClient.Helper.CustomProperties(); Helper.CustomProperty customProperty = new DemoClient.Helper.CustomProperty("URL", "System.String", "General", null, aeSession.Url); customProperty.Attributes = new Attribute[] { ReadOnlyAttribute.Yes }; propServiceColl.Properties.Add(customProperty); //AeSession Locale Id ServerStatus status = null; if (ResultCode.SUCCEEDED(aeSession.GetStatus(out status, null))) { LocaleId.SelectedItem = aeSession.LocaleId; LocaleId.LocaleIdList = status.SupportedLcIds; customProperty = new DemoClient.Helper.CustomProperty("Locale Id", "System.String", "General", null, aeSession.LocaleId, typeof(Helper.LCIDEditor), typeof(Helper.LCIDEditor)); } else { customProperty = new DemoClient.Helper.CustomProperty("Locale Id", "System.String", "General", null, aeSession.LocaleId); } propServiceColl.Properties.Add(customProperty); //AeSession Client name customProperty = new DemoClient.Helper.CustomProperty("Client Name", "System.String", "General", null, aeSession.ClientName); propServiceColl.Properties.Add(customProperty); //AeSession Available filter criterias EnumFilterBy filters; if (ResultCode.SUCCEEDED(aeSession.QueryAvailableAeFilters(out filters, null))) { customProperty = new DemoClient.Helper.CustomProperty("Available Filter Criterias", "System.String", "General", null, GetFilter(filters)); } else { customProperty = new DemoClient.Helper.CustomProperty("Available Filter Criterias", "System.String", "General", null, ""); } customProperty.Attributes = new Attribute[] { ReadOnlyAttribute.Yes }; propServiceColl.Properties.Add(customProperty); //AeSession Class Context EnumClassContext classContext = aeSession.ClassContext; customProperty = new DemoClient.Helper.CustomProperty("DCOM Class Context", typeof(EnumClassContext), "General", null, classContext); propServiceColl.Properties.Add(customProperty); if (status != null) { //AeSession Vendor info customProperty = new DemoClient.Helper.CustomProperty("Vendor Info", "System.String", "Status", null, status.VendorInfo); customProperty.Attributes = new Attribute[] { ReadOnlyAttribute.Yes }; propServiceColl.Properties.Add(customProperty); //AeSession Version customProperty = new DemoClient.Helper.CustomProperty("Version", "System.String", "Status", null, status.ProductVersion); customProperty.Attributes = new Attribute[] { ReadOnlyAttribute.Yes }; propServiceColl.Properties.Add(customProperty); //AeSession Start time customProperty = new DemoClient.Helper.CustomProperty("Start Time", "System.String", "Status", null, ValueConverter.DateTimeOptions(status.StartTime)); customProperty.Attributes = new Attribute[] { ReadOnlyAttribute.Yes }; propServiceColl.Properties.Add(customProperty); //AeSession Current time customProperty = new DemoClient.Helper.CustomProperty("Current Time", "System.String", "Status", null, ValueConverter.DateTimeOptions(status.CurrentTime)); customProperty.Attributes = new Attribute[] { ReadOnlyAttribute.Yes }; propServiceColl.Properties.Add(customProperty); //AeSession Last update time customProperty = new DemoClient.Helper.CustomProperty("Last Update Time", "System.String", "Status", null, ValueConverter.DateTimeOptions(status.LastUpdateTime)); customProperty.Attributes = new Attribute[] { ReadOnlyAttribute.Yes }; propServiceColl.Properties.Add(customProperty); //AeSession Status info customProperty = new DemoClient.Helper.CustomProperty("Status Info", "System.String", "Status", null, status.StatusInfo); customProperty.Attributes = new Attribute[] { ReadOnlyAttribute.Yes }; propServiceColl.Properties.Add(customProperty); //AeSession Server state customProperty = new DemoClient.Helper.CustomProperty("Server State", "System.String", "Status", null, status.State); customProperty.Attributes = new Attribute[] { ReadOnlyAttribute.Yes }; propServiceColl.Properties.Add(customProperty); } this.propertyGrid.PropertySort = PropertySort.Categorized; this.propertyGrid.SelectedObject = propServiceColl; return(true); }
/// <summary> /// Write Address Space Element /// </summary> /// <param name="session"></param> /// <param name="itemId"></param> public void WriteAddresSpaceItem(DaSession session, string itemId, object selectedObject, bool isAddSpaceElem) { Helper.DataTypes dataTypeHelper = new DataTypes(); this.panelBottom.Visible = true; isDaItem = false; this.session = session; ValueQT[] itemValues; int[] itemResults; int result = session.Read(MAX_AGE_DEVICE, new string[] { itemId }, null, out itemValues, out itemResults, null); if (itemResults.Length == 0) { return; } if (itemValues.Length == 0) { return; } Type itemDataType = typeof(short); EnumAccessRights itemAccessRighs = EnumAccessRights.READWRITEABLE; bool hasWriteAccess = true; if (ResultCode.SUCCEEDED(result) && ResultCode.SUCCEEDED(itemResults[0])) { DaGetPropertiesOptions propertyGetOptions = new DaGetPropertiesOptions(); propertyGetOptions.WhatPropertyData = EnumPropertyData.ALL; DaProperty[] properties = null; if (isAddSpaceElem) { if (ResultCode.SUCCEEDED(session.GetDaProperties(itemId, null, propertyGetOptions, out properties, null))) { if (properties == null) { this.propertyGrid.SelectedObject = FillEmptyValueQT(itemId, null); return; } if (properties.Length < 5) { this.propertyGrid.SelectedObject = FillEmptyValueQT(itemId, null); return; } itemDataType = DataTypeConverter.GetSysType((short)properties[0].ValueQT.Data); itemAccessRighs = ObjToAccesssRights(properties[4].ValueQT.Data); } } else { itemDataType = (selectedObject as DaProperty).DataType; } //the item value is null if (itemValues[0] == null) { this.propertyGrid.SelectedObject = FillEmptyValueQT(itemId, itemDataType); return; } if (itemAccessRighs == EnumAccessRights.READABLE) { hasWriteAccess = false; } } this.propertyGrid.SelectedObject = FillWriteService(itemId, itemDataType, hasWriteAccess, itemValues[0]); }
/// <summary> /// DaSubscription Properties /// </summary> /// <param name="subscription"></param> internal bool DaSubscription(DaSubscription subscription) { panelBottom.Visible = true; this.daItem = null; daSubscription = subscription; daSession = null; aeSubscription = null; aeSession = null; Helper.DataTypes dataTypeHelper = new DataTypes(); this.panelBottom.Visible = true; //DaSubscription Name Helper.CustomProperties propServiceColl = new DemoClient.Helper.CustomProperties(); Helper.CustomProperty customProperty = new DemoClient.Helper.CustomProperty("Name", "System.String", "General", null, daSubscription.Name); propServiceColl.Properties.Add(customProperty); //DaSubscription Update Rate customProperty = new DemoClient.Helper.CustomProperty("Update Rate(ms)", "System.String", "General", null, daSubscription.RequestedUpdateRate); propServiceColl.Properties.Add(customProperty); //DaSubscription Revised Update Rate customProperty = new DemoClient.Helper.CustomProperty("Revised Update Rate(ms)", "System.String", "General", null, daSubscription.RevisedUpdateRate); customProperty.Attributes = new Attribute[] { ReadOnlyAttribute.Yes }; propServiceColl.Properties.Add(customProperty); //DaSubscription Deadband customProperty = new DemoClient.Helper.CustomProperty("Deadband", "System.String", "General", null, daSubscription.Deadband.ToString()); propServiceColl.Properties.Add(customProperty); //DaSubscription Time Bias customProperty = new DemoClient.Helper.CustomProperty("Time Bias(min)", "System.String", "General", null, daSubscription.TimeBias); propServiceColl.Properties.Add(customProperty); //DaSubscription Locale Id ServerStatus status; if (ResultCode.SUCCEEDED(daSubscription.DaSession.GetStatus(out status, null))) { LocaleId.SelectedItem = daSubscription.LocaleId; LocaleId.LocaleIdList = status.SupportedLcIds; customProperty = new DemoClient.Helper.CustomProperty("Locale Id", "System.String", "General", null, daSubscription.LocaleId, typeof(Helper.LCIDEditor), typeof(Helper.LCIDEditor)); } else { customProperty = new DemoClient.Helper.CustomProperty("Locale Id", "System.String", "General", null, daSubscription.LocaleId); } propServiceColl.Properties.Add(customProperty); //DaSubscription Revised Keep Alive Time customProperty = new DemoClient.Helper.CustomProperty("Keep Alive Time(ms)", "System.String", "General", null, daSubscription.RequestedKeepAliveTime); propServiceColl.Properties.Add(customProperty); customProperty = new DemoClient.Helper.CustomProperty("Revised Keep Alive Time(ms)", "System.String", "General", null, daSubscription.RevisedKeepAliveTime); customProperty.Attributes = new Attribute[] { ReadOnlyAttribute.Yes }; propServiceColl.Properties.Add(customProperty); this.propertyGrid.PropertySort = PropertySort.Categorized; this.propertyGrid.SelectedObject = propServiceColl; return(true); }
public override TestResult Execute() { if (string.IsNullOrEmpty(SessionProperty)) { return(TestResult.ParameterMissing("Session")); } DaSession session = GetProperty(SessionProperty) as DaSession; if (session == null) { return(TestResult.ParameterInvalid("Session")); } try { Softing.OPCToolbox.Client.DaAddressSpaceElement[] adElements; 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 adElements, new ExecutionOptions(EnumExecutionType.SYNCHRONOUS, m_asyncExecutionContext)); Softing.OPCToolbox.Client.DaAddressSpaceElement addressSpaceElement = null; if (ResultCode.SUCCEEDED(result)) { for (int i = 0; i < adElements.Length; i++) { if (adElements[i].ItemId == RootID) { addressSpaceElement = adElements[i]; } } } else { EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString()); return(TestResult.Failed(string.Format("Call returned: {0} ({1})", resCode.ToString(), result))); } if (addressSpaceElement == null) { return(TestResult.Failed(string.Format("Address space element {0} not found!", RootID))); } Softing.OPCToolbox.Client.DaProperty[] elements; result = int.MaxValue; if (ExecutionType == EnumExecutionType.SYNCHRONOUS) { result = addressSpaceElement.GetDaProperties(DaGetPropertiesOptions, out elements, new ExecutionOptions(ExecutionType, 0)); } else { m_asyncExecutionContext = DaExecutionContext.Next; session.GetDaPropertiesCompleted += session_GetDaPropertiesCompleted; m_waitHandle = new System.Threading.AutoResetEvent(false); result = addressSpaceElement.GetDaProperties(DaGetPropertiesOptions, out elements, new ExecutionOptions(EnumExecutionType.ASYNCHRONOUS, m_asyncExecutionContext)); if (m_waitHandle.WaitOne(3000)) { result = m_browseAsyncResult; elements = m_browseAsyncResults; } session.GetDaPropertiesCompleted -= session_GetDaPropertiesCompleted; } if (ResultCode.SUCCEEDED(result)) { if (!string.IsNullOrEmpty(Property)) { SetProperty(Property, elements); } if (ExpectedElements.Count != 0 && ExpectedElements.Count != elements.Length) { return(TestResult.Failed(string.Format("Unexpected number of results, expected {0}, actual {1}", ExpectedElements.Count, elements.Length))); } for (int i = 0; i < ExpectedElements.Count; i++) { Softing.OPCToolbox.Client.DaProperty receivedElement = elements[i]; TestClientGui.Support.DaProperty expectedElement = ExpectedElements[i]; if ((expectedElement.ItemId != null && expectedElement.ItemId != receivedElement.ItemId) || (expectedElement.ItemPath != null && expectedElement.ItemPath != receivedElement.ItemPath) || (!string.IsNullOrEmpty(expectedElement.Name) && expectedElement.Name != receivedElement.Name) || (expectedElement.DataType != null && expectedElement.DataType != receivedElement.DataType) || (!string.IsNullOrEmpty(expectedElement.Description) && expectedElement.Description != receivedElement.Description) || (expectedElement.ValueQT != null && !expectedElement.ValueQT.Data.Equals(receivedElement.ValueQT.Data)) || (expectedElement.ValueQT != null && expectedElement.ValueQT.Quality != receivedElement.ValueQT.Quality)) { return(TestResult.Failed(string.Format("Unexpected result for item #{0}", i))); } if (DaGetPropertiesOptions.WhatPropertyData == EnumPropertyData.ITEMID || DaGetPropertiesOptions.WhatPropertyData == EnumPropertyData.NONE) { if (receivedElement.ValueQT.Data != null) { return(TestResult.Failed(string.Format("Value was not NULL for element #{0}", i))); } } if (DaGetPropertiesOptions.WhatPropertyData == EnumPropertyData.VALUE) { if (!string.IsNullOrEmpty(receivedElement.ItemId)) { return(TestResult.Failed(string.Format("ItemId was not NULL for element #{0}", i))); } } } return(TestResult.Success()); } else { EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString()); return(TestResult.Failed(string.Format("Call returned: {0}\t({1})", resCode.ToString(), result))); } } catch (Exception ex) { return(new TestResult(ex)); } }
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 (Count <= 0) { return(TestResult.ParameterInvalid("Count")); } try { // prepare values to write List <string> itemToWrite = new List <string>(); itemToWrite.Add(m_ItemCountNodeId); itemToWrite.Add(m_ItemTypeNodeId); itemToWrite.Add(m_ItemIsAnalogNodeId); itemToWrite.Add(m_CreateItemsNodeId); string[] itemIDs = itemToWrite.ToArray(); List <ValueQT> valuesToWrite = new List <ValueQT>(); valuesToWrite.Add(new ValueQT(Count, EnumQuality.GOOD, DateTime.Now)); valuesToWrite.Add(new ValueQT((uint)NodeType, EnumQuality.GOOD, DateTime.Now)); valuesToWrite.Add(new ValueQT(IsAnalog, EnumQuality.GOOD, DateTime.Now)); guid = Guid.NewGuid().ToString(); valuesToWrite.Add(new ValueQT(guid, EnumQuality.GOOD, DateTime.Now)); ValueQT[] values = valuesToWrite.ToArray(); int result = (int)EnumResultCode.S_FALSE; int[] results; // send CreateItemsRequest result = session.Write(itemIDs, null, values, out results, null); if (ResultCode.SUCCEEDED(result)) { // wait for Variables to be created System.Threading.Thread.Sleep(1000); string[] itemsToRead = new string[] { ItemSetIDNodeId }; ValueQT[] readValues; result = session.Read(0, itemsToRead, null, out readValues, out results, null); if (ResultCode.SUCCEEDED(result)) { string itemSetIdValue = string.Empty; string[] stringArray = readValues[0].Data as string[]; string item = string.Empty; for (int i = 0; i < stringArray.Length; i++) { item = stringArray[i]; if (item.Split('#')[1] == guid) { itemSetIdValue = item.Split('#')[0]; break; } } if (itemSetIdValue == string.Empty) { return(TestResult.Failed(string.Format("ItemSetId value was not found! {0}", guid))); } itemSetIdValue = m_nodeSetPrefix + itemSetIdValue; SetProperty(Property, itemSetIdValue); 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))); } } 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)); } }
public MyDaSubscription(uint subscriptionId, uint updateRate, DaSession parentSession) : base(updateRate, parentSession) { m_subscriptionId = subscriptionId; }
/// <summary> /// Show DaItem Properties /// </summary> /// <param name="daItem"></param> internal bool DaItem(DaItem item) { panelBottom.Visible = true; this.daItem = item; daSubscription = null; daSession = null; aeSubscription = null; aeSession = null; Helper.DataTypes dataTypeHelper = new DataTypes(); this.panelBottom.Visible = true; //Item Id Helper.CustomProperties propServiceColl = new DemoClient.Helper.CustomProperties(); Helper.CustomProperty customProperty = new DemoClient.Helper.CustomProperty("Item Id", "System.String", "General", null, daItem.Id); propServiceColl.Properties.Add(customProperty); //Item Path customProperty = new DemoClient.Helper.CustomProperty("Item Path", "System.String", "General", null, daItem.Path); propServiceColl.Properties.Add(customProperty); //Requested Data Type string dataType = daItem.NativeDatatype.FullName; if (dataType.Contains("*")) { dataType = dataType.Remove(dataType.IndexOf('*')); } dataTypeHelper.Type = System.Type.GetType(dataType); customProperty = new DemoClient.Helper.CustomProperty("Requested Data Type", dataTypeHelper.RequiredDataTypes.Values.GetType().ToString(), "General", null, dataTypeHelper.NativeDataType, typeof(Helper.DataTypeEditor), typeof(Helper.DataTypeEditor)); propServiceColl.Properties.Add(customProperty); //Deadband customProperty = new DemoClient.Helper.CustomProperty("Deadband", "System.String", "General", null, daItem.Deadband.ToString()); propServiceColl.Properties.Add(customProperty); //Native Data Type customProperty = new DemoClient.Helper.CustomProperty("Native Data Type", "System.String", "General", null, dataTypeHelper.NativeDataType); customProperty.Attributes = new Attribute[] { ReadOnlyAttribute.Yes }; propServiceColl.Properties.Add(customProperty); //Access Rights string strAccesRights = ""; switch (daItem.AccessRights) { case EnumAccessRights.READABLE: strAccesRights = "read"; break; case EnumAccessRights.READWRITEABLE: strAccesRights = "read and write"; break; case EnumAccessRights.WRITEABLE: strAccesRights = "write"; break; } customProperty = new DemoClient.Helper.CustomProperty("Acces Rights", "System.String", "General", null, strAccesRights); customProperty.Attributes = new Attribute[] { ReadOnlyAttribute.Yes }; propServiceColl.Properties.Add(customProperty); //Engineering Units Type string strEUType = ""; switch (daItem.EUType) { case EnumEUType.ANALOG: strEUType = "analog"; break; case EnumEUType.ENUMERATED: strEUType = "enumerated"; break; case EnumEUType.NOENUM: strEUType = "no"; break; } customProperty = new DemoClient.Helper.CustomProperty("EU Type", "System.String", "General", null, strEUType); customProperty.Attributes = new Attribute[] { ReadOnlyAttribute.Yes }; propServiceColl.Properties.Add(customProperty); //Engeneering Units Info string euInfo = ""; if (daItem.EUInfo != null) { euInfo = daItem.EUInfo.ToString(); } customProperty = new DemoClient.Helper.CustomProperty("EU Info", "System.String", "General", null, euInfo); customProperty.Attributes = new Attribute[] { ReadOnlyAttribute.Yes }; propServiceColl.Properties.Add(customProperty); this.propertyGrid.SelectedObject = propServiceColl; return(true); }