data_ascii_write_proxy.py 832 Bytes
Newer Older
1 2 3 4
# -*- coding: utf-8 -*-
# Copyright (c) 2016-2018 Braintech Sp. z o.o. [Ltd.] <http://www.braintech.pl>
# All rights reserved.

5 6 7 8 9 10
"""
Module defines single :class: 'DataAsciiWriteProxy'.

Author:
    Mateusz Kruszyński <mateusz.kruszynski@gmail.com>
"""
11
from .data_generic_write_proxy import DataGenericWriteProxy, SamplePacket
12 13


14
class DataAsciiWriteProxy(DataGenericWriteProxy):
15
    """Subclass write data in ASCII format to file."""
16 17 18 19

    def __init__(self, p_file_path):
        """Open p_file_path file for writing."""
        super().__init__(p_file_path, 'wt')
20

21
    def data_received(self, packet: SamplePacket):
22 23 24 25 26
        """
        Method gets and saves next sample of signal.

        :param packet: 'SamplePacket'
        """
27
        self._write_file(str(packet.samples.tolist()) + '\n')
28
        self._number_of_samples += 1