This commit is contained in:
Wolfgang Hottgenroth 2020-09-02 22:05:43 +02:00
parent ffe3ff249f
commit 6d87ca1ee3
Signed by: wn
GPG Key ID: B586EAFCDF2F65F4
3 changed files with 34 additions and 13 deletions

View File

@ -11,7 +11,7 @@ import org.apache.logging.log4j.Logger;
public class MbusMaster {
static final String PROPS_FILENAME = "mbusMaster.props";
static final Logger logger = LogManager.getRootLogger();
static boolean stopSignal = false;
public static void main(String[] args) throws Exception {
logger.info("MbusMaster starting");
@ -24,23 +24,43 @@ public class MbusMaster {
logger.debug("Configuration loaded");
*/
/*
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
stopSignal = true;
}));
logger.debug("Shutdown hook added");
*/
MbusgwChild mbusgw = new MbusgwChild(false);
mbusgw.start();
byte[] devices = { (byte)80, (byte)81, (byte)82, (byte)83, (byte)84, (byte)85, (byte)86, (byte)87 };
try {
mbusgw.sendRequest((byte)0x5b, (byte)80);
int cnt = 0;
while (! stopSignal) {
System.out.println("--- " + cnt + " ----------------------------------------------------");
cnt++;
for (byte device : devices) {
System.out.println("Querying device " + device);
try {
mbusgw.sendRequest((byte)0x5b, device);
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 " + e.toString() + ", " + e.getMessage() + " in Meterbus dialog for device " + device);
}
}
System.out.println();
} catch (IOException e) {
logger.error("Error in Meterbus dialog: " + e.toString() + ", " + e.getMessage());
// if (cnt >= 10) {
// break;
//}
Thread.sleep(15*1000);
}
System.out.println("Stopping mbusgw process");
logger.info("Stopping mbusgw process");
mbusgw.stop();
}

View File

@ -63,9 +63,10 @@ public class MbusgwChild {
logger.debug("stderrToLog thread started");
}
public void stop() throws InterruptedException {
public void stop() throws InterruptedException, IOException {
logger.info("About to stop mbusgw child process");
this.mbusgwProcess.destroy();
this.sendRequest((byte)0, (byte)0);
// this.mbusgwProcess.destroy();
this.mbusgwProcess.waitFor();
logger.info("Process stopped");

View File

@ -9,7 +9,7 @@
</File>
</Appenders>
<Loggers>
<Root level="debug">
<Root level="error">
<AppenderRef ref="ConsoleAppender"/>
<AppenderRef ref="FileAppender"/>
</Root>