use of io.openems.impl.protocol.modbus.internal.SignedDoublewordElement in project openems by OpenEMS.
the class BHKWMeter method defineModbusProtocol.
/*
* Methods
*/
@Override
protected ModbusProtocol defineModbusProtocol() throws ConfigException {
ModbusProtocol protocol = new //
ModbusProtocol(new ModbusRegisterRange(370, new //
UnsignedDoublewordElement(//
370, voltageL1 = new ModbusReadLongChannel("VoltageL1", this).unit("mV").multiplier(2))), new ModbusRegisterRange(371, new //
UnsignedDoublewordElement(//
371, voltageL2 = new ModbusReadLongChannel("VoltageL2", this).unit("mV").multiplier(2))), new ModbusRegisterRange(372, new //
UnsignedDoublewordElement(//
372, voltageL3 = new ModbusReadLongChannel("VoltageL3", this).unit("mV").multiplier(2))), new ModbusRegisterRange(373, new //
UnsignedDoublewordElement(//
373, frequencyL1 = new ModbusReadLongChannel("FrequencyL1", this).unit("mHZ").multiplier(1))), new ModbusRegisterRange(374, new //
UnsignedDoublewordElement(//
374, frequencyL1 = new ModbusReadLongChannel("FrequencyL2", this).unit("mHZ").multiplier(1))), new ModbusRegisterRange(375, new //
UnsignedDoublewordElement(//
375, frequencyL1 = new ModbusReadLongChannel("FrequencyL3", this).unit("mHZ").multiplier(1))), new ModbusRegisterRange(376, new //
UnsignedDoublewordElement(//
376, currentL1 = new ModbusReadLongChannel("CurrentL1", this).unit("mA").multiplier(2))), new ModbusRegisterRange(377, new //
UnsignedDoublewordElement(//
377, currentL2 = new ModbusReadLongChannel("CurrentL2", this).unit("mA").multiplier(2))), new ModbusRegisterRange(378, new //
UnsignedDoublewordElement(//
378, currentL3 = new ModbusReadLongChannel("CurrentL3", this).unit("mA").multiplier(2))), new ModbusRegisterRange(379, new //
SignedDoublewordElement(//
379, cosPhiL1 = new ModbusReadLongChannel("CosPhiL1", this))), new ModbusRegisterRange(380, new //
SignedDoublewordElement(//
380, cosPhiL2 = new ModbusReadLongChannel("CosPhiL2", this))), new ModbusRegisterRange(381, new //
SignedDoublewordElement(//
381, cosPhiL3 = new ModbusReadLongChannel("SocPhiL3", this))), new ModbusRegisterRange(382, new //
SignedDoublewordElement(//
382, activePowerL1 = new ModbusReadLongChannel("ActivePowerL1", this).unit("W").multiplier(-2))), new ModbusRegisterRange(383, new //
SignedDoublewordElement(//
383, activePowerL2 = new ModbusReadLongChannel("ActivePowerL2", this).unit("W").multiplier(-2))), new ModbusRegisterRange(384, new //
SignedDoublewordElement(//
384, activePowerL3 = new ModbusReadLongChannel("ActivePowerL3", this).unit("W").multiplier(-2))));
activePower = new FunctionalReadChannel<Long>("ActivePower", this, new FunctionalReadChannelFunction<Long>() {
@Override
public Long handle(@SuppressWarnings("unchecked") ReadChannel<Long>... channels) throws InvalidValueException {
Long value = 0L;
for (ReadChannel<Long> channel : channels) {
if (channel.valueOptional().isPresent()) {
value += channel.valueOptional().get();
} else {
return null;
}
}
return value;
}
}, activePowerL1, activePowerL2, activePowerL3);
reactivePowerL1 = new FunctionalReadChannel<Long>("ReactivePowerL1", this, new FunctionalReadChannelFunction<Long>() {
@Override
public Long handle(@SuppressWarnings("unchecked") ReadChannel<Long>... channels) throws InvalidValueException {
if (channels.length == 2 && channels[0].valueOptional().isPresent() && channels[1].valueOptional().isPresent()) {
return ControllerUtils.calculateReactivePower(channels[0].valueOptional().get(), ((double) channels[1].valueOptional().get()) / 100.0, false);
}
return null;
}
}, activePowerL1, cosPhiL1);
reactivePowerL2 = new FunctionalReadChannel<Long>("ReactivePowerL2", this, new FunctionalReadChannelFunction<Long>() {
@Override
public Long handle(@SuppressWarnings("unchecked") ReadChannel<Long>... channels) throws InvalidValueException {
if (channels.length == 2 && channels[0].valueOptional().isPresent() && channels[1].valueOptional().isPresent()) {
return ControllerUtils.calculateReactivePower(channels[0].valueOptional().get(), ((double) channels[1].valueOptional().get()) / 100.0, false);
}
return null;
}
}, activePowerL2, cosPhiL2);
reactivePowerL3 = new FunctionalReadChannel<Long>("ReactivePowerL3", this, new FunctionalReadChannelFunction<Long>() {
@Override
public Long handle(@SuppressWarnings("unchecked") ReadChannel<Long>... channels) throws InvalidValueException {
if (channels.length == 2 && channels[0].valueOptional().isPresent() && channels[1].valueOptional().isPresent()) {
return ControllerUtils.calculateReactivePower(channels[0].valueOptional().get(), ((double) channels[1].valueOptional().get()) / 100.0, false);
}
return null;
}
}, activePowerL3, cosPhiL3);
reactivePower = new FunctionalReadChannel<Long>("ReactivePower", this, new FunctionalReadChannelFunction<Long>() {
@Override
public Long handle(@SuppressWarnings("unchecked") ReadChannel<Long>... channels) throws InvalidValueException {
Long value = 0L;
for (ReadChannel<Long> channel : channels) {
if (channel.valueOptional().isPresent()) {
value += channel.valueOptional().get();
} else {
return null;
}
}
return value;
}
}, reactivePowerL1, reactivePowerL2, reactivePowerL3);
apparentPower = new FunctionalReadChannel<Long>("ApparentPower", this, new FunctionalReadChannelFunction<Long>() {
@Override
public Long handle(@SuppressWarnings("unchecked") ReadChannel<Long>... channels) throws InvalidValueException {
if (channels.length == 2 && channels[0].valueOptional().isPresent() && channels[1].valueOptional().isPresent()) {
return ControllerUtils.calculateApparentPower(channels[0].valueOptional().get(), channels[1].valueOptional().get());
}
return null;
}
}, activePower, reactivePower);
return protocol;
}
use of io.openems.impl.protocol.modbus.internal.SignedDoublewordElement in project openems by OpenEMS.
the class SunnyIsland6Ess method defineModbusProtocol.
@Override
protected ModbusProtocol defineModbusProtocol() throws ConfigException {
ModbusProtocol protokol = new ModbusProtocol(new ModbusRegisterRange(30201, new UnsignedDoublewordElement(30201, systemState = new ModbusReadLongChannel("SystemState", this).label(35, "Fehler").label(303, "Aus").label(307, "OK").label(455, "Warnung")), new UnsignedDoublewordElement(30203, maxPower = new ModbusReadLongChannel("MaxPower", this).unit("W"))), new //
ModbusRegisterRange(//
30775, new //
SignedDoublewordElement(//
30775, activePower = new ModbusReadLongChannel("ActivePower", this).unit("W")), new DummyElement(30777, 30802), new //
UnsignedDoublewordElement(//
30803, frequency = new ModbusReadLongChannel("Frequency", this).unit("mHz").multiplier(1)), new //
SignedDoublewordElement(//
30805, reactivePower = new ModbusReadLongChannel("ReactivePower", this).unit("var").negate())), new //
ModbusRegisterRange(//
30843, new //
SignedDoublewordElement(//
30843, batteryCurrent = new ModbusReadLongChannel("BatteryCurrent", this).unit("mA")), new //
UnsignedDoublewordElement(//
30845, soc = new ModbusReadLongChannel("Soc", this).unit("%").interval(0, 100)), new DummyElement(30847, 30848), new //
SignedDoublewordElement(//
30849, batteryTemperature = new ModbusReadLongChannel("BatteryTemperature", this).unit("°C").multiplier(-1)), new //
UnsignedDoublewordElement(//
30851, batteryVoltage = new ModbusReadLongChannel("BatteryVoltage", this).unit("mV").multiplier(1))), new ModbusRegisterRange(40189, new //
UnsignedDoublewordElement(//
40189, allowedCharge = new ModbusReadLongChannel("AllowedCharge", this).unit("W").negate()), new //
UnsignedDoublewordElement(//
40191, allowedDischarge = new ModbusReadLongChannel("AllowedDischarge", this).unit("W"))), new //
WriteableModbusRegisterRange(//
40149, new SignedDoublewordElement(40149, //
setActivePower = new ModbusWriteLongChannel("SetActivePower", this).unit("W")), new UnsignedDoublewordElement(40151, setControlMode = new ModbusWriteLongChannel("SetControlMode", this).label(802, START).label(803, //
STOP)), new SignedDoublewordElement(40153, setReactivePower = new ModbusWriteLongChannel("SetReactivePower", this).unit("Var"))), new WriteableModbusRegisterRange(40705, new UnsignedDoublewordElement(40705, //
minSocPowerOn = new ModbusWriteLongChannel("MinSocPowerOn", this)), new UnsignedDoublewordElement(40707, //
minSocPowerOff = new ModbusWriteLongChannel("MinSocPowerOff", this))), new WriteableModbusRegisterRange(41187, new UnsignedDoublewordElement(41187, meterSetting = new ModbusWriteLongChannel("MeterSetting", this).label(3053, "SMA Energy Meter").label(3547, "Wechselrichter"))));
this.power = new SymmetricPowerImpl(40000, setActivePower, setReactivePower, getParent().getBridge());
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;
}
Aggregations