Hi,
I need to create a FC/FB to sort through DB error messages and prioritise them in the order of Importance. the values generated(x5) will be the basis for the display Text using the highest number as the highest priority.
I wrote a single block which when called in seperate instances (x5) does what i want,but i'm trying to combine it all into one call.
I'm having problems ironing out the issues with the code and tightening it up and would apprieciate some help!
Problem 1 - When DBX0.0 is set the CPU stops
Problem 2 - I've tried to add range protection to the Loop_index, but each way i try either stops the cpu or causes the Loop not to work!
I need to create a FC/FB to sort through DB error messages and prioritise them in the order of Importance. the values generated(x5) will be the basis for the display Text using the highest number as the highest priority.
I wrote a single block which when called in seperate instances (x5) does what i want,but i'm trying to combine it all into one call.
I'm having problems ironing out the issues with the code and tightening it up and would apprieciate some help!
Problem 1 - When DBX0.0 is set the CPU stops
Problem 2 - I've tried to add range protection to the Loop_index, but each way i try either stops the cpu or causes the Loop not to work!
FUNCTION "Alarm generator V3" : VOID
TITLE =
VERSION : 0.1
VAR_INPUT
Alarm_DB : BLOCK_DB ;
DB_Length : INT ;
END_VAR
VAR_IN_OUT
Loop_Index : INT ;
END_VAR
BEGIN
NETWORK
TITLE =Check Range
L #DB_Length;
L 0; // if zero then no further bits to interrogate
<=I ;
BEC ;
OPN #Alarm_DB; // Open Alarm Datablock
NETWORK
TITLE =Scan the Alarm DB Looking for Active Faults
//
//
//
L #DB_Length; // Total number of Alarm bits to scan
TOP: T #Loop_Index;
+ -1; // align index to array i.e dbx0.0 = ALARM[1]
LAR1 ;
A DBX [AR1,P#0.0]; // Scan for match
JC ERR1; // Jump out if match found
L #Loop_Index;
LOOP TOP; // minus 1 from index and re-scan until match or zero achieved
//No match found
L 0;
T #Loop_Index;
JU end;
//Match found
ERR1: L #Loop_Index;
T DBW [AR2,P#14.0]; // Point to beginning of Text storage (DBW14)
+AR2 P#2.0; // increment pointer to transfer additional matches to next word (max 5)
TAK ; // move index back to accu 1
JC TOP;
end: NOP 0;
END_FUNCTION