Search in sources :

Example 16 with ConfigException

use of io.openems.api.exception.ConfigException in project openems by OpenEMS.

the class ModbusDeviceNature method createModbusProtocol.

private void createModbusProtocol() {
    try {
        this.protocol = defineModbusProtocol();
        for (ThingChannelsUpdatedListener listener : this.listeners) {
            listener.thingChannelsUpdated(this);
        }
        if (this.parent instanceof ModbusDevice) {
            ModbusDevice parent = (ModbusDevice) this.parent;
            if (parent.getBridge() instanceof ModbusBridge) {
                ModbusBridge bridge = (ModbusBridge) parent.getBridge();
                // create WriteTasks
                writeTasks = Collections.synchronizedList(new ArrayList<>());
                for (WriteableModbusRange range : protocol.getWritableRanges()) {
                    writeTasks.add(new ModbusBridgeWriteTask(parent.getModbusUnitId(), bridge, range));
                }
                // create ReadTasks
                readTasks = Collections.synchronizedList(new ArrayList<>());
                otherReadTasks = Collections.synchronizedList(new ArrayList<>());
                for (ModbusRange range : protocol.getReadRanges()) {
                    otherReadTasks.add(new ModbusBridgeReadTask(parent.getModbusUnitId(), bridge, range));
                }
            } else {
                log.error("Invalid Bridge Type. The bridge needs to inherit from ModbusBridge.");
            }
        } else {
            log.error("Invalid Device Type. The Device needs to inherit from ModbusDevice");
        }
    } catch (ConfigException e) {
        log.error("Failed to define modbus protocol!", e);
    } catch (Throwable t) {
        log.error("Some error occured while create ModbusProtocol", t);
    }
}
Also used : WriteableModbusRange(io.openems.impl.protocol.modbus.internal.range.WriteableModbusRange) ModbusRange(io.openems.impl.protocol.modbus.internal.range.ModbusRange) ArrayList(java.util.ArrayList) ConfigException(io.openems.api.exception.ConfigException) ThingChannelsUpdatedListener(io.openems.api.thing.ThingChannelsUpdatedListener) WriteableModbusRange(io.openems.impl.protocol.modbus.internal.range.WriteableModbusRange)

Aggregations

ConfigException (io.openems.api.exception.ConfigException)16 InvalidValueException (io.openems.api.exception.InvalidValueException)6 JsonObject (com.google.gson.JsonObject)4 ConfigChannel (io.openems.api.channel.ConfigChannel)4 FunctionalReadChannel (io.openems.api.channel.FunctionalReadChannel)4 ReadChannel (io.openems.api.channel.ReadChannel)4 ThingStateChannels (io.openems.api.channel.thingstate.ThingStateChannels)4 Device (io.openems.api.device.Device)4 ThingInfo (io.openems.api.doc.ThingInfo)4 ModbusDeviceNature (io.openems.impl.protocol.modbus.ModbusDeviceNature)4 ModbusReadLongChannel (io.openems.impl.protocol.modbus.ModbusReadLongChannel)4 DummyElement (io.openems.impl.protocol.modbus.internal.DummyElement)4 ModbusProtocol (io.openems.impl.protocol.modbus.internal.ModbusProtocol)4 UnsignedDoublewordElement (io.openems.impl.protocol.modbus.internal.UnsignedDoublewordElement)4 UnsignedWordElement (io.openems.impl.protocol.modbus.internal.UnsignedWordElement)4 ModbusRegisterRange (io.openems.impl.protocol.modbus.internal.range.ModbusRegisterRange)4 IOException (java.io.IOException)4 LocalTime (java.time.LocalTime)4 JsonArray (com.google.gson.JsonArray)3 JsonElement (com.google.gson.JsonElement)3