specific exception

This commit is contained in:
Wolfgang Hottgenroth 2020-09-02 18:43:38 +02:00
parent 59bf7d65a0
commit ffe3ff249f
Signed by: wn
GPG Key ID: B586EAFCDF2F65F4
3 changed files with 36 additions and 5 deletions

View File

@ -1,5 +1,7 @@
package de.hottis.mbusMaster;
import java.io.IOException;
import java.util.Properties;
import org.apache.logging.log4j.LogManager;
@ -26,13 +28,17 @@ public class MbusMaster {
mbusgw.start();
mbusgw.sendRequest((byte)0x5b, (byte)80);
try {
mbusgw.sendRequest((byte)0x5b, (byte)80);
byte[] frame = mbusgw.collectResponse();
for (byte x : frame) {
System.out.print(Integer.toHexString(Byte.toUnsignedInt(x)) + " ");
byte[] frame = mbusgw.collectResponse();
for (byte x : frame) {
System.out.print(Integer.toHexString(Byte.toUnsignedInt(x)) + " ");
}
System.out.println();
} catch (IOException e) {
logger.error("Error in Meterbus dialog: " + e.toString() + ", " + e.getMessage());
}
System.out.println();
System.out.println("Stopping mbusgw process");
mbusgw.stop();

View File

@ -99,6 +99,10 @@ public class MbusgwChild {
int responseCode = Byte.toUnsignedInt(header[0]);
int responseLen = Byte.toUnsignedInt(header[1]);
logger.debug("n: " + n + ", h: " + responseCode + ", l: " + responseLen);
if (responseCode != 0) {
logger.debug("Received error from child: " + responseCode);
throw new MbusgwChildException("Error " + responseCode + " from child");
}
byte[] frame = new byte[responseLen];
n = this.processInput.read(frame, 0, responseLen);
logger.debug("frame completely read");

View File

@ -0,0 +1,21 @@
package de.hottis.mbusMaster;
import java.io.IOException;
public class MbusgwChildException extends IOException {
public MbusgwChildException() {
super();
}
public MbusgwChildException(String message, Throwable cause) {
super(message, cause);
}
public MbusgwChildException(String message) {
super(message);
}
public MbusgwChildException(Throwable cause) {
super(cause);
}
}