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);
}
}
Aggregations