public CompletableFuture<ModbusTcpMaster> createModbusConnector(String ipAddr, int port) {
if (modbusMaster == null) {
ModbusTcpMasterConfig masterConfig = new ModbusTcpMasterConfig.Builder(ipAddr).setPort(port).setTimeout(Duration.parse(TIMEOUT_DURATION)).build();
modbusMaster = new ModbusTcpMaster(masterConfig);
}
return modbusMaster.connect();
}
My step is like this.
create a common ModbusTcpMaster instance.
then invoke collectModbusData for multi-thread
collectModbusData function will create a supplyAsync process use customized thread pool "modbusExecutor".
finally, they will invoke into ModbusMasterUtil class and sendRequest.