Search in sources :

Example 16 with InvalidValueException

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

the class MeterClusterNature method update.

@Override
protected void update() {
    Long activePower = null;
    Long activePowerL1 = null;
    Long activePowerL2 = null;
    Long activePowerL3 = null;
    Long reactivePower = null;
    Long reactivePowerL1 = null;
    Long reactivePowerL2 = null;
    Long reactivePowerL3 = null;
    Long voltage = null;
    Long voltageL1 = null;
    Long voltageL2 = null;
    Long voltageL3 = null;
    synchronized (asymmetricMeterList) {
        for (AsymmetricMeterNature meter : asymmetricMeterList) {
            if (meter.activePowerL1().valueOptional().isPresent()) {
                if (activePower == null) {
                    activePower = 0L;
                }
                if (activePowerL1 == null) {
                    activePowerL1 = 0L;
                }
                activePower += meter.activePowerL1().valueOptional().get();
                activePowerL1 += meter.activePowerL1().valueOptional().get();
            } else {
                log.warn(meter.id() + ": activePowerL1 is invalid!");
            }
            if (meter.activePowerL2().valueOptional().isPresent()) {
                if (activePower == null) {
                    activePower = 0L;
                }
                if (activePowerL2 == null) {
                    activePowerL2 = 0L;
                }
                activePower += meter.activePowerL2().valueOptional().get();
                activePowerL2 += meter.activePowerL2().valueOptional().get();
            } else {
                log.warn(meter.id() + ": activePowerL2 is invalid!");
            }
            if (meter.activePowerL3().valueOptional().isPresent()) {
                if (activePower == null) {
                    activePower = 0L;
                }
                if (activePowerL3 == null) {
                    activePowerL3 = 0L;
                }
                activePower += meter.activePowerL3().valueOptional().get();
                activePowerL3 += meter.activePowerL3().valueOptional().get();
            } else {
                log.warn(meter.id() + ": activePowerL3 is invalid!");
            }
            if (meter.reactivePowerL1().valueOptional().isPresent()) {
                if (reactivePower == null) {
                    reactivePower = 0L;
                }
                if (reactivePowerL1 == null) {
                    reactivePowerL1 = 0L;
                }
                reactivePower += meter.reactivePowerL1().valueOptional().get();
                reactivePowerL1 += meter.reactivePowerL1().valueOptional().get();
            } else {
                log.warn(meter.id() + ": reactivePowerL1 is invalid!");
            }
            if (meter.reactivePowerL2().valueOptional().isPresent()) {
                if (reactivePower == null) {
                    reactivePower = 0L;
                }
                if (reactivePowerL2 == null) {
                    reactivePowerL2 = 0L;
                }
                reactivePower += meter.reactivePowerL2().valueOptional().get();
                reactivePowerL2 += meter.reactivePowerL2().valueOptional().get();
            } else {
                log.warn(meter.id() + ": reactivePowerL2 is invalid!");
            }
            if (meter.reactivePowerL3().valueOptional().isPresent()) {
                if (reactivePower == null) {
                    reactivePower = 0L;
                }
                if (reactivePowerL3 == null) {
                    reactivePowerL3 = 0L;
                }
                reactivePower += meter.reactivePowerL3().valueOptional().get();
                reactivePowerL3 += meter.reactivePowerL3().valueOptional().get();
            } else {
                log.warn(meter.id() + ": reactivePowerL3 is invalid!");
            }
            try {
                if (voltage == null) {
                    voltage = meter.voltageL1().value();
                }
                if (voltageL1 == null) {
                    voltageL1 = meter.voltageL1().value();
                }
            } catch (InvalidValueException e) {
                log.warn(meter.id() + ": voltageL1 is invalid!");
            }
            try {
                if (voltage == null) {
                    voltage = meter.voltageL2().value();
                }
                if (voltageL2 == null) {
                    voltageL2 = meter.voltageL2().value();
                }
            } catch (InvalidValueException e) {
                log.warn(meter.id() + ": voltageL2 is invalid!");
            }
            try {
                if (voltage == null) {
                    voltage = meter.voltageL3().value();
                }
                if (voltageL3 == null) {
                    voltageL3 = meter.voltageL3().value();
                }
            } catch (InvalidValueException e) {
                log.warn(meter.id() + ": voltageL3 is invalid!");
            }
        }
    }
    synchronized (symmetricMeterList) {
        for (SymmetricMeterNature meter : symmetricMeterList) {
            if (meter.activePower().valueOptional().isPresent()) {
                if (activePower == null) {
                    activePower = 0L;
                }
                if (activePowerL1 == null) {
                    activePowerL1 = 0L;
                }
                if (activePowerL2 == null) {
                    activePowerL2 = 0L;
                }
                if (activePowerL3 == null) {
                    activePowerL3 = 0L;
                }
                activePower += meter.activePower().valueOptional().get();
                activePowerL1 += meter.activePower().valueOptional().get() / 3;
                activePowerL2 += meter.activePower().valueOptional().get() / 3;
                activePowerL3 += meter.activePower().valueOptional().get() / 3;
            } else {
                log.warn(meter.id() + ": activePower is invalid!");
            }
            if (meter.activePower().valueOptional().isPresent()) {
                if (reactivePower == null) {
                    reactivePower = 0L;
                }
                if (reactivePowerL1 == null) {
                    reactivePowerL1 = 0L;
                }
                if (reactivePowerL2 == null) {
                    reactivePowerL2 = 0L;
                }
                if (reactivePowerL3 == null) {
                    reactivePowerL3 = 0L;
                }
                reactivePower += meter.reactivePower().valueOptional().get();
                reactivePowerL1 += meter.reactivePower().valueOptional().get() / 3;
                reactivePowerL2 += meter.reactivePower().valueOptional().get() / 3;
                reactivePowerL3 += meter.reactivePower().valueOptional().get() / 3;
            } else {
                log.warn(meter.id() + ": reactivePower is invalid!");
            }
            try {
                if (voltage == null) {
                    voltage = meter.voltage().value();
                }
            } catch (InvalidValueException e) {
                log.warn(meter.id() + ": voltage is invalid!");
            }
        }
    }
    this.activePower.updateValue(activePower);
    this.activePowerL1.updateValue(activePowerL1);
    this.activePowerL2.updateValue(activePowerL2);
    this.activePowerL3.updateValue(activePowerL3);
    this.reactivePower.updateValue(reactivePower);
    this.reactivePowerL1.updateValue(reactivePowerL1);
    this.reactivePowerL2.updateValue(reactivePowerL2);
    this.reactivePowerL3.updateValue(reactivePowerL3);
    if (activePower != null && reactivePower != null) {
        this.apparentPower.updateValue(ControllerUtils.calculateApparentPower(activePower, reactivePower));
    } else {
        this.apparentPower.updateValue(null);
    }
    this.voltage.updateValue(voltage);
    this.voltageL1.updateValue(voltageL1);
    this.voltageL2.updateValue(voltageL2);
    this.voltageL3.updateValue(voltageL3);
}
Also used : InvalidValueException(io.openems.api.exception.InvalidValueException) SymmetricMeterNature(io.openems.api.device.nature.meter.SymmetricMeterNature) AsymmetricMeterNature(io.openems.api.device.nature.meter.AsymmetricMeterNature)

Example 17 with InvalidValueException

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

the class ModbusTcp method getModbusConnection.

private TCPMasterConnection getModbusConnection() throws OpenemsModbusException {
    if (!connection.isPresent()) {
        try {
            TCPMasterConnection tcpCon = new TCPMasterConnection(ip.value());
            tcpCon.setPort(port.valueOptional().orElse(502));
            connection = Optional.of(tcpCon);
            this.configurationFault.setValue(false);
        } catch (InvalidValueException e) {
            this.configurationFault.setValue(true);
            throw new OpenemsModbusException("Modbus-TCP is not configured completely");
        }
    }
    if (!connection.get().isConnected()) {
        try {
            TCPMasterConnection tcpCon = connection.get();
            tcpCon.connect();
            tcpCon.getModbusTransport().setTimeout(1000);
            this.connectionFault.setValue(false);
        } catch (Exception e) {
            this.connectionFault.setValue(true);
            throw new OpenemsModbusException("Unable to open Modbus-TCP connection: " + ip.valueOptional().get());
        }
    }
    return connection.get();
}
Also used : InvalidValueException(io.openems.api.exception.InvalidValueException) TCPMasterConnection(com.ghgande.j2mod.modbus.net.TCPMasterConnection) OpenemsModbusException(io.openems.api.exception.OpenemsModbusException) OpenemsModbusException(io.openems.api.exception.OpenemsModbusException) ConfigException(io.openems.api.exception.ConfigException) InvalidValueException(io.openems.api.exception.InvalidValueException)

Example 18 with InvalidValueException

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

the class RiedmannController method run.

@Override
public void run() {
    // Check if all parameters are available
    Ess ess;
    Custom sps;
    try {
        ess = this.ess.value();
        sps = this.sps.value();
    } catch (InvalidValueException | NullPointerException e) {
        log.error("TimelineChargeController error: " + e.getMessage());
        return;
    }
    // Watchdog
    try {
        if (watchdogState) {
            sps.watchdog.pushWrite(0L);
            watchdogState = false;
        } else {
            sps.watchdog.pushWrite(1L);
            watchdogState = true;
        }
    } catch (WriteChannelException e) {
        log.error("Failed to set Watchdog: " + e.getMessage());
    }
    // Water level
    if (updateWaterLevelBorehole1Off) {
        try {
            sps.setWaterLevelBorehole1Off.pushWrite(setWaterLevelBorehole1Off.value());
            updateWaterLevelBorehole1Off = false;
        } catch (InvalidValueException | WriteChannelException e) {
            log.error("Failed to set WaterLevelBorehole1Off!", e);
        }
    }
    if (updateWaterLevelBorehole1On) {
        try {
            sps.setWaterLevelBorehole1On.pushWrite(setWaterLevelBorehole1On.value());
            updateWaterLevelBorehole1On = false;
        } catch (InvalidValueException | WriteChannelException e) {
            log.error("Failed to set WaterLevelBorehole1On!", e);
        }
    }
    if (updateWaterLevelBorehole2Off) {
        try {
            sps.setWaterLevelBorehole2Off.pushWrite(setWaterLevelBorehole2Off.value());
            updateWaterLevelBorehole2Off = false;
        } catch (InvalidValueException | WriteChannelException e) {
            log.error("Failed to set WaterLevelBorehole2Off!", e);
        }
    }
    if (updateWaterLevelBorehole2On) {
        try {
            sps.setWaterLevelBorehole2On.pushWrite(setWaterLevelBorehole2On.value());
            updateWaterLevelBorehole2On = false;
        } catch (InvalidValueException | WriteChannelException e) {
            log.error("Failed to set WaterLevelBorehole2On!", e);
        }
    }
    if (updateWaterLevelBorehole3Off) {
        try {
            sps.setWaterLevelBorehole3Off.pushWrite(setWaterLevelBorehole3Off.value());
            updateWaterLevelBorehole3Off = false;
        } catch (InvalidValueException | WriteChannelException e) {
            log.error("Failed to set WaterLevelBorehole3Off!", e);
        }
    }
    if (updateWaterLevelBorehole3On) {
        try {
            sps.setWaterLevelBorehole3On.pushWrite(setWaterLevelBorehole3On.value());
            updateWaterLevelBorehole3On = false;
        } catch (InvalidValueException | WriteChannelException e) {
            log.error("Failed to set WaterLevelBorehole3On!", e);
        }
    }
    /*
		 * Load switching
		 */
    // Check if all parameters are available
    long essSoc;
    long socHysteresis;
    long socLoad1Off;
    long socLoad2Off;
    long socLoad3Off;
    long socLoad4Off;
    try {
        essSoc = ess.soc.value();
        socHysteresis = this.socHysteresis.value();
        socLoad1Off = this.socLoad1Off.value();
        socLoad2Off = this.socLoad2Off.value();
        socLoad3Off = this.socLoad3Off.value();
        socLoad4Off = this.socLoad4Off.value();
    } catch (InvalidValueException | NullPointerException e) {
        log.error("TimelineChargeController error: " + e.getMessage());
        return;
    }
    // Load1
    try {
        if (essSoc >= socLoad1Off + socHysteresis || ess.gridMode.labelOptional().equals(Optional.of(EssNature.ON_GRID))) {
            load1On = true;
        } else if (essSoc <= socLoad1Off) {
            load1On = false;
        }
        if (load1On) {
            sps.setClima1On.pushWrite(1L);
            sps.setClima2On.pushWrite(1L);
        } else {
            sps.setClima1On.pushWrite(0L);
            sps.setClima2On.pushWrite(0L);
        }
    } catch (WriteChannelException e) {
        log.error("Failed to connect/disconnect Load 1: " + e.getMessage());
    }
    // Load2
    try {
        if (essSoc >= socLoad2Off + socHysteresis || ess.gridMode.labelOptional().equals(Optional.of(EssNature.ON_GRID))) {
            load2On = true;
        } else if (essSoc <= socLoad2Off) {
            load2On = false;
        }
        if (load2On) {
            sps.setPivotOn.pushWrite(1L);
        } else {
            sps.setPivotOn.pushWrite(0L);
        }
    } catch (WriteChannelException e) {
        log.error("Failed to connect/disconnect Load 2: " + e.getMessage());
    }
    // Load3
    try {
        if (essSoc >= socLoad3Off + socHysteresis || ess.gridMode.labelOptional().equals(Optional.of(EssNature.ON_GRID))) {
            load3On = true;
        } else if (essSoc <= socLoad3Off) {
            load3On = false;
        }
        if (load3On) {
            sps.setBorehole1On.pushWrite(1L);
            sps.setBorehole2On.pushWrite(1L);
            sps.setBorehole3On.pushWrite(1L);
        } else {
            sps.setBorehole1On.pushWrite(0L);
            sps.setBorehole2On.pushWrite(0L);
            sps.setBorehole3On.pushWrite(0L);
        }
    } catch (WriteChannelException e) {
        log.error("Failed to connect/disconnect Load 3: " + e.getMessage());
    }
    // Load4
    try {
        if (essSoc >= socLoad4Off + socHysteresis || ess.gridMode.labelOptional().equals(Optional.of(EssNature.ON_GRID))) {
            load4On = true;
        } else if (essSoc <= socLoad4Off) {
            load4On = false;
        }
        if (load4On) {
            sps.setOfficeOn.pushWrite(1L);
            sps.setTraineeCenterOn.pushWrite(1L);
        } else {
            sps.setOfficeOn.pushWrite(0L);
            sps.setTraineeCenterOn.pushWrite(0L);
        }
    } catch (WriteChannelException e) {
        log.error("Failed to connect/disconnect Load 4: " + e.getMessage());
    }
}
Also used : InvalidValueException(io.openems.api.exception.InvalidValueException) Ess(io.openems.impl.controller.symmetric.timelinecharge.Ess) WriteChannelException(io.openems.api.exception.WriteChannelException)

Aggregations

InvalidValueException (io.openems.api.exception.InvalidValueException)18 ConfigException (io.openems.api.exception.ConfigException)7 JsonArray (com.google.gson.JsonArray)6 ModbusProtocol (io.openems.impl.protocol.modbus.internal.ModbusProtocol)6 ConfigChannel (io.openems.api.channel.ConfigChannel)5 FunctionalReadChannel (io.openems.api.channel.FunctionalReadChannel)4 ReadChannel (io.openems.api.channel.ReadChannel)4 WriteChannel (io.openems.api.channel.WriteChannel)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 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 JsonElement (com.google.gson.JsonElement)3 StaticValueChannel (io.openems.api.channel.StaticValueChannel)3 AsymmetricMeterNature (io.openems.api.device.nature.meter.AsymmetricMeterNature)3