} // end HandleStateChanged public static void HandleValueChanged(DaItem aDaItem, ValueQT aValue) { if (aDaItem.Id == "maths.sin") { System.Console.WriteLine("Value changed!"); System.Console.WriteLine(String.Format("{0,-19} {1} {2,-50} ", aDaItem.Id, "-", aValue.ToString())); } } // end HandleValueChanged
} // 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() { 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()); }
void item_ValueChanged(DaItem aDaItem, ValueQT aValue) { m_bReceived = true; //find the right item for (int i = 0; i < m_items.Length; i++) { if (m_items[i] == aDaItem) { m_valueChanges[i].Values.Add(new Value(aValue)); } } }
} // end InitializeDaObjects public string ReadItem() { string message = String.Empty; try { uint readCount = 1; DaItem[] itemList = new DaItem[readCount]; itemList[0] = m_daItem; ValueQT[] values = null; int[] results = null; if (ResultCode.SUCCEEDED( m_daSubscription.Read( 0, itemList, out values, out results, null))) { message += " \nRead item synchronously using subscription \n"; for (int i = 0; i < values.Length; i++) { if (ResultCode.SUCCEEDED(results[i])) { message += " " + itemList[i].Id + " - "; message += values[i].ToString() + "\n\n"; } else { message += "Read failed for item " + itemList[i].Id + "\n\n"; } // end if...else } // end for } else { message += " Subscription synchronous read failed!" + "\n\n"; } // end if...else } catch (Exception exc) { GetApplication().Trace( EnumTraceLevel.ERR, EnumTraceGroup.USER, "OpcClient::ReadItem", exc.ToString()); } // end try...catch return(message); } // end ReadItem
/// <summary> /// Display the item new properties /// </summary> /// <param name="obj"></param> /// <param name="executionContext"></param> /// <param name="whatAttributes"></param> /// <param name="results"></param> /// <param name="result"></param> void DaSubscription_SetDaItemAttributesToServerCompleted(DaSubscription aDaSubscription, uint executionContext, DaItem[] items, EnumObjectAttribute[] whatAttributes, int[] results, int result) { if (this.InvokeRequired) { Softing.OPCToolbox.Client.SetDaItemAttributesToServerEventHandler callback = new Softing.OPCToolbox.Client.SetDaItemAttributesToServerEventHandler(DaSubscription_SetDaItemAttributesToServerCompleted); this.Invoke(callback, new object[] { aDaSubscription, executionContext, items, whatAttributes, results, result }); return; } if (ResultCode.SUCCEEDED(result)) { for (int i = 0; i < items.Length; i++) { if (ResultCode.SUCCEEDED(results[i])) { DaItem item = items[i]; foreach (EnumObjectAttribute objAttrib in whatAttributes) { if (objAttrib == EnumObjectAttribute.DAITEM_ID || objAttrib == EnumObjectAttribute.DAITEM_ALL) { //find the element and reset the ID foreach (ListViewItem listViewItem in itemsListView.Items) { if (listViewItem == null) { continue; } if (listViewItem.Tag == null) { return; } DaItem daItem = listViewItem.Tag as DaItem; if (daItem == null) { continue; } if (daItem == item) { listViewItem.Text = item.Id; SetItemImage(daItem.CurrentState, listViewItem); item.DaSubscription.SetDaItemAttributesToServerCompleted -= new SetDaItemAttributesToServerEventHandler(DaSubscription_SetDaItemAttributesToServerCompleted); break; } } } } } } } }
/// <summary> /// Read Item /// </summary> private void ReadItem() { if (itemsListView.SelectedItems.Count > 0) { ListViewItem firstSelectedItem = itemsListView.SelectedItems[0]; if (firstSelectedItem == null) { return; } if (firstSelectedItem.Tag == null) { return; } string itemText = firstSelectedItem.Text; DaItem daItem = firstSelectedItem.Tag as DaItem; if (daItem == null) { return; } if (serviceWindow == null) { return; } ValueQT itemValues; bool result = serviceWindow.ReadDaItem(daItem, out itemValues); if (result) { firstSelectedItem.SubItems.Clear(); firstSelectedItem.Text = itemText; firstSelectedItem.Tag = daItem; if (daItem.AccessRights != EnumAccessRights.WRITEABLE && itemValues != null) { firstSelectedItem.SubItems.Add(ValueConverter.ArrayToString(itemValues)); firstSelectedItem.SubItems.Add(itemValues.Quality.ToString()); firstSelectedItem.SubItems.Add(ValueConverter.DateTimeOptions(itemValues.TimeStamp)); } else { firstSelectedItem.SubItems.Add(""); firstSelectedItem.SubItems.Add(""); firstSelectedItem.SubItems.Add(""); } firstSelectedItem.SubItems.Add(daItem.DaSubscription.DaSession.Url); firstSelectedItem.SubItems.Add(daItem.DaSubscription.Name); } if (result) { serviceWindow.Show(this.dockPanel); } } }
/// <summary> /// Update list view items if are an item form the collection /// </summary> /// <param name="aDaSubscription"></param> /// <param name="items"></param> /// <param name="values"></param> /// <param name="results"></param> public void DataChanged(DaSubscription aDaSubscription, DaItem[] items, ValueQT[] values, int[] results) { foreach (ListViewItem listViewItem in itemsListView.Items) { if (listViewItem == null) { continue; } if (listViewItem.Tag == null) { continue; } DaItem daItem = listViewItem.Tag as DaItem; if (daItem == null) { continue; } string itemText = listViewItem.Text; for (int i = 0; i < items.Length; i++) { if (daItem == items[i]) { if (ResultCode.SUCCEEDED(results[i])) { listViewItem.SubItems.Clear(); listViewItem.Text = itemText; listViewItem.Tag = daItem; if (daItem.AccessRights != EnumAccessRights.WRITEABLE && values[i] != null) { listViewItem.SubItems.Add(ValueConverter.ArrayToString(values[i])); listViewItem.SubItems.Add(values[i].Quality.ToString()); listViewItem.SubItems.Add(ValueConverter.DateTimeOptions(values[i].TimeStamp)); } else { listViewItem.SubItems.Add(""); listViewItem.SubItems.Add(""); listViewItem.SubItems.Add(""); } listViewItem.SubItems.Add(daItem.DaSubscription.DaSession.Url); listViewItem.SubItems.Add(daItem.DaSubscription.Name); } } } } }
/// <summary> /// Add an item /// </summary> /// <param name="item"></param> public void AddItem(DaItem item) { try { ValueQT itemValues; int itemResult; int result = item.Read(100, out itemValues, out itemResult, new ExecutionOptions()); if (ResultCode.SUCCEEDED(result) && ResultCode.SUCCEEDED(itemResult)) { AddListViewItem(item, itemValues); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
} //end PrintDaSubscription public void PrintDaItem(DaItem item) { System.Console.WriteLine("Item's Attributes:"); System.Console.WriteLine(" ID: "+ item.Id); System.Console.WriteLine(" Path: "+ item.Path); System.Console.WriteLine(" NativeDatatype: "+ item.NativeDatatype.ToString()); System.Console.WriteLine(" AccessRights: "+ item.AccessRights.ToString()); System.Console.WriteLine(" RequestedDatatype: "+ item.RequestedDatatype); System.Console.WriteLine(" Deadband: "+ item.Deadband); System.Console.WriteLine(" EUType: "+ item.EUType); if (item.EUInfo != null) { ValueData euValue; euValue = new ValueData(item.EUInfo); System.Console.WriteLine(" EUInfo: "+ euValue.ToString()); } System.Console.WriteLine(); } // end PrintDaItem
/// <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); }
/// <summary> /// Fill ReadDaItem Window with data /// </summary> /// <param name="daItem"></param> /// <param name="itemValues"></param> /// <returns></returns> public bool ReadDaItem(DaItem daItem, out ValueQT itemValues) { //read the item values this.panelBottom.Visible = false; isDaItem = true; int itemResult; int result = daItem.Read(100, out itemValues, out itemResult, new ExecutionOptions()); if (ResultCode.SUCCEEDED(result) && ResultCode.SUCCEEDED(itemResult)) { bool hasReadRights = false; if (daItem.AccessRights != EnumAccessRights.WRITEABLE) { hasReadRights = true; } this.propertyGrid.SelectedObject = FillReadService(daItem.Id, hasReadRights, itemValues); return(true); } return(false); }
/// <summary> /// Connect SelectedItems /// </summary> private void ConnectSelectedItems() { if (itemsListView.SelectedItems.Count > 0) { foreach (ListViewItem selectedItem in itemsListView.SelectedItems) { if (selectedItem == null) { continue; } if (selectedItem.Tag == null) { continue; } DaItem daItem = selectedItem.Tag as DaItem; if (daItem == null) { continue; } daItem.StateChangeCompleted -= new Softing.OPCToolbox.Client.StateChangeEventHandler(item_StateChangeCompleted); daItem.Connect(false, false, null); if (daItem.CurrentState == EnumObjectState.ACTIVATED) { SetIntermediareImage(ACTIVATED, selectedItem); } else if (daItem.CurrentState == EnumObjectState.CONNECTED) { SetIntermediareImage(CONNECTED, selectedItem); } else if (daItem.CurrentState == EnumObjectState.DISCONNECTED) { SetIntermediareImage(DISCONNECTED, selectedItem); } daItem.StateChangeCompleted -= new Softing.OPCToolbox.Client.StateChangeEventHandler(item_StateChangeCompleted); daItem.StateChangeCompleted += new Softing.OPCToolbox.Client.StateChangeEventHandler(item_StateChangeCompleted); } } }
/// <summary> /// Item state changed /// </summary> /// <param name="obj"></param> /// <param name="state"></param> private void item_StateChangeCompleted(ObjectSpaceElement obj, EnumObjectState state) { if (this.InvokeRequired) { Softing.OPCToolbox.Client.StateChangeEventHandler callback = new Softing.OPCToolbox.Client.StateChangeEventHandler(item_StateChangeCompleted); this.Invoke(callback, new object[] { obj, state }); return; } if (obj is DaItem) { //search item in list and uptade it if (itemsListView == null) { return; } foreach (ListViewItem listViewItem in itemsListView.Items) { if (listViewItem == null) { continue; } if (listViewItem.Tag == null) { continue; } DaItem daItem = listViewItem.Tag as DaItem; if (daItem == null) { continue; } string itemText = listViewItem.Text; if (daItem == (obj as DaItem)) { SetItemImage((obj as DaItem).CurrentState, listViewItem); } } } }
/// <summary> /// Add List View Items /// </summary> /// <param name="item"></param> /// <param name="itemValuesO"></param> private void AddListViewItem(DaItem item, ValueQT itemValues) { ListViewItem listViewItem = new ListViewItem(item.Id); if (item.AccessRights != EnumAccessRights.WRITEABLE && itemValues != null) { listViewItem.SubItems.Add(ValueConverter.ArrayToString(itemValues)); listViewItem.SubItems.Add(itemValues.Quality.ToString()); listViewItem.SubItems.Add(ValueConverter.DateTimeOptions(itemValues.TimeStamp)); } else { listViewItem.SubItems.Add(""); listViewItem.SubItems.Add(""); listViewItem.SubItems.Add(""); } listViewItem.SubItems.Add(item.DaSubscription.DaSession.Url); listViewItem.SubItems.Add(item.DaSubscription.Name); listViewItem.Tag = item; SetItemImage(item.CurrentState, listViewItem); itemsListView.Items.Add(listViewItem); item.StateChangeCompleted -= new Softing.OPCToolbox.Client.StateChangeEventHandler(item_StateChangeCompleted); item.StateChangeCompleted += new Softing.OPCToolbox.Client.StateChangeEventHandler(item_StateChangeCompleted); }
/// <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> /// 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); }
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)); } }
/// <summary> /// Write Value /// </summary> /// <param name="strValue"></param> private void WriteValue(string strValue) { if (itemsListView.SelectedItems.Count > 0) { //get the item session DaSession session = null; string[] itemIds = new string[itemsListView.SelectedItems.Count]; ValueQT[] itemValues = new ValueQT[itemsListView.SelectedItems.Count]; for (int i = 0; i < itemsListView.SelectedItems.Count; i++) { ListViewItem listViewItem = itemsListView.SelectedItems[i]; if (listViewItem == null) { return; } if (listViewItem.Tag == null) { return; } DaItem daItem = listViewItem.Tag as DaItem; if (daItem == null) { return; } //if no VALUE QT return if (daItem.ValueQT.Data == null) { return; } if (session == null) { session = daItem.DaSubscription.DaSession; } string itemId = null; Type dataType = typeof(System.Byte); int startIndex = 0; itemId = daItem.Id; dataType = daItem.NativeDatatype; if (dataType.IsArray) { startIndex = ((daItem.ValueQT.Data) as Array).GetLowerBound(0); } if (String.IsNullOrEmpty(itemId)) { return; } if (dataType == null) { return; } ValueQT itemValue = new ValueQT(); if (!dataType.IsArray) { //data type is not array object objData = null; ConvertToType(dataType, out objData, strValue); itemValue.SetData(objData, EnumQuality.GOOD, DateTime.Now); } else { //data type is array string typeStr = dataType.FullName; Type arrayType = System.Type.GetType(typeStr.Substring(0, typeStr.IndexOf('['))); string[] objDatas = strValue.Trim().Split(';'); if (objDatas == null) { return; } Array array = null; if (startIndex > 0) { //non-zero bound array array = Array.CreateInstance(arrayType, new int[] { objDatas.Length }, new int[] { startIndex }); } else { //zero boud array array = Array.CreateInstance(arrayType, objDatas.Length); } int strIndex = 0; for (int index = array.GetLowerBound(0); index <= array.GetUpperBound(0); index++) { object objData = null; ConvertToType(arrayType, out objData, objDatas[strIndex]); array.SetValue(objData, index); strIndex++; } itemValue.SetData(array, EnumQuality.GOOD, DateTime.Now); } itemIds[i] = itemId; itemValues[i] = itemValue; } //Write DaItem Values ExecutionOptions executionOptions = new ExecutionOptions(); executionOptions.ExecutionType = EnumExecutionType.ASYNCHRONOUS; executionOptions.ExecutionContext = 0; int[] results; session.Write(itemIds, null, itemValues, out results, executionOptions); } }
/// <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(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(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(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()); }
public DaItemValueChange(DaItem item, List <Value> values) { ItemID = item.Id; Values = values; }
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)); } }
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)); } }
} // end Add /// <summary> /// Determines whether the collection contains a specific element. /// </summary> /// <param name="item">The <see cref="ControlDaItem">ControlDaItem</see> to locate in the collection.</param> /// <returns><b>true</b> if the collection contains the specified value; otherwise, <b>false</b>.</returns> internal bool Contains(DaItem item) { return(this.List.Contains(item)); }
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)); } }
/// <summary> /// Searches for the specified <see cref="ControlDaItem">ControlDaItem</see> and returns the zero-based index of the first occurrence within the entire collection. /// </summary> /// <param name="item">The <b>ControlDaItem</b> to locate in the collection.</param> /// <returns>The zero-based index of the first occurrence of value within the entire collection, if found; otherwise, -1.</returns> internal int IndexOf(DaItem item) { return(this.List.IndexOf(item)); }