@@ -20,23 +20,29 @@ class FliCamera(BaseCamera, ICamera, IWindow, IBinning, ICooling):
20
20
21
21
__module__ = "pyobs_fli"
22
22
23
- def __init__ (self , setpoint : float = - 20.0 , ** kwargs : Any ):
23
+ def __init__ (self , setpoint : float = - 20.0 , keep_alive_ping : int = 10 , ** kwargs : Any ):
24
24
"""Initializes a new FliCamera.
25
25
26
26
Args:
27
27
setpoint: Cooling temperature setpoint.
28
+ keep_alive_ping: Interval in seconds to ping camera.
28
29
"""
29
30
BaseCamera .__init__ (self , ** kwargs )
30
31
from .flidriver import FliDriver # type: ignore
31
32
32
33
# variables
33
34
self ._driver : Optional [FliDriver ] = None
35
+ self ._device : Optional [Any ] = None
34
36
self ._temp_setpoint : Optional [float ] = setpoint
37
+ self ._keep_alive_ping = keep_alive_ping
35
38
36
39
# window and binning
37
40
self ._window = (0 , 0 , 0 , 0 )
38
41
self ._binning = (1 , 1 )
39
42
43
+ # keep alive
44
+ self .add_background_task (self ._keep_alive )
45
+
40
46
async def open (self ) -> None :
41
47
"""Open module."""
42
48
await BaseCamera .open (self )
@@ -48,9 +54,13 @@ async def open(self) -> None:
48
54
raise ValueError ("No camera found." )
49
55
50
56
# open first one
51
- d = devices [0 ]
52
- log .info ('Opening connection to "%s" at %s...' , d .name .decode ("utf-8" ), d .filename .decode ("utf-8" ))
53
- self ._driver = FliDriver (d )
57
+ self ._device = devices [0 ]
58
+ log .info (
59
+ 'Opening connection to "%s" at %s...' ,
60
+ self ._device .name .decode ("utf-8" ),
61
+ self ._device .filename .decode ("utf-8" ),
62
+ )
63
+ self ._driver = FliDriver (self ._device )
54
64
try :
55
65
self ._driver .open ()
56
66
except ValueError as e :
@@ -73,6 +83,24 @@ async def close(self) -> None:
73
83
self ._driver .close ()
74
84
self ._driver = None
75
85
86
+ async def _keep_alive (self ) -> None :
87
+ """Keep connection to camera alive."""
88
+ from .flidriver import FliDriver
89
+
90
+ while True :
91
+ # is there a valid driver?
92
+ if self ._driver is not None :
93
+ # then we should be able to call it
94
+ try :
95
+ self ._driver .get_full_frame ()
96
+ except ValueError :
97
+ # no? then reopen driver
98
+ log .warning ("Lost connection to camera, reopening it." )
99
+ self ._driver .close ()
100
+ self ._driver = FliDriver (self ._device )
101
+
102
+ await asyncio .sleep (self ._keep_alive_ping )
103
+
76
104
async def get_full_frame (self , ** kwargs : Any ) -> Tuple [int , int , int , int ]:
77
105
"""Returns full size of CCD.
78
106
0 commit comments