FUNCTION_BLOCK AOI_MessageHandlerInstant

VAR_INPUT
Cmd_Reset : BOOL;
In_MessageID : INT;
In_MessageText : STRING;
In_MessageCategory : INT;
In_MessageTime : Tc2_Utilities.TIMESTRUCT;

BootupTimer : Tc2_Standard.TON;
END_VAR

VAR_OUTPUT
Out_ActiveMessageArray : ARRAY[0..201] OF UDT_MessageStructure;
Out_ActiveMessageCount : INT;
END_VAR

VAR
MessageID_Old : INT;
IndexActiveMessages : INT ;
UpdateActiveMessages : BOOL;
ONS01 : BOOL;
WaitTimer : Tc2_Standard.TON;
ResetAllHighlight : BOOL;
idx : INT;
stTest : STRING;
dtDateTime : DT;
stWithoutDT : STRING;
stWithoutHyphen : STRING;
stWithGap : STRING;
stWithoutDate : STRING;
stWithNewLine : STRING;
tTime : TIME;
END_VAR

 

BootupTimer(IN:=1 , PT:=T#5S , Q=> , ET=> );
IF NOT BootupTimer.Q THEN
MessageID_Old := In_MessageID;
END_IF
//------------------------------------------------------------------------
// Date To String
//Makes TimeStruct to DateTime
dtDateTime := SYSTEMTIME_TO_DT(TIMESTR:= In_MessageTime);

//Makes DateTime to String
stTest := DT_TO_STRING(dtDateTime);

//Delete #DT from String
stWithOutDT := Tc2_Standard.DELETE(STR:=stTest, LEN:=4,POS:=0);

//Delete hyphen between date and time
stWithOutHyphen:=Tc2_Standard.DELETE(STR:=stWithOutDT, LEN:=1,POS:=11);

//Insert a gap between date and time
stWithGap := Tc2_Standard.INSERT(STR1:=stWithOutHyphen,STR2:=' ', POS:=10);


//------------------------------------------------------------------------
// Reset all active alarms
IF Cmd_Reset THEN
Cmd_Reset :=0;
Out_ActiveMessageCount :=0;

FOR idx :=1 TO 201 DO
Out_ActiveMessageArray[idx].Status :=0;
END_FOR;
END_IF
//------------------------------------------------------------------------
// Register New Messages
IF In_MessageID <> MessageID_Old THEN
MessageID_Old := In_MessageID;
UpdateActiveMessages :=1;
Out_ActiveMessageCount := Out_ActiveMessageCount + 1;
END_IF

//------------------------------------------------------------------------
// Update History Alarms
IF UpdateActiveMessages THEN
FOR IndexActiveMessages:= 201 TO 2 BY -1 DO
Out_ActiveMessageArray[IndexActiveMessages] := Out_ActiveMessageArray[IndexActiveMessages-1] ;
END_FOR ;
Out_ActiveMessageArray[1].ID :=In_MessageID ;
Out_ActiveMessageArray[1].Text :=In_MessageText ;
Out_ActiveMessageArray[1].Timestamp :=stWithGap ;
Out_ActiveMessageArray[1].Category :=In_MessageCategory ;
Out_ActiveMessageArray[1].Status :=1 ;
UpdateActiveMessages :=0;
In_MessageCategory :=0;

END_IF

//------------------------------------------------------------------------