<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4026.8">
  <POU Name="FB_Module" Id="{87be924f-018d-4c09-997b-f0c0054414cc}" SpecialFunc="None">
    <Declaration><![CDATA[FUNCTION_BLOCK FB_Module
VAR_INPUT
	// Emergency stop ok
	xEmergencyStopOk : BOOL;
	
	// Unit numbering start (0 based index)
	// Unit 1 -> Index 0
	uiFirstUnitIndex : UINT;
	
	// Enable
	xEnable : BOOL;
	
	// Start balancing
	xStartBalancing : BOOL;
	
	// Module in safety check mode
	xInSafetyCheckMode : BOOL;
	
	// String operation mode
	eStringOperatingMode : E_STRING_OPERATING_MODE;
	
	// All safetyinterlocks are ok
	xSafetyIntlksOk : BOOL;
	
	// Module completely off
	xOff : BOOL := TRUE;
	
	// HMI Interface
	refstHMIInterface : REFERENCE TO ST_MODULE_HMI_INTERFACE;
	
	// Release alarms
	xReleaseErrors : BOOL;
	
	// Release analog io limit errors
	xReleaseLimitErrors : BOOL;
	
	// Release manual mode
	xReleaseManualMode : BOOL;
	
	// Switch all components to manual mode
	xAllToManualMode : BOOL;
	
	// Input to confirm all errors
	xConfirmAlarms : BOOL;
	
	// Balancing target Voltage
	rBalancingTargetVoltage : REAL;
	
	// Inverter enabled status
	xInverterEnabled : BOOL;
	
	// Leakage double segment 1/2
	xLeakageSegments12 AT %I* : BOOL;
	
	// Leakage double segment 3/4
	xLeakageSegments34 AT %I* : BOOL;
	
	// Leakage tank
	xLeakageTank AT %I* : BOOL;
	
	// Current current value from string to copy to HMI interface
	rCurrent : REAL;
	
	// Current EtherCAT state
	uiECState AT %I* : UINT;
END_VAR
VAR_OUTPUT
	// Module voltage
	rCurrentVoltage : REAL;	
	
	// Module ready
	xReady : BOOL;
	
	// Module in shutdown segment discharge mode
	xInShutdownDischargeMode : BOOL;
	
	// Module can be discharged during shutdown sequence
	xShutdownDischargeAllowed : BOOL;

	// One unit has an error
	xError : BOOL;
	
	// One unit has a warning
	xWarning : BOOL;
	
	// Temperature control cabinet above 40 °C 
	xTempCabinetWarning : BOOL;
	
	// All modules in automatic mode
	xAllUnitsInAutomatic : BOOL;
	
	// Smallest segment voltage
	rSmallestSegmentVoltage : REAL;
	
	// Highest segment voltage
	rHighestSegmentVoltage : REAL;
	
	// Balancing done
	xBalancingDone : BOOL;
END_VAR
VAR
	_fbUnit1 : FB_Unit(CONCAT(Name, ' - Unit 1'));
	_fbUnit2 : FB_Unit(CONCAT(Name, ' - Unit 2'));
	_fbUnit3 : FB_Unit(CONCAT(Name, ' - Unit 3'));
	_fbUnit4 : FB_Unit(CONCAT(Name, ' - Unit 4'));
	
	// Temperature sensor cabinet
	_fbTempSensorCabinet : FB_AnalogInput(CONCAT(Name, ' - T1_Cabinet'));
	
	// Flag for unit balance checking
	_xBalanceOk : BOOL;
	
	// All units are ready
	_xAllUnitsReady : BOOL;
	
	// Units out of balance alarm
	_fbUnitsOutOfBalanceAlarm : FB_TcAlarm;
	
	// Leackage tank alarm
	_fbLeackageTankAlarm : FB_TcAlarm;
	
	// Leackage Segment 1/2 alarm
	_fbLeackageSegment12Alarm : FB_TcAlarm;
	
	// Leackage Segemnt 3/4 alarm
	_fbLeackageSegment34Alarm : FB_TcAlarm;
	
	// Connection lost alarm
	_fbConnLostAlarm : FB_TcAlarm;
	
	// Module name
	_sName : STRING;
	
	_fbBalanceNotOkSignal : FB_ReleaseSignal;
	
	_xECModuleInOP : BOOL;
	
	_xFirstCycle : BOOL := TRUE;
END_VAR
]]></Declaration>
    <Implementation>
      <ST><![CDATA[IF _xFirstCycle THEN
	_xFirstCycle := FALSE;
	
	_fbUnit1.Name := CONCAT(Name, ' - Unit 1');
	_fbUnit2.Name := CONCAT(Name, ' - Unit 2');
	_fbUnit3.Name := CONCAT(Name, ' - Unit 3');
	_fbUnit4.Name := CONCAT(Name, ' - Unit 4');
	
	_fbTempSensorCabinet.Name := CONCAT(Name, ' - T1_Cabinet');
END_IF

// Reset error and warning flag
xError := FALSE;
xWarning := FALSE;

// Reset automatic mode flag
xAllUnitsInAutomatic := TRUE;

// Reset safety interlocks flag
xSafetyIntlksOk := TRUE;

// ===============================
// Handle module connection lost error
// ===============================
_xECModuleInOP := (uiECState AND 16#000F) = 8;
IF (NOT _xECModuleInOP) AND (NOT _fbConnLostAlarm.bRaised) AND xReleaseErrors THEN
	_fbConnLostAlarm.Raise(0);
END_IF

IF (_xECModuleInOP) AND _fbConnLostAlarm.bRaised THEN
	_fbConnLostAlarm.Clear(0, FALSE);
END_IF

IF _fbConnLostAlarm.eConfirmationState = TcEventConfirmationState.WaitForConfirmation AND xConfirmAlarms THEN
	_fbConnLostAlarm.Confirm(0);
END_IF


// ===============================
// Leackage tank error (1 - OK; 0 - Leackage)
// ===============================
IF (NOT xLeakageTank) AND (NOT _fbLeackageTankAlarm.bRaised) AND xReleaseErrors THEN
	_fbLeackageTankAlarm.Raise(0);
END_IF

IF xLeakageTank AND _fbLeackageTankAlarm.bRaised THEN
	_fbLeackageTankAlarm.Clear(0, FALSE);
END_IF

IF _fbLeackageTankAlarm.eConfirmationState = TcEventConfirmationState.WaitForConfirmation AND xConfirmAlarms THEN
	_fbLeackageTankAlarm.Confirm(0);
END_IF


// ===============================
// Leackage Unit 1/2 error (1 - OK; 0 - Leackage)
// ===============================
IF (NOT xLeakageSegments12) AND (NOT _fbLeackageSegment12Alarm.bRaised) AND xReleaseErrors THEN
	GVL_MODBUS.awErrorsUnitsActive[uiFirstUnitIndex].stBitmap.bLeack := 1;
	GVL_MODBUS.awErrorsUnitsActive[uiFirstUnitIndex+1].stBitmap.bLeack := 1;
	_fbLeackageSegment12Alarm.Raise(0);
END_IF

IF xLeakageSegments12 AND _fbLeackageSegment12Alarm.bRaised THEN
	_fbLeackageSegment12Alarm.Clear(0, FALSE);
END_IF

IF _fbLeackageSegment12Alarm.eConfirmationState = TcEventConfirmationState.WaitForConfirmation AND xConfirmAlarms THEN
	_fbLeackageSegment12Alarm.Confirm(0);
END_IF


// ===============================
// Leackage Unit 3/4 error (1 - OK; 0 - Leackage)
// ===============================
IF (NOT xLeakageSegments34) AND (NOT _fbLeackageSegment34Alarm.bRaised) AND xReleaseErrors THEN
	GVL_MODBUS.awErrorsUnitsActive[uiFirstUnitIndex+2].stBitmap.bLeack := 1;
	GVL_MODBUS.awErrorsUnitsActive[uiFirstUnitIndex+3].stBitmap.bLeack := 1;
	_fbLeackageSegment34Alarm.Raise(0);
END_IF

IF xLeakageSegments34 AND _fbLeackageSegment34Alarm.bRaised THEN
	_fbLeackageSegment34Alarm.Clear(0, FALSE);
END_IF

IF _fbLeackageSegment34Alarm.eConfirmationState = TcEventConfirmationState.WaitForConfirmation AND xConfirmAlarms THEN
	_fbLeackageSegment34Alarm.Confirm(0);
END_IF


// ===============================
// Unit 1
// ===============================
_fbUnit1(
	xEnable := xEnable,
	xStartBalancing := xStartBalancing,
	eStringOperatingMode := eStringOperatingMode,
	xInverterEnabled := xInverterEnabled,
	xInSafetyCheckMode := xInSafetyCheckMode,
	stUnitConfig:= GVL_CONFIG.stUnitConfig, 
	stHMIInterface:= refstHMIInterface.stHMIInterfaceUnit1, 
	xEmergencyStopOk:= xEmergencyStopOk,  
	xReleaseErrors:= xReleaseErrors, 
	xReleaseLimitErrors:= xReleaseLimitErrors, 
	xConfirmAlarms:= xConfirmAlarms,
	xReleaseManualMode := xReleaseManualMode,
	rBalancingTargetVoltage := rBalancingTargetVoltage,
	xAllToManualMode := xAllToManualMode,
	stModbusWarnings := GVL_MODBUS.awWarningsUnitsActive[uiFirstUnitIndex],
	stModbusErrors := GVL_MODBUS.awErrorsUnitsActive[uiFirstUnitIndex]);
	
refstHMIInterface.stHMIInterfaceUnit1.rCurrent := rCurrent;

IF _fbUnit1.xWarning THEN
	xWarning := TRUE;
END_IF

IF _fbUnit1.xError THEN
	xError := TRUE;
END_IF

IF NOT _fbUnit1.xSafetyIntlksOk THEN
	xSafetyIntlksOk := FALSE;
END_IF

IF NOT _fbUnit1.xAllComponentsInAuto THEN
	xAllUnitsInAutomatic := FALSE;
END_IF


// ===============================
// Unit 2
// ===============================
_fbUnit2(
	xEnable := xEnable,
	xStartBalancing := xStartBalancing,
	eStringOperatingMode := eStringOperatingMode,
	xInverterEnabled := xInverterEnabled,
	xInSafetyCheckMode := xInSafetyCheckMode,
	stUnitConfig:= GVL_CONFIG.stUnitConfig, 
	stHMIInterface:= refstHMIInterface.stHMIInterfaceUnit2, 
	xEmergencyStopOk:= xEmergencyStopOk,  
	xReleaseErrors:= xReleaseErrors, 
	xReleaseLimitErrors:= xReleaseLimitErrors, 
	xConfirmAlarms:= xConfirmAlarms,
	xReleaseManualMode := xReleaseManualMode,
	rBalancingTargetVoltage := rBalancingTargetVoltage,
	xAllToManualMode := xAllToManualMode,
	stModbusWarnings := GVL_MODBUS.awWarningsUnitsActive[uiFirstUnitIndex+1],
	stModbusErrors := GVL_MODBUS.awErrorsUnitsActive[uiFirstUnitIndex+1]);
	
refstHMIInterface.stHMIInterfaceUnit2.rCurrent := rCurrent;

IF _fbUnit2.xWarning THEN
	xWarning := TRUE;
END_IF

IF _fbUnit2.xError THEN
	xError := TRUE;
END_IF

IF NOT _fbUnit2.xSafetyIntlksOk THEN
	xSafetyIntlksOk := FALSE;
END_IF

IF NOT _fbUnit2.xAllComponentsInAuto THEN
	xAllUnitsInAutomatic := FALSE;
END_IF


// ===============================
// Unit 3
// ===============================
_fbUnit3(
	xEnable := xEnable,
	xStartBalancing := xStartBalancing,
	eStringOperatingMode := eStringOperatingMode,
	xInverterEnabled := xInverterEnabled,
	xInSafetyCheckMode := xInSafetyCheckMode,
	stUnitConfig:= GVL_CONFIG.stUnitConfig, 
	stHMIInterface:= refstHMIInterface.stHMIInterfaceUnit3, 
	xEmergencyStopOk:= xEmergencyStopOk,  
	xReleaseErrors:= xReleaseErrors, 
	xReleaseLimitErrors:= xReleaseLimitErrors, 
	xConfirmAlarms:= xConfirmAlarms,
	xReleaseManualMode := xReleaseManualMode,
	rBalancingTargetVoltage := rBalancingTargetVoltage,
	xAllToManualMode := xAllToManualMode,
	stModbusWarnings := GVL_MODBUS.awWarningsUnitsActive[uiFirstUnitIndex+2],
	stModbusErrors := GVL_MODBUS.awErrorsUnitsActive[uiFirstUnitIndex+2]);
	
refstHMIInterface.stHMIInterfaceUnit3.rCurrent := rCurrent;

IF _fbUnit3.xWarning THEN
	xWarning := TRUE;
END_IF

IF _fbUnit3.xError THEN
	xError := TRUE;
END_IF

IF NOT _fbUnit3.xSafetyIntlksOk THEN
	xSafetyIntlksOk := FALSE;
END_IF

IF NOT _fbUnit3.xAllComponentsInAuto THEN
	xAllUnitsInAutomatic := FALSE;
END_IF


// ===============================
// Unit 4
// ===============================
_fbUnit4(
	xEnable := xEnable,
	xStartBalancing := xStartBalancing,
	eStringOperatingMode := eStringOperatingMode,
	xInverterEnabled := xInverterEnabled,
	xInSafetyCheckMode := xInSafetyCheckMode,
	stUnitConfig:= GVL_CONFIG.stUnitConfig, 
	stHMIInterface:= refstHMIInterface.stHMIInterfaceUnit4, 
	xEmergencyStopOk:= xEmergencyStopOk,  
	xReleaseErrors:= xReleaseErrors, 
	xReleaseLimitErrors:= xReleaseLimitErrors, 
	xConfirmAlarms:= xConfirmAlarms,
	xReleaseManualMode := xReleaseManualMode,
	rBalancingTargetVoltage := rBalancingTargetVoltage,
	xAllToManualMode := xAllToManualMode,
	stModbusWarnings := GVL_MODBUS.awWarningsUnitsActive[uiFirstUnitIndex+3],
	stModbusErrors := GVL_MODBUS.awErrorsUnitsActive[uiFirstUnitIndex+3]);
	
refstHMIInterface.stHMIInterfaceUnit4.rCurrent := rCurrent;

IF _fbUnit4.xWarning THEN
	xWarning := TRUE;
END_IF

IF _fbUnit4.xError THEN
	xError := TRUE;
END_IF

IF NOT _fbUnit4.xSafetyIntlksOk THEN
	xSafetyIntlksOk := FALSE;
END_IF

IF NOT _fbUnit4.xAllComponentsInAuto THEN
	xAllUnitsInAutomatic := FALSE;
END_IF


// ===============================
// Temperature sensor control cabinet
// ===============================
_fbTempSensorCabinet(
	stScalingConfig:= GVL_CONFIG.stConfigCabinetTemp, 
	stEWConfig:= GVL_CONFIG.stEWLCabinetTemp, 
	stEWDelayConfig:= GVL_CONFIG.stEWDCabinetTemp,  
	xReleaseErrors:= xReleaseErrors, 
	xReleaseLimitErrors:= xReleaseLimitErrors, 
	xReleaseHardwareErrors:= xReleaseErrors, 
	xConfirmAlarms:= xConfirmAlarms, 
	stHMIInterface=> refstHMIInterface.stTempCabinet);

// Set warning output for modbus register bits
IF _fbTempSensorCabinet.xWarningHigh THEN
	xTempCabinetWarning := TRUE;
END_IF
	
IF _fbTempSensorCabinet.xError THEN
	xError := TRUE;
END_IF

IF _fbTempSensorCabinet.xWarning THEN
	xWarning := TRUE;
END_IF


// ===============================
// Units ready check
// ===============================
_xAllUnitsReady := _fbUnit1.xReady AND _fbUnit2.xReady AND _fbUnit3.xReady AND _fbUnit4.xReady;


// ===============================
// Balancing done check
// ===============================
xBalancingDone := _fbUnit1.xBalancingDone AND _fbUnit2.xBalancingDone AND _fbUnit3.xBalancingDone AND _fbUnit4.xBalancingDone;


// ===============================
// Units in shutdown discharge mode
// ===============================
xInShutdownDischargeMode := _fbUnit1.xInShutdownDischargeMode AND _fbUnit2.xInShutdownDischargeMode AND _fbUnit3.xInShutdownDischargeMode AND _fbUnit4.xInShutdownDischargeMode;


// ===============================
// Units shutdown discharge allowed
// ===============================
xShutdownDischargeAllowed := _fbUnit1.xShutdownDischargeAllowed AND _fbUnit2.xShutdownDischargeAllowed AND _fbUnit3.xShutdownDischargeAllowed AND _fbUnit4.xShutdownDischargeAllowed;


// ===============================
// All units off
// ===============================
xOff := _fbUnit1.xOff AND _fbUnit2.xOff AND _fbUnit3.xOff AND _fbUnit4.xOff;


// ===============================
// Calculate module voltage
// ===============================
rCurrentVoltage := _fbUnit1.rCurrentVoltage + _fbUnit2.rCurrentVoltage + _fbUnit3.rCurrentVoltage + _fbUnit4.rCurrentVoltage;
refstHMIInterface.rVoltage := refstHMIInterface.rVoltage * 0.9 + rCurrentVoltage * 0.1;


// ===============================
// Module balance check
// ===============================
// Reset balance ok flag
_xBalanceOk := TRUE;

// Test unit 1 with unit 2
IF ABS(_fbUnit1.rCurrentVoltage - _fbUnit2.rCurrentVoltage) > GVL_CONFIG.rMaxAbsDiffVoltageUnitsOnModule THEN
	_xBalanceOk := FALSE;
END_IF

// Test unit 1 with unit 3
IF ABS(_fbUnit1.rCurrentVoltage - _fbUnit3.rCurrentVoltage) > GVL_CONFIG.rMaxAbsDiffVoltageUnitsOnModule THEN
	_xBalanceOk := FALSE;
END_IF

// Test unit 1 with unit 4
IF ABS(_fbUnit1.rCurrentVoltage - _fbUnit4.rCurrentVoltage) > GVL_CONFIG.rMaxAbsDiffVoltageUnitsOnModule THEN
	_xBalanceOk := FALSE;
END_IF

// Test unit 2 with unit 3
IF ABS(_fbUnit2.rCurrentVoltage - _fbUnit3.rCurrentVoltage) > GVL_CONFIG.rMaxAbsDiffVoltageUnitsOnModule THEN
	_xBalanceOk := FALSE;
END_IF

// Test unit 2 with unit 4
IF ABS(_fbUnit2.rCurrentVoltage - _fbUnit4.rCurrentVoltage) > GVL_CONFIG.rMaxAbsDiffVoltageUnitsOnModule THEN
	_xBalanceOk := FALSE;
END_IF

// Test unit 3 with unit 4
IF ABS(_fbUnit3.rCurrentVoltage - _fbUnit4.rCurrentVoltage) > GVL_CONFIG.rMaxAbsDiffVoltageUnitsOnModule THEN
	_xBalanceOk := FALSE;
END_IF

// Release signal for balance not ok
_fbBalanceNotOkSignal(
	xSignal:= NOT _xBalanceOk, 
	xRelease:= xEnable AND _xAllUnitsReady, 
	timOnDelay:= T#10S,
	timOffDelay:= T#5S,
	xReleaseSignal=> );

// Signal an error if all units are ready and module is out of balance
IF _xAllUnitsReady AND _fbBalanceNotOkSignal.xReleaseSignal THEN
	xError := TRUE;
END_IF

// Raise error
IF _fbBalanceNotOkSignal.xReleaseSignal AND (NOT _fbUnitsOutOfBalanceAlarm.bRaised) THEN
	_fbUnitsOutOfBalanceAlarm.Raise(0);
END_IF

// Clear error only with confirmation because of voltage ripple event spam
IF (NOT _fbBalanceNotOkSignal.xReleaseSignal) AND _fbUnitsOutOfBalanceAlarm.bRaised AND xConfirmAlarms THEN
	_fbUnitsOutOfBalanceAlarm.Clear(0, FALSE);
END_IF

// Confirm error
IF _fbUnitsOutOfBalanceAlarm.eConfirmationState = TcEventConfirmationState.WaitForConfirmation AND xConfirmAlarms THEN
	_fbUnitsOutOfBalanceAlarm.Confirm(0);
END_IF

// ===============================
// Module ready validation check
// ===============================
IF _xAllUnitsReady AND _xBalanceOk THEN
	xReady := TRUE;
ELSE
	xReady := FALSE;
END_IF


// ===============================
// Get the smallest segment Voltage
// for balancing
// ===============================
rSmallestSegmentVoltage := MIN(_fbUnit1.rCurrentVoltage, _fbUnit2.rCurrentVoltage, _fbUnit3.rCurrentVoltage, _fbUnit4.rCurrentVoltage);
rHighestSegmentVoltage := MAX(_fbUnit1.rCurrentVoltage, _fbUnit2.rCurrentVoltage, _fbUnit3.rCurrentVoltage, _fbUnit4.rCurrentVoltage);

// ===============================
// Copy string current to module current
// ===============================
refstHMIInterface.rCurrent := rCurrent;

// ===============================
// Module status sum
// ===============================
// Module ready
IF xReady AND (NOT xError) THEN
	refstHMIInterface.eStatus := E_COMPONENT_STATUS.ON;
END_IF

// Module starting
IF (NOT xOff) AND (NOT xReady) AND xEnable AND (NOT xError) THEN
	refstHMIInterface.eStatus := E_COMPONENT_STATUS.STARTING;
END_IF

// Module shutdown
IF (NOT xOff) AND (NOT xReady) AND (NOT xEnable) AND (NOT xError) THEN
	refstHMIInterface.eStatus := E_COMPONENT_STATUS.SHUTDOWN;
END_IF

// Module off
IF xOff AND (NOT xError) THEN
	refstHMIInterface.eStatus := E_COMPONENT_STATUS.OFF;
END_IF

// Module error
IF xError THEN
	refstHMIInterface.eStatus := E_COMPONENT_STATUS.ERROR;
END_IF
]]></ST>
    </Implementation>
    <Method Name="FB_init" Id="{369c1d27-76e4-45f8-9dbe-03524d3389df}">
      <Declaration><![CDATA[METHOD FB_init : BOOL
VAR_INPUT
	bInitRetains : BOOL; // if TRUE, the retain variables are initialized (warm start / cold start)
	bInCopyCode : BOOL;  // if TRUE, the instance afterwards gets moved into the copy code (online change)
	
	sName : STRING;
END_VAR
]]></Declaration>
      <Implementation>
        <ST><![CDATA[_sName := sName;

// Set unit names
_fbUnit1.Name := CONCAT(_sName, 'Unit 1');
_fbUnit2.Name := CONCAT(_sName, 'Unit 2');
_fbUnit3.Name := CONCAT(_sName, 'Unit 3');
_fbUnit4.Name := CONCAT(_sName, 'Unit 4');

// Create out of balance alarm
_fbUnitsOutOfBalanceAlarm.CreateEx(stEventEntry := TC_EVENTS.BMSEvents.ModuleImbalance, bWithConfirmation := TRUE, 0);

// Create alarm message
_fbUnitsOutOfBalanceAlarm.ipArguments.Clear().AddString(_sName);

// Create connection lost alarm
_fbConnLostAlarm.CreateEx(stEventEntry := TC_EVENTS.General.CommError, bWithConfirmation := TRUE, 0);
_fbConnLostAlarm.ipArguments.Clear().AddString(_sName);


// Create leakage alarm messages
_fbLeackageTankAlarm.CreateEx(stEventEntry := TC_EVENTS.General.LeakageTank, bWithConfirmation := TRUE, 0);
_fbLeackageTankAlarm.ipArguments.Clear().AddString(_sName);

_fbLeackageSegment12Alarm.CreateEx(stEventEntry := TC_EVENTS.General.LeakageDS12, bWithConfirmation := TRUE, 0);
_fbLeackageSegment12Alarm.ipArguments.Clear().AddString(_sName);

_fbLeackageSegment34Alarm.CreateEx(stEventEntry := TC_EVENTS.General.LeakageDS34, bWithConfirmation := TRUE, 0);
_fbLeackageSegment34Alarm.ipArguments.Clear().AddString(_sName);]]></ST>
      </Implementation>
    </Method>
    <Property Name="Name" Id="{bc8bc990-5071-47c9-a928-a129c60c6f41}">
      <Declaration><![CDATA[PROPERTY Name : String]]></Declaration>
      <Get Name="Get" Id="{c00a6d41-9156-49b5-aa08-e4cc4c913fca}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[Name := _sName;]]></ST>
        </Implementation>
      </Get>
      <Set Name="Set" Id="{ade5f4d9-ff42-4236-b5fc-e43a53c9ca28}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[_sName := Name;

// Set unit names
_fbUnit1.Name := CONCAT(_sName, ' - Unit 1');
_fbUnit2.Name := CONCAT(_sName, ' - Unit 2');
_fbUnit3.Name := CONCAT(_sName, ' - Unit 3');
_fbUnit4.Name := CONCAT(_sName, ' - Unit 4');

// Create alarm message
_fbUnitsOutOfBalanceAlarm.ipArguments.Clear().AddString(_sName);

// Create connection lost alarm
_fbConnLostAlarm.ipArguments.Clear().AddString(_sName);

// Create leackage alarm messages
_fbLeackageTankAlarm.ipArguments.Clear().AddString(_sName);
_fbLeackageSegment12Alarm.ipArguments.Clear().AddString(_sName);
_fbLeackageSegment34Alarm.ipArguments.Clear().AddString(_sName);]]></ST>
        </Implementation>
      </Set>
    </Property>
  </POU>
</TcPlcObject>