Search in sources :

Example 6 with ConfigException

use of io.openems.api.exception.ConfigException in project openems by OpenEMS.

the class FeneconProEss method defineModbusProtocol.

/*
	 * Methods
	 */
@Override
protected ModbusProtocol defineModbusProtocol() throws ConfigException {
    ModbusProtocol protokol = new ModbusProtocol(new // 
    ModbusRegisterRange(// 
    100, new // 
    UnsignedWordElement(// 
    100, systemState = // 
    new ModbusReadLongChannel("SystemState", this).label(0, // 
    STANDBY).label(1, // 
    "Start Off-Grid").label(2, // 
    START).label(3, // 
    FAULT).label(4, "Off-grid PV")), new // 
    UnsignedWordElement(// 
    101, controlMode = // 
    new ModbusReadLongChannel("ControlMode", this).label(1, // 
    "Remote").label(2, // 
    "Local")), new // 
    UnsignedWordElement(// 
    102, workMode = // 
    new ModbusReadLongChannel("WorkMode", this).label(2, // 
    "Economy").label(6, // 
    "Remote").label(8, // 
    "Timing")), // 
    new DummyElement(103), new // 
    UnsignedDoublewordElement(// 
    104, totalBatteryChargeEnergy = new ModbusReadLongChannel("TotalBatteryChargeEnergy", this).unit(// 
    "Wh")), new // 
    UnsignedDoublewordElement(// 
    106, totalBatteryDischargeEnergy = new ModbusReadLongChannel("TotalBatteryDischargeEnergy", this).unit(// 
    "Wh")), new // 
    UnsignedWordElement(// 
    108, batteryGroupState = // 
    new ModbusReadLongChannel("BatteryGroupState", this).label(0, // 
    "Initial").label(1, // 
    "Stop").label(2, // 
    "Starting").label(3, // 
    "Running").label(4, // 
    "Stopping").label(5, "Fail")), new // 
    UnsignedWordElement(// 
    109, soc = new ModbusReadLongChannel("Soc", this).unit("%").interval(0, 100)), new // 
    UnsignedWordElement(// 
    110, batteryVoltage = new ModbusReadLongChannel("BatteryVoltage", this).unit("mV").multiplier(2)), new // 
    SignedWordElement(// 
    111, batteryCurrent = new ModbusReadLongChannel("BatteryCurrent", this).unit("mA").multiplier(2)), new // 
    SignedWordElement(// 
    112, batteryPower = new ModbusReadLongChannel("BatteryPower", this).unit("W")), new UnsignedWordElement(113, // 
    new ModbusBitWrappingChannel("BatteryGroupAlarm", this, state).warningBit(0, // Fail, The system should be stopped
    WarningEss.FailTheSystemShouldBeStopped).warningBit(1, // Common low voltage alarm
    WarningEss.CommonLowVoltageAlarm).warningBit(2, // Common high voltage alarm
    WarningEss.CommonHighVoltageAlarm).warningBit(3, // Charging over current alarm
    WarningEss.ChargingOverCurrentAlarm).warningBit(4, // Discharging over current alarm
    WarningEss.DischargingOverCurrentAlarm).warningBit(5, // Over temperature alarm
    WarningEss.OverTemperatureAlarm).warningBit(6, // Interal communication abnormal
    WarningEss.InteralCommunicationAbnormal)), new // 
    UnsignedWordElement(// 
    114, pcsOperationState = new ModbusReadLongChannel("PcsOperationState", this).label(0, // 
    "Self-checking").label(1, // 
    "Standby").label(2, // 
    "Off grid PV").label(3, // 
    "Off grid").label(4, // 
    ON_GRID).label(5, // 
    "Fail").label(6, // 
    "bypass 1").label(7, "bypass 2")), // 
    new DummyElement(115, 117), new // 
    SignedWordElement(// 
    118, currentL1 = new ModbusReadLongChannel("CurrentL1", this).unit("mA").multiplier(2)), new // 
    SignedWordElement(// 
    119, currentL2 = new ModbusReadLongChannel("CurrentL2", this).unit("mA").multiplier(2)), new // 
    SignedWordElement(// 
    120, currentL3 = new ModbusReadLongChannel("CurrentL3", this).unit("mA").multiplier(2)), new // 
    UnsignedWordElement(// 
    121, voltageL1 = new ModbusReadLongChannel("VoltageL1", this).unit("mV").multiplier(2)), new // 
    UnsignedWordElement(// 
    122, voltageL2 = new ModbusReadLongChannel("VoltageL2", this).unit("mV").multiplier(2)), new // 
    UnsignedWordElement(// 
    123, voltageL3 = new ModbusReadLongChannel("VoltageL3", this).unit("mV").multiplier(2)), new // 
    SignedWordElement(// 
    124, activePowerL1 = new ModbusReadLongChannel("ActivePowerL1", this).unit("W")), new // 
    SignedWordElement(// 
    125, activePowerL2 = new ModbusReadLongChannel("ActivePowerL2", this).unit("W")), new // 
    SignedWordElement(// 
    126, activePowerL3 = new ModbusReadLongChannel("ActivePowerL3", this).unit("W")), new // 
    SignedWordElement(// 
    127, reactivePowerL1 = new ModbusReadLongChannel("ReactivePowerL1", this).unit("var")), new // 
    SignedWordElement(// 
    128, reactivePowerL2 = new ModbusReadLongChannel("ReactivePowerL2", this).unit("var")), new // 
    SignedWordElement(// 
    129, reactivePowerL3 = new ModbusReadLongChannel("ReactivePowerL3", this).unit("var")), new DummyElement(130), new // 
    UnsignedWordElement(// 
    131, frequencyL1 = new ModbusReadLongChannel("FrequencyL1", this).unit("mHz").multiplier(1)), new // 
    UnsignedWordElement(// 
    132, frequencyL2 = new ModbusReadLongChannel("FrequencyL2", this).unit("mHz").multiplier(1)), new // 
    UnsignedWordElement(// 
    133, frequencyL3 = new ModbusReadLongChannel("FrequencyL3", this).unit("mHz").multiplier(1)), new // 
    UnsignedWordElement(// 
    134, phaseAllowedApparent = new ModbusReadLongChannel("PhaseAllowedApparentPower", this).unit("VA")), new DummyElement(135, 140), new // 
    UnsignedWordElement(// 
    141, allowedCharge = new ModbusReadLongChannel("AllowedCharge", this).negate().unit("W")), new // 
    UnsignedWordElement(// 
    142, allowedDischarge = new ModbusReadLongChannel("AllowedDischarge", this).unit("W"))), new ModbusRegisterRange(150, new UnsignedWordElement(150, // 
    new ModbusBitWrappingChannel("PcsAlarm1L1", this, state).warningBit(0, // Grid undervoltage
    WarningEss.GridUndervoltageL1).warningBit(1, // Grid overvoltage
    WarningEss.GridOvervoltageL1).warningBit(2, // Grid under frequency
    WarningEss.GridUnderFrequencyL1).warningBit(3, // Grid over frequency
    WarningEss.GridOverFrequencyL1).warningBit(4, // Grid power supply off
    WarningEss.GridPowerSupplyOffL1).warningBit(5, // Grid condition unmeet
    WarningEss.GridConditionUnmeetL1).warningBit(6, // DC under voltage
    WarningEss.DCUnderVoltageL1).warningBit(7, // Input over resistance
    WarningEss.InputOverResistanceL1).warningBit(8, // Combination error
    WarningEss.CombinationErrorL1).warningBit(9, // Comm with inverter error
    WarningEss.CommWithInverterErrorL1).warningBit(10, // Tme error
    WarningEss.TmeErrorL1)), new UnsignedWordElement(151, new ModbusBitWrappingChannel("PcsAlarm2L1", this, state)), new UnsignedWordElement(152, // 
    new ModbusBitWrappingChannel("PcsFault1L1", this, state).faultBit(0, // Control current overload
    FaultEss.ControlCurrentOverload100PercentL1).faultBit(1, // Control current overload
    FaultEss.ControlCurrentOverload110PercentL1).faultBit(2, // Control current overload
    FaultEss.ControlCurrentOverload150PercentL1).faultBit(3, // Control current overload
    FaultEss.ControlCurrentOverload200PercentL1).faultBit(4, // Control current overload
    FaultEss.ControlCurrentOverload120PercentL1).faultBit(5, // Control current overload
    FaultEss.ControlCurrentOverload300PercentL1).faultBit(6, // Control transient load 300%
    FaultEss.ControlTransientLoad300PercentL1).faultBit(7, // Grid over current
    FaultEss.GridOverCurrentL1).faultBit(8, // Locking waveform too many times
    FaultEss.LockingWaveformTooManyTimesL1).faultBit(9, // Inverter voltage zero drift
    FaultEss.InverterVoltageZeroDriftErrorL1).faultBit(10, // Grid voltage zero drift error
    FaultEss.GridVoltageZeroDriftErrorL1).faultBit(11, // Control current zero drift
    FaultEss.ControlCurrentZeroDriftErrorL1).faultBit(12, // Inverter current zero drift
    FaultEss.InverterCurrentZeroDriftErrorL1).faultBit(13, // Grid current zero drift error
    FaultEss.GridCurrentZeroDriftErrorL1).faultBit(14, // PDP protection
    FaultEss.PDPProtectionL1).faultBit(15, // Hardware control current
    FaultEss.HardwareControlCurrentProtectionL1)), // protection
    new UnsignedWordElement(153, // 
    new ModbusBitWrappingChannel("PcsFault2L1", this, state).faultBit(0, // Hardware AC volt. protection
    FaultEss.HardwareACVoltageProtectionL1).faultBit(1, // Hardware DC curr. protection
    FaultEss.HardwareDCCurrentProtectionL1).faultBit(2, // Hardware temperature
    FaultEss.HardwareTemperatureProtectionL1).faultBit(3, // No capturing signal
    FaultEss.NoCapturingSignalL1).faultBit(4, // DC overvoltage
    FaultEss.DCOvervoltageL1).faultBit(5, // DC disconnected
    FaultEss.DCDisconnectedL1).faultBit(6, // Inverter undervoltage
    FaultEss.InverterUndervoltageL1).faultBit(7, // Inverter overvoltage
    FaultEss.InverterOvervoltageL1).faultBit(8, // Current sensor fail
    FaultEss.CurrentSensorFailL1).faultBit(9, // Voltage sensor fail
    FaultEss.VoltageSensorFailL1).faultBit(10, // Power uncontrollable
    FaultEss.PowerUncontrollableL1).faultBit(11, // Current uncontrollable
    FaultEss.CurrentUncontrollableL1).faultBit(12, // Fan error
    FaultEss.FanErrorL1).faultBit(13, // Phase lack
    FaultEss.PhaseLackL1).faultBit(14, // Inverter relay fault
    FaultEss.InverterRelayFaultL1).faultBit(15, // Grid relay fault
    FaultEss.GridRealyFaultL1)), new UnsignedWordElement(154, // 
    new ModbusBitWrappingChannel("PcsFault3L1", this, state).faultBit(0, // Control panel overtemp
    FaultEss.ControlPanelOvertempL1).faultBit(1, // Power panel overtemp
    FaultEss.PowerPanelOvertempL1).faultBit(2, // DC input overcurrent
    FaultEss.DCInputOvercurrentL1).faultBit(3, // Capacitor overtemp
    FaultEss.CapacitorOvertempL1).faultBit(4, // Radiator overtemp
    FaultEss.RadiatorOvertempL1).faultBit(5, // Transformer overtemp
    FaultEss.TransformerOvertempL1).faultBit(6, // Combination comm error
    FaultEss.CombinationCommErrorL1).faultBit(7, // EEPROM error
    FaultEss.EEPROMErrorL1).faultBit(8, // Load current zero drift error
    FaultEss.LoadCurrentZeroDriftErrorL1).faultBit(9, // Current limit-R error
    FaultEss.CurrentLimitRErrorL1).faultBit(10, // Phase sync error
    FaultEss.PhaseSyncErrorL1).faultBit(11, // External PV current zero
    FaultEss.ExternalPVCurrentZeroDriftErrorL1).faultBit(12, // External grid current
    FaultEss.ExternalGridCurrentZeroDriftErrorL1)), // zero drift error
    new UnsignedWordElement(155, // 
    new ModbusBitWrappingChannel("PcsAlarm1L2", this, state).warningBit(0, // Grid undervoltage
    WarningEss.GridUndervoltageL2).warningBit(1, // Grid overvoltage
    WarningEss.GridOvervoltageL2).warningBit(2, // Grid under frequency
    WarningEss.GridUnderFrequencyL2).warningBit(3, // Grid over frequency
    WarningEss.GridOverFrequencyL2).warningBit(4, // Grid power supply off
    WarningEss.GridPowerSupplyOffL2).warningBit(5, // Grid condition unmeet
    WarningEss.GridConditionUnmeetL2).warningBit(6, // DC under voltage
    WarningEss.DCUnderVoltageL2).warningBit(7, // Input over resistance
    WarningEss.InputOverResistanceL2).warningBit(8, // Combination error
    WarningEss.CombinationErrorL2).warningBit(9, // Comm with inverter error
    WarningEss.CommWithInverterErrorL2).warningBit(10, // Tme error
    WarningEss.TmeErrorL2)), new UnsignedWordElement(156, new ModbusBitWrappingChannel("PcsAlarm2L2", this, state)), new UnsignedWordElement(157, // 
    new ModbusBitWrappingChannel("PcsFault1L2", this, state).faultBit(0, // Control current overload
    FaultEss.ControlCurrentOverload100PercentL2).faultBit(1, // Control current overload
    FaultEss.ControlCurrentOverload110PercentL2).faultBit(2, // Control current overload
    FaultEss.ControlCurrentOverload150PercentL2).faultBit(3, // Control current overload
    FaultEss.ControlCurrentOverload200PercentL2).faultBit(4, // Control current overload
    FaultEss.ControlCurrentOverload120PercentL2).faultBit(5, // Control current overload
    FaultEss.ControlCurrentOverload300PercentL2).faultBit(6, // Control transient load 300%
    FaultEss.ControlTransientLoad300PercentL2).faultBit(7, // Grid over current
    FaultEss.GridOverCurrentL2).faultBit(8, // Locking waveform too many times
    FaultEss.LockingWaveformTooManyTimesL2).faultBit(9, // Inverter voltage zero drift
    FaultEss.InverterVoltageZeroDriftErrorL2).faultBit(10, // Grid voltage zero drift error
    FaultEss.GridVoltageZeroDriftErrorL2).faultBit(11, // Control current zero drift
    FaultEss.ControlCurrentZeroDriftErrorL2).faultBit(12, // Inverter current zero drift
    FaultEss.InverterCurrentZeroDriftErrorL2).faultBit(13, // Grid current zero drift error
    FaultEss.GridCurrentZeroDriftErrorL2).faultBit(14, // PDP protection
    FaultEss.PDPProtectionL2).faultBit(15, // Hardware control current
    FaultEss.HardwareControlCurrentProtectionL2)), // protection
    new UnsignedWordElement(158, // 
    new ModbusBitWrappingChannel("PcsFault2L2", this, state).faultBit(0, // Hardware AC volt. protection
    FaultEss.HardwareACVoltageProtectionL2).faultBit(1, // Hardware DC curr. protection
    FaultEss.HardwareDCCurrentProtectionL2).faultBit(2, // Hardware temperature
    FaultEss.HardwareTemperatureProtectionL2).faultBit(3, // No capturing signal
    FaultEss.NoCapturingSignalL2).faultBit(4, // DC overvoltage
    FaultEss.DCOvervoltageL2).faultBit(5, // DC disconnected
    FaultEss.DCDisconnectedL2).faultBit(6, // Inverter undervoltage
    FaultEss.InverterUndervoltageL2).faultBit(7, // Inverter overvoltage
    FaultEss.InverterOvervoltageL2).faultBit(8, // Current sensor fail
    FaultEss.CurrentSensorFailL2).faultBit(9, // Voltage sensor fail
    FaultEss.VoltageSensorFailL2).faultBit(10, // Power uncontrollable
    FaultEss.PowerUncontrollableL2).faultBit(11, // Current uncontrollable
    FaultEss.CurrentUncontrollableL2).faultBit(12, // Fan error
    FaultEss.FanErrorL2).faultBit(13, // Phase lack
    FaultEss.PhaseLackL2).faultBit(14, // Inverter relay fault
    FaultEss.InverterRelayFaultL2).faultBit(15, // Grid relay fault
    FaultEss.GridRealyFaultL2)), new UnsignedWordElement(159, // 
    new ModbusBitWrappingChannel("PcsFault3L2", this, state).faultBit(0, // Control panel overtemp
    FaultEss.ControlPanelOvertempL2).faultBit(1, // Power panel overtemp
    FaultEss.PowerPanelOvertempL2).faultBit(2, // DC input overcurrent
    FaultEss.DCInputOvercurrentL2).faultBit(3, // Capacitor overtemp
    FaultEss.CapacitorOvertempL2).faultBit(4, // Radiator overtemp
    FaultEss.RadiatorOvertempL2).faultBit(5, // Transformer overtemp
    FaultEss.TransformerOvertempL2).faultBit(6, // Combination comm error
    FaultEss.CombinationCommErrorL2).faultBit(7, // EEPROM error
    FaultEss.EEPROMErrorL2).faultBit(8, // Load current zero drift error
    FaultEss.LoadCurrentZeroDriftErrorL2).faultBit(9, // Current limit-R error
    FaultEss.CurrentLimitRErrorL2).faultBit(10, // Phase sync error
    FaultEss.PhaseSyncErrorL2).faultBit(11, // External PV current zero
    FaultEss.ExternalPVCurrentZeroDriftErrorL2).faultBit(12, // External grid current
    FaultEss.ExternalGridCurrentZeroDriftErrorL2)), // zero drift error
    new UnsignedWordElement(160, // 
    new ModbusBitWrappingChannel("PcsAlarm1L3", this, state).warningBit(0, // Grid undervoltage
    WarningEss.GridUndervoltageL3).warningBit(1, // Grid overvoltage
    WarningEss.GridOvervoltageL3).warningBit(2, // Grid under frequency
    WarningEss.GridUnderFrequencyL3).warningBit(3, // Grid over frequency
    WarningEss.GridOverFrequencyL3).warningBit(4, // Grid power supply off
    WarningEss.GridPowerSupplyOffL3).warningBit(5, // Grid condition unmeet
    WarningEss.GridConditionUnmeetL3).warningBit(6, // DC under voltage
    WarningEss.DCUnderVoltageL3).warningBit(7, // Input over resistance
    WarningEss.InputOverResistanceL3).warningBit(8, // Combination error
    WarningEss.CombinationErrorL3).warningBit(9, // Comm with inverter error
    WarningEss.CommWithInverterErrorL3).warningBit(10, // Tme error
    WarningEss.TmeErrorL3)), new UnsignedWordElement(161, new ModbusBitWrappingChannel("PcsAlarm2L3", this, state)), new UnsignedWordElement(162, // 
    new ModbusBitWrappingChannel("PcsFault1L3", this, state).faultBit(0, // Control current overload
    FaultEss.ControlCurrentOverload100PercentL3).faultBit(1, // Control current overload
    FaultEss.ControlCurrentOverload110PercentL3).faultBit(2, // Control current overload
    FaultEss.ControlCurrentOverload150PercentL3).faultBit(3, // Control current overload
    FaultEss.ControlCurrentOverload200PercentL3).faultBit(4, // Control current overload
    FaultEss.ControlCurrentOverload120PercentL3).faultBit(5, // Control current overload
    FaultEss.ControlCurrentOverload300PercentL3).faultBit(6, // Control transient load 300%
    FaultEss.ControlTransientLoad300PercentL3).faultBit(7, // Grid over current
    FaultEss.GridOverCurrentL3).faultBit(8, // Locking waveform too many times
    FaultEss.LockingWaveformTooManyTimesL3).faultBit(9, // Inverter voltage zero drift
    FaultEss.InverterVoltageZeroDriftErrorL3).faultBit(10, // Grid voltage zero drift error
    FaultEss.GridVoltageZeroDriftErrorL3).faultBit(11, // Control current zero drift
    FaultEss.ControlCurrentZeroDriftErrorL3).faultBit(12, // Inverter current zero drift
    FaultEss.InverterCurrentZeroDriftErrorL3).faultBit(13, // Grid current zero drift error
    FaultEss.GridCurrentZeroDriftErrorL3).faultBit(14, // PDP protection
    FaultEss.PDPProtectionL3).faultBit(15, // Hardware control current
    FaultEss.HardwareControlCurrentProtectionL3)), // protection
    new UnsignedWordElement(163, // 
    new ModbusBitWrappingChannel("PcsFault2L3", this, state).faultBit(0, // Hardware AC volt. protection
    FaultEss.HardwareACVoltageProtectionL3).faultBit(1, // Hardware DC curr. protection
    FaultEss.HardwareDCCurrentProtectionL3).faultBit(2, // Hardware temperature
    FaultEss.HardwareTemperatureProtectionL3).faultBit(3, // No capturing signal
    FaultEss.NoCapturingSignalL3).faultBit(4, // DC overvoltage
    FaultEss.DCOvervoltageL3).faultBit(5, // DC disconnected
    FaultEss.DCDisconnectedL3).faultBit(6, // Inverter undervoltage
    FaultEss.InverterUndervoltageL3).faultBit(7, // Inverter overvoltage
    FaultEss.InverterOvervoltageL3).faultBit(8, // Current sensor fail
    FaultEss.CurrentSensorFailL3).faultBit(9, // Voltage sensor fail
    FaultEss.VoltageSensorFailL3).faultBit(10, // Power uncontrollable
    FaultEss.PowerUncontrollableL3).faultBit(11, // Current uncontrollable
    FaultEss.CurrentUncontrollableL3).faultBit(12, // Fan error
    FaultEss.FanErrorL3).faultBit(13, // Phase lack
    FaultEss.PhaseLackL3).faultBit(14, // Inverter relay fault
    FaultEss.InverterRelayFaultL3).faultBit(15, // Grid relay fault
    FaultEss.GridRealyFaultL3)), new UnsignedWordElement(164, // 
    new ModbusBitWrappingChannel("PcsFault3L3", this, state).faultBit(0, // Control panel overtemp
    FaultEss.ControlPanelOvertempL3).faultBit(1, // Power panel overtemp
    FaultEss.PowerPanelOvertempL3).faultBit(2, // DC input overcurrent
    FaultEss.DCInputOvercurrentL3).faultBit(3, // Capacitor overtemp
    FaultEss.CapacitorOvertempL3).faultBit(4, // Radiator overtemp
    FaultEss.RadiatorOvertempL3).faultBit(5, // Transformer overtemp
    FaultEss.TransformerOvertempL3).faultBit(6, // Combination comm error
    FaultEss.CombinationCommErrorL3).faultBit(7, // EEPROM error
    FaultEss.EEPROMErrorL3).faultBit(8, // Load current zero drift error
    FaultEss.LoadCurrentZeroDriftErrorL3).faultBit(9, // Current limit-R error
    FaultEss.CurrentLimitRErrorL3).faultBit(10, // Phase sync error
    FaultEss.PhaseSyncErrorL3).faultBit(11, // External PV current zero
    FaultEss.ExternalPVCurrentZeroDriftErrorL3).faultBit(12, // External grid current
    FaultEss.ExternalGridCurrentZeroDriftErrorL3))), // zero drift error
    new // 
    WriteableModbusRegisterRange(// 
    200, new UnsignedWordElement(200, setWorkState = // 
    new ModbusWriteLongChannel("SetWorkState", this).label(0, // 
    "Local control").label(1, // "Remote control on grid starting"
    START).label(2, // 
    "Remote control off grid starting").label(3, // 
    STANDBY).label(4, STOP))), new // 
    WriteableModbusRegisterRange(// 
    206, new SignedWordElement(206, // 
    setActivePowerL1 = new ModbusWriteLongChannel("SetActivePowerL1", this).unit("W")), new SignedWordElement(207, setReactivePowerL1 = new ModbusWriteLongChannel("SetReactivePowerL1", this).unit(// 
    "Var")), new SignedWordElement(208, // 
    setActivePowerL2 = new ModbusWriteLongChannel("SetActivePowerL2", this).unit("W")), new SignedWordElement(209, setReactivePowerL2 = new ModbusWriteLongChannel("SetReactivePowerL2", this).unit(// 
    "Var")), new SignedWordElement(210, // 
    setActivePowerL3 = new ModbusWriteLongChannel("SetActivePowerL3", this).unit("W")), new SignedWordElement(211, // 
    setReactivePowerL3 = new ModbusWriteLongChannel("SetReactivePowerL3", this).unit("Var"))), // 
    new ModbusRegisterRange(3020, new UnsignedWordElement(3020, batteryVoltageSection1 = new ModbusReadLongChannel("BatteryVoltageSection1", this).unit("mV")), new UnsignedWordElement(3021, batteryVoltageSection2 = new ModbusReadLongChannel("BatteryVoltageSection2", this).unit("mV")), new UnsignedWordElement(3022, batteryVoltageSection3 = new ModbusReadLongChannel("BatteryVoltageSection3", this).unit("mV")), new UnsignedWordElement(3023, batteryVoltageSection4 = new ModbusReadLongChannel("BatteryVoltageSection4", this).unit("mV")), new UnsignedWordElement(3024, batteryVoltageSection5 = new ModbusReadLongChannel("BatteryVoltageSection5", this).unit("mV")), new UnsignedWordElement(3025, batteryVoltageSection6 = new ModbusReadLongChannel("BatteryVoltageSection6", this).unit("mV")), new UnsignedWordElement(3026, batteryVoltageSection7 = new ModbusReadLongChannel("BatteryVoltageSection7", this).unit("mV")), new UnsignedWordElement(3027, batteryVoltageSection8 = new ModbusReadLongChannel("BatteryVoltageSection8", this).unit("mV")), new UnsignedWordElement(3028, batteryVoltageSection9 = new ModbusReadLongChannel("BatteryVoltageSection9", this).unit("mV")), new UnsignedWordElement(3029, batteryVoltageSection10 = new ModbusReadLongChannel("BatteryVoltageSection10", this).unit("mV")), new UnsignedWordElement(3030, batteryVoltageSection11 = new ModbusReadLongChannel("BatteryVoltageSection11", this).unit("mV")), new UnsignedWordElement(3031, batteryVoltageSection12 = new ModbusReadLongChannel("BatteryVoltageSection12", this).unit("mV")), new UnsignedWordElement(3032, batteryVoltageSection13 = new ModbusReadLongChannel("BatteryVoltageSection13", this).unit("mV")), new UnsignedWordElement(3033, batteryVoltageSection14 = new ModbusReadLongChannel("BatteryVoltageSection14", this).unit("mV")), new UnsignedWordElement(3034, batteryVoltageSection15 = new ModbusReadLongChannel("BatteryVoltageSection15", this).unit("mV")), new UnsignedWordElement(3035, batteryVoltageSection16 = new ModbusReadLongChannel("BatteryVoltageSection16", this).unit("mV")), new UnsignedWordElement(3036, batteryTemperatureSection1 = new ModbusReadLongChannel("BatteryTemperatureSection1", this).unit("°C").delta(-40L)), new UnsignedWordElement(3037, batteryTemperatureSection2 = new ModbusReadLongChannel("BatteryTemperatureSection2", this).unit("°C").delta(-40L)), new UnsignedWordElement(3038, batteryTemperatureSection3 = new ModbusReadLongChannel("BatteryTemperatureSection3", this).unit("°C").delta(-40L)), new UnsignedWordElement(3039, batteryTemperatureSection4 = new ModbusReadLongChannel("BatteryTemperatureSection4", this).unit("°C").delta(-40L)), new UnsignedWordElement(3040, batteryTemperatureSection5 = new ModbusReadLongChannel("BatteryTemperatureSection5", this).unit("°C").delta(-40L)), new UnsignedWordElement(3041, batteryTemperatureSection6 = new ModbusReadLongChannel("BatteryTemperatureSection6", this).unit("°C").delta(-40L)), new UnsignedWordElement(3042, batteryTemperatureSection7 = new ModbusReadLongChannel("BatteryTemperatureSection7", this).unit("°C").delta(-40L)), new UnsignedWordElement(3043, batteryTemperatureSection8 = new ModbusReadLongChannel("BatteryTemperatureSection8", this).unit("°C").delta(-40L)), new UnsignedWordElement(3044, batteryTemperatureSection9 = new ModbusReadLongChannel("BatteryTemperatureSection9", this).unit("°C").delta(-40L)), new UnsignedWordElement(3045, batteryTemperatureSection10 = new ModbusReadLongChannel("BatteryTemperatureSection10", this).unit("°C").delta(-40L)), new UnsignedWordElement(3046, batteryTemperatureSection11 = new ModbusReadLongChannel("BatteryTemperatureSection11", this).unit("°C").delta(-40L)), new UnsignedWordElement(3047, batteryTemperatureSection12 = new ModbusReadLongChannel("BatteryTemperatureSection12", this).unit("°C").delta(-40L)), new UnsignedWordElement(3048, batteryTemperatureSection13 = new ModbusReadLongChannel("BatteryTemperatureSection13", this).unit("°C").delta(-40L)), new UnsignedWordElement(3049, batteryTemperatureSection14 = new ModbusReadLongChannel("BatteryTemperatureSection14", this).unit("°C").delta(-40L)), new UnsignedWordElement(3050, batteryTemperatureSection15 = new ModbusReadLongChannel("BatteryTemperatureSection15", this).unit("°C").delta(-40L)), new UnsignedWordElement(3051, batteryTemperatureSection16 = new ModbusReadLongChannel("BatteryTemperatureSection16", this).unit("°C").delta(-40L))), new // 
    WriteableModbusRegisterRange(// 
    9014, new UnsignedWordElement(9014, rtcYear = new ModbusWriteLongChannel("Year", this)), new UnsignedWordElement(9015, rtcMonth = new ModbusWriteLongChannel("Month", this)), new UnsignedWordElement(9016, rtcDay = new ModbusWriteLongChannel("Day", this)), new UnsignedWordElement(9017, rtcHour = new ModbusWriteLongChannel("Hour", this)), new UnsignedWordElement(9018, rtcMinute = new ModbusWriteLongChannel("Minute", this)), new UnsignedWordElement(9019, rtcSecond = new ModbusWriteLongChannel("Second", this))), new WriteableModbusRegisterRange(30558, new UnsignedWordElement(30558, setSetupMode = new ModbusWriteLongChannel("SetSetupMode", this).label(0, EssNature.OFF).label(1, EssNature.ON))), new WriteableModbusRegisterRange(30559, new UnsignedWordElement(30559, setPcsMode = // 
    new ModbusWriteLongChannel("SetPcsMode", this).label(0, // 
    "Emergency").label(1, // 
    "ConsumersPeakPattern").label(2, // 
    "Economic").label(3, // 
    "Eco").label(4, // 
    "Debug").label(5, // 
    "SmoothPv").label(6, "Remote"))), new ModbusRegisterRange(30157, new UnsignedWordElement(30157, setupMode = // 
    new ModbusReadLongChannel("SetupMode", this).label(0, // 
    EssNature.OFF).label(1, EssNature.ON)), new UnsignedWordElement(30158, pcsMode = // 
    new ModbusReadLongChannel("PcsMode", this).label(0, // 
    "Emergency").label(1, // 
    "ConsumersPeakPattern").label(2, // 
    "Economic").label(3, // 
    "Eco").label(4, // 
    "Debug").label(5, // 
    "SmoothPv").label(6, "Remote"))));
    gridMode = new FunctionalReadChannel<Long>("GridMode", this, (channels) -> {
        ReadChannel<Long> state = channels[0];
        try {
            if (state.value() == 1L) {
                return 0L;
            } else {
                return 1L;
            }
        } catch (InvalidValueException e) {
            return null;
        }
    }, systemState).label(0L, OFF_GRID).label(1L, ON_GRID);
    allowedApparent = new FunctionalReadChannel<Long>("AllowedApparent", this, (channels) -> {
        ReadChannel<Long> apparent = channels[0];
        try {
            return apparent.value() * 3;
        } catch (InvalidValueException e) {
            log.error(e.getMessage());
        }
        return 0l;
    }, phaseAllowedApparent);
    // FaultChannels
    state.addFaultChannel(new ValueToBooleanThingStateChannel(FaultEss.SystemFault, this, systemState, 3L));
    state.addFaultChannel(new ValueToBooleanThingStateChannel(FaultEss.BatteryFault, this, batteryGroupState, 5L));
    state.addFaultChannel(new ValueToBooleanThingStateChannel(FaultEss.PCSFault, this, pcsOperationState, 5L));
    // WarningChannels
    state.addWarningChannel(new ValueToBooleanThingStateChannel(WarningEss.OFFGrid, this, systemState, 1L));
    return protokol;
}
Also used : ReadChannel(io.openems.api.channel.ReadChannel) ModbusRegisterRange(io.openems.impl.protocol.modbus.internal.range.ModbusRegisterRange) ThingInfo(io.openems.api.doc.ThingInfo) AsymmetricEssNature(io.openems.api.device.nature.ess.AsymmetricEssNature) LoggerFactory(org.slf4j.LoggerFactory) WriteChannel(io.openems.api.channel.WriteChannel) ConfigChannel(io.openems.api.channel.ConfigChannel) EssNature(io.openems.api.device.nature.ess.EssNature) ChannelInfo(io.openems.api.doc.ChannelInfo) ModbusProtocol(io.openems.impl.protocol.modbus.internal.ModbusProtocol) ModbusBitWrappingChannel(io.openems.impl.protocol.modbus.ModbusBitWrappingChannel) ModbusReadLongChannel(io.openems.impl.protocol.modbus.ModbusReadLongChannel) ModbusWriteLongChannel(io.openems.impl.protocol.modbus.ModbusWriteLongChannel) UnsignedWordElement(io.openems.impl.protocol.modbus.internal.UnsignedWordElement) WriteableModbusRegisterRange(io.openems.impl.protocol.modbus.internal.range.WriteableModbusRegisterRange) RealTimeClockNature(io.openems.api.device.nature.realtimeclock.RealTimeClockNature) ValueToBooleanThingStateChannel(io.openems.api.channel.ValueToBooleanThingStateChannel) Logger(org.slf4j.Logger) ConfigException(io.openems.api.exception.ConfigException) FunctionalReadChannel(io.openems.api.channel.FunctionalReadChannel) UnsignedDoublewordElement(io.openems.impl.protocol.modbus.internal.UnsignedDoublewordElement) Device(io.openems.api.device.Device) ThingStateChannels(io.openems.api.channel.thingstate.ThingStateChannels) InvalidValueException(io.openems.api.exception.InvalidValueException) SignedWordElement(io.openems.impl.protocol.modbus.internal.SignedWordElement) ModbusDeviceNature(io.openems.impl.protocol.modbus.ModbusDeviceNature) StaticValueChannel(io.openems.api.channel.StaticValueChannel) DummyElement(io.openems.impl.protocol.modbus.internal.DummyElement) ModbusReadLongChannel(io.openems.impl.protocol.modbus.ModbusReadLongChannel) WriteableModbusRegisterRange(io.openems.impl.protocol.modbus.internal.range.WriteableModbusRegisterRange) ModbusWriteLongChannel(io.openems.impl.protocol.modbus.ModbusWriteLongChannel) ValueToBooleanThingStateChannel(io.openems.api.channel.ValueToBooleanThingStateChannel) ReadChannel(io.openems.api.channel.ReadChannel) FunctionalReadChannel(io.openems.api.channel.FunctionalReadChannel) InvalidValueException(io.openems.api.exception.InvalidValueException) DummyElement(io.openems.impl.protocol.modbus.internal.DummyElement) ModbusBitWrappingChannel(io.openems.impl.protocol.modbus.ModbusBitWrappingChannel) UnsignedWordElement(io.openems.impl.protocol.modbus.internal.UnsignedWordElement) UnsignedDoublewordElement(io.openems.impl.protocol.modbus.internal.UnsignedDoublewordElement) SignedWordElement(io.openems.impl.protocol.modbus.internal.SignedWordElement) ModbusProtocol(io.openems.impl.protocol.modbus.internal.ModbusProtocol) ModbusRegisterRange(io.openems.impl.protocol.modbus.internal.range.ModbusRegisterRange) WriteableModbusRegisterRange(io.openems.impl.protocol.modbus.internal.range.WriteableModbusRegisterRange)

Example 7 with ConfigException

use of io.openems.api.exception.ConfigException in project openems by OpenEMS.

the class Config method writeConfigFile.

/**
 * Writes the config file. Holds a backup config file and restores it on error. Method is executed asynchronously.
 *
 * @throws NotImplementedException
 */
public void writeConfigFile() throws NotImplementedException {
    // get config as json
    JsonObject jConfig = this.getJson(ConfigFormat.FILE, Role.ADMIN, "en");
    Runnable writeConfigRunnable = new Runnable() {

        @Override
        public void run() {
            Gson gson = new GsonBuilder().setPrettyPrinting().create();
            String config = gson.toJson(jConfig);
            /*
				 * create 'Latest Backup' of config file
				 */
            createConfigLatestBackup();
            try {
                /*
					 * write config file
					 */
                Files.write(configFile, config.getBytes(DEFAULT_CHARSET));
            } catch (IOException e) {
                ConfigException ex = new ConfigException("Unable to write config file [" + configFile.toString() + "]", e);
                log.error(ex.getMessage(), ex);
                try {
                    /*
						 * On error: recover 'Latest Backup' file
						 */
                    Files.copy(configLatestBackupFile, configFile, StandardCopyOption.REPLACE_EXISTING);
                } catch (IOException e2) {
                    ConfigException ex2 = new ConfigException("Unable to recover 'Latest Backup' [" + configLatestBackupFile.toString() + "]");
                    log.error(ex2.getMessage(), ex2);
                    try {
                        /*
							 * recover 'Working Backup' file
							 */
                        Files.copy(configWorkingBackupFile, configFile, StandardCopyOption.REPLACE_EXISTING);
                    } catch (IOException e3) {
                        ConfigException ex3 = new ConfigException("Unable to recover 'Working Backup' [" + configWorkingBackupFile.toString() + "]");
                        log.error(ex3.getMessage(), ex3);
                    }
                }
            }
        }
    };
    this.writeConfigExecutor.execute(writeConfigRunnable);
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) ConfigException(io.openems.api.exception.ConfigException) IOException(java.io.IOException)

Example 8 with ConfigException

use of io.openems.api.exception.ConfigException in project openems by OpenEMS.

the class FeneconProPvMeter method defineModbusProtocol.

@Override
protected ModbusProtocol defineModbusProtocol() throws ConfigException {
    ModbusProtocol protocol = new // 
    ModbusProtocol(new ModbusRegisterRange(121, new // 
    UnsignedWordElement(// 
    121, voltageL1 = new ModbusReadLongChannel("VoltageL1", this).unit("mV").multiplier(2)), new // 
    UnsignedWordElement(// 
    122, voltageL2 = new ModbusReadLongChannel("VoltageL2", this).unit("mV").multiplier(2)), new // 
    UnsignedWordElement(// 
    123, voltageL3 = new ModbusReadLongChannel("VoltageL3", this).unit("mV").multiplier(2))), new // 
    ModbusRegisterRange(// 
    2035, new // 
    UnsignedDoublewordElement(// 
    2035, activeEnergyL1 = new ModbusReadLongChannel("ActiveEnergyL1", this).unit("Wh").multiplier(2)), new DummyElement(2037, 2065), new // 
    UnsignedWordElement(// 
    2066, orginalActivePowerL1 = new ModbusReadLongChannel("OriginalActivePowerL1", this).unit("W").delta(10000L))), new // 
    ModbusRegisterRange(// 
    2135, new // 
    UnsignedDoublewordElement(// 
    2135, activeEnergyL2 = new ModbusReadLongChannel("ActiveEnergyL2", this).unit("Wh").multiplier(2)), new DummyElement(2137, 2165), new // 
    UnsignedWordElement(// 
    2166, orginalActivePowerL2 = new ModbusReadLongChannel("OriginalActivePowerL2", this).unit("W").delta(10000L))), new // 
    ModbusRegisterRange(// 
    2235, new // 
    UnsignedDoublewordElement(// 
    2235, activeEnergyL3 = new ModbusReadLongChannel("ActiveEnergyL3", this).unit("Wh").multiplier(2)), new DummyElement(2237, 2265), new // 
    UnsignedWordElement(// 
    2266, orginalActivePowerL3 = new ModbusReadLongChannel("OriginalActivePowerL3", this).unit("W").delta(10000L))));
    activePowerL1 = new FunctionalReadChannel<Long>("ActivePowerL1", this, (channels) -> {
        ReadChannel<Long> power = channels[0];
        try {
            if (power.value() >= 0) {
                this.negativePowerL1.setValue(false);
                return power.value();
            } else {
                this.negativePowerL1.setValue(true);
                return 0L;
            }
        } catch (InvalidValueException e) {
            return null;
        }
    }, orginalActivePowerL1);
    activePowerL2 = new FunctionalReadChannel<Long>("ActivePowerL2", this, (channels) -> {
        ReadChannel<Long> power = channels[0];
        try {
            if (power.value() >= 0) {
                this.negativePowerL2.setValue(false);
                return power.value();
            } else {
                this.negativePowerL2.setValue(true);
                return 0L;
            }
        } catch (InvalidValueException e) {
            return null;
        }
    }, orginalActivePowerL2);
    activePowerL3 = new FunctionalReadChannel<Long>("ActivePowerL3", this, (channels) -> {
        ReadChannel<Long> power = channels[0];
        try {
            if (power.value() >= 0) {
                this.negativePowerL3.setValue(false);
                return power.value();
            } else {
                this.negativePowerL3.setValue(true);
                return 0L;
            }
        } catch (InvalidValueException e) {
            return null;
        }
    }, orginalActivePowerL3);
    activePower = new FunctionalReadChannel<Long>("ActivePower", this, (channels) -> {
        ReadChannel<Long> L1 = channels[0];
        ReadChannel<Long> L2 = channels[1];
        ReadChannel<Long> L3 = channels[2];
        try {
            return L1.value() + L2.value() + L3.value();
        } catch (InvalidValueException e) {
            return null;
        }
    }, activePowerL1, activePowerL2, activePowerL3);
    reactivePower = new FunctionalReadChannel<Long>("ReactivePower", this, (channels) -> {
        ReadChannel<Long> L1 = channels[0];
        ReadChannel<Long> L2 = channels[1];
        ReadChannel<Long> L3 = channels[2];
        try {
            return L1.value() + L2.value() + L3.value();
        } catch (InvalidValueException e) {
            return null;
        }
    }, reactivePowerL1, reactivePowerL2, reactivePowerL3);
    return protocol;
}
Also used : ReadChannel(io.openems.api.channel.ReadChannel) ModbusRegisterRange(io.openems.impl.protocol.modbus.internal.range.ModbusRegisterRange) ThingInfo(io.openems.api.doc.ThingInfo) ConfigException(io.openems.api.exception.ConfigException) StaticThingStateChannel(io.openems.api.channel.StaticThingStateChannel) FunctionalReadChannel(io.openems.api.channel.FunctionalReadChannel) UnsignedDoublewordElement(io.openems.impl.protocol.modbus.internal.UnsignedDoublewordElement) ConfigChannel(io.openems.api.channel.ConfigChannel) Device(io.openems.api.device.Device) ModbusProtocol(io.openems.impl.protocol.modbus.internal.ModbusProtocol) ThingStateChannels(io.openems.api.channel.thingstate.ThingStateChannels) SymmetricMeterNature(io.openems.api.device.nature.meter.SymmetricMeterNature) ModbusReadChannel(io.openems.impl.protocol.modbus.ModbusReadChannel) AsymmetricMeterNature(io.openems.api.device.nature.meter.AsymmetricMeterNature) InvalidValueException(io.openems.api.exception.InvalidValueException) ModbusDeviceNature(io.openems.impl.protocol.modbus.ModbusDeviceNature) ModbusReadLongChannel(io.openems.impl.protocol.modbus.ModbusReadLongChannel) DummyElement(io.openems.impl.protocol.modbus.internal.DummyElement) UnsignedWordElement(io.openems.impl.protocol.modbus.internal.UnsignedWordElement) InvalidValueException(io.openems.api.exception.InvalidValueException) ModbusReadLongChannel(io.openems.impl.protocol.modbus.ModbusReadLongChannel) DummyElement(io.openems.impl.protocol.modbus.internal.DummyElement) UnsignedWordElement(io.openems.impl.protocol.modbus.internal.UnsignedWordElement) UnsignedDoublewordElement(io.openems.impl.protocol.modbus.internal.UnsignedDoublewordElement) ModbusProtocol(io.openems.impl.protocol.modbus.internal.ModbusProtocol) ModbusRegisterRange(io.openems.impl.protocol.modbus.internal.range.ModbusRegisterRange) ReadChannel(io.openems.api.channel.ReadChannel) FunctionalReadChannel(io.openems.api.channel.FunctionalReadChannel) ModbusReadChannel(io.openems.impl.protocol.modbus.ModbusReadChannel)

Example 9 with ConfigException

use of io.openems.api.exception.ConfigException in project openems by OpenEMS.

the class FeneconMiniEss method defineModbusProtocol.

/*
	 * Methods
	 */
@Override
protected ModbusProtocol defineModbusProtocol() throws ConfigException {
    ModbusProtocol protokol = new ModbusProtocol(new // 
    ModbusRegisterRange(// 
    100, new // 
    UnsignedWordElement(// 
    100, systemState = // 
    new ModbusReadLongChannel("SystemState", this).label(0, // 
    STANDBY).label(1, // 
    "Start Off-Grid").label(2, // 
    START).label(3, // 
    FAULT).label(4, "Off-grid PV")), new // 
    UnsignedWordElement(// 
    101, controlMode = // 
    new ModbusReadLongChannel("ControlMode", this).label(1, // 
    "Remote").label(2, // 
    "Local")), // 
    new DummyElement(102, 103), new // 
    UnsignedDoublewordElement(// 
    104, totalBatteryChargeEnergy = new ModbusReadLongChannel("TotalBatteryChargeEnergy", this).unit(// 
    "Wh")), new // 
    UnsignedDoublewordElement(// 
    106, totalBatteryDischargeEnergy = new ModbusReadLongChannel("TotalBatteryDischargeEnergy", this).unit(// 
    "Wh")), new // 
    UnsignedWordElement(// 
    108, batteryGroupState = // 
    new ModbusReadLongChannel("BatteryGroupState", this).label(0, // 
    "Initial").label(1, // 
    "Stop").label(2, // 
    "Starting").label(3, // 
    "Running").label(4, // 
    "Stopping").label(5, "Fail")), new // 
    UnsignedWordElement(// 
    109, soc = new ModbusReadLongChannel("Soc", this).unit("%").interval(0, 100)), new // 
    UnsignedWordElement(// 
    110, batteryVoltage = new ModbusReadLongChannel("BatteryVoltage", this).unit("mV").multiplier(2)), new // 
    SignedWordElement(// 
    111, batteryCurrent = new ModbusReadLongChannel("BatteryCurrent", this).unit("mA").multiplier(2)), new // 
    SignedWordElement(// 
    112, batteryPower = new ModbusReadLongChannel("BatteryPower", this).unit("W")), new // 
    UnsignedWordElement(// 
    113, // 
    new ModbusBitWrappingChannel("BatteryGroupAlarm", this, this.thingState).warningBit(0, // 
    WarningEss.FailTheSystemShouldBeStopped).warningBit(1, // 
    WarningEss.CommonLowVoltageAlarm).warningBit(2, // 
    WarningEss.CommonHighVoltageAlarm).warningBit(3, // 
    WarningEss.ChargingOverCurrentAlarm).warningBit(4, // 
    WarningEss.DischargingOverCurrentAlarm).warningBit(5, // 
    WarningEss.OverTemperatureAlarm).warningBit(6, // 
    WarningEss.InteralCommunicationAbnormal)), new // 
    UnsignedWordElement(// 
    114, pcsOperationState = new ModbusReadLongChannel("PcsOperationState", this).label(0, // 
    "Self-checking").label(1, // 
    "Standby").label(2, // 
    "Off grid PV").label(3, // 
    "Off grid").label(4, // 
    ON_GRID).label(5, // 
    "Fail").label(6, // 
    "bypass 1").label(7, "bypass 2")), // 
    new DummyElement(115, 117), new // 
    SignedWordElement(// 
    118, current = new ModbusReadLongChannel("Current", this).unit("mA").multiplier(2)), new DummyElement(119, 120), new // 
    UnsignedWordElement(// 
    121, voltage = new ModbusReadLongChannel("Voltage", this).unit("mV").multiplier(2)), new DummyElement(122, 123), new // 
    SignedWordElement(// 
    124, activePower = new ModbusReadLongChannel("ActivePower", this).unit("W")), new DummyElement(125, 126), new // 
    SignedWordElement(// 
    127, reactivePower = new ModbusReadLongChannel("ReactivePower", this).unit("var")), new DummyElement(128, 130), new // 
    UnsignedWordElement(// 
    131, frequency = new ModbusReadLongChannel("Frequency", this).unit("mHz").multiplier(1)), new DummyElement(132, 133), new // 
    UnsignedWordElement(// 
    134, phaseAllowedApparent = new ModbusReadLongChannel("PhaseAllowedApparentPower", this).unit("VA")), new DummyElement(135, 140), new // 
    UnsignedWordElement(// 
    141, allowedCharge = new ModbusReadLongChannel("AllowedCharge", this).unit("W").negate()), new // 
    UnsignedWordElement(// 
    142, allowedDischarge = new ModbusReadLongChannel("AllowedDischarge", this).unit("W")), new DummyElement(143, 149), new // 
    UnsignedWordElement(// 
    150, // 
    new ModbusBitWrappingChannel("PcsAlarm1", this, this.thingState).warningBit(0, // 
    WarningEss.GridUndervoltage).warningBit(1, // 
    WarningEss.GridOvervoltage).warningBit(2, // 
    WarningEss.GridUnderFrequency).warningBit(3, // 
    WarningEss.GridOverFrequency).warningBit(4, // 
    WarningEss.GridPowerSupplyOff).warningBit(5, // 
    WarningEss.GridConditionUnmeet).warningBit(6, // 
    WarningEss.DCUnderVoltage).warningBit(7, // 
    WarningEss.InputOverResistance).warningBit(8, // 
    WarningEss.CombinationError).warningBit(9, // 
    WarningEss.CommWithInverterError).warningBit(10, // 
    WarningEss.TmeError)), new UnsignedWordElement(151, // 
    new ModbusBitWrappingChannel("PcsAlarm2", this, this.thingState)), new UnsignedWordElement(152, // 
    new ModbusBitWrappingChannel("PcsFault1", this, this.thingState).faultBit(0, // 
    FaultEss.ControlCurrentOverload100Percent).faultBit(1, // 
    FaultEss.ControlCurrentOverload110Percent).faultBit(2, // 
    FaultEss.ControlCurrentOverload150Percent).faultBit(3, // 
    FaultEss.ControlCurrentOverload200Percent).faultBit(4, // 
    FaultEss.ControlCurrentOverload120Percent).faultBit(5, // 
    FaultEss.ControlCurrentOverload300Percent).faultBit(6, // 
    FaultEss.ControlTransientLoad300Percent).faultBit(7, // 
    FaultEss.GridOverCurrent).faultBit(8, // 
    FaultEss.LockingWaveformTooManyTimes).faultBit(9, // 
    FaultEss.InverterVoltageZeroDriftError).faultBit(10, // 
    FaultEss.GridVoltageZeroDriftError).faultBit(11, // 
    FaultEss.ControlCurrentZeroDriftError).faultBit(12, // 
    FaultEss.InverterCurrentZeroDriftError).faultBit(13, // 
    FaultEss.GridCurrentZeroDriftError).faultBit(14, // 
    FaultEss.PDPProtection).faultBit(15, // 
    FaultEss.HardwareControlCurrentProtection)), new // 
    UnsignedWordElement(// 
    153, // 
    new ModbusBitWrappingChannel("PcsFault2", this, this.thingState).faultBit(0, // 
    FaultEss.HardwareACVoltProtection).faultBit(1, // 
    FaultEss.HardwareDCCurrentProtection).faultBit(2, // 
    FaultEss.HardwareTemperatureProtection).faultBit(3, // 
    FaultEss.NoCapturingSignal).faultBit(4, // 
    FaultEss.DCOvervoltage).faultBit(5, // 
    FaultEss.DCDisconnected).faultBit(6, // 
    FaultEss.InverterUndervoltage).faultBit(7, // 
    FaultEss.InverterOvervoltage).faultBit(8, // 
    FaultEss.CurrentSensorFail).faultBit(9, // 
    FaultEss.VoltageSensorFail).faultBit(10, // 
    FaultEss.PowerUncontrollable).faultBit(11, // 
    FaultEss.CurrentUncontrollable).faultBit(12, // 
    FaultEss.FanError).faultBit(13, // 
    FaultEss.PhaseLack).faultBit(14, // 
    FaultEss.InverterRelayFault).faultBit(15, // 
    FaultEss.GridRelayFault)), new // 
    UnsignedWordElement(// 
    154, // 
    new ModbusBitWrappingChannel("PcsFault3", this, this.thingState).faultBit(0, // 
    FaultEss.ControlPanelOvertemp).faultBit(1, // 
    FaultEss.PowerPanelOvertemp).faultBit(2, // 
    FaultEss.DCInputOvercurrent).faultBit(3, // 
    FaultEss.CapacitorOvertemp).faultBit(4, // 
    FaultEss.RadiatorOvertemp).faultBit(5, // 
    FaultEss.TransformerOvertemp).faultBit(6, // 
    FaultEss.CombinationCommError).faultBit(7, // 
    FaultEss.EEPROMError).faultBit(8, // 
    FaultEss.LoadCurrentZeroDriftError).faultBit(9, // 
    FaultEss.CurrentLimitRError).faultBit(10, // 
    FaultEss.PhaseSyncError).faultBit(11, // 
    FaultEss.ExternalPVCurrentZeroDriftError).faultBit(12, // 
    FaultEss.ExternalGridCurrentZeroDriftError))), new // 
    WriteableModbusRegisterRange(// 
    200, new UnsignedWordElement(200, setWorkState = // 
    new ModbusWriteLongChannel("SetWorkState", this).label(0, // 
    "Local control").label(1, // "Remote control on grid starting"
    START).label(2, // 
    "Remote control off grid starting").label(3, // 
    STOP).label(4, "Emergency Stop"))), new // 
    WriteableModbusRegisterRange(// 
    201, new SignedWordElement(201, // 
    setActivePower = new ModbusWriteLongChannel("SetActivePower", this).unit("W")), new SignedWordElement(202, // 
    setReactivePower = new ModbusWriteLongChannel("SetReactivePower", this).unit("Var"))), new // 
    WriteableModbusRegisterRange(// 
    9014, new UnsignedWordElement(9014, rtcYear = new ModbusWriteLongChannel("Year", this)), new UnsignedWordElement(9015, rtcMonth = new ModbusWriteLongChannel("Month", this)), new UnsignedWordElement(9016, rtcDay = new ModbusWriteLongChannel("Day", this)), new UnsignedWordElement(9017, rtcHour = new ModbusWriteLongChannel("Hour", this)), new UnsignedWordElement(9018, rtcMinute = new ModbusWriteLongChannel("Minute", this)), new UnsignedWordElement(9019, rtcSecond = new ModbusWriteLongChannel("Second", this))), new WriteableModbusRegisterRange(30558, new UnsignedWordElement(30558, setSetupMode = new ModbusWriteLongChannel("SetSetupMode", this).label(0, EssNature.OFF).label(1, EssNature.ON))), new WriteableModbusRegisterRange(30559, new UnsignedWordElement(30559, setPcsMode = // 
    new ModbusWriteLongChannel("SetPcsMode", this).label(0, // 
    "Emergency").label(1, // 
    "ConsumersPeakPattern").label(2, // 
    "Economic").label(3, // 
    "Eco").label(4, // 
    "Debug").label(5, // 
    "SmoothPv").label(6, "Remote"))), new ModbusRegisterRange(30157, new UnsignedWordElement(30157, setupMode = // 
    new ModbusReadLongChannel("SetupMode", this).label(0, // 
    EssNature.OFF).label(1, EssNature.ON)), new UnsignedWordElement(30158, pcsMode = // 
    new ModbusReadLongChannel("PcsMode", this).label(0, // 
    "Emergency").label(1, // 
    "ConsumersPeakPattern").label(2, // 
    "Economic").label(3, // 
    "Eco").label(4, // 
    "Debug").label(5, // 
    "SmoothPv").label(6, "Remote"))));
    gridMode = new FunctionalReadChannel<Long>("GridMode", this, (channels) -> {
        ReadChannel<Long> state = channels[0];
        try {
            if (state.value() == 1L) {
                return 0L;
            } else {
                return 1L;
            }
        } catch (InvalidValueException e) {
            return null;
        }
    }, systemState).label(0L, OFF_GRID).label(1L, ON_GRID);
    apparentPower = new FunctionalReadChannel<Long>("ApparentPower", this, (channels) -> {
        ReadChannel<Long> activePower = channels[0];
        ReadChannel<Long> reactivePower = channels[1];
        try {
            return ControllerUtils.calculateApparentPower(activePower.value(), reactivePower.value());
        } catch (InvalidValueException e) {
            log.error("failed to calculate apparentPower. some value is missing.", e);
        }
        return 0l;
    }, activePower, reactivePower);
    this.power = new SymmetricPowerImpl(3000, setActivePower, setReactivePower, getParent().getBridge());
    this.allowedApparentLimit = new SMaxLimitation(power);
    this.allowedApparentLimit.setSMax(phaseAllowedApparent.valueOptional().orElse(0L) * 3, 0L, 0L);
    this.phaseAllowedApparent.addChangeListener(new ChannelChangeListener() {

        @Override
        public void channelChanged(Channel channel, Optional<?> newValue, Optional<?> oldValue) {
            allowedApparentLimit.setSMax(phaseAllowedApparent.valueOptional().orElse(0L) * 3, 0L, 0L);
        }
    });
    this.power.addStaticLimitation(this.allowedApparentLimit);
    this.allowedChargeLimit = new PGreaterEqualLimitation(power);
    this.allowedChargeLimit.setP(this.allowedCharge.valueOptional().orElse(0L));
    this.allowedCharge.addChangeListener(new ChannelChangeListener() {

        @Override
        public void channelChanged(Channel channel, Optional<?> newValue, Optional<?> oldValue) {
            allowedChargeLimit.setP(allowedCharge.valueOptional().orElse(0L));
        }
    });
    this.power.addStaticLimitation(this.allowedChargeLimit);
    this.allowedDischargeLimit = new PSmallerEqualLimitation(power);
    this.allowedDischargeLimit.setP(this.allowedDischarge.valueOptional().orElse(0L));
    this.allowedDischarge.addChangeListener(new ChannelChangeListener() {

        @Override
        public void channelChanged(Channel channel, Optional<?> newValue, Optional<?> oldValue) {
            allowedDischargeLimit.setP(allowedDischarge.valueOptional().orElse(0L));
        }
    });
    return protokol;
}
Also used : ReadChannel(io.openems.api.channel.ReadChannel) ModbusRegisterRange(io.openems.impl.protocol.modbus.internal.range.ModbusRegisterRange) ThingInfo(io.openems.api.doc.ThingInfo) PGreaterEqualLimitation(io.openems.core.utilities.power.symmetric.PGreaterEqualLimitation) LoggerFactory(org.slf4j.LoggerFactory) WriteChannel(io.openems.api.channel.WriteChannel) PSmallerEqualLimitation(io.openems.core.utilities.power.symmetric.PSmallerEqualLimitation) ConfigChannel(io.openems.api.channel.ConfigChannel) EssNature(io.openems.api.device.nature.ess.EssNature) ChannelChangeListener(io.openems.api.channel.ChannelChangeListener) ModbusProtocol(io.openems.impl.protocol.modbus.internal.ModbusProtocol) SMaxLimitation(io.openems.core.utilities.power.symmetric.SMaxLimitation) ModbusBitWrappingChannel(io.openems.impl.protocol.modbus.ModbusBitWrappingChannel) ModbusReadLongChannel(io.openems.impl.protocol.modbus.ModbusReadLongChannel) ModbusWriteLongChannel(io.openems.impl.protocol.modbus.ModbusWriteLongChannel) UnsignedWordElement(io.openems.impl.protocol.modbus.internal.UnsignedWordElement) WriteableModbusRegisterRange(io.openems.impl.protocol.modbus.internal.range.WriteableModbusRegisterRange) RealTimeClockNature(io.openems.api.device.nature.realtimeclock.RealTimeClockNature) SymmetricPowerImpl(io.openems.core.utilities.power.symmetric.SymmetricPowerImpl) Logger(org.slf4j.Logger) SymmetricEssNature(io.openems.api.device.nature.ess.SymmetricEssNature) StatusBitChannel(io.openems.api.channel.StatusBitChannel) ConfigException(io.openems.api.exception.ConfigException) FunctionalReadChannel(io.openems.api.channel.FunctionalReadChannel) UnsignedDoublewordElement(io.openems.impl.protocol.modbus.internal.UnsignedDoublewordElement) ControllerUtils(io.openems.core.utilities.ControllerUtils) Device(io.openems.api.device.Device) ThingStateChannels(io.openems.api.channel.thingstate.ThingStateChannels) InvalidValueException(io.openems.api.exception.InvalidValueException) SignedWordElement(io.openems.impl.protocol.modbus.internal.SignedWordElement) ModbusDeviceNature(io.openems.impl.protocol.modbus.ModbusDeviceNature) Optional(java.util.Optional) StaticValueChannel(io.openems.api.channel.StaticValueChannel) DummyElement(io.openems.impl.protocol.modbus.internal.DummyElement) Channel(io.openems.api.channel.Channel) SMaxLimitation(io.openems.core.utilities.power.symmetric.SMaxLimitation) ReadChannel(io.openems.api.channel.ReadChannel) FunctionalReadChannel(io.openems.api.channel.FunctionalReadChannel) InvalidValueException(io.openems.api.exception.InvalidValueException) PGreaterEqualLimitation(io.openems.core.utilities.power.symmetric.PGreaterEqualLimitation) ModbusBitWrappingChannel(io.openems.impl.protocol.modbus.ModbusBitWrappingChannel) UnsignedWordElement(io.openems.impl.protocol.modbus.internal.UnsignedWordElement) ChannelChangeListener(io.openems.api.channel.ChannelChangeListener) SignedWordElement(io.openems.impl.protocol.modbus.internal.SignedWordElement) PSmallerEqualLimitation(io.openems.core.utilities.power.symmetric.PSmallerEqualLimitation) ModbusReadLongChannel(io.openems.impl.protocol.modbus.ModbusReadLongChannel) WriteableModbusRegisterRange(io.openems.impl.protocol.modbus.internal.range.WriteableModbusRegisterRange) ReadChannel(io.openems.api.channel.ReadChannel) WriteChannel(io.openems.api.channel.WriteChannel) ConfigChannel(io.openems.api.channel.ConfigChannel) ModbusBitWrappingChannel(io.openems.impl.protocol.modbus.ModbusBitWrappingChannel) ModbusReadLongChannel(io.openems.impl.protocol.modbus.ModbusReadLongChannel) ModbusWriteLongChannel(io.openems.impl.protocol.modbus.ModbusWriteLongChannel) StatusBitChannel(io.openems.api.channel.StatusBitChannel) FunctionalReadChannel(io.openems.api.channel.FunctionalReadChannel) StaticValueChannel(io.openems.api.channel.StaticValueChannel) Channel(io.openems.api.channel.Channel) ModbusWriteLongChannel(io.openems.impl.protocol.modbus.ModbusWriteLongChannel) DummyElement(io.openems.impl.protocol.modbus.internal.DummyElement) SymmetricPowerImpl(io.openems.core.utilities.power.symmetric.SymmetricPowerImpl) UnsignedDoublewordElement(io.openems.impl.protocol.modbus.internal.UnsignedDoublewordElement) ModbusProtocol(io.openems.impl.protocol.modbus.internal.ModbusProtocol) ModbusRegisterRange(io.openems.impl.protocol.modbus.internal.range.ModbusRegisterRange) WriteableModbusRegisterRange(io.openems.impl.protocol.modbus.internal.range.WriteableModbusRegisterRange)

Example 10 with ConfigException

use of io.openems.api.exception.ConfigException in project openems by OpenEMS.

the class TimelineChargeController method higherSoc.

private Map.Entry<LocalTime, Integer> higherSoc(JsonArray jHours, LocalTime time) throws ConfigException {
    // fill times map; sorted by hour
    try {
        TreeMap<LocalTime, Integer> times = new TreeMap<>();
        for (JsonElement jHourElement : jHours) {
            JsonObject jHour = JsonUtils.getAsJsonObject(jHourElement);
            String hourTime = JsonUtils.getAsString(jHour, "time");
            int jsoc = JsonUtils.getAsInt(jHourElement, "soc");
            times.put(LocalTime.parse(hourTime), jsoc);
        }
        // return matching controllers
        if (times.higherEntry(time) != null) {
            return times.higherEntry(time);
        } else {
            throw new IndexOutOfBoundsException("No smaller time found");
        }
    } catch (OpenemsException e) {
        throw new ConfigException("cant read config", e);
    }
}
Also used : LocalTime(java.time.LocalTime) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) ConfigException(io.openems.api.exception.ConfigException) OpenemsException(io.openems.common.exceptions.OpenemsException) TreeMap(java.util.TreeMap)

Aggregations

ConfigException (io.openems.api.exception.ConfigException)16 InvalidValueException (io.openems.api.exception.InvalidValueException)6 JsonObject (com.google.gson.JsonObject)4 ConfigChannel (io.openems.api.channel.ConfigChannel)4 FunctionalReadChannel (io.openems.api.channel.FunctionalReadChannel)4 ReadChannel (io.openems.api.channel.ReadChannel)4 ThingStateChannels (io.openems.api.channel.thingstate.ThingStateChannels)4 Device (io.openems.api.device.Device)4 ThingInfo (io.openems.api.doc.ThingInfo)4 ModbusDeviceNature (io.openems.impl.protocol.modbus.ModbusDeviceNature)4 ModbusReadLongChannel (io.openems.impl.protocol.modbus.ModbusReadLongChannel)4 DummyElement (io.openems.impl.protocol.modbus.internal.DummyElement)4 ModbusProtocol (io.openems.impl.protocol.modbus.internal.ModbusProtocol)4 UnsignedDoublewordElement (io.openems.impl.protocol.modbus.internal.UnsignedDoublewordElement)4 UnsignedWordElement (io.openems.impl.protocol.modbus.internal.UnsignedWordElement)4 ModbusRegisterRange (io.openems.impl.protocol.modbus.internal.range.ModbusRegisterRange)4 IOException (java.io.IOException)4 LocalTime (java.time.LocalTime)4 JsonArray (com.google.gson.JsonArray)3 JsonElement (com.google.gson.JsonElement)3