Search in sources :

Example 11 with ModbusProtocol

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;
}
Also used : ModbusCoilRange(io.openems.impl.protocol.modbus.internal.range.ModbusCoilRange) WriteableModbusCoilRange(io.openems.impl.protocol.modbus.internal.range.WriteableModbusCoilRange) WriteableModbusCoilRange(io.openems.impl.protocol.modbus.internal.range.WriteableModbusCoilRange) ModbusRange(io.openems.impl.protocol.modbus.internal.range.ModbusRange) ArrayList(java.util.ArrayList) ModbusCoilWriteChannel(io.openems.impl.protocol.modbus.ModbusCoilWriteChannel) InvalidValueException(io.openems.api.exception.InvalidValueException) CoilElement(io.openems.impl.protocol.modbus.internal.CoilElement) ArrayList(java.util.ArrayList) List(java.util.List) ModbusProtocol(io.openems.impl.protocol.modbus.internal.ModbusProtocol)

Example 12 with ModbusProtocol

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;
}
Also used : 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) ModbusReadLongChannel(io.openems.impl.protocol.modbus.ModbusReadLongChannel) ModbusWriteLongChannel(io.openems.impl.protocol.modbus.ModbusWriteLongChannel) StaticValueChannel(io.openems.api.channel.StaticValueChannel) Channel(io.openems.api.channel.Channel) ModbusWriteLongChannel(io.openems.impl.protocol.modbus.ModbusWriteLongChannel) PGreaterEqualLimitation(io.openems.core.utilities.power.symmetric.PGreaterEqualLimitation) DummyElement(io.openems.impl.protocol.modbus.internal.DummyElement) SymmetricPowerImpl(io.openems.core.utilities.power.symmetric.SymmetricPowerImpl) SignedDoublewordElement(io.openems.impl.protocol.modbus.internal.SignedDoublewordElement) UnsignedDoublewordElement(io.openems.impl.protocol.modbus.internal.UnsignedDoublewordElement) ChannelChangeListener(io.openems.api.channel.ChannelChangeListener) ModbusProtocol(io.openems.impl.protocol.modbus.internal.ModbusProtocol) PSmallerEqualLimitation(io.openems.core.utilities.power.symmetric.PSmallerEqualLimitation) ModbusRegisterRange(io.openems.impl.protocol.modbus.internal.range.ModbusRegisterRange) WriteableModbusRegisterRange(io.openems.impl.protocol.modbus.internal.range.WriteableModbusRegisterRange)

Aggregations

ModbusProtocol (io.openems.impl.protocol.modbus.internal.ModbusProtocol)12 ModbusReadLongChannel (io.openems.impl.protocol.modbus.ModbusReadLongChannel)10 DummyElement (io.openems.impl.protocol.modbus.internal.DummyElement)9 ReadChannel (io.openems.api.channel.ReadChannel)8 UnsignedDoublewordElement (io.openems.impl.protocol.modbus.internal.UnsignedDoublewordElement)8 ConfigChannel (io.openems.api.channel.ConfigChannel)7 UnsignedWordElement (io.openems.impl.protocol.modbus.internal.UnsignedWordElement)7 ModbusRegisterRange (io.openems.impl.protocol.modbus.internal.range.ModbusRegisterRange)7 FunctionalReadChannel (io.openems.api.channel.FunctionalReadChannel)6 StaticValueChannel (io.openems.api.channel.StaticValueChannel)6 InvalidValueException (io.openems.api.exception.InvalidValueException)6 ModbusBitWrappingChannel (io.openems.impl.protocol.modbus.ModbusBitWrappingChannel)6 ModbusWriteLongChannel (io.openems.impl.protocol.modbus.ModbusWriteLongChannel)6 WriteChannel (io.openems.api.channel.WriteChannel)5 SymmetricPowerImpl (io.openems.core.utilities.power.symmetric.SymmetricPowerImpl)5 SignedWordElement (io.openems.impl.protocol.modbus.internal.SignedWordElement)5 WriteableModbusRegisterRange (io.openems.impl.protocol.modbus.internal.range.WriteableModbusRegisterRange)5 Channel (io.openems.api.channel.Channel)4 ChannelChangeListener (io.openems.api.channel.ChannelChangeListener)4 StatusBitChannel (io.openems.api.channel.StatusBitChannel)4