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
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
ARG img_user=ghcr.io/driplineorg
ARG img_repo=dripline-python
#ARG img_tag=develop-dev
ARG img_tag=receiver-test
ARG img_tag=v5.0.0-dev

FROM ${img_user}/${img_repo}:${img_tag}

Expand Down
2 changes: 2 additions & 0 deletions dripline/extensions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
# Modules in this directory

from .add_auth_spec import *
from .cmd_endpoint import *
from .asteval_endpoint import *
from .thermo_fisher_endpoint import *
from .ethernet_thermo_fisher_service import *
40 changes: 40 additions & 0 deletions dripline/extensions/asteval_endpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import asteval # used for FormatEntity
import re # used for FormatEntity

from dripline.core import calibrate, ThrowReply
from dripline.implementations import FormatEntity

import logging
logger = logging.getLogger(__name__)

__all__ = []



__all__.append('AstevalFormatEntity')
class AstevalFormatEntity(FormatEntity):
'''
Utility Entity allowing arbitrary set and query syntax and formatting for more complicated usage cases
No assumption about SCPI communication syntax.
'''

def __init__(self,
asteval_format_response_string="def f(response): return response",
**kwargs):
'''
Args:
asteval_format_response_string (str): function definition to format response. Default: "def f(response): return response"
*kwargs -> FormatEntity
'''
FormatEntity.__init__(self, **kwargs)
self.asteval_format_response_string = asteval_format_response_string # has to contain a definition "def f(response): ... return value"
logger.debug(f'asteval_format_response_string: {repr(self.asteval_format_response_string)}')
self.evaluator(asteval_format_response_string)

@calibrate()
def on_get(self):
result =FormatEntity.on_get(self)
raw = result["value_raw"]
processed_result = self.evaluator(f"f('{raw}')")
logger.debug(f"processed_result: {repr(processed_result)}")
return processed_result
31 changes: 31 additions & 0 deletions dripline/extensions/cmd_endpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import re # used for FormatEntity

from dripline.core import calibrate, ThrowReply
from dripline.core import Entity

import logging
logger = logging.getLogger(__name__)

__all__ = []

__all__.append('CmdEntity')
class CmdEntity(Entity):
'''
SCPI Entity to execute a command, instead of a get or set.
The command is given via "cmd_str" and takes no additional arguments.
This can e.g. be used to auto-calibrate, set to zero or similar device commands.
'''
def __init__(self, cmd_str=None, **kwargs):
'''
Args:
cmd_str (str): sent verbatim in the event of cmd().
'''
Entity.__init__(self, **kwargs)
logger.debug(f"I get cmd_str: {cmd_str}, which is of type {type(cmd_str)}.")
if cmd_str is None:
raise ValueError("cmd_str is required for CmdEntity")
self.cmd_str = cmd_str

def cmd(self):
logger.debug("Command function was successfully called")
return self.service.send_to_device([self.cmd_str])