forked from Biophotonics-Tyndall/QY-DAQInterface
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
113 lines (95 loc) · 3.21 KB
/
main.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import os
import subprocess
import platform
import logging
logging.basicConfig(
filename='output/logs/errors.log',
format='%(asctime)s | %(levelname)s: %(message)s',
datefmt='%d/%m/%Y %I:%M:%S %p'
)
debug = False
def main():
from source.daq import Controler
# import configparser
# Create daq object
Controler.debug = debug
Daq = Controler()
def clear():
os.system('cls' if os.name == 'nt' else 'clear')
# Menu creation
def row(s):
return(' ' + '\u2502' + s.ljust(width - 4) + '\u2502')
width = 70
upHline = ' ' + '\u250C' + '\u2500' * (width - 4) + '\u2510'
downHline = ' ' + '\u2514' + '\u2500' * (width - 4) + '\u2518'
print('Atention! The saved data will be always the last run!')
input('>> ')
def menu(statusMsg):
return(
'\n'.join([
upHline,
row(" "),
row(" QY - System"),
row(f" \xa9 {Daq._appDetails['name']} v{Daq._appDetails['version']}"),
row(" "),
row(" "),
row(" t. Settings"),
row(" r. Run"),
row(" s. Save"),
row(" p. Plot data"),
row(" x. Exit"),
row(" "),
row(f" {statusMsg}"),
downHline,
])
)
running = True
while running:
clear()
print(menu(Daq.status()))
action = input(' >> ').lower().strip()
clear()
if action == 'x':
running = False
print('Closing...\n')
if not Daq.isdatasaved():
yORn = input(
'Would you like to save last data? [y/n]: ').lower().strip()
while (yORn != 'y') and (yORn != 'n'):
clear()
yORn = input(
'Would you like to save last data? [y/n]: ').lower().strip()
if yORn == 'y':
Daq.save()
else:
Daq.savelog()
elif action == 'p':
print('Plotting...\n')
Daq.plot()
elif action == 's':
print('Saving...\n')
Daq.save()
elif action == 'r':
print('Running...\n')
try:
Daq.run()
# bug here. Should close the task after the error.
except Exception as e:
logging.error(str(e))
print('Something went wrong...\n',
'Check if device is connected and its name is Dev1, then try again.\n')
elif action == 't':
print('Change the file, save and close it.')
if platform.system() == 'Darwin': # macOS
subprocess.call(('open', 'config.txt'))
elif platform.system() == 'Windows': # Windows
os.startfile('config.txt')
else: # linux variants
subprocess.call(('xdg-open', 'config.txt'), shell=False)
else:
print('Invalid option...')
input('\nPress ENTER to continue...')
try:
main()
except Exception as e:
logging.error(str(e))