-
Notifications
You must be signed in to change notification settings - Fork 3
/
watchdog3.py
executable file
·60 lines (55 loc) · 2.06 KB
/
watchdog3.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
#watchdog.py
""" Watchdog.py modified for python 3 compatibility.
This is a convenience function implementing a watchdog timer with indirect loop
control via inspection of provided PVs. This is used throughout the fstiming
codebase. This tool is not currently asynchronous.
Dependencies:
- pyepics
"""
import time #includes sleep command to wait for other users
import epics
class watchdog():
def __init__(self, pv): # pv is an already connected pv
self.pv = pv
self.counter = 0;
try:
self.pv.get( timeout=1.0)
self.value = self.pv.value
if self.value < 0:#command to exit programs
self.error = 1 #exit program
print('watchdog pv negative - exiting')
return
print('initializing watchdog')
time.sleep(1) # wait 1 second1 for an update
self.pv.get(timeout=1.0)
except:
print('cant write watchdog pv, exiting')
self.error = 1
return
if self.pv.value < 0:#command to exit programs
self.error = 1 #exit program
print('watchdog pv negative - exiting')
return
if self.pv.value != self.value:
self.error = 1
print('another program is incrementing the watchdog')
return
self.error = 0 # OK to continue
def check(self): # check watchdog timer
try:
self.pv.get(timeout=1.0)
except:
print('not able to read watchdog PV, continuing to try')
self.error = 0 # not an error (at least for now)
return
if self.pv.value < 0:
self.error = 1 #exit program
print('watchdog pv negative - exiting')
return
if self.pv.value != self.value: # value changed
self.error = 1
print('another program is incrementing the watchdog')
return
self.error = 0
self.value = self.pv.value+1
self.pv.put(value = self.value, timeout=1.0) # write new number to increment