use of io.openems.impl.protocol.modbus.internal.ModbusProtocol 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;
}
use of io.openems.impl.protocol.modbus.internal.ModbusProtocol 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