Adding logger and is_connected function to recorder
authorPaul Robinson <darkraver@gmail.com>
Mon, 5 Nov 2012 17:37:04 +0000 (17:37 +0000)
committerPaul Robinson <darkraver@gmail.com>
Mon, 5 Nov 2012 17:37:04 +0000 (17:37 +0000)
obd_recorder.py

index fb242b8..a543b1f 100644 (file)
@@ -1,10 +1,20 @@
 import obd_io
 import serial
 import platform
+import logging
 
 from obd_utils import scanSerial
 
 class OBD_Recorder():
+    def __init__(self, filename):
+        self.port = None
+        self.logger = logging.getLogger(__name__)
+        log_handler = logging.FileHandler(filename)
+        log_formatter = logging.Formatter('%(asctime)s %(message)s')
+        log_handler.setFormatter(log_formatter)
+        self.logger.addHandler(log_handler)
+        self.logger.setLevel(logging.INFO)
+        
     def connect(self):
         portnames = scanSerial()
         print portnames
@@ -19,5 +29,18 @@ class OBD_Recorder():
         if(self.port):
             print "Connected to "+self.port.port.name
             
-o = OBD_Recorder()
-o.connect()
\ No newline at end of file
+    def is_connected(self):
+        return self.port
+        
+#    def record_data(self):
+#        for n in range(1,10):
+#            self.logger.info('woo %s %s %s yay', n, n, n)
+            
+            
+        
+o = OBD_Recorder('bikestuff.log')
+o.connect()
+if not o.is_connected():
+    print "Not connected"
+    
+#o.record_data()
\ No newline at end of file