public void ConditionsAdd(AeSubscription anAeSubscription, AeCondition[] conditions, ShownConditions cond, AeSession[] sessions) { try { this.SuspendLayout(); conditionsListView.Items.Clear(); switch (cond) { case ShownConditions.All: ShowAllConditions(sessions); break; case ShownConditions.Session: ShowSessionConditions(sessions); break; case ShownConditions.Subscription: ShowSubscriptionConditions(anAeSubscription, conditions); break; } conditionsListView.Sort(); if (conditionsListView.Items.Count > 0) { this.Enabled = true; } else { this.Enabled = false; } this.ResumeLayout(); } catch { } }
} //end GetConditionState public int InitializeAeObjects() { int connectResult = (int)EnumResultCode.E_FAIL; try{ m_aeSession = new AeSession("opcae:///Softing.OPCToolboxDemo_ServerAE.1/{2E565243-B238-11D3-842D-0008C779D775}"); m_aeSubscription = new AeSubscription(m_aeSession); connectResult = m_aeSession.Connect( true, true, null); m_aeSubscription.RefreshAeConditions(null); } catch (Exception exc) { GetApplication().Trace( EnumTraceLevel.ERR, EnumTraceGroup.USER, "OpcClient::InitializeAeObjects", exc.ToString()); } // end try...catch return(connectResult); } // end InitializeAeObjects
public void ReceivedEvents(AeSubscription anAeSubscription, bool isRefresh, bool lastRefresh, AeEvent[] events) { try { this.SuspendLayout(); for (int i = 0; i < events.Length; i++) { if (events[i].EventType == Softing.OPCToolbox.EnumEventType.SIMPLE || events[i].EventType == Softing.OPCToolbox.EnumEventType.TRACKING) { ListViewItem item = new ListViewItem(events[i].SourcePath); item.Tag = events[i]; item.ImageIndex = IMAGE_INDEX; item.SubItems.Add(events[i].Severity.ToString()); item.SubItems.Add(events[i].Message); item.SubItems.Add(events[i].OccurenceTime.ToString()); item.SubItems.Add(events[i].ActorId); item.SubItems.Add(anAeSubscription.AeSession.Url); item.SubItems.Add(SUBSCRIPTION); eventsListView.Items.Insert(0, item); } } this.ResumeLayout(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
} // end ProcessCommandLine public void Terminate() { GetApplication().Terminate(); m_daSession = null; m_daSubscription = null; m_daItem = null; m_aeSession = null; m_aeSubscription = null; } // end Terminate
/// <summary> /// Add all subscription conditions /// </summary> /// <param name="aeSubscription"></param> /// <param name="conditions"></param> private void ShowSubscriptionConditions(AeSubscription aeSubscription, AeCondition[] conditions) { if (conditions == null) { conditions = aeSubscription.AeConditionList; } foreach (AeCondition condition in conditions) { AddCondition(condition, aeSubscription); } }
/// <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); }
//-- #endregion #region Public Properties //----------------------- //-- #endregion #region Handles //----------------------- private void HandleAeConditionsChanged(AeSubscription anAeSubscription, AeCondition[] conditions) { if (m_opcForm.conditionlistView.InvokeRequired) { RemoveItemsFromListView riflw = new RemoveItemsFromListView(m_opcForm.RemoveItems); m_opcForm.conditionlistView.BeginInvoke(riflw, null); } else { m_opcForm.conditionlistView.Items.Clear(); } string state = String.Empty; for (int i = 0; i < conditions.Length; i++) { AeCondition condition = conditions[i]; state = GetState(condition.State); if (m_opcForm.conditionlistView.InvokeRequired) { ChangeConditionListView cclw = new ChangeConditionListView(m_opcForm.ChangeItem); m_opcForm.conditionlistView.BeginInvoke(cclw, new object[] { condition, state }); } else { ListViewItem item = new ListViewItem(state); item.Tag = condition; m_opcForm.conditionlistView.Items.Add(item); item.SubItems.Add(condition.SourcePath); item.SubItems.Add(condition.ConditionName); item.SubItems.Add(condition.Severity.ToString()); item.SubItems.Add(condition.Message); item.SubItems.Add(condition.OccurenceTime.ToString("hh:mm:ss.fff")); item.SubItems.Add(condition.ActorId); item.SubItems.Add(condition.SubConditionName); state = String.Empty; } } //end for System.Diagnostics.Debug.WriteLine("The conditions list has changed "); }
/// <summary> /// Add Condition /// </summary> /// <param name="condition"></param> /// <param name="subsciption"></param> private void AddCondition(AeCondition condition, AeSubscription subsciption) { try { ListViewItem item = new ListViewItem(condition.SourcePath); item.ImageIndex = SetConditionImage(condition.State); condition.AeSession = subsciption.AeSession; item.Tag = condition; item.SubItems.Add(condition.ConditionName); item.SubItems.Add(condition.Severity.ToString()); item.SubItems.Add(condition.Message); item.SubItems.Add(ValueConverter.DateTimeOptions(condition.OccurenceTime)); item.SubItems.Add(condition.ActorId); item.SubItems.Add(condition.SubConditionName); item.SubItems.Add(subsciption.AeSession.Url); item.SubItems.Add(SUBSCRIPTION); conditionsListView.Items.Add(item); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
// method that handles the AeSubscription.AeConditionsChanged event public static void HandleConditionsChanged(AeSubscription anAeSubscription, AeCondition[] conditions) { System.Diagnostics.Debug.WriteLine("Conditions changed"); }
// method that handles the AeSubscription.AeEventsReceived event; it displays on the console the received events public static void HandleEventsReceived(AeSubscription anAeSubscription, bool refresh, bool lastRefresh, AeEvent[] events) { System.Console.WriteLine(); System.Console.WriteLine(anAeSubscription.ToString() + " Events Received:"+ events.Length); for (int i = 0; i < events.Length; i++) { if ((events[i].EventType == EnumEventType.SIMPLE) || (events[i].EventType == EnumEventType.TRACKING)) { System.Console.WriteLine(" Event type: "+ events[i].EventType); System.Console.WriteLine(" Event category: "+ events[i].Category); System.Console.WriteLine(" Source path: "+ events[i].SourcePath); System.Console.WriteLine(" Message: "+ events[i].Message); System.Console.WriteLine(" Occurence time: "+ events[i].OccurenceTime.ToString()); System.Console.WriteLine(" Severity: "+ events[i].Severity); System.Console.WriteLine(" Actor id: "+ events[i].ActorId); ArrayList attributes = events[i].Attributes; System.Console.WriteLine(" Attributes: " + attributes.Count); for (int j = 0; j < events[i].Attributes.Count; j++) { System.Console.WriteLine(events[i].Attributes[j]); } } //end if if (events[i].EventType == EnumEventType.CONDITION) { System.Console.WriteLine(" Event type: "+ events[i].EventType); System.Console.WriteLine(" Event category: "+ events[i].Category); System.Console.WriteLine(" Source path: "+ events[i].SourcePath); System.Console.WriteLine(" Message: "+ events[i].Message); System.Console.WriteLine(" Occurence time: "+ events[i].OccurenceTime.ToString()); System.Console.WriteLine(" Severity: "+ events[i].Severity); System.Console.WriteLine(" Actor id: "+ events[i].ActorId); ArrayList attributes = events[i].Attributes; System.Console.WriteLine(" Attributes: " + attributes.Count); for (int j = 0; i < events[i].Attributes.Count; j++) { System.Console.WriteLine(events[i].Attributes[j]); } System.Console.WriteLine(" Change mask: "+ GetWhatChanged(((AeCondition)events[i]).ChangeMask)); string state = String.Empty; System.Console.WriteLine(" New state: "+ GetState(((AeCondition)events[i]).State)); System.Console.WriteLine(" Ack Required: "+ ((AeCondition)events[i]).AckRequired); System.Console.WriteLine(" Quality: "+ ((AeCondition)events[i]).Quality); System.Console.WriteLine(" Condition name: "+ ((AeCondition)events[i]).ConditionName); System.Console.WriteLine(" Sub condition name: "+ ((AeCondition)events[i]).SubConditionName); System.Console.WriteLine(" Active time: "+ ((AeCondition)events[i]).ActiveTime.ToString()); string[] sourceConditions; int res = anAeSubscription.AeSession.QueryAeSourceConditions(events[i].SourcePath, out sourceConditions, new ExecutionOptions()); if (ResultCode.SUCCEEDED(res)) { System.Console.WriteLine("Source conditions for " + events[i].SourcePath); foreach (string source in sourceConditions) { System.Console.WriteLine(source); } } else { System.Console.WriteLine("Error while querying source conditions for" + events[i].SourcePath + " : " + res); } } //end if } //end for }
/// <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); }
/// <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); }
// method that handles the AeSubscription.AeEventsReceived event; it displays on the console the received events public static void HandleEventsReceived(AeSubscription anAeSubscription, bool refresh, bool lastRefresh, AeEvent[] events) { for (int i = 0; i < events.Length; i++) { string time = events[i].OccurenceTime.AddHours(8).ToString(); string bitNumber = events[i].SourcePath; string bitNumberDescribe = string.Empty; string aeType = string.Empty; string priority = events[i].Severity.ToString(); string realTimeValue = string.Empty; string limitValue = string.Empty; string engineeringUnit = string.Empty; string aeDescribe = events[i].Message; string device = string.Empty; string area = string.Empty; string operatingFloor = string.Empty; string operatingPersonnel = string.Empty; string extension_1 = string.Empty; string extension_2 = string.Empty; string extension_3 = string.Empty; string extension_4 = string.Empty; string extension_5 = string.Empty; string messageType = events[i].Category.ToString(); string isDCS = string.Empty; string aeSubType = string.Empty; string areaNumber = string.Empty; string stationNumber = string.Empty; string alarmLevel = string.Empty; string alarmOff = string.Empty; string alarmBlink = string.Empty; string alarmFilter = string.Empty; string ackRequired = string.Empty; string quality = string.Empty; if (events[i].EventType == EnumEventType.CONDITION) { aeType = ((AeCondition)events[i]).ConditionName; aeSubType = ((AeCondition)events[i]).SubConditionName; ackRequired = ((AeCondition)events[i]).AckRequired.ToString(); quality = ((AeCondition)events[i]).Quality.ToString(); } ArrayList attributes = events[i].Attributes; List <string> temp = CategoriesAndAttribute.getAttributeNamesFromCategoryID(events[i].Category); for (int j = 0; j < events[i].Attributes.Count; j++) { if (temp[j].Equals("Data_value")) { realTimeValue = attributes[j].ToString(); } if (temp[j].Equals("Engineering_unit")) { engineeringUnit = attributes[j].ToString(); } if (temp[j].Equals("Area_number")) { areaNumber = attributes[j].ToString(); } if (temp[j].Equals("Station_number")) { stationNumber = attributes[j].ToString(); } if (temp[j].Equals("Alarm_level")) { alarmLevel = attributes[j].ToString(); } if (temp[j].Equals("Alarm_off")) { alarmOff = attributes[j].ToString(); } if (temp[j].Equals("Alarm_blink")) { alarmBlink = attributes[j].ToString(); } if (temp[j].Equals("Alarm_filter")) { alarmFilter = attributes[j].ToString(); } } AEInfos oneAEInfo = new AEInfos { Time = time, BitNumber = bitNumber, BitNumberDescribe = bitNumberDescribe, AEType = aeType, Priority = priority, RealTimeValue = realTimeValue, LimitValue = limitValue, EngineeringUnit = engineeringUnit, AEDescribe = aeDescribe, Device = device, Area = area, OperatingFloor = operatingFloor, OperatingPersonnel = operatingPersonnel, Extension_1 = extension_1, Extension_2 = extension_2, Extension_3 = extension_3, Extension_4 = extension_4, Extension_5 = extension_5, MessageType = messageType, IsDCS = isDCS, AESubType = aeSubType, AreaNumber = areaNumber, StationNumber = stationNumber, AlarmLevel = alarmLevel, AlarmOff = alarmOff, AlarmBlink = alarmBlink, AlarmFilter = alarmFilter, AckRequired = ackRequired, Quality = quality }; MessageQueueTool.EnMessage(oneAEInfo); File.AppendAllText(@"./AEInfos.json", JsonConvert.SerializeObject(oneAEInfo, Formatting.Indented) + "\n"); if (new FileInfo(@"./AEInfos.json").Length >= 50 * 1024 * 1024) { File.Delete(@"./AEInfos_backup.json"); File.Move(@"./AEInfos.json", @"./AEInfos_backup.json"); } }//end for }