Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.1 kB
2
Indexable
FUNCTION_BLOCK Manager
VAR_INPUT
	MyPump: POINTER TO PumpControl;
	FStart:BOOL;
	FStop:BOOL;
	NextManager: POINTER TO Manager;
END_VAR
VAR_OUTPUT
	Trip:BOOL;
	Available:BOOL;
	ThisObj:POINTER TO Manager;
END_VAR
VAR
	PumpsFailed, PumpsRunning, PumpsAvailable:INT;
	Timer:TON;
	ElapsedTime:TIME;
	TotalRuntime : TIME := T#0S;
	prevFStart, prevFStop :BOOL;
END_VAR

#Method

ThisObj := THIS;
PumpsFailed:=0;
PumpsRunning:=0;
PumpsAvailable:=0;
ElapsedTime:=T#0S;


IF FStart AND NOT prevFStart AND NOT MyPump^.PFail THEN
    StartRequest();
END_IF

IF FStart AND FStop THEN 
	StopRequest();
END_IF

IF FStop AND NOT prevFStop THEN
    StopRequest();
	Timer(IN:= FALSE,PT:= T#100S);
END_IF

prevFStart:=ThisObj^.FStart;
prevFstop:=ThisObj^.FStop;


IF MyPump^.PFail  THEN 
    Trip := TRUE;
    PumpsFailed := PumpsFailed + 1;
ELSE
    Trip := FALSE;
END_IF

IF NOT MyPump^.PRun AND NOT MyPump^.PFail THEN
    Available := TRUE;
ELSE
	Available:=FALSE;	
END_IF

IF MyPump^.PRun THEN 
	PumpsRunning := PumpsRunning + 1;
	Timer(IN:= TRUE,PT:= T#100S);
	ElapsedTime:=Timer.ET;
	TotalRuntime := TotalRuntime + ElapsedTime;
END_IF

IF Available AND Trip THEN 
    Available := FALSE;
END_IF

IF Available THEN 
	PumpsAvailable := PumpsAvailable + 1;
END_IF

IF NextManager <> 0 THEN 
	PumpsRunning := PumpsRunning + NextManager^.PumpsRunning;
	PumpsAvailable := PumpsAvailable + NextManager^.PumpsAvailable;
	PumpsFailed := PumpsFailed + NextManager^.PumpsFailed;
END_IF

//Manager 2, 3, 4

IF ThisObj^.Trip THEN 
    IF  NextManager <> 0 AND NextManager^.Available AND NOT ThisObj^.FStop THEN
            NextManager^.StartRequest();
    END_IF;
	IF ThisObj^.FStop AND NextManager <> 0 THEN
		NextManager^.StopRequest();
	END_IF
	IF NextManager^.Trip AND ThisObj^.FStop AND NextManager^.NextManager <> 0  THEN 
		NextManager^.NextManager^.StopRequest();
	END_IF
	IF NextManager^.Trip AND ThisObj^.FStop AND NextManager^.NextManager^.Trip AND NextManager^.NextManager^.NextManager <> 0  THEN 
		NextManager^.NextManager^.StopRequest();
	END_IF
END_IF


Leave a Comment