Skip to content

Commit b88ae22

Browse files
authored
v0.18.2
version 0.18.2
2 parents c4b221b + 394ef57 commit b88ae22

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

pyobs_fli/flicamera.py

+32-4
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,29 @@ class FliCamera(BaseCamera, ICamera, IWindow, IBinning, ICooling):
2020

2121
__module__ = "pyobs_fli"
2222

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):
2424
"""Initializes a new FliCamera.
2525
2626
Args:
2727
setpoint: Cooling temperature setpoint.
28+
keep_alive_ping: Interval in seconds to ping camera.
2829
"""
2930
BaseCamera.__init__(self, **kwargs)
3031
from .flidriver import FliDriver # type: ignore
3132

3233
# variables
3334
self._driver: Optional[FliDriver] = None
35+
self._device: Optional[Any] = None
3436
self._temp_setpoint: Optional[float] = setpoint
37+
self._keep_alive_ping = keep_alive_ping
3538

3639
# window and binning
3740
self._window = (0, 0, 0, 0)
3841
self._binning = (1, 1)
3942

43+
# keep alive
44+
self.add_background_task(self._keep_alive)
45+
4046
async def open(self) -> None:
4147
"""Open module."""
4248
await BaseCamera.open(self)
@@ -48,9 +54,13 @@ async def open(self) -> None:
4854
raise ValueError("No camera found.")
4955

5056
# 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)
5464
try:
5565
self._driver.open()
5666
except ValueError as e:
@@ -73,6 +83,24 @@ async def close(self) -> None:
7383
self._driver.close()
7484
self._driver = None
7585

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+
76104
async def get_full_frame(self, **kwargs: Any) -> Tuple[int, int, int, int]:
77105
"""Returns full size of CCD.
78106

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pyobs-fli"
3-
version = "0.18.1"
3+
version = "0.18.2"
44
description = "pyobs module for FLI cameras"
55
authors = ["Tim-Oliver Husser <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)