Search in sources :

Example 1 with ThingChannelsUpdatedListener

use of io.openems.api.thing.ThingChannelsUpdatedListener in project openems by OpenEMS.

the class StuderDeviceNature method createStuderProtocol.

private void createStuderProtocol() {
    try {
        this.protocol = defineStuderProtocol();
        if (this.parent instanceof StuderDevice) {
            StuderDevice parent = (StuderDevice) this.parent;
            if (parent.getBridge() instanceof StuderBridge) {
                StuderBridge bridge = (StuderBridge) parent.getBridge();
                // create WriteTasks
                writeTasks = Collections.synchronizedList(new ArrayList<>());
                for (WriteProperty<?> property : protocol.getWritableProperties()) {
                    writeTasks.add(new StuderBridgeWriteTask(property, bridge.getSrcAddress(), parent.getDstAddress(), bridge));
                }
                // create ReadTasks
                readTasks = Collections.synchronizedList(new ArrayList<>());
                requiredReadTasks = Collections.synchronizedList(new ArrayList<>());
                for (ReadProperty<?> property : protocol.getReadProperties()) {
                    readTasks.add(new StuderBridgeReadTask(property, bridge.getSrcAddress(), parent.getDstAddress(), bridge));
                }
            } 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");
        }
        for (ThingChannelsUpdatedListener listener : this.listeners) {
            listener.thingChannelsUpdated(this);
        }
    } catch (OpenemsException e) {
        log.error("Failed to define modbus protocol!", e);
    }
}
Also used : ArrayList(java.util.ArrayList) ThingChannelsUpdatedListener(io.openems.api.thing.ThingChannelsUpdatedListener) OpenemsException(io.openems.common.exceptions.OpenemsException)

Example 2 with ThingChannelsUpdatedListener

use of io.openems.api.thing.ThingChannelsUpdatedListener 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

ThingChannelsUpdatedListener (io.openems.api.thing.ThingChannelsUpdatedListener)2 ArrayList (java.util.ArrayList)2 ConfigException (io.openems.api.exception.ConfigException)1 OpenemsException (io.openems.common.exceptions.OpenemsException)1 ModbusRange (io.openems.impl.protocol.modbus.internal.range.ModbusRange)1 WriteableModbusRange (io.openems.impl.protocol.modbus.internal.range.WriteableModbusRange)1