use of io.openems.api.exception.InvalidValueException 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;
}
use of io.openems.api.exception.InvalidValueException 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;
}
use of io.openems.api.exception.InvalidValueException in project openems by OpenEMS.
the class AvoidTotalDischargeSocTimeLineController method channelChanged.
@Override
public void channelChanged(Channel channel, Optional<?> newValue, Optional<?> oldValue) {
if (channel.equals(esss) || channel.equals(socTimeline)) {
if (esss.valueOptional().isPresent() && socTimeline.valueOptional().isPresent() && socTimeline.valueOptional().get() instanceof JsonArray) {
JsonArray timeline = socTimeline.valueOptional().get();
for (JsonElement e : timeline) {
JsonObject obj = e.getAsJsonObject();
int minSoc = obj.get("minSoc").getAsInt();
int chargeSoc = obj.get("chargeSoc").getAsInt();
LocalTime time = LocalTime.parse(obj.get("time").getAsString(), DateTimeFormatter.ISO_LOCAL_TIME);
JsonArray storages = obj.get("esss").getAsJsonArray();
for (JsonElement storage : storages) {
Ess ess;
try {
ess = getEss(storage.getAsString());
if (ess != null) {
ess.addTime(time, minSoc, chargeSoc);
}
} catch (InvalidValueException e1) {
log.error(e1.getMessage());
}
}
}
}
} else if (this.nextDischarge.equals(channel)) {
if (newValue.isPresent()) {
nextDischargeDate = LocalDate.parse((String) newValue.get());
} else {
nextDischargeDate = null;
}
} else if (this.dischargeTime.equals(channel)) {
if (newValue.isPresent()) {
this.dischargeStartTime = LocalTime.parse((String) newValue.get());
} else {
this.dischargeStartTime = null;
}
}
if (nextDischargeDate != null && nextDischargeDate.isBefore(LocalDate.now())) {
addPeriod();
}
if (nextDischargeDate != null && dischargeStartTime != null) {
dischargeStart = nextDischargeDate.atTime(dischargeStartTime);
} else {
dischargeStart = null;
}
}
use of io.openems.api.exception.InvalidValueException in project openems by OpenEMS.
the class WagoFBInput method defineModbusProtocol.
@Override
protected ModbusProtocol defineModbusProtocol() throws ConfigException {
List<ModbusCoilRange> ranges = new ArrayList<>();
HashMap<String, List<String>> channels;
try {
channels = WagoFB.getConfig(ip.value());
for (String key : channels.keySet()) {
switch(key) {
case "DI":
{
List<CoilElement> elements = new ArrayList<>();
int count = 0;
for (@SuppressWarnings("unused") String channel : channels.get(key)) {
ModbusCoilReadChannel ch = new ModbusCoilReadChannel(Integer.toString(count), this);
this.channel.add(ch);
elements.add(new CoilElement(count, ch));
count++;
if (count % 63 == 0) {
ranges.add(new ModbusCoilRange(elements.get(0).getAddress(), elements.toArray(new CoilElement[elements.size()])));
elements.clear();
}
}
if (this.channel.size() > 0) {
ranges.add(new ModbusCoilRange(elements.get(0).getAddress(), elements.toArray(new CoilElement[elements.size()])));
}
}
break;
}
}
} catch (InvalidValueException e) {
log.error("Ip-Address is Invalid", e);
}
ModbusProtocol protocol = new ModbusProtocol(ranges.toArray(new ModbusRange[ranges.size()]));
return protocol;
}
use of io.openems.api.exception.InvalidValueException in project openems by OpenEMS.
the class WagoFBOutput method defineModbusProtocol.
@Override
protected ModbusProtocol defineModbusProtocol() throws ConfigException {
List<ModbusCoilRange> ranges = new ArrayList<>();
HashMap<String, List<String>> channels;
try {
channels = WagoFB.getConfig(ip.value());
for (String key : channels.keySet()) {
switch(key) {
case "DO":
{
List<CoilElement> elements = new ArrayList<>();
int count = 0;
for (@SuppressWarnings("unused") String channel : channels.get(key)) {
ModbusCoilWriteChannel ch = new ModbusCoilWriteChannel(Integer.toString(count), this);
this.channel.add(ch);
elements.add(new CoilElement(512 + count, ch));
count++;
if (count % 63 == 0) {
ranges.add(new ModbusCoilRange(elements.get(0).getAddress(), elements.toArray(new CoilElement[elements.size()])));
elements.clear();
}
}
if (this.channel.size() > 0) {
ranges.add(new WriteableModbusCoilRange(elements.get(0).getAddress(), elements.toArray(new CoilElement[elements.size()])));
}
}
break;
}
}
} catch (InvalidValueException e) {
log.error("Ip-Address is Invalid", e);
}
ModbusProtocol protocol = new ModbusProtocol(ranges.toArray(new ModbusRange[ranges.size()]));
return protocol;
}
Aggregations