Index: dialin/protocols/CAN.py =================================================================== diff -u -r46ebf93d3666db40f25ad1e9170426853aa845d4 -r12fc8d4dee213f861ee7645ce83c8b3a79896e10 --- dialin/protocols/CAN.py (.../CAN.py) (revision 46ebf93d3666db40f25ad1e9170426853aa845d4) +++ dialin/protocols/CAN.py (.../CAN.py) (revision 12fc8d4dee213f861ee7645ce83c8b3a79896e10) @@ -25,6 +25,7 @@ from logging import Logger import struct from .. import common +from ..utils import SingletonMeta class DenaliMessage: @@ -432,7 +433,7 @@ return None -class DenaliCanMessenger: +class DenaliCanMessenger(metaclass=SingletonMeta): START_BYTE = DenaliMessage.START_BYTE DIALIN_MSG_RESP_TO = 0.5 # number of seconds to wait for a response to a send command @@ -444,7 +445,6 @@ @return: DialityCanMessenger object """ - super().__init__() self.logger = logger self.log_can = log_can @@ -494,9 +494,12 @@ else: self.run = True if self.message_queue_thread is not None and self.canbus_thread is not None: - self.canbus_thread.start() - self.message_queue_thread.start() - self.logger.info("Can listener has started.") + if not self.canbus_thread.is_alive(): + self.canbus_thread.start() + self.logger.info("Canbus thread has started.") + if not self.message_queue_thread.is_alive(): + self.message_queue_thread.start() + self.logger.info("Message queue thread has started.") else: self.logger.error("Cannot start listener...") Index: dialin/utils/__init__.py =================================================================== diff -u -rb20262631dc86edf5c3550762bc888089fa2626d -r12fc8d4dee213f861ee7645ce83c8b3a79896e10 --- dialin/utils/__init__.py (.../__init__.py) (revision b20262631dc86edf5c3550762bc888089fa2626d) +++ dialin/utils/__init__.py (.../__init__.py) (revision 12fc8d4dee213f861ee7645ce83c8b3a79896e10) @@ -3,6 +3,7 @@ from .conversions import * from .excel_ops import * from .nv_ops_utils import * +from .singleton import * from .data_logger import DataLogger YES = 1 NO = 0 \ No newline at end of file Index: dialin/utils/conversions.py =================================================================== diff -u -rb17d2a1969b535d66bf534556ac42fd2bb28fd1d -r12fc8d4dee213f861ee7645ce83c8b3a79896e10 --- dialin/utils/conversions.py (.../conversions.py) (revision b17d2a1969b535d66bf534556ac42fd2bb28fd1d) +++ dialin/utils/conversions.py (.../conversions.py) (revision 12fc8d4dee213f861ee7645ce83c8b3a79896e10) @@ -55,6 +55,7 @@ """ return struct.pack(" None: """ @@ -100,10 +102,13 @@ :param output_path: (str) the destination output path :return: None """ + self.logger.debug("Starting data export to {0}".format(output_path)) + self.disable_logging = True log_path = os.path.join(self.base_folder, "*Log") folders = glob.glob(log_path) if len(folders) == 0: self.logger.debug("No folder with data to export") + self.disable_logging = False return writer = pd.ExcelWriter(output_path) for folder in folders: @@ -115,19 +120,26 @@ df_data = pd.read_csv(csv_file) df_data = df_data.set_index("timestamp") df = df.join(df_data, how="outer") - df.to_excel(writer, sheet_name=module_name) - self.logger.debug("Added {0} to {1}".format(module_name, output_path)) + try: + df.to_excel(writer, sheet_name=module_name) + self.logger.debug("Added {0} to {1}".format(module_name, output_path)) + except ValueError as e: + self.logger.error("Error during write to excel: {0}".format(e)) + writer.save() self.logger.debug("Finished data export to {0}".format(output_path)) + self.disable_logging = False def clear_logs(self): """ Called when the user clears the logs :return: None """ + self.disable_logging = True log_path = os.path.join(self.base_folder, "*Log") folders = glob.glob(log_path) for folder in folders: self.logger.debug("Removing {0}".format(folder)) shutil.rmtree(folder) + self.disable_logging = False Index: dialin/utils/singleton.py =================================================================== diff -u -r6780ca960d531deda7056cf910baa59826468223 -r12fc8d4dee213f861ee7645ce83c8b3a79896e10 --- dialin/utils/singleton.py (.../singleton.py) (revision 6780ca960d531deda7056cf910baa59826468223) +++ dialin/utils/singleton.py (.../singleton.py) (revision 12fc8d4dee213f861ee7645ce83c8b3a79896e10) @@ -24,6 +24,7 @@ _instances = {} _lock: Lock = Lock() + _creation_attempts = 0 """ Synchronizes threads during first access to the Singleton. """ @@ -33,6 +34,9 @@ Possible changes to the value of the `__init__` argument do not affect the returned instance. """ + cls._creation_attempts += 1 + # Keep for debugging + # print("CAN interface constructor call counter: {0}".format(cls._creation_attempts)) # First thread acquires the lock with cls._lock: if cls not in cls._instances: