Search in sources :

Example 1 with FunctionalReadChannelFunction

use of io.openems.api.channel.FunctionalReadChannelFunction 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;
}
Also used : ModbusReadLongChannel(io.openems.impl.protocol.modbus.ModbusReadLongChannel) SignedDoublewordElement(io.openems.impl.protocol.modbus.internal.SignedDoublewordElement) 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) FunctionalReadChannelFunction(io.openems.api.channel.FunctionalReadChannelFunction) ReadChannel(io.openems.api.channel.ReadChannel) FunctionalReadChannel(io.openems.api.channel.FunctionalReadChannel)

Aggregations

FunctionalReadChannel (io.openems.api.channel.FunctionalReadChannel)1 FunctionalReadChannelFunction (io.openems.api.channel.FunctionalReadChannelFunction)1 ReadChannel (io.openems.api.channel.ReadChannel)1 ModbusReadLongChannel (io.openems.impl.protocol.modbus.ModbusReadLongChannel)1 ModbusProtocol (io.openems.impl.protocol.modbus.internal.ModbusProtocol)1 SignedDoublewordElement (io.openems.impl.protocol.modbus.internal.SignedDoublewordElement)1 UnsignedDoublewordElement (io.openems.impl.protocol.modbus.internal.UnsignedDoublewordElement)1 ModbusRegisterRange (io.openems.impl.protocol.modbus.internal.range.ModbusRegisterRange)1