Search in sources :

Example 6 with ModbusBitWrappingChannel

use of io.openems.impl.protocol.modbus.ModbusBitWrappingChannel 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;
}
Also used : ReadChannel(io.openems.api.channel.ReadChannel) ModbusRegisterRange(io.openems.impl.protocol.modbus.internal.range.ModbusRegisterRange) ThingInfo(io.openems.api.doc.ThingInfo) PGreaterEqualLimitation(io.openems.core.utilities.power.symmetric.PGreaterEqualLimitation) LoggerFactory(org.slf4j.LoggerFactory) WriteChannel(io.openems.api.channel.WriteChannel) PSmallerEqualLimitation(io.openems.core.utilities.power.symmetric.PSmallerEqualLimitation) ConfigChannel(io.openems.api.channel.ConfigChannel) EssNature(io.openems.api.device.nature.ess.EssNature) ChannelChangeListener(io.openems.api.channel.ChannelChangeListener) ModbusProtocol(io.openems.impl.protocol.modbus.internal.ModbusProtocol) SMaxLimitation(io.openems.core.utilities.power.symmetric.SMaxLimitation) ModbusBitWrappingChannel(io.openems.impl.protocol.modbus.ModbusBitWrappingChannel) ModbusReadLongChannel(io.openems.impl.protocol.modbus.ModbusReadLongChannel) ModbusWriteLongChannel(io.openems.impl.protocol.modbus.ModbusWriteLongChannel) UnsignedWordElement(io.openems.impl.protocol.modbus.internal.UnsignedWordElement) WriteableModbusRegisterRange(io.openems.impl.protocol.modbus.internal.range.WriteableModbusRegisterRange) RealTimeClockNature(io.openems.api.device.nature.realtimeclock.RealTimeClockNature) SymmetricPowerImpl(io.openems.core.utilities.power.symmetric.SymmetricPowerImpl) Logger(org.slf4j.Logger) SymmetricEssNature(io.openems.api.device.nature.ess.SymmetricEssNature) StatusBitChannel(io.openems.api.channel.StatusBitChannel) ConfigException(io.openems.api.exception.ConfigException) FunctionalReadChannel(io.openems.api.channel.FunctionalReadChannel) UnsignedDoublewordElement(io.openems.impl.protocol.modbus.internal.UnsignedDoublewordElement) ControllerUtils(io.openems.core.utilities.ControllerUtils) Device(io.openems.api.device.Device) ThingStateChannels(io.openems.api.channel.thingstate.ThingStateChannels) InvalidValueException(io.openems.api.exception.InvalidValueException) SignedWordElement(io.openems.impl.protocol.modbus.internal.SignedWordElement) ModbusDeviceNature(io.openems.impl.protocol.modbus.ModbusDeviceNature) Optional(java.util.Optional) StaticValueChannel(io.openems.api.channel.StaticValueChannel) DummyElement(io.openems.impl.protocol.modbus.internal.DummyElement) Channel(io.openems.api.channel.Channel) SMaxLimitation(io.openems.core.utilities.power.symmetric.SMaxLimitation) ReadChannel(io.openems.api.channel.ReadChannel) FunctionalReadChannel(io.openems.api.channel.FunctionalReadChannel) InvalidValueException(io.openems.api.exception.InvalidValueException) PGreaterEqualLimitation(io.openems.core.utilities.power.symmetric.PGreaterEqualLimitation) ModbusBitWrappingChannel(io.openems.impl.protocol.modbus.ModbusBitWrappingChannel) UnsignedWordElement(io.openems.impl.protocol.modbus.internal.UnsignedWordElement) ChannelChangeListener(io.openems.api.channel.ChannelChangeListener) SignedWordElement(io.openems.impl.protocol.modbus.internal.SignedWordElement) PSmallerEqualLimitation(io.openems.core.utilities.power.symmetric.PSmallerEqualLimitation) 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) ModbusBitWrappingChannel(io.openems.impl.protocol.modbus.ModbusBitWrappingChannel) ModbusReadLongChannel(io.openems.impl.protocol.modbus.ModbusReadLongChannel) ModbusWriteLongChannel(io.openems.impl.protocol.modbus.ModbusWriteLongChannel) StatusBitChannel(io.openems.api.channel.StatusBitChannel) FunctionalReadChannel(io.openems.api.channel.FunctionalReadChannel) StaticValueChannel(io.openems.api.channel.StaticValueChannel) Channel(io.openems.api.channel.Channel) ModbusWriteLongChannel(io.openems.impl.protocol.modbus.ModbusWriteLongChannel) DummyElement(io.openems.impl.protocol.modbus.internal.DummyElement) SymmetricPowerImpl(io.openems.core.utilities.power.symmetric.SymmetricPowerImpl) UnsignedDoublewordElement(io.openems.impl.protocol.modbus.internal.UnsignedDoublewordElement) ModbusProtocol(io.openems.impl.protocol.modbus.internal.ModbusProtocol) ModbusRegisterRange(io.openems.impl.protocol.modbus.internal.range.ModbusRegisterRange) WriteableModbusRegisterRange(io.openems.impl.protocol.modbus.internal.range.WriteableModbusRegisterRange)

Aggregations

ModbusBitWrappingChannel (io.openems.impl.protocol.modbus.ModbusBitWrappingChannel)6 ModbusReadLongChannel (io.openems.impl.protocol.modbus.ModbusReadLongChannel)6 DummyElement (io.openems.impl.protocol.modbus.internal.DummyElement)6 ModbusProtocol (io.openems.impl.protocol.modbus.internal.ModbusProtocol)6 UnsignedWordElement (io.openems.impl.protocol.modbus.internal.UnsignedWordElement)6 ConfigChannel (io.openems.api.channel.ConfigChannel)5 ReadChannel (io.openems.api.channel.ReadChannel)5 StaticValueChannel (io.openems.api.channel.StaticValueChannel)5 ModbusWriteLongChannel (io.openems.impl.protocol.modbus.ModbusWriteLongChannel)5 SignedWordElement (io.openems.impl.protocol.modbus.internal.SignedWordElement)5 StatusBitChannel (io.openems.api.channel.StatusBitChannel)4 WriteChannel (io.openems.api.channel.WriteChannel)4 SymmetricPowerImpl (io.openems.core.utilities.power.symmetric.SymmetricPowerImpl)4 UnsignedDoublewordElement (io.openems.impl.protocol.modbus.internal.UnsignedDoublewordElement)4 ModbusRegisterRange (io.openems.impl.protocol.modbus.internal.range.ModbusRegisterRange)4 WriteableModbusRegisterRange (io.openems.impl.protocol.modbus.internal.range.WriteableModbusRegisterRange)4 Channel (io.openems.api.channel.Channel)3 ChannelChangeListener (io.openems.api.channel.ChannelChangeListener)3 FunctionalReadChannel (io.openems.api.channel.FunctionalReadChannel)3 ThingStateChannels (io.openems.api.channel.thingstate.ThingStateChannels)3