# HG changeset patch # User Daniel O'Connor # Date 1639372869 -37800 # Node ID 02ba26698696f4da4db84fe32507ca9d6847cf80 # Parent 625064987b7cce631f2ac4470b0129b96a475cd8 Change to run as a service by serial-starter. - Remove file logging. - Take TTY from argv - Just blow up if the serial port read fails, we will die and get resurrected if the TTY comes back. diff -r 625064987b7c -r 02ba26698696 eprodbus.py --- a/eprodbus.py Thu Dec 09 23:52:54 2021 +1030 +++ b/eprodbus.py Mon Dec 13 15:51:09 2021 +1030 @@ -23,22 +23,15 @@ formatter = logging.Formatter('%(asctime)s - %(message)s') -#fh = logging.FileHandler('/var/log/eprodbus.log') -#fh.setLevel(logging.DEBUG) -#fh.setFormatter(formatter) - ch = logging.StreamHandler() ch.setLevel(logging.INFO) ch.setFormatter(formatter) -#logger.addHandler(fh) logger.addHandler(ch) logger.info(__file__ + " is starting up") dbpath = '/home/root/vanlogger/log.db' -port = 'ttyepro' -servicename = 'com.victronenergy.battery.' + port instance = 0 class eProUpdater: @@ -52,11 +45,7 @@ gobject.timeout_add(60000, exit_on_error, self.log_epro) def read_serial(self, fd, userdata): - try: - data = self.s.read(1024) - except Exception as e: - logger.error('Failed to read from serial port: %s', str(e)) - return False + data = self.s.read(1024) logger.debug('Read %d bytes from serial port', len(data)) self.p.process(data) @@ -162,6 +151,8 @@ sys.exit(1) def main(): + port = sys.argv[1] + servicename = 'com.victronenergy.battery.' + port # Add signal handler to exit, otherwise we have to press ctrl-c twice to quit signal.signal(signal.SIGINT, doexit)