<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4026.12">
  <POU Name="FB_Safety" Id="{f74eb8e4-e878-485f-9706-8dd039061a6b}" SpecialFunc="None">
    <Declaration><![CDATA[FUNCTION_BLOCK FB_Safety
VAR_INPUT
	xVoltagesInRange AT %I* : BOOL;
	xPressureInRange AT %I* : BOOL;
	xTemperaturesInRange AT %I* : BOOL;
	
	xReset : BOOL;
	refuStringErrorsModbus : REFERENCE TO U_BMS_ERROR_REGISTER;
END_VAR
VAR_OUTPUT
END_VAR
VAR
	_latchedVoltages : BOOL;
	_latchedPressures : BOOL;
	_latechedTemperatures : BOOL;
	
	_xErrorLatched : BOOL;
END_VAR
]]></Declaration>
    <Implementation>
      <ST><![CDATA[IF xReset THEN
	xReset := FALSE;
	_latchedVoltages := FALSE;
	_latchedPressures := FALSE;
	_latechedTemperatures := FALSE;
	_xErrorLatched := FALSE;
END_IF

IF (NOT xVoltagesInRange) AND NOT _xErrorLatched THEN
	_latchedVoltages := TRUE;
	_xErrorLatched := TRUE;
	refuStringErrorsModbus.stBitmap.bSafetyErrorVoltage := 1;
END_IF

IF (NOT xPressureInRange) AND NOT _xErrorLatched THEN
	_latchedPressures := TRUE;
	_xErrorLatched := TRUE;
	refuStringErrorsModbus.stBitmap.bSafetyErrorPressure := 1;
END_IF

IF (NOT xTemperaturesInRange) AND NOT _xErrorLatched THEN
	_latechedTemperatures := TRUE;
	_xErrorLatched := TRUE;
	refuStringErrorsModbus.stBitmap.bSafetyErrorTemperature := 1;
END_IF]]></ST>
    </Implementation>
  </POU>
</TcPlcObject>