예제 #1
0
 def _parse_csv(self, time, line):
     """
     Parses incoming data and distributes to external processes.
     :param time: Timestamp.
     :type time: float.
     :param line: Raw data coming from acquisition process.
     :type line: basestring.
     :return:
     """
     if len(line) > 0:
         try:
             if type(line) == bytes:
                 values = line.decode("UTF-8").split(self._split)
             elif type(line) == str:
                 values = line.split(self._split)
             else:
                 raise TypeError
             values = [float(v) for v in values]
             Log.d(TAG, values)
             self._out_queue.put((time, values))
             if self._store_reference is not None:
                 self._store_reference.add(time, values)
         except ValueError:
             Log.w(TAG, "Can't convert to float. Raw: {}".format(line.strip()))
         except AttributeError:
             Log.w(TAG, "Attribute error on type ({}). Raw: {}".format(type(line), line.strip()))
예제 #2
0
 def stop(self):
     """
     Signals the process to stop parsing data.
     :return:
     """
     Log.d(TAG, "Process finishing...")
     self._exit.set()
예제 #3
0
    def __init__(self,
                 data_queue,
                 store_reference=None,
                 split=Constants.csv_delimiter,
                 consumer_timeout=Constants.parser_timeout_ms):
        """

        :param data_queue: Reference to Queue where processed data will be put.
        :type data_queue: multiprocessing Queue.
        :param store_reference: Reference to CSVProcess instance, if needed.
        :type store_reference: CSVProcess (multiprocessing.Process)
        :param split: Delimiter in incoming data.
        :type split: str.
        :param consumer_timeout: Time to wait after emptying the internal buffer before next parsing.
        :type consumer_timeout: float.
        """
        mp.Process.__init__(self)
        self._exit = mp.Event()
        self._in_queue = mp.Queue()
        self._out_queue = data_queue  # Queue from the worker process
        self._consumer_timeout = consumer_timeout
        self._split = split
        self._store_reference = store_reference
        self._leftover = ''
        Log.d(TAG, "Process ready")
예제 #4
0
 def run(self):
     """
     Process will monitor the internal buffer to parse raw data and distribute to graph and storage, if needed.
     The process will loop again after timeout if more data is available.
     :return:
     """
     Log.d(TAG, "Process starting...")
     while not self._exit.is_set():
         self._consume_queue()
         sleep(self._consumer_timeout)
     # last check on the queue to completely remove data.
     self._consume_queue()
     Log.d(TAG, "Process finished")
예제 #5
0
파일: worker.py 프로젝트: spewil/RTGraph
 def consume_queue(self):
     """
     Empties the internal queue, updating data to consumers.
     :return:
     """
     # i = 0
     while True:
         try:
             # i += 1
             self._store_data(self._queue.get(block=False))
         except queue.Empty:
             # print("parsed queue: ", i)
             return
     Log.d(TAG, f"queue len: {i}")
예제 #6
0
 def get_ports():
     """
     Gets a list of the available serial ports.
     :return: List of available serial ports.
     :rtype: str list.
     """
     if Architecture.get_os() is OSType.macosx:
         import glob
         return glob.glob("/dev/tty.*")
     else:
         found_ports = []
         for port in list(list_ports.comports()):
             Log.d(TAG, "found device {}".format(port))
             found_ports.append(port.device)
         return found_ports