diff --git a/Custom_AlarmLine.zap19 b/Custom_AlarmLine.zap19 new file mode 100644 index 0000000..b125eaf Binary files /dev/null and b/Custom_AlarmLine.zap19 differ diff --git a/doc/AlarmLine.docx b/doc/AlarmLine.docx new file mode 100644 index 0000000..026e2a0 Binary files /dev/null and b/doc/AlarmLine.docx differ diff --git a/src/Alarming.js b/src/Alarmline.js similarity index 68% rename from src/Alarming.js rename to src/Alarmline.js index bacf66d..affc9df 100644 --- a/src/Alarming.js +++ b/src/Alarmline.js @@ -156,3 +156,46 @@ export class AlarmManager { }; } } + +/* +Global definition area of module "Alarmline" +*/ +//Number of configured Alarmline tags. When maxAlarmLineAlarms is increased also tagSetTags needs to extend +const maxAlarmLineAlarms = 3; +const tagSetTags = ['Alarm1_DateTimeRaised', 'Alarm1_AlarmText', 'Alarm1_MachineUnitAssyPart', 'Alarm1_Status', 'Alarm1_Address', 'Alarm1_BackColor', 'Alarm1_TextColor', 'Alarm1_Flashing', + 'Alarm2_DateTimeRaised', 'Alarm2_AlarmText', 'Alarm2_MachineUnitAssyPart', 'Alarm2_Status', 'Alarm2_Address', 'Alarm2_BackColor', 'Alarm2_TextColor', 'Alarm2_Flashing', + 'Alarm3_DateTimeRaised', 'Alarm3_AlarmText', 'Alarm3_MachineUnitAssyPart', 'Alarm3_Status', 'Alarm3_Address', 'Alarm3_BackColor', 'Alarm3_TextColor', 'Alarm3_Flashing']; +/** +* Updates the alarm tags based on the provided array of alarms. +* @param {Array} allAlarms - The array of alarms to update the tags with. +*/ + + +export function UpdateActiveAlarms(allAlarms) { + let alarmIndex = allAlarms.length; + const tagSet = Tags.CreateTagSet(tagSetTags); + for (let index = 1; index <= maxAlarmLineAlarms; index++) { + const prefixTagName = 'Alarm' + index; + if (index <= allAlarms.length) { + alarmIndex = index - 1; + tagSet(prefixTagName + '_DateTimeRaised').Value = allAlarms[alarmIndex].RaiseTime; + tagSet(prefixTagName + '_AlarmText').Value = allAlarms[alarmIndex].EventText; + tagSet(prefixTagName + '_MachineUnitAssyPart').Value = allAlarms[alarmIndex].EventText; + tagSet(prefixTagName + '_Status').Value = allAlarms[alarmIndex].AlarmText[0]; + tagSet(prefixTagName + '_Address').Value = allAlarms[alarmIndex].AlarmText[1]; + tagSet(prefixTagName + '_BackColor').Value = allAlarms[alarmIndex].BackColor; + tagSet(prefixTagName + '_TextColor').Value = allAlarms[alarmIndex].TextColor; + tagSet(prefixTagName + '_Flashing').Value = allAlarms[alarmIndex].Flashing; + } else { + tagSet(prefixTagName + '_DateTimeRaised').Value = new Date(0); + tagSet(prefixTagName + '_AlarmText').Value = ''; + tagSet(prefixTagName + '_MachineUnitAssyPart').Value = ''; + tagSet(prefixTagName + '_Status').Value = ''; + tagSet(prefixTagName + '_Address').Value = ''; + tagSet(prefixTagName + '_BackColor').Value = HMIRuntime.Math.RGB(255, 255, 255); + tagSet(prefixTagName + '_TextColor').Value = HMIRuntime.Math.RGB(255, 255, 255); + tagSet(prefixTagName + '_Flashing').Value = false; + } + } + tagSet.Write(); +} diff --git a/src/ScheduledTasks.js b/src/ScheduledTasks.js index 1a35429..ecf0903 100644 --- a/src/ScheduledTasks.js +++ b/src/ScheduledTasks.js @@ -1,25 +1,32 @@ /* Global definition area of "Scheduled Tasks" */ -import { AlarmManager } from 'Alarming'; +import * as module_alarmline from 'Alarmline'; + + +//Alarmfilter string for Alarmlines configured like Alarm Control Filter +export const alarmlineFilter = "AlarmClassName <> 'SystemNotification' AND AlarmClassName <> 'SystemAlarm' AND AlarmClassName <> 'SystemAlarmWithoutClearEvent' AND AlarmClassName <> 'SystemInformation' AND AlarmClassName <> 'SystemWarning' AND AlarmClassName <> 'SystemWarningWithoutClearEvent'"; let alMgr = undefined; + /** * Task to update the alarms. * This function is responsible for starting the alarm-subscription based on the system activation state. */ -export function Task_AlarmsUpdate_Update() { +export function Task_AlarmUpdate_Update() { if (Tags('@SystemActivationState').Read() === 2) { //on startup, start the alarm subscription if (!alMgr) { - const alarmlineFilter = ''; //"AlarmClassName <> 'SystemNotification' AND AlarmClassName <> 'SystemAlarm' AND AlarmClassName <> 'SystemAlarmWithoutClearEvent' AND AlarmClassName <> 'SystemInformation' AND AlarmClassName <> 'SystemWarning' AND AlarmClassName <> 'SystemWarningWithoutClearEvent'"; - alMgr = new AlarmManager({ - language: 127, // default language + alMgr = new module_alarmline.AlarmManager({ + language: 1033, filter: alarmlineFilter, - sortOrderDescending: false, - callback: (allAlarms) => { Tags('AlarmsCount').Write(allAlarms.length); }, + sortOrderDescending: Tags('SortOrderDescending').Read(), + callback: module_alarmline.UpdateActiveAlarms, delayInMilliseconds: 250 }); alMgr.StartSubscription(); + } else { + //if alarm subscription was already started, update on the sort order + alMgr.SetSortOrder(Tags('SortOrderDescending').Read()); } } }