# POUs

FUNCTION_BLOCK FB_Module(xEmergencyStopOk, uiFirstUnitIndex, xEnable, xStartBalancing, xInSafetyCheckMode, xSafetyIntlksOk, xOff, refstHMIInterface, xReleaseErrors, xReleaseLimitErrors, xReleaseManualMode, xAllToManualMode, xConfirmAlarms, rBalancingTargetVoltage, xInverterEnabled, xLeakageSegments12, xLeakageSegments34, xLeakageTank, rCurrent, uiECState, rCurrentVoltage, xReady, xInShutdownDischargeMode, xShutdownDischargeAllowed, xError, xWarning, xAllUnitsInAutomatic, rSmallestSegmentVoltage, rHighestSegmentVoltage, xBalancingDone)
  VAR_IN:

    - xEmergencyStopOk (`BOOL`) – Emergency stop ok

    - uiFirstUnitIndex (`UINT`) – Unit numbering start (0 based index) Unit 1 -> Index 0

    - xEnable (`BOOL`) – Enable

    - xStartBalancing (`BOOL`) – Start balancing

    - xInSafetyCheckMode (`BOOL`) – Module in safety check mode

    - xSafetyIntlksOk (`BOOL`) – All safetyinterlocks are ok

    - xOff (`BOOL`) – Module completely off

    - refstHMIInterface (`ST_MODULE_HMI_INTERFACE`) – HMI Interface

    - xReleaseErrors (`BOOL`) – Release alarms

    - xReleaseLimitErrors (`BOOL`) – Release analog io limit errors

    - xReleaseManualMode (`BOOL`) – Release manual mode

    - xAllToManualMode (`BOOL`) – Switch all components to manual mode

    - xConfirmAlarms (`BOOL`) – Input to confirm all errors

    - rBalancingTargetVoltage (`REAL`) – Balancing target Voltage

    - xInverterEnabled (`BOOL`) – Inverter enabled status

    - xLeakageSegments12 (`BOOL`) – Leakage double segment 1/2

    - xLeakageSegments34 (`BOOL`) – Leakage double segment 3/4

    - xLeakageTank (`BOOL`) – Leakage tank

    - rCurrent (`REAL`) – Current current value from string to copy to HMI interface

    - uiECState (`UINT`) – Current EtherCAT state

  VAR_OUT:

    - rCurrentVoltage (`REAL`) – Module voltage

    - xReady (`BOOL`) – Module ready

    - xInShutdownDischargeMode (`BOOL`) – Module in shutdown segment discharge mode

    - xShutdownDischargeAllowed (`BOOL`) – Module can be discharged during shutdown sequence

    - xError (`BOOL`) – One unit has an error

    - xWarning (`BOOL`) – One unit has a warning

    - xAllUnitsInAutomatic (`BOOL`) – All modules in automatic mode

    - rSmallestSegmentVoltage (`REAL`) – Smallest segment voltage

    - rHighestSegmentVoltage (`REAL`) – Highest segment voltage

    - xBalancingDone (`BOOL`) – Balancing done

  VAR:

    - _fbUnit1 (`FB_Unit`) –

    - _fbUnit2 (`FB_Unit`) –

    - _fbUnit3 (`FB_Unit`) –

    - _fbUnit4 (`FB_Unit`) –

    - _xBalanceOk (`BOOL`) – Flag for unit balance checking

    - _xAllUnitsReady (`BOOL`) – All units are ready

    - _fbUnitsOutOfBalanceAlarm (`FB_TcAlarm`) – Units out of balance alarm

    - _fbLeackageTankAlarm (`FB_TcAlarm`) – Leackage tank alarm

    - _fbLeackageSegment12Alarm (`FB_TcAlarm`) – Leackage Segment 1/2 alarm

    - _fbLeackageSegment34Alarm (`FB_TcAlarm`) – Leackage Segemnt 3/4 alarm

    - _fbConnLostAlarm (`FB_TcAlarm`) – Connection lost alarm

    - _sName (`STRING`) – Module name

    - _fbBalanceNotOkSignal (`FB_ReleaseSignal`) –

    - _xECModuleInOP (`BOOL`) –

    - xDebug1 (`BOOL`) –

    - xDebug2 (`BOOL`) –

    - xDebug3 (`BOOL`) –

    - xDebug4 (`BOOL`) –

  METHOD FB_init(bInitRetains, bInCopyCode, sName)
    VAR_IN:

      - 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`) –

  PROPERTY Name

FUNCTION_BLOCK FB_PowerMeter(xGetEnergyCounters, sIpAddress, lrEnergyFromGrid, lrEnergyIntoGrid, xBusy, xError)
  VAR_IN:

    - xGetEnergyCounters (`BOOL`) –

    - sIpAddress (`STRING(80)`) – IP 75 -> Umrichter IP 80 -> Hilfsenergie

  VAR_OUT:

    - lrEnergyFromGrid (`LREAL`) –

    - lrEnergyIntoGrid (`LREAL`) –

    - xBusy (`BOOL`) –

    - xError (`BOOL`) –

  VAR:

    - _fbReadRegs (`FB_MBReadRegs`) –

    - _awWordArray (`ARRAY[0..3] OF WORD`) –

    - _awSwapped (`ARRAY[0..3] OF WORD`) –

    - _udiErrorId (`UDINT`) –

    - _fbGetEnergyCounters (`R_TRIG`) –

    - _xResetEnergyCounter (`BOOL`) –

    - _iState (`INT`) –

FUNCTION_BLOCK FB_Safety(xVoltagesInRange, xPressureInRange, xTemperaturesInRange, xReset)
  VAR_IN:

    - xVoltagesInRange (`BOOL`) –

    - xPressureInRange (`BOOL`) –

    - xTemperaturesInRange (`BOOL`) –

    - xReset (`BOOL`) –

  VAR:

    - _latchedVoltages (`BOOL`) –

    - _latchedPressures (`BOOL`) –

    - _latechedTemperatures (`BOOL`) –

    - _xErrorLatched (`BOOL`) –

FUNCTION_BLOCK FB_String(xEnable, uiStringNumber, xErrorShutdown, xStartBalancing, xInSafetyCheckMode, rPowerInverter, stHMIInterface, xEmergencyStopOk, xResetSafety, xSafetyComError, xReleaseErrors, xReleaseLimitErrors, xReleaseManualMode, xConfirmAlarms, xAllToManualMode, sInverterIP, xECStateSCS, xIsoErrorL1, xIsoErrorL2, xRepairSwitchOk, xSafetyIntlksOk, xSafetyIntlksComponentsOk, rCurrentVoltage, xInShutdownDischargeMode, xShutdownDischargeAllowed, xReady, xOff, xCloseDCCB, xDCCBOpen, xResetSafetyDCCB, xAllModulesInAutoMode, xError, xWarning, eStatus, stInverterData, rSmallestSegmentVoltage, rHighestSegmentVoltage, xBalancingDone)
  VAR_IN:

    - xEnable (`BOOL`) – Enable

    - uiStringNumber (`UINT`) – String number for unit numbering starting with 0 for String 1

    - xErrorShutdown (`BOOL`) – Error shutdown -> No discharge throught inverter

    - xStartBalancing (`BOOL`) – Start in balancing mode

    - xInSafetyCheckMode (`BOOL`) – String in safety check mode

    - rPowerInverter (`REAL`) – Requested inverter power

    - stHMIInterface (`ST_STRING_HMI_INTERFACE`) – String HMI interface

    - xEmergencyStopOk (`BOOL`) – Emergency stop ok

    - xResetSafety (`BOOL`) – Reset Safety

    - xSafetyComError (`BOOL`) – Attr: analysis := ‚-33‘, Safety communication error

    - xReleaseErrors (`BOOL`) – Release alarms

    - xReleaseLimitErrors (`BOOL`) – Release analog io limit errors

    - xReleaseManualMode (`BOOL`) – Release manual mode

    - xConfirmAlarms (`BOOL`) – Input to confirm all errors

    - xAllToManualMode (`BOOL`) – Switch all components to manual mode

    - sInverterIP (`STRING`) – String inverter ip

    - xECStateSCS (`UINT`) –

    - xIsoErrorL1 (`BOOL`) –

    - xIsoErrorL2 (`BOOL`) –

  VAR_OUT:

    - xRepairSwitchOk (`BOOL`) – Repair switch closed

    - xSafetyIntlksOk (`BOOL`) – All safetyinterlocks from safety plc are ok

    - xSafetyIntlksComponentsOk (`BOOL`) – All component safety interlocks are ok

    - rCurrentVoltage (`REAL`) – Current string voltage

    - xInShutdownDischargeMode (`BOOL`) – Module in shutdown segment discharge mode

    - xShutdownDischargeAllowed (`BOOL`) – Module can be discharged during shutdown sequence

    - xReady (`BOOL`) – String ready

    - xOff (`BOOL`) – String completely off

    - xCloseDCCB (`BOOL`) – Signal to close dc circuit breaker

    - xDCCBOpen (`BOOL`) – Signal that dc circuit breakers are closed

    - xResetSafetyDCCB (`BOOL`) – Reset signal for safety dc circuit breaker

    - xAllModulesInAutoMode (`BOOL`) – All modules in automatic mode

    - xError (`BOOL`) –

    - xWarning (`BOOL`) –

    - eStatus (`E_COMPONENT_STATUS`) –

    - stInverterData (`ST_SUNSPEC_CURRENT_VALUES`) – Inverter status data

    - rSmallestSegmentVoltage (`REAL`) – Smallest segment voltage

    - rHighestSegmentVoltage (`REAL`) – Highest segment voltage

    - xBalancingDone (`BOOL`) – Balancing done

  VAR:

    - _fbModule1 (`FB_Module`) –

    - _fbModule2 (`FB_Module`) –

    - _fbModule3 (`FB_Module`) –

    - _xModuleError (`BOOL`) – Summed status of all module errors

    - _xAllModulesReady (`BOOL`) – All modules are ready

    - _xAllModulesInShutdownDischargeMode (`BOOL`) – All modules in shutdown discharge mode

    - _xBalanceOk (`BOOL`) – Flag for module balance checking

    - _fbModulesOutOfBalanceAlarm (`Fb_TcAlarm`) – Modules out of balance alarm message

    - _fbSafetyInterlocksNotOkAlarm (`FB_TcAlarm`) – Safetyinterlocks pending alarm

    - _fbInverterStartupTimeoutAlarm (`FB_TcAlarm`) – Inverter startup error

    - _fbDCMainSwitchNotClosed (`FB_TcAlarm`) – DC Main switch not closed

    - _fbSCSConnLost (`FB_TcAlarm`) – Connection to SCS lost

    - _fbIsolationAlarm (`FB_TcAlarm`) – Isolatio alarm

    - _fbSafetyIntlkTimeoutAlarm (`FB_TcAlarm`) – Safety interlock reset timeout

    - _fbSDDCLevel (`FB_TcMessage`) – Shutdown discharge stopped messages

    - _fbSDUnitThreshold (`FB_TcMessage`) –

    - _iState (`INT`) – State for start and stop

    - _tonResetPulseLength (`TON`) – Timer for result pulse to safety

    - _tonErrorDCCBNotClosed (`TON`) – Error timer for not closing dc relais

    - _fbBalanceNotOkSignal (`FB_ReleaseSignal`) – Delayed balance check signal

    - _sName (`STRING`) – String name

    - _fbInverter (`FB_PowerSupplySunspec`) – String inverter

    - _rPowerInverterInternal (`REAL`) – Internal inverter power command

    - _xEnableInverter (`BOOL`) – Enable inverter flag

    - _tonInverterStartupTimeout (`TON`) – Fault timer for inverter startup

    - _tonInverterShutdownError (`TON`) – Fault timer for inverter shutdown

    - _tonInverterShutdownDelay (`TON`) – Debug delay timer for inverter shutdown

    - _tonSafetyOkTimeout (`TON`) – Timer for Safety ok timeout

    - _fbStringCurrent (`FB_AnalogInput`) – Analog input for string current measurement

    - xErrorInverter (`BOOL`) –

    - _xReleaseLimitErrorsInternal (`BOOL`) –

    - _xBalancingDone (`BOOL`) – Balancing done

    - _xEnable (`BOOL`) – Enable modules internal signal

    - _xStartBalancing (`BOOL`) – Start balancing internal signal

    - _xIsoError (`BOOL`) –

    - _fbTONIsoError (`TON`) – Iso error timeout

    - _rSOC (`REAL`) – Internal SOC

  VAR PERSISTENT:

    - rCapacityWH (`REAL`) –

    - rCapacityAH (`REAL`) –

  METHOD FB_init(bInitRetains, bInCopyCode, sName)
    VAR_IN:

      - 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`) –

    VAR:

      - _sTemp (`STRING`) –

  PROPERTY Name

FUNCTION_BLOCK FB_UMD705()
  VAR:

    - _xExecute (`BOOL`) –

    - _fbReadRegister (`FB_MBReadRegs`) – FB for reading Modbus holding registers

    - _fbWriteRegister (`FB_MBWriteRegs`) – FB for writing Modbus holding registers

    - _diLastReset (`DINT`) –

  VAR CONSTANT:

    - STATUS_REGISTER (`WORD`) –

FUNCTION_BLOCK FB_Unit(stUnitConfig, stHMIInterface, xEnable, xStartBalancing, xInSafetyCheckMode, xEmergencyStopOk, xSafetyIntlksOk, xReleaseErrors, xReleaseLimitErrors, xReleaseManualMode, xConfirmAlarms, rBalancingTargetVoltage, xAllToManualMode, xInverterEnabled, stModbusWarnings, stModbusErrors, xReady, xOff, xShutdownDischargeAllowed, xInShutdownDischargeMode, xError, xWarning, rCurrentVoltage, xAllComponentsInAuto, xBalancingDone, xResetMCB)
  VAR_IN:

    - stUnitConfig (`ST_UNIT_CONFIG`) – Unit configuration

    - stHMIInterface (`ST_UNIT_HMI_INTERFACE`) – HMI interface

    - xEnable (`BOOL`) – Components shortage workaround xVoltageSensorIs1500V : BOOL; Start unit

    - xStartBalancing (`BOOL`) – Star balancing

    - xInSafetyCheckMode (`BOOL`) – Unit in safety check mode

    - xEmergencyStopOk (`BOOL`) – Emergency stop ok

    - xSafetyIntlksOk (`BOOL`) – All safetyinterlocks are ok

    - xReleaseErrors (`BOOL`) – Release alarms

    - xReleaseLimitErrors (`BOOL`) – Release analog io limit errors

    - xReleaseManualMode (`BOOL`) – Release manual mode

    - xConfirmAlarms (`BOOL`) – Input to confirm all errors

    - rBalancingTargetVoltage (`REAL`) – Balancing target Voltage

    - xAllToManualMode (`BOOL`) – Switch all components to manual mode

    - xInverterEnabled (`BOOL`) – Inverter enabled status

  VAR_IN_OUT:

    - stModbusWarnings (`U_UNIT_WARNING_REGISTER`) – Modbus warning register

    - stModbusErrors (`U_UNIT_ERROR_REGISTER`) – Modbus error register

  VAR_OUT:

    - xReady (`BOOL`) – Unit state eUnitState : E_COMPONENT_STATUS := E_COMPONENT_STATUS.OFF; Unit ready

    - xOff (`BOOL`) – Unit completely off

    - xShutdownDischargeAllowed (`BOOL`) – Unit can be discharged during shutdown sequence

    - xInShutdownDischargeMode (`BOOL`) – Unit in shutdown segment discharge mode

    - xError (`BOOL`) – Error active

    - xWarning (`BOOL`) – Warning active

    - rCurrentVoltage (`REAL`) – Current Unit voltage

    - xAllComponentsInAuto (`BOOL`) – All components in automatic mode

    - xBalancingDone (`BOOL`) – Balancing done

    - xResetMCB (`BOOL`) – Reset MCB

  VAR:

    - _timUnitStartupWaitTime (`TIME`) – Check unit condition after some time during startup

    - _fbPosolytValveTankOutlet (`FB_Valve`) – Valves posolyt

    - _fbNegolytValveTankOutlet (`FB_Valve`) – Valves negolyt

    - _fbPosolytPumpInlet (`FB_MotorAnalog`) – Pumps posolyt

    - _fbNegolytPumpInlet (`FB_MotorAnalog`) – Pumps negolyt

    - _fbPressurePosolytSegmentInlet (`FB_AnalogInput`) – Pressure sensors posolyt

    - _fbPressurePosolytTankInlet (`FB_AnalogInput`) –

    - _fbPressureNegolytSegmentInlet (`FB_AnalogInput`) – Pressure sensors negolyt

    - _fbPressureNegolytTankInlet (`FB_AnalogInput`) –

    - _fbTempSensorPosolyt (`FB_AnalogInput`) – Temperature sensor posolyt

    - _fbTempSensorNegolyt (`FB_AnalogInput`) – Temperature sensor negolyt

    - _fbVoltageSegment (`FB_AnalogInput`) – Unit voltage

    - _stPosolytValveTankOutletPIntlk (`T_INTERLOCK`) – Valve posolyt tank outlet interlocks

    - _stPosolytValveTankOutletPIntlkUsed (`T_INTERLOCK`) –

    - _stPosolytValveTankOutletSIntlk (`T_INTERLOCK`) –

    - _stPosolytValveTankOutletSIntlkUsed (`T_INTERLOCK`) –

    - _stNegolytValveTankOutletPIntlk (`T_INTERLOCK`) – Valve negolyt tank outlet interlocks

    - _stNegolytValveTankOutletPIntlkUsed (`T_INTERLOCK`) –

    - _stNegolytValveTankOutletSIntlk (`T_INTERLOCK`) –

    - _stNegolytValveTankOutletSIntlkUsed (`T_INTERLOCK`) –

    - _stPosolytPumpInletPIntlk (`T_INTERLOCK`) – Pump posolyt inlet interlocks

    - _stPosolytPumpInletPIntlkUsed (`T_INTERLOCK`) –

    - _stPosolytPumpInletSIntlk (`T_INTERLOCK`) –

    - _stPosolytPumpInletSIntlkUsed (`T_INTERLOCK`) –

    - _stNegolytPumpInletPIntlk (`T_INTERLOCK`) – Pump negolyt inlet interlocks

    - _stNegolytPumpInletPIntlkUsed (`T_INTERLOCK`) –

    - _stNegolytPumpInletSIntlk (`T_INTERLOCK`) –

    - _stNegolytPumpInletSIntlkUsed (`T_INTERLOCK`) –

    - _xErrorActive (`BOOL`) – Error active

    - _xWarningActive (`BOOL`) – Warning active

    - _rShutdownDischargeVoltageThreshold (`REAL`) – Shutdown discharge allowed voltage

    - _iState (`INT`) – Current state

    - _xAllComponentsInAutomatic (`BOOL`) – All components in automatic mode

    - _fbNotAllAutomaticAlarm (`FB_TcAlarm`) – Not all components in automatic mode alarm

    - _fbPressureDiffToBig (`FB_TcAlarm`) – Pressure difference between pos and neg inlet to big

    - _fbUnitError (`FB_TcAlarm`) – General unit error

    - _sName (`STRING`) – Unit name

    - _tonStartupCheck (`TON`) – Unit startup check timer

    - _xEnableVoltageLimitChecks (`BOOL`) – Enable voltage limit checks

    - _xReleaseManualMode (`BOOL`) – Manual mode allowed flag

    - _xReleaseSignalDeltaPSegment (`FB_ReleaseSignal`) –

    - _xDeltaPSegmentInletToHigh (`BOOL`) –

    - _xEnableCheckForDeltaPSegmentInlet (`BOOL`) –

    - _xErrorDeltaPSegmentInlet (`BOOL`) –

    - _rSetpointPosolytPumpInlet (`REAL`) – Setpoint posolyt pump inlet

    - _rSetpointNegolytPumpInlet (`REAL`) – Setpoint negolyt pump inlet

    - _tofResetMCB (`TOF`) – Timer for resetting the MCB (minimum on time 0,5s)

    - _tonVoltageCheckTimeput (`TON`) – Timeout Voltage not reached

    - _rBalancingTargetVoltage (`REAL`) – Freezed balancing target voltage

    - _rtrigSwitchToManualMode (`R_TRIG`) – Trigger for switching to manual mode

    - _rtrigSwitchToAutoMode (`R_TRIG`) – Trigger for switching to automatic mode

    - _tonManualMode (`TON`) –

    - _rFilteredPressPosolytInlet (`REAL`) – Filtered pressure sensor posolyt segment inlet data for HMI

    - _rFilteredPressNegolytInlet (`REAL`) – Filtered pressure sensor posolyt segment inlet data for HMI

    - _rFilteredPressPosolytTank (`REAL`) – Filtered pressure sensor posolyt tank inlet data for HMI

    - _rFilteredPressNegolytTank (`REAL`) – Filtered pressure sensor posolyt tank inlet data for HMI

    - _xPumpsReady (`BOOL`) – Pumps ready

    - xFirstCycle (`BOOL`) – Indicate if it ise the first cycle

  METHOD FB_init(bInitRetains, bInCopyCode, sName)
    VAR_IN:

      - 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`) –

  PROPERTY Name

PROGRAM MAIN()
  VAR:

    - _xEmergencyStopOk (`BOOL`) –

    - _xShowAckEmergencyStop (`BOOL`) –

    - _xReleaseErrors (`BOOL`) –

    - _xReleaseLimitsErrors (`BOOL`) –

    - _xConfirmAlarms (`BOOL`) –

    - _xEnableString (`BOOL`) –

    - _xStartBalancing (`BOOL`) –

    - _xCanChangeMode (`BOOL`) –

    - _afbStrings (`ARRAY[0..1] OF FB_String`) – Attr: OPC.UA.DA := ‚0‘,

    - _xErrorShutdown (`BOOL`) – Variable to detect charge status change _eLastChargeStatus : E_CHARGE_STATUS; Variable to detect battery status change _eLastBatteryStatus : E_BATTERY_STATUS; Battery shutdown due to error

    - _iState (`INT`) – State machine state

    - _iStateSafetyCheck (`INT`) –

    - _iStateBalancing (`INT`) –

    - _xStartSafetyCheck (`BOOL`) – Start safety check mode

    - _rAutoPowerRequest (`REAL`) – Auto remote and auto local power request

    - _rPowerInverter (`REAL`) – Internal inverter power

    - _xNoPowerRequested (`BOOL`) – Flag for zero power indication

    - _tonStartupDelay (`TON`) – Startup delay for error release during plc startup

    - _tonBeginShutdown (`TON`) – Small delay for inverter shutdown

    - _fbNoAutomaticModeAlarm (`FB_TcAlarm`) – Not all strings in automatic mode

    - _fbEStopNotOk (`FB_TcAlarm`) – Emergency stop not ok alarm

    - _fbEtherCATErrorString1 (`FB_TcAlarm`) – String 1 Error Mssage

    - _stECString1ErrSI (`FB_TcSourceInfo`) –

    - _fbEtherCATErrorString2 (`FB_TcAlarm`) – String 2 Error Mssage

    - _stECString2ErrSI (`FB_TcSourceInfo`) –

    - _xFirstCycle (`BOOL`) – First cycle tag

    - _fbADSReader (`ADSREAD`) – ADS reader for modbus server data

    - _timADSReadTimer (`TON`) – Timer for ADS read

    - _xReleaseManualMode (`BOOL`) – Release manual mode

    - _eBMSControlMode (`E_BMS_CONTROL_MODE`) – Current BMS control mode (Auto local, Auto remote, etc…) On restart star in manual mode (so the ems can not directly start the bms)

    - _fbUPS (`FB_S_UPS_BAPI`) – UPS

    - xSafetyRun (`BOOL`) – Attr: analysis := ‚-33‘, Safety

    - xSafetyErrAck (`BOOL`) –

    - xSafetyResterTaster (`BOOL`) –

    - _xHarwareResetButton (`BOOL`) – Hardware reset button

    - _xShowErrorOnButton (`BOOL`) –

    - _tonHardwareResetButton (`TON`) –

    - _rtHardwareResetButton (`R_TRIG`) –

    - _xErrorActive (`BOOL`) –

    - _xInSafetyCheckMode (`BOOL`) – Battery in safety check mode

    - _fbBatteryFullMessage (`FB_TcMessage`) – Battery full message

    - _fbBatteryEmptyMessage (`FB_TcMessage`) –

    - _rSmallestSegmentVoltage (`REAL`) – Smallest segment voltage

    - _rHighestSegmentVoltage (`REAL`) – Highest segment voltage

    - _fbSafety (`FB_Safety`) – Safety

    - _uiEtherCATState (`UINT`) – String EtherCAT state

    - _wEtherCATState (`WORD`) –

    - _xEtherCatString1Ok (`BOOL`) –

    - _xEtherCatString2Ok (`BOOL`) –

    - _xAllComponentsToManualMode (`BOOL`) – Flag to set all components in manual mode

    - _fbRTrigHardwareAck (`R_TRIG`) – Hardware reset button rising edge trigger

    - _ModbusDebugTest (`ST_MODBUS_REG_11`) – DEBUG

    - _fbStringReadyTimeout (`TON`) –

    - _rStringsSumVoltage (`REAL`) – Sum of voltage of all active strings

    - _rDeltaUm (`REAL`) –

    - _arPowerString (`ARRAY[0..(GVL_CONFIG.uiNumberOfStrings-1)] OF REAL`) –

    - _ui (`UINT`) –

    - _xStringsReady (`BOOL`) –

    - _xStringsErrorActive (`BOOL`) –

    - _xStringsInSchutdownDischargeMode (`BOOL`) –

    - _xStringsShutdownDischargeAllowed (`BOOL`) –

    - _xStringsAllInAutomaticMode (`BOOL`) –

    - _xStringsOff (`BOOL`) –

    - _xStringsBalancingDone (`BOOL`) –

    - _xStringsInAutoMode (`BOOL`) –

    - _rMaxCurrentInverterDCVoltage (`REAL`) –

    - _rMinCurrentInverterDCVoltage (`REAL`) –

    - _fbModbusRead (`FB_MBReadRegs`) –

    - xDebugTest (`BOOL`) – _wLength : WORD := 49;

    - _wDebug1 (`WORD`) –

    - _wDebug2 (`WORD`) –

    - _fbPowerMeterPower (`FB_PowerMeter`) –

    - _fbPowerMeter24V (`FB_PowerMeter`) –

    - _uiNumberOfActiveStrings (`UINT`) – Number of activated strings (from configuration)

    - _xGetPowerMeterData (`BOOL`) –

## Sunspec

FUNCTION_BLOCK FB_PowerSupplySunspec(sInverterIPAddr, xEnable, rPower, xReset, rMaxBattPower, xActive, xError, xHeartbeatOk, stCurrentValues)
  VAR_IN:

    - sInverterIPAddr (`STRING`) –

    - xEnable (`BOOL`) –

    - rPower (`REAL`) –

    - xReset (`BOOL`) – rReactivePower : REAL := 0.0;

    - rMaxBattPower (`REAL`) – 24kW

  VAR_OUT:

    - xActive (`BOOL`) – Inverter active

    - xError (`BOOL`) – FB error

    - xHeartbeatOk (`BOOL`) – Heartbeat ok signal

    - stCurrentValues (`ST_SUNSPEC_CURRENT_VALUES`) – Current inverter values

  VAR:

    - _iState (`INT`) – Current state

    - _rPowerInternal (`REAL`) – Internal power command

    - _fbReadRegister (`FB_MBReadRegs`) – FB for reading Modbus holding registers

    - _fbWriteRegister (`FB_MBWriteRegs`) – FB for writing Modbus holding registers

    - _iWMaxSF (`INT`) – Timer for checking if the inverter started in a reasonable amount of time _tonInverterStartup : TON; converter max power scaling factor

    - _uiWMax (`UINT`) – Unscaled converter max power

    - _rWMax (`REAL`) – Scaled converter max power

    - _iWMaxLimPct (`INT`) – Unscaled limit for converter power

    - _iVarPctSF (`INT`) – Scaling factor for reactive power percent value

    - _iWMaxLimPctSF (`INT`) – Reread set power limit _iWMaxLimPctRead : INT; _rWMaxLimPctReadScaled : REAL; Scaling factor for power limiting

    - _uiInverterState (`UINT`) – Unscaled maximum power from type label _iWRTGSF : INT; Scaling for maximum power from type label _rWRTGScaling : REAL; Current state of the inverters internal statemachine

    - _uiMaxLimEn (`UINT`) – Value to enable or dissable the Power limiting feature

    - _uiPCSSetOperation (`UINT`) – Value for commanding the target state of the inverter

    - _iMaxPowerVar (`INT`) – Maximum reactive power

    - _iMaxVarPct (`INt`) – Enable max reactive power percent controller

    - _iErrorInState (`INT`) – Holds the state number in which an error occured

    - _timPollingDelay (`TIME`) – Time for polling for current dc values and check for inverter error

    - _timSetPowerDelay (`TIME`) – Time for setting the current power

    - _tonPollingTimer (`TON`) – Timer for polling of current values

    - _tonSetPowerTimer (`TON`) – Timer for setting the inverter power

    - _tonHearbeatIncTimer (`TON`) – Timer for incrementing heartbeat signal

    - _awCurrentDCValues (`ARRAY[0..5] OF WORD`) – Current DC values (DCA, DCA_SF, DCV, DCV_SF, DCW, DCW_SF) in word array for efficient modbus reading

    - _awCurrentACValues (`ARRAY[0..21] OF WORD`) – Current AC values (W, W_SF, Hz, Hz_SF, VA, VA_SF, VAr, VAr_SF, PF, PF_SF) in word array for efficient modbus reading

    - _dwErrorBits (`DWORD`) – Inverter error bits

    - _uiResetInverter (`UINT`) – Inverter reset errors command

    - _uiPLCToInverterCounter (`UINT`) – PLC -> Inverter heartbeat

    - _uiInverterToPLCCounter (`UINT`) – Inverter -> PLC heartbeat

    - _uiInverterToPLCCounterOld (`UINT`) –

    - _xInverterHBCounterIncremented (`BOOL`) – Flag to check if inverter has incremented the heartbeat counter

    - _fbErrorInverterAlarm (`FB_TcAlarm`) – Inverter alarm

    - _fbHeartbeatTimeout (`TON`) – Heartbeat timeout

    - _sName (`STRING`) –

    - _uiSetPowerLimitErrorCounter (`UINT`) –

    - _uiLastSetPowerLimitErrorCounter (`UINT`) –

  VAR CONSTANT:

    - STATUS_REGISTER (`WORD`) – Inverter statemachine status register Size 1, enum16 (Range = 0 .. 65534, Not implemented = 0xFFFF)

    - W_MAX_LIM_PCT_REGISTER (`WORD`) – Throttled power register Size 1, int16 (Range = -32767 .. 32767, Not implemented 0x8000)

    - W_MAX_LIM_PCT_SF_REGISTER (`WORD`) – Throttled power register scaling factor Size 1, sunssf (int16) (Range = -10 .. 10, Not implemented 0x8000)

    - W_MAX_LIM_EN_REGISTER (`WORD`) – Control register to enable and dissable if the power throttleing should be active Size1, enum16 (Range = 0 .. 65534, Not implemented = 0xFFFF)

    - PCS_ALARM_RESET_REGISTER (`WORD`) – Register to reset latched alarms in the inverter Size 1, uint16 (Range = 0 .. 65534, Not implemented = 0xFFFF)

    - PCS_SET_OPERATION_REGISTER (`WORD`) – Control register to set the target state of the inverters state machine Size 1, enum16 (Range = 0 .. 65534, Not implemented = 0xFFFF)

    - W_MAX_REGISTER (`WORD`) – Maximum inverter output power Size 1, uint16 (Range = 0 .. 65534, Not implemented = 0xFFFF)

    - W_MAX_SF_REGISTER (`WORD`) – Maximum inverter output power scaling factor Size 1, sunssf (int16) (Range = -10 .. 10, Not implemented 0x8000)

    - DC_VALUES_START_REGISTER (`WORD`) – Maximum inverter output power from type label Size 1, uint16 (Range = 0 .. 65534, Not implemented = 0xFFFF) W_RTG_REGISTER : WORD := 40125; Maximum inverter output power from type label scaling factor Size 1, sunssf (int16) (Range = -10 .. 10, Not implemented 0x8000) W_RTG_SF_REGISTER : WORD := 40126; Start of register with the current dc values Size 4

    - AC_VALUES_START_REGISTER (`WORD`) – Start of register with the current ac values SIZE 10

    - VAR_W_MAX_PCT (`WORD`) – Power factor register in cosine of angle Size 1, int16 (Range = -32767 .. 32767, Not implemented 0x8000) OUT_PF_SET : WORD := 40192; Enable power factor controller Size 1, enum16 (Range = 0 .. 65534, Not implemented = 0xFFFF) OUT_PF_SET_ENA : WORD := 40196; Reactive power in percent of W_Max Size 1, int16 (Range = -32767 .. 32767, Not implemented 0x8000)

    - VAR_PCT_ENA (`WORD`) – Enable percent limited var controller Size 1, enum16 (Range = 0 .. 65534, Not implemented = 0xFFFF)

    - VAR_PCT_SF (`WORD`) – Register for reactive power percent scaling factor Size 1, sunssf (int16) (Range = -10 .. 10, Not implemented 0x8000)

    - EVT_1_REGISTER (`WORD`) – Error bits register Size 2

    - CONTROLLER_HB (`WORD`) – PLC -> Inverter Heartbeat register

    - PCS_HB (`WORD`) – Inverter -> PLC heartbeat register

  METHOD FB_init(bInitRetains, bInCopyCode, sName)
    VAR_IN:

      - 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`) –

  PROPERTY Name

### ST_SUNSPEC_CURRENT_VALUES

STRUCT ST_SUNSPEC_CURRENT_VALUES
  rActDCCurrent → REAL

    > Attr: OPC.UA.DA := ‚1‘, Attr: OPC.UA.DA.Access := ‚1‘, Current DC current (A)

  rActDCVoltage → REAL

    > Attr: OPC.UA.DA := ‚1‘, Attr: OPC.UA.DA.Access := ‚1‘, Current DC voltage (V)

  rActDCPower → REAL

    > Attr: OPC.UA.DA := ‚1‘, Attr: OPC.UA.DA.Access := ‚1‘, Current DC power (W)

  rActACCurrent → REAL

    > Attr: OPC.UA.DA := ‚1‘, Attr: OPC.UA.DA.Access := ‚1‘, Current AC current. Sum of active phases (A)

  rActtACPhaseACurrent → REAL

    > Attr: OPC.UA.DA := ‚1‘, Attr: OPC.UA.DA.Access := ‚1‘, Current AC current. Phase A (A)

  rActtACPhaseBCurrent → REAL

    > Attr: OPC.UA.DA := ‚1‘, Attr: OPC.UA.DA.Access := ‚1‘, Current AC current. Phase B (A)

  rActtACPhaseCCurrent → REAL

    > Attr: OPC.UA.DA := ‚1‘, Attr: OPC.UA.DA.Access := ‚1‘, Current AC current. Phase C (A)

  rActACPower → REAL

    > Attr: OPC.UA.DA := ‚1‘, Attr: OPC.UA.DA.Access := ‚1‘, Current AC power (W)

  rActACFreq → REAL

    > Attr: OPC.UA.DA := ‚1‘, Attr: OPC.UA.DA.Access := ‚1‘, Current AC frequency (Hz)

  rActApparentPower → REAL

    > Attr: OPC.UA.DA := ‚1‘, Attr: OPC.UA.DA.Access := ‚1‘, Current AC apparent power (VA)

  rActReactivePower → REAL

    > Attr: OPC.UA.DA := ‚1‘, Attr: OPC.UA.DA.Access := ‚1‘, Current AC reactive power (VAr)

  rActPowerFactor → REAL

    > Attr: OPC.UA.DA := ‚1‘, Attr: OPC.UA.DA.Access := ‚1‘, Current AC power factor

  uiStatus → UINT

    > Attr: OPC.UA.DA := ‚1‘, Attr: OPC.UA.DA.Access := ‚1‘, Current inverter status

### U_SUNSPEC_ERROR

### ModelData

#### ST_SunspecInverterThreePhase

STRUCT ST_SunspecInverterThreePhase

  Sunspec register 40.070 - 40.120 (Size 52)

  uiID → UINT

    > Model value

  uiL → UINT

    > Model length

  iA → INT

    > AC current. Sum of active phases

  iAphA → INT

    > AC current. Phase A

  iAphB → INT

    > AC current. Phase B

  iAphC → INT

    > AC current. Phase C

  iASF → INT

    > AC current scaling factor

  uiPPVphAB → UINT

    > Phase voltage AB

  uiPPVphBC → UINT

    > Phase voltage BC

  uiPPVphCA → UINT

    > Phase voltage CA

  uiPhVphA → UINT

    > Phase voltage AN

  uiPhVphB → UINT

    > Phase voltage BN

  uiPhVphC → UINT

    > Phase voltage CN

  iVSF → INT

    > Phase voltage scaling factor

  iW → INT

    > AC Power

  iWSF → INT

    > AC power scaling factor

  uiHz → UINT

    > Line frequency

  iHzSF → INT

    > Line frequency scaling factor

  iVA → INT

    > AC apparent power

  iVASF → INT

    > AC apparent power scaling factor

  iVAr → INT

    > AC reactive power

  iVArSF → INT

    > AC reactive power scaling factor

  iPF → INT

    > AC power factor

  iPFSF → INT

    > AC power factor scaling factor

  udiWH → UDINT

    > AC Energy

  iWHSF → INT

    > AC Energy scaling factor

  uiDCA → UINT

    > DC current

  iDCASF → INT

    > DC current scaling factor

  uiDCV → UINT

    > DC voltage

  iDCVSF → INT

    > DC voltage scaling factor

  iDCW → INT

    > DC power

  iDCWSF → INT

    > DC power scaling factor

  iTmpCab → INT

    > Cabinet temperature

  iTmpSnk → INT

    > Heat sink temperature

  iTmpTrns → INT

    > Transformer temperature

  iTmpOt → INT

    > Other temperature

  iTmpSF → INT

    > Temperature scaling factor

  wSt → WORD

    > Operating state

  wStVnd → WORD

    > Vendor specific operating state

  dwEvt1 → DWORD

    > Bitmask value. Event fields.

  dwEvt2 → DWORD

    > Reserved for future use

  dwEvtVnd1 → DWORD

    > Vendor defined events 1

  dwEvtVnd2 → DWORD

    > Vendor defined events 2

  dwEvtVnd3 → DWORD

    > Vendor defined events 3

  dwEvtVnd4 → DWORD

    > Vendor defined events 4

#### ST_SunspecNameplateRatings

STRUCT ST_SunspecNameplateRatings

  Sunspec register 40.122 - 40.149 (Size 28)

  uiID → UINT

    > Model value

  uiL → UINT

    > Model length

  wDERTyp → WORD

    > Type of DER device

  uiWRtg → UINT

    > Continuous power output capability of the inverter

  uiWRtgSF → INT

    > Continuous power output capability of the inverter scaling factor

  uiVARtg → UINT

    > Continuous volt-ampere output capability of the inverter

  uiVARtgSF → INT

    > Continuous volt-ampere output capability of the inverter scaling factor

  iVArRtgQ1 → INT

    > Continuous VAR capability of the inverter in quadrant 1

  iVArRtgQ2 → INT

    > Continuous VAR capability of the inverter in quadrant 2

  iVArRtgQ3 → INT

    > Continuous VAR capability of the inverter in quadrant 3

  iVArRtgQ4 → INT

    > Continuous VAR capability of the inverter in quadrant 4

  iVArRtgSF → INT

    > Continuous VAR capability of the inverter in quadrant 1-4 scaling factor

  uiARtg → UINT

    > Maximum RMS AC current level capability of the inverter

  uiARtgSF → INT

    > Maximum RMS AC current level capability of the inverter scaling factor

  iPFRtgQ1 → INT

    > Minimum power factor capability of the inverter in quadrant 1

  iPFRtgQ2 → INT

    > Minimum power factor capability of the inverter in quadrant 2

  iPFRtgQ3 → INT

    > Minimum power factor capability of the inverter in quadrant 3

  iPFRtgQ4 → INT

    > Minimum power factor capability of the inverter in quadrant 4

  iPFRtgSF → INT

    > Minimum power factor capability of the inverter in quadrant 1-4 scaling factor

  uiWHRtg → UINT

    > Nominal energy rating of storage device

  uiWHRtgSF → INT

    > Nominal energy rating of storage device scaling factor

  uiAhrRtg → UINT

    > The usable capacity of the battery

  uiAhrRtgSF → INT

    > The usable capacity of the battery scaling factor

  uiMaxChaRte → UINT

    > Maximum rate of energy transfer into the storage device

  uiMaxChaRteSF → INT

    > Maximum rate of energy transfer into the storage device scaling factor

  uiMaxDisChaRte → UINT

    > Maximum rate of energy transfer out of the storage device

  uiMaxDisChaRteSF → INT

    > Maximum rate of energy transfer out of the storage device scaling factor

  wPad → WORD

    > Padding register

### StatePattern

#### StateEvents

FUNCTION_BLOCK I_SunspecStateEvents()
  METHOD Error()
  METHOD PowerSetpointChanged()
  PROPERTY sDescription
  METHOD Start()

#### States

FUNCTION_BLOCK FB_SunspecErrorState()
  METHOD Error()
  METHOD PowerSetpointChanged()
  PROPERTY sDescription
  METHOD Start()

FUNCTION_BLOCK FB_SunspecOffState()
  METHOD Error()
  METHOD PowerSetpointChanged()
  PROPERTY sDescription
  METHOD Start()