Skip to content
Open
Show file tree
Hide file tree
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
59 changes: 43 additions & 16 deletions python/pysmurf/client/base/base_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,26 @@
# copied, modified, propagated, or distributed except according to the terms
# contained in the LICENSE.txt file.
#-----------------------------------------------------------------------------
import pyrogue.interfaces
try:
import pyrogue.interfaces
except ModuleNotFoundError:
import warnings
warnings.warn("Could not import pyrogue. Can only use offline mode.")

from pysmurf.client.command.cryo_card import CryoCard
from pysmurf.client.util.pub import Publisher
from .logger import SmurfLogger

class _DummyClient:
"""Dummy client to raise informative error messages
when trying to access clients in offline mode."""
def __init__(self, name=None):
self.name = name

def __getattr__(self, name):
raise AttributeError(f"{self.name} not available.")


class SmurfBase:
"""
Base class for common things
Expand Down Expand Up @@ -62,7 +76,8 @@ class SmurfBase:
Overall progress on a task
"""

def __init__(self, log=None, server_addr="localhost", server_port=9000, atca_port=9100, offline=False, pub_root=None, script_id=None, **kwargs):
def __init__(self, log=None, server_addr="localhost", server_port=9000, atca_port=9100,
atca_monitor=False, offline=False, pub_root=None, script_id=None, **kwargs):
"""
"""

Expand All @@ -80,13 +95,20 @@ def __init__(self, log=None, server_addr="localhost", server_port=9000, atca_por
self._atca_port = atca_port

# connect to rogue servers
self._client = pyrogue.interfaces.VirtualClient(addr=self._server_addr, port=self._server_port)
self._atca = pyrogue.interfaces.VirtualClient(addr=self._server_addr, port=self._atca_port)
if self._atca.root is None:
self.log(f"Could not connect to ATCA monitor at port {self._atca_port}.")
# but disable monitor thread to avoid issues on exit. Socket remains open
self._client.stop()
self._atca.stop()
if not offline:
self._client = pyrogue.interfaces.VirtualClient(addr=self._server_addr, port=self._server_port)
# but disable monitor thread to avoid issues on exit. Socket remains open
self._client.stop()
if atca_monitor:
self._atca = pyrogue.interfaces.VirtualClient(addr=self._server_addr, port=self._atca_port)
if self._atca.root is None:
self.log(f"Could not connect to ATCA monitor at port {self._atca_port}.")
self._atca.stop()
else:
self._atca = _DummyClient("ATCA monitor client")
else:
self._client = _DummyClient("OFFLINE: Server client")
self._atca = _DummyClient("OFFLINE: ATCA monitor client")

# If <pub_root>BACKEND environment variable is not set to 'udp', all
# publish calls will be no-ops.
Expand Down Expand Up @@ -192,13 +214,18 @@ def __init__(self, log=None, server_addr="localhost", server_port=9000, atca_por
self.trigger_root = self.amctiming + 'EvrV2CoreTriggers.'
self.timing_status = self.amctiming + 'TimingFrameRx.'

self.C = CryoCard(
self.rtm_spi_cryo_root + 'read',
self.rtm_spi_cryo_root + 'write',
server_addr=self._server_addr,
server_port=self._server_port,
log=self.log,
)
if offline:
self.log('Offline mode, skipping CryoCard initialization')
self.C = _DummyClient("OFFLINE: CryoCard client")
else:
self.C = CryoCard(
self.rtm_spi_cryo_root + 'read',
self.rtm_spi_cryo_root + 'write',
server_addr=self._server_addr,
server_port=self._server_port,
log=self.log,
)

self.freq_resp = {}

# RTM slow DAC parameters (used, e.g., for TES biasing). The
Expand Down
10 changes: 9 additions & 1 deletion python/pysmurf/client/command/cryo_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
import os

import numpy as np
import pyrogue.interfaces
try:
import pyrogue.interfaces
ROGUE_AVAILABLE = True
except ModuleNotFoundError:
ROGUE_AVAILABLE = False

from ..base.logger import SmurfLogger

Expand All @@ -39,6 +43,10 @@ def __init__(self, readpv_in, writepv_in, log=None, server_addr="localhost", ser
Ref https://github.com/slaclab/smurfc/blob/C04/firmware/src/ccard.h
"""

if not ROGUE_AVAILABLE:
raise ImportError(
"pyrogue is required to use the CryoCard class. Use offline mode or install pyrogue."
)
self._client = pyrogue.interfaces.VirtualClient(addr=server_addr, port=server_port)
self.readpv = self._client.root.getNode(readpv_in)
self.writepv = self._client.root.getNode(writepv_in)
Expand Down
15 changes: 10 additions & 5 deletions python/pysmurf/client/command/smurf_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@

import numpy as np
from packaging import version
from pyrogue import VariableWait
try:
from pyrogue import VariableWait
except ModuleNotFoundError:
# there will be warnings elsewhere
pass

from pysmurf.client.base import SmurfBase
from pysmurf.client.command.sync_group import SyncGroup
Expand Down Expand Up @@ -168,16 +172,17 @@ def _caget(self, pvname, index=-1, write_log=False, log_level=None, execute=True
self.log(ret, log_level)
return ret

if not execute or self.offline:
self.log(f"Not executing caget for {pvname} (execute={execute}, offline={self.offline})", log_level)
# don't perform the read
return None

var = self._client.root.getNode(pvname)
if var is None:
raise ValueError(f"Invalid node: {pvname}")

if write_log:
self.log('caget ' + pvname, log_level)

if not execute or self.offline:
# don't perform the read
return None
# Get the data
if as_string:
ret = var.getDisp(index=index)
Expand Down
6 changes: 5 additions & 1 deletion python/pysmurf/client/command/sync_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
# copied, modified, propagated, or distributed except according to the terms
# contained in the LICENSE.txt file.
#-----------------------------------------------------------------------------
from pyrogue import VariableWaitClass
try:
from pyrogue import VariableWaitClass
except ModuleNotFoundError:
# there will be warnings elsewhere
pass

"""
Wait for a group of PVs to be updated before reading their values.
Expand Down