use of io.openems.impl.protocol.modbus.internal.range.WriteableModbusRange in project openems by OpenEMS.
the class ModbusProtocol method addRange.
public void addRange(ModbusRange range) {
// check each range for plausibility
checkRange(range);
// fill writableRanges
if (range instanceof WriteableModbusRange) {
WriteableModbusRange writableRange = (WriteableModbusRange) range;
writableRanges.put(writableRange.getStartAddress(), writableRange);
}
// fill readRanges Map
readRanges.put(range.getStartAddress(), range);
// fill channelElementMap
for (ModbusElement<?> element : range.getElements()) {
if (element.getChannel() != null) {
// ignore Elements without Channel (DummyChannels)
channelElementMap.put(element.getChannel(), element);
}
}
}
use of io.openems.impl.protocol.modbus.internal.range.WriteableModbusRange 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