Search in sources :

Example 6 with UnsignedDoublewordElement

use of io.openems.impl.protocol.modbus.internal.UnsignedDoublewordElement 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)

Example 7 with UnsignedDoublewordElement

use of io.openems.impl.protocol.modbus.internal.UnsignedDoublewordElement in project openems by OpenEMS.

the class BControlMeter method defineModbusProtocol.

@Override
protected ModbusProtocol defineModbusProtocol() throws ConfigException {
    ModbusProtocol mp = new // 
    ModbusProtocol(new // 
    ModbusInputRegisterRange(// 
    0, new UnsignedDoublewordElement(0, activePowerPos = new ModbusReadLongChannel("ActivePowerPos", this).unit("W").multiplier(-1)), new UnsignedDoublewordElement(2, activePowerNeg = new ModbusReadLongChannel("ActivePowerNeg", this).unit("W").multiplier(-1)), new UnsignedDoublewordElement(4, reactivePowerPos = new ModbusReadLongChannel("ReactivePowerPos", this).unit("Var").multiplier(-1)), new UnsignedDoublewordElement(6, reactivePowerNeg = new ModbusReadLongChannel("ReactivePowerNeg", this).unit("Var").multiplier(-1)), new DummyElement(8, 15), new UnsignedDoublewordElement(16, apparentPowerPos = new ModbusReadLongChannel("ApparentPowerPos", this).unit("VA").multiplier(-1)), new UnsignedDoublewordElement(18, apparentPowerNeg = new ModbusReadLongChannel("ApparentPowerNeg", this).unit("VA").multiplier(-1)), new DummyElement(20, 25), new // 
    UnsignedDoublewordElement(// 
    26, frequency = new ModbusReadLongChannel("Frequency", this).unit("mHZ"))), new ModbusInputRegisterRange(40, new // 
    UnsignedDoublewordElement(// 
    40, activePowerL1Pos = new ModbusReadLongChannel("ActivePowerL1Pos", this).unit("W").multiplier(-1)), new // 
    UnsignedDoublewordElement(// 
    42, activePowerL1Neg = new ModbusReadLongChannel("ActivePowerL1Neg", this).unit("W").multiplier(-1)), new // 
    UnsignedDoublewordElement(// 
    44, reactivePowerL1Pos = new ModbusReadLongChannel("ReactivePowerL1Pos", this).unit("Var").multiplier(-1)), new // 
    UnsignedDoublewordElement(// 
    46, reactivePowerL1Neg = new ModbusReadLongChannel("ReactivePowerL1Neg", this).unit("Var").multiplier(-1)), new DummyElement(48, 59), new // 
    UnsignedDoublewordElement(// 
    60, currentL1 = new ModbusReadLongChannel("CurrentL1", this).unit("mA")), new // 
    UnsignedDoublewordElement(// 
    62, voltageL1 = new ModbusReadLongChannel("VoltageL1", this).unit("mV"))), new ModbusInputRegisterRange(80, new // 
    UnsignedDoublewordElement(// 
    80, activePowerL2Pos = new ModbusReadLongChannel("ActivePowerL2Pos", this).unit("W").multiplier(-1)), new // 
    UnsignedDoublewordElement(// 
    82, activePowerL2Neg = new ModbusReadLongChannel("ActivePowerL2Neg", this).unit("W").multiplier(-1)), new // 
    UnsignedDoublewordElement(// 
    84, reactivePowerL2Pos = new ModbusReadLongChannel("ReactivePowerL2Pos", this).unit("Var").multiplier(-1)), new // 
    UnsignedDoublewordElement(// 
    86, reactivePowerL2Neg = new ModbusReadLongChannel("ReactivePowerL2Neg", this).unit("Var").multiplier(-1)), new DummyElement(88, 99), new // 
    UnsignedDoublewordElement(// 
    100, currentL2 = new ModbusReadLongChannel("CurrentL2", this).unit("mA")), new // 
    UnsignedDoublewordElement(// 
    102, voltageL2 = new ModbusReadLongChannel("VoltageL2", this).unit("mV"))), new ModbusInputRegisterRange(120, new // 
    UnsignedDoublewordElement(// 
    120, activePowerL3Pos = new ModbusReadLongChannel("ActivePowerL3Pos", this).unit("W").multiplier(-1)), new // 
    UnsignedDoublewordElement(// 
    122, activePowerL3Neg = new ModbusReadLongChannel("ActivePowerL3Neg", this).unit("W").multiplier(-1)), new // 
    UnsignedDoublewordElement(// 
    124, reactivePowerL3Pos = new ModbusReadLongChannel("ReactivePowerL3Pos", this).unit("Var").multiplier(-1)), new // 
    UnsignedDoublewordElement(// 
    126, reactivePowerL3Neg = new ModbusReadLongChannel("ReactivePowerL3Neg", this).unit("Var").multiplier(-1)), new DummyElement(128, 139), new // 
    UnsignedDoublewordElement(// 
    140, currentL3 = new ModbusReadLongChannel("CurrentL3", this).unit("mA")), new // 
    UnsignedDoublewordElement(// 
    142, voltageL3 = new ModbusReadLongChannel("VoltageL3", this).unit("mV"))));
    activePower = new FunctionalReadChannel<Long>("ActivePower", this, (channels) -> {
        return channels[0].valueOptional().orElse(0L) + (channels[1].valueOptional().orElse(0L) * -1);
    }, activePowerPos, activePowerNeg).unit("W");
    activePowerL1 = new FunctionalReadChannel<Long>("ActivePowerL1", this, (channels) -> {
        return channels[0].valueOptional().orElse(0L) + (channels[1].valueOptional().orElse(0L) * -1);
    }, activePowerL1Pos, activePowerL1Neg).unit("W");
    activePowerL2 = new FunctionalReadChannel<Long>("ActivePowerL2", this, (channels) -> {
        return channels[0].valueOptional().orElse(0L) + (channels[1].valueOptional().orElse(0L) * -1);
    }, activePowerL2Pos, activePowerL2Neg).unit("W");
    activePowerL3 = new FunctionalReadChannel<Long>("ActivePowerL3", this, (channels) -> {
        return channels[0].valueOptional().orElse(0L) + (channels[1].valueOptional().orElse(0L) * -1);
    }, activePowerL3Pos, activePowerL3Neg).unit("W");
    reactivePower = new FunctionalReadChannel<Long>("ReactivePower", this, (channels) -> {
        return channels[0].valueOptional().orElse(0L) + (channels[1].valueOptional().orElse(0L) * -1);
    }, reactivePowerPos, reactivePowerNeg).unit("Var");
    reactivePowerL1 = new FunctionalReadChannel<Long>("ReactivePowerL1", this, (channels) -> {
        return channels[0].valueOptional().orElse(0L) + (channels[1].valueOptional().orElse(0L) * -1);
    }, reactivePowerL1Pos, reactivePowerL1Neg).unit("Var");
    reactivePowerL2 = new FunctionalReadChannel<Long>("ReactivePowerL2", this, (channels) -> {
        return channels[0].valueOptional().orElse(0L) + (channels[1].valueOptional().orElse(0L) * -1);
    }, reactivePowerL2Pos, reactivePowerL2Neg).unit("Var");
    reactivePowerL3 = new FunctionalReadChannel<Long>("ReactivePowerL3", this, (channels) -> {
        return channels[0].valueOptional().orElse(0L) + (channels[1].valueOptional().orElse(0L) * -1);
    }, reactivePowerL3Pos, reactivePowerL3Neg).unit("Var");
    apparentPower = new FunctionalReadChannel<Long>("ApparentPower", this, (channels) -> {
        return channels[0].valueOptional().orElse(0L) + (channels[1].valueOptional().orElse(0L) * -1);
    }, apparentPowerPos, apparentPowerNeg).unit("VA");
    return mp;
}
Also used : ModbusReadLongChannel(io.openems.impl.protocol.modbus.ModbusReadLongChannel) DummyElement(io.openems.impl.protocol.modbus.internal.DummyElement) ModbusInputRegisterRange(io.openems.impl.protocol.modbus.internal.range.ModbusInputRegisterRange) UnsignedDoublewordElement(io.openems.impl.protocol.modbus.internal.UnsignedDoublewordElement) FunctionalReadChannel(io.openems.api.channel.FunctionalReadChannel) ModbusProtocol(io.openems.impl.protocol.modbus.internal.ModbusProtocol)

Example 8 with UnsignedDoublewordElement

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

ModbusReadLongChannel (io.openems.impl.protocol.modbus.ModbusReadLongChannel)8 ModbusProtocol (io.openems.impl.protocol.modbus.internal.ModbusProtocol)8 UnsignedDoublewordElement (io.openems.impl.protocol.modbus.internal.UnsignedDoublewordElement)8 DummyElement (io.openems.impl.protocol.modbus.internal.DummyElement)7 ModbusRegisterRange (io.openems.impl.protocol.modbus.internal.range.ModbusRegisterRange)7 FunctionalReadChannel (io.openems.api.channel.FunctionalReadChannel)6 ReadChannel (io.openems.api.channel.ReadChannel)6 ConfigChannel (io.openems.api.channel.ConfigChannel)5 UnsignedWordElement (io.openems.impl.protocol.modbus.internal.UnsignedWordElement)5 StaticValueChannel (io.openems.api.channel.StaticValueChannel)4 WriteChannel (io.openems.api.channel.WriteChannel)4 ThingStateChannels (io.openems.api.channel.thingstate.ThingStateChannels)4 Device (io.openems.api.device.Device)4 ThingInfo (io.openems.api.doc.ThingInfo)4 ConfigException (io.openems.api.exception.ConfigException)4 InvalidValueException (io.openems.api.exception.InvalidValueException)4 ModbusBitWrappingChannel (io.openems.impl.protocol.modbus.ModbusBitWrappingChannel)4 ModbusDeviceNature (io.openems.impl.protocol.modbus.ModbusDeviceNature)4 ModbusWriteLongChannel (io.openems.impl.protocol.modbus.ModbusWriteLongChannel)4 WriteableModbusRegisterRange (io.openems.impl.protocol.modbus.internal.range.WriteableModbusRegisterRange)4