changeset 22:02ba26698696

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.
author Daniel O'Connor <darius@dons.net.au>
date Mon, 13 Dec 2021 15:51:09 +1030
parents 625064987b7c
children 7bca87ca06e4
files eprodbus.py
diffstat 1 files changed, 3 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- 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)