-
Notifications
You must be signed in to change notification settings - Fork 1
/
TempSens.py
121 lines (104 loc) · 3.55 KB
/
TempSens.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
114
115
116
117
118
119
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
from datalogger import *
import threading
from time import sleep
from config import *
print("Doreturn inicializado")
doReturn = True
def keep_alive():
global talive
print("TEMP RECOVERY: ",PfLog.dre.command_tx_buf)
PfLog.sendCtrlCommand()
talive = threading.Timer(10.0,keep_alive)
talive.start()
def doit():
#print("doit: ", threading.get_ident())
global doReturn
doReturn = True
def getDataLakeshore():
if (cte_simulate_sensors) or (cte_emulate_devices):
#print("Espero 0.3 segundos")
sleep(.5)
return 99, 5555.0, 98, 5554
else:
global t
global doReturn
global talive
while not doReturn:
sleep(0.05)
#print("getDataLakeshore: ", threading.get_ident())
t = threading.Timer(cfg_temp_read_period, doit)
t.start()
doReturn = False
PfLog.dre.command_tx_buf="RDGST? A".encode()
PfLog.sendCtrlCommand()
talive = threading.Timer(10.0,keep_alive)
talive.start()
#print("programo timer")
PfLog.getCtrlResponse()
#print("cancelo timer")
talive.cancel()
resp1 = PfLog.dre.command_rx_str
status1 = int(resp1.strip()) # Removes whitespaces and assign to status of first channel
PfLog.dre.command_tx_buf="KRDG? A".encode()
PfLog.sendCtrlCommand()
talive = threading.Timer(10.0,keep_alive)
talive.start()
#print("programo timer")
PfLog.getCtrlResponse()
#print("cancelo timer")
talive.cancel()
resp1 = PfLog.dre.command_rx_str
value1 = float(resp1.strip()) # Removes whitespaces and assign to value of first channel
PfLog.dre.command_tx_buf="RDGST? B".encode()
PfLog.sendCtrlCommand()
talive = threading.Timer(10.0,keep_alive)
talive.start()
#print("programo timer")
PfLog.getCtrlResponse()
#print("cancelo timer")
talive.cancel()
resp2 = PfLog.dre.command_rx_str
status2 = int(resp2.strip()) # Removes whitespaces and assign to status of second channel
PfLog.dre.command_tx_buf="KRDG? B".encode()
PfLog.sendCtrlCommand()
talive = threading.Timer(10.0,keep_alive)
talive.start()
#print("programo timer")
PfLog.getCtrlResponse()
#print("cancelo timer")
talive.cancel()
resp2 = PfLog.dre.command_rx_str
value2 = float(resp2.strip()) # Removes whitespaces and assign to value of second channel
return status1, value1, status2, value2
# In[ ]:
if not cte_emulate_devices:
serport = serial.Serial(
port=config.cte_serial_port2,
baudrate=9600,
parity=serial.PARITY_ODD,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.SEVENBITS,
rtscts=False,
dsrdtr=False,
xonxoff=True
)
if config.cte_verbose:
print("Chosen serial port: " + config.cte_serial_port2)
else:
serport = None
def execTempDatalog():
datalogger(serport,getDataLakeshore,"Temp1","Temp2","temp",cfg_temp_nsamples_period1, cfg_temp_nsamples_period2)
tempDatalog = threading.Thread(target=execTempDatalog, name="tempDatalog")
print("*** Lanzo tempDatalog")
tempDatalog.start()
veces = 1
while(1):
sleep(10)
threadvivo = tempDatalog.is_alive()
if not threadvivo:
tempDatalog = threading.Thread(target=execTempDatalog, name="tempDatalog")
print("*** Relanzo tempDatalog",veces)
tempDatalog.start()