use of me.retrodaredevil.solarthing.program.modbus.ModbusCacheSlave in project solarthing by wildmountainfarms.
the class TracerModbusRequester method create.
@Override
public DataRequesterResult create(RequestObject requestObject, SuccessReporter successReporter, ModbusSlave modbus) {
final TracerReadTable read;
final Runnable reloadCache;
if (bulkRequest) {
ModbusCacheSlave modbusCacheSlave = new ModbusCacheSlave(modbus);
read = new TracerModbusSlaveRead(modbusCacheSlave);
reloadCache = () -> cacheRegisters(modbusCacheSlave);
} else {
read = new TracerModbusSlaveRead(modbus);
reloadCache = () -> {
};
}
TracerWriteTable write = new TracerModbusSlaveWrite(modbus);
TracerModbusEnvironment tracerModbusEnvironment = new TracerModbusEnvironment(read, write);
final NetCatServerHandler netCatServerHandler;
if (configurationServerConfig == null) {
netCatServerHandler = null;
} else {
try {
netCatServerHandler = new NetCatServerHandler(configurationServerConfig.getBindAddress(), configurationServerConfig.getPort());
} catch (IOException e) {
throw new RuntimeException("Could not create NetCatServerHandler", e);
}
}
return new DataRequesterResult(new ModbusListUpdaterWrapper(new TracerPacketListUpdater(number, read, write, tracerClockOptions, netCatServerHandler == null ? null : new ConnectionHandler(netCatServerHandler), connectionHandlerHasFlushLogic), reloadCache, successReporter, sendErrorPackets, "tracer.error." + number), new AttachToCommandEnvironmentUpdater(Collections.singletonList(tracerModbusEnvironment), attachToCommands::contains));
}
use of me.retrodaredevil.solarthing.program.modbus.ModbusCacheSlave in project solarthing by wildmountainfarms.
the class RoverMain method doRoverProgram.
private static int doRoverProgram(RoverOption options, RoverProgramRunner runner, @Nullable RegisterCacheHandler registerCacheHandler) {
IOConfig ioConfig = ConfigUtil.parseIOConfig(options.getIOBundleFile(), RoverReadTable.SERIAL_CONFIG);
try (ReloadableIOBundle ioBundle = new ReloadableIOBundle(ioConfig::createIOBundle)) {
ModbusSlaveBus modbus = new IOModbusSlaveBus(ioBundle, new RtuDataEncoder(2000, 20, 4));
MutableAddressModbusSlave slave = new MutableAddressModbusSlave(options.getModbusAddress(), modbus);
final RoverReadTable read;
final Runnable reloadCache;
if (registerCacheHandler != null) {
ModbusCacheSlave modbusCacheSlave = new ModbusCacheSlave(slave);
read = new RoverModbusSlaveRead(modbusCacheSlave);
reloadCache = () -> registerCacheHandler.cacheRegisters(modbusCacheSlave);
} else {
read = new RoverModbusSlaveRead(slave);
reloadCache = () -> {
};
}
RoverWriteTable write = new RoverModbusSlaveWrite(slave);
return runner.doProgram(slave, read, write, reloadCache, ioBundle::reload);
} catch (Exception e) {
LOGGER.error(SolarThingConstants.SUMMARY_MARKER, "(Fatal)Got exception!", e);
return SolarThingConstants.EXIT_CODE_CRASH;
}
}
use of me.retrodaredevil.solarthing.program.modbus.ModbusCacheSlave in project solarthing by wildmountainfarms.
the class RoverModbusRequester method create.
@Override
public DataRequesterResult create(RequestObject requestObject, SuccessReporter successReporter, ModbusSlave modbus) {
final RoverReadTable read;
final Runnable reloadCache;
if (bulkRequest) {
ModbusCacheSlave modbusCacheSlave = new ModbusCacheSlave(modbus);
read = new RoverModbusSlaveRead(modbusCacheSlave);
reloadCache = () -> cacheRegisters(modbusCacheSlave);
} else {
read = new RoverModbusSlaveRead(modbus);
reloadCache = () -> {
};
}
RoverWriteTable write = new RoverModbusSlaveWrite(modbus);
RoverModbusEnvironment roverModbusEnvironment = new RoverModbusEnvironment(read, write);
final NetCatServerHandler netCatServerHandler;
if (configurationServerConfig == null) {
netCatServerHandler = null;
} else {
try {
netCatServerHandler = new NetCatServerHandler(configurationServerConfig.getBindAddress(), configurationServerConfig.getPort());
} catch (IOException e) {
throw new RuntimeException("Could not create NetCatServerHandler", e);
}
}
return new DataRequesterResult(new ModbusListUpdaterWrapper(new RoverPacketListUpdater(number, read, write, netCatServerHandler == null ? null : new ConnectionHandler(netCatServerHandler)), reloadCache, successReporter, sendErrorPackets, "rover.error." + number), new AttachToCommandEnvironmentUpdater(Collections.singletonList(roverModbusEnvironment), attachToCommands::contains));
}
Aggregations