Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion socs/agents/lakeshore425/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import time

import serial
import txaio
from ocs import ocs_agent, site_config
from ocs.ocs_twisted import TimeoutLock
Expand Down Expand Up @@ -123,13 +124,42 @@ def acq(self, session, params):

last_release = time.time()
while self.take_data:
if self.dev is None:
try:
self.dev = ls.LakeShore425(self.port)
self.log.info('Connected to LS425')
except (ConnectionRefusedError, serial.serialutil.SerialException):
self.log.error(
"Could not connect to LS425. "
"Retrying after 30 sec..."
)
time.sleep(30)
continue
if time.time() - last_release > 1.:
last_release = time.time()
if not self.lock.release_and_acquire(timeout=10):
self.log.warn(f"Failed to re-acquire lock, currently held by {self.lock.job}.")
continue

Bfield = self.dev.get_field()
try:
Bfield = self.dev.get_field()
except serial.serialutil.SerialException:
self.log.error(
"Decive reports readiness to read but returned no data. "
"Reconnect to LS425."
)
self.dev.close()
self.dev = None
session.degraded = True
continue
except Exception as e:
self.log.error(f"Caught unexpected {type(e).__name__} during get_field:")
self.log.error(f" {e}")
self.dev.close()
self.dev = None
session.degraded = True
continue

current_time = time.time()
data = {
'timestamp': current_time,
Expand All @@ -141,6 +171,7 @@ def acq(self, session, params):
session.data.update({'timestamp': current_time})
self.agent.feeds['mag_field'].flush_buffer()

session.degraded = False
time.sleep(sleep_time)

return True, 'Acquisition exited cleanly.'
Expand Down