use of me.retrodaredevil.io.modbus.ModbusRuntimeException in project solarthing by wildmountainfarms.
the class CheckMain method doModbus.
private static boolean doModbus(@NotNull String port, int startingAddress, boolean scan, SerialConfig serialConfig, Function<ModbusSlave, BatteryVoltage> slaveToReadTable) throws SerialPortException {
System.out.println("Going to open serial port using default serial configuration...");
try (JSerialIOBundle ioBundle = JSerialIOBundle.createPort(port, serialConfig)) {
System.out.println("Successfully opened serial port...");
ModbusSlaveBus bus = new IOModbusSlaveBus(ioBundle, new RtuDataEncoder());
MutableAddressModbusSlave modbusSlave = new MutableAddressModbusSlave(startingAddress, bus);
BatteryVoltage readTable = slaveToReadTable.apply(modbusSlave);
int maxAddress = scan ? 247 : startingAddress;
for (int currentAddress = startingAddress; currentAddress <= maxAddress; currentAddress++) {
modbusSlave.setAddress(currentAddress);
System.out.println("Checking on address: " + currentAddress);
try {
float batteryVoltage = readTable.getBatteryVoltage();
System.out.println("Success! Battery Voltage: " + batteryVoltage);
return true;
} catch (ModbusTimeoutException e) {
System.err.println("Got timeout. This means that the modbus address is incorrect or that the cable is not functioning properly.");
} catch (ModbusRuntimeException e) {
e.printStackTrace();
System.err.println("Got some sort of modbus error. Info logged above");
}
}
System.err.println("Did not find a device");
return false;
}
}
use of me.retrodaredevil.io.modbus.ModbusRuntimeException in project solarthing by wildmountainfarms.
the class PzemShuntPacketListUpdater method receive.
@Override
public void receive(List<Packet> packets) {
final PzemShuntStatusPacket packet;
try {
packet = ImmutablePzemShuntStatusPacket.createFromReadTable(dataId, modbusAddress, read);
} catch (ModbusRuntimeException ex) {
LOGGER.error("Modbus exception", ex);
return;
}
packets.add(packet);
}
Aggregations