Search in sources :

Example 16 with Channel

use of io.openems.api.channel.Channel in project openems by OpenEMS.

the class ModbusTcpApiController method updateChannelMapping.

protected void updateChannelMapping(Optional<JsonObject> jMappingOpt) {
    processImage.clearMapping();
    ThingRepository thingRepository = ThingRepository.getInstance();
    if (jMappingOpt.isPresent()) {
        JsonObject jMapping = jMappingOpt.get();
        for (Entry<String, JsonElement> entry : jMapping.entrySet()) {
            try {
                int ref = Integer.parseInt(entry.getKey());
                ChannelAddress channelAddress = ChannelAddress.fromString(JsonUtils.getAsString(entry.getValue()));
                Optional<ChannelDoc> channelDocOpt = thingRepository.getChannelDoc(channelAddress);
                if (channelDocOpt.isPresent()) {
                    processImage.addMapping(ref, channelAddress, channelDocOpt.get());
                } else {
                    Optional<Channel> channelOpt = thingRepository.getChannel(channelAddress);
                    if (channelOpt.isPresent()) {
                        throw new OpenemsException("ChannelDoc for channel [" + channelAddress + "] is not available.");
                    } else {
                        throw new OpenemsException("Channel [" + channelAddress + "] does not exist.");
                    }
                }
            } catch (Exception e) {
                log.error("Unable to add channel mapping: " + e.getMessage());
            }
        }
    }
}
Also used : ConfigChannel(io.openems.api.channel.ConfigChannel) Channel(io.openems.api.channel.Channel) JsonObject(com.google.gson.JsonObject) ChannelAddress(io.openems.common.types.ChannelAddress) OpenemsException(io.openems.common.exceptions.OpenemsException) ChannelDoc(io.openems.api.doc.ChannelDoc) OpenemsException(io.openems.common.exceptions.OpenemsException) ModbusException(com.ghgande.j2mod.modbus.ModbusException) ThingRepository(io.openems.core.ThingRepository) JsonElement(com.google.gson.JsonElement)

Aggregations

Channel (io.openems.api.channel.Channel)16 ConfigChannel (io.openems.api.channel.ConfigChannel)14 WriteChannel (io.openems.api.channel.WriteChannel)12 ReadChannel (io.openems.api.channel.ReadChannel)9 OpenemsException (io.openems.common.exceptions.OpenemsException)8 ChannelDoc (io.openems.api.doc.ChannelDoc)5 JsonObject (com.google.gson.JsonObject)4 ChannelChangeListener (io.openems.api.channel.ChannelChangeListener)4 StaticValueChannel (io.openems.api.channel.StaticValueChannel)4 ThingStateChannel (io.openems.api.channel.ThingStateChannel)4 ThingDoc (io.openems.api.doc.ThingDoc)4 PGreaterEqualLimitation (io.openems.core.utilities.power.symmetric.PGreaterEqualLimitation)4 PSmallerEqualLimitation (io.openems.core.utilities.power.symmetric.PSmallerEqualLimitation)4 SymmetricPowerImpl (io.openems.core.utilities.power.symmetric.SymmetricPowerImpl)4 ModbusReadLongChannel (io.openems.impl.protocol.modbus.ModbusReadLongChannel)4 ModbusWriteLongChannel (io.openems.impl.protocol.modbus.ModbusWriteLongChannel)4 DummyElement (io.openems.impl.protocol.modbus.internal.DummyElement)4 ModbusProtocol (io.openems.impl.protocol.modbus.internal.ModbusProtocol)4 ArrayList (java.util.ArrayList)4 StatusBitChannel (io.openems.api.channel.StatusBitChannel)3