use of me.retrodaredevil.io.modbus.handling.ParsedResponseException in project solarthing by wildmountainfarms.
the class ModbusListUpdaterWrapper method receive.
@Override
public void receive(List<Packet> packets) {
final long startTimeNanos = System.nanoTime();
try {
reloadCache.run();
packetListReceiver.receive(packets);
} catch (ModbusRuntimeException e) {
LOGGER.error("Modbus exception", e);
if (isSendErrorPackets) {
LOGGER.debug("Sending error packets");
packets.add(new ImmutableExceptionErrorPacket(e.getClass().getName(), e.getMessage(), MODBUS_RUNTIME_EXCEPTION_CATCH_LOCATION_IDENTIFIER, errorIdentifierString));
}
boolean isTimeout = false;
if (e.getCause() instanceof NotInitializedIOException) {
isTimeout = true;
}
if (e instanceof ModbusTimeoutException) {
isTimeout = true;
// These messages will hopefully help people with problems fix it faster.
if (hasBeenSuccessful) {
LOGGER.info("\n\nHey! We noticed you got a ModbusTimeoutException after getting this to work.\n" + "This is likely a fluke and hopefully this message isn't printed a bunch of times. If it is not a fluke, you may want to check your cable.\n");
} else {
LOGGER.info("\n\nHey! We noticed you got a ModbusTimeoutException.\n" + "This is likely a problem with your cable. SolarThing is communicating fine with your serial adapter, but it cannot reach the device.\n" + "Make sure the cable you have has the correct pinout, and feel free to open an issue at https://github.com/wildmountainfarms/solarthing/issues if you need help.\n");
}
} else if (e instanceof ParsedResponseException) {
ParsedResponseException parsedResponseException = (ParsedResponseException) e;
ModbusMessage message = parsedResponseException.getResponse();
String hexFunctionCode = String.format("%02X", message.getFunctionCode());
LOGGER.info("Communication with rover working well. Got this response back: function code=0x" + hexFunctionCode + " data='" + dataToSplitHex(message.getByteData()) + "' feel free to open issue at https://github.com/wildmountainfarms/solarthing/issues/");
} else if (e instanceof RawResponseException) {
byte[] data = ((RawResponseException) e).getRawData();
LOGGER.info("Got part of a response back. (Maybe timed out halfway through?) data='" + dataToSplitHex(data) + "' Feel free to open an issue at https://github.com/wildmountainfarms/solarthing/issues/");
}
if (isTimeout) {
successReporter.reportTimeout();
} else {
successReporter.reportSuccessWithError();
}
return;
}
hasBeenSuccessful = true;
successReporter.reportSuccess();
final long readDurationNanos = System.nanoTime() - startTimeNanos;
LOGGER.debug("took " + TimeUtil.nanosToSecondsString(readDurationNanos) + " seconds to read from device");
}
use of me.retrodaredevil.io.modbus.handling.ParsedResponseException in project solarthing by wildmountainfarms.
the class RoverMessageHandler method handleResponse.
@Override
public Void handleResponse(ModbusMessage response) {
HandleResponseHelper.checkResponse(response, this.functionCode, 4);
int[] data = response.getData();
if (data[0] != 0)
throw new ParsedResponseException(response, "data[0] must be 0! It's: " + data[0]);
if (data[1] != 0)
throw new ParsedResponseException(response, "data[1] must be 0! It's: " + data[1]);
if (data[2] != 0)
throw new ParsedResponseException(response, "data[2] must be 0! It's: " + data[2]);
if (data[3] != 1)
throw new ParsedResponseException(response, "data[3] must be 1! It's: " + data[3]);
return null;
}
Aggregations