Project

General

Profile

Task #3119 » record_lfr_console.py

Script pour enregistrer la sortie de LFR - Alexis Jeandet, 01/10/2018 09:53 AM

 
1
#!/usr/bin/env python3
2

    
3
__author__ = "Alexis Jeandet"
4
__copyright__ = "Copyright 2018, Laboratory of Plasma Physics"
5
__credits__ = []
6
__license__ = "GPLv2"
7
__version__ = "1.0.0"
8
__maintainer__ = "Alexis Jeandet"
9
__email__ = "alexis.jeandet@member.fsf.org"
10
__status__ = "Development"
11

    
12
import time
13
import sys
14
import os
15
import serial
16
import argparse
17
from datetime import datetime
18

    
19
parser = argparse.ArgumentParser()
20
parser.add_argument("-p", "--port", help="Serial port")
21
parser.add_argument("-s", "--speed", help="Baud rate")
22
args = parser.parse_args()
23

    
24

    
25

    
26
def main():
27
    with open('gcov_out_'+str(datetime.now())+'.txt','w') as gcov:
28
        with open('console_'+str(datetime.now())+'.txt','w') as console:
29
            with serial.Serial(args.port, args.speed, timeout=None) as ser:
30
                line = ser.readline().decode()
31
                while '_GCOVEXIT_BEGIN_' not in line:
32
                    console.write(line)
33
                    line = ser.readline().decode()
34
                line = ser.readline().decode()
35
                while '_GCOVEXIT_END_' not in line:
36
                    gcov.write(line)
37
                    line = ser.readline().decode()
38

    
39
if __name__ == "__main__":
40
    main()
(2-2/10)