Skip to content

Commit

Permalink
Publish Alarmline example
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Kollinger committed Apr 15, 2024
1 parent c73046a commit ad8811b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 7 deletions.
Binary file added Custom_AlarmLine.zap19
Binary file not shown.
Binary file added doc/AlarmLine.docx
Binary file not shown.
43 changes: 43 additions & 0 deletions src/Alarming.js → src/Alarmline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
21 changes: 14 additions & 7 deletions src/ScheduledTasks.js
Original file line number Diff line number Diff line change
@@ -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());
}
}
}

0 comments on commit ad8811b

Please sign in to comment.