Revision 2ea7698ff7e59d1867a9ea1375c95e75e00ae1a6

HW/Radiation/Monitoring/GammaScout/gs_online_log.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import sys
import time
import serial


def conn_factory(devname='/dev/ttyUSB0'):
    conn = serial.Serial(devname, baudrate=460800, bytesize=7, parity='E', stopbits=1, timeout=2)
    return conn

if __name__ == '__main__':
    try:
        fout = sys.argv[1]
    except IndexError:
        print('provide output filename (or - for STDOUT) as first argument')
        fout = '-'
    if fout == '-':
        fout = sys.stdout
    else:
        fout = open(fout, 'a')
    conn = conn_factory()
    buff = ''
    conn.write('XD')  # X - start measurements, D - report cumulative dose values
    while True:
        buff = conn.readline()
        fout.write(time.strftime('%F %T ') + buff)
        fout.flush()
        try:
            time.sleep(0.1)
        except KeyboardInterrupt:
            break
    fout.close()