diff --git a/Dockerfile b/Dockerfile index 27455bb..4a0d367 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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} diff --git a/dripline/extensions/__init__.py b/dripline/extensions/__init__.py index e9cb836..f016cc8 100644 --- a/dripline/extensions/__init__.py +++ b/dripline/extensions/__init__.py @@ -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 * diff --git a/dripline/extensions/asteval_endpoint.py b/dripline/extensions/asteval_endpoint.py new file mode 100644 index 0000000..93df946 --- /dev/null +++ b/dripline/extensions/asteval_endpoint.py @@ -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 diff --git a/dripline/extensions/cmd_endpoint.py b/dripline/extensions/cmd_endpoint.py new file mode 100644 index 0000000..7524dda --- /dev/null +++ b/dripline/extensions/cmd_endpoint.py @@ -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])