Ejemplo n.º 1
0
class VerySimpleStreamInterface(StreamInterface):
    """This is a TCP stream interface to the epics device, which only exposes param."""

    commands = {
        Var('param', read_pattern=r'P\?$', write_pattern=r'P=(\d+)', argument_mappings=(int,),
            doc='An integer parameter.')
    }

    in_terminator = '\r\n'
    out_terminator = '\r\n'
Ejemplo n.º 2
0
class VerySimpleInterface(StreamInterface):
    """
    A very simple device with TCP-stream interface

    The device has only one parameter, which can be set to an arbitrary
    value. The interface consists of five commands which can be invoked via telnet.
    To connect:

        $ telnet host port

    After that, typing either of the commands and pressing enter sends them to the server.

    The commands are:

     - ``V``: Returns the parameter as part of a verbose message.
     - ``V=something``: Sets the parameter to ``something``.
     - ``P``: Returns the device parameter unmodified.
     - ``P=something``: Exactly the same as ``V=something``.
     - ``R`` or ``r``: Returns the number 4.

    """

    commands = {
        Cmd("get_param",
            pattern="^V$",
            return_mapping="The value is {}".format),
        Cmd("set_param", pattern="^V=(.+)$", argument_mappings=(int, )),
        Var(
            "param",
            read_pattern="^P$",
            write_pattern="^P=(.+)$",
            doc="The only parameter.",
        ),
        Cmd(lambda: 4, pattern="^R$(?i)", doc='"Random" number (4).'),
    }

    in_terminator = "\r\n"
    out_terminator = "\r\n"

    def get_param(self):
        """Returns the device parameter."""
        return self.device.param

    def set_param(self, new_param):
        """Set the device parameter, does not return anything."""
        self.device.param = new_param

    def handle_error(self, request, error):
        return "An error occurred: " + repr(error)
Ejemplo n.º 3
0
class VerySimpleStreamInterface(StreamInterface):
    """This is a TCP stream interface to the epics device, which only exposes param."""

    commands = {
        Var(
            "param",
            read_pattern=r"P\?$",
            write_pattern=r"P=(\d+)",
            argument_mappings=(int, ),
            doc="An integer parameter.",
        )
    }

    in_terminator = "\r\n"
    out_terminator = "\r\n"
Ejemplo n.º 4
0
class TimeTerminatedInterface(StreamInterface):
    """
    A simple device where commands are terminated by a timeout.

    This demonstrates how to implement devices that do not have standard
    terminators and where a command is considered terminated after a certain
    time delay of not receiving more data.

    To interact with this device, you must switch telnet into char mode, or use
    netcat with special tty settings:

        $ telnet host port
        ^]
        telnet> mode char
        [type command and wait]

        $ stty -icanon && nc host port
        hello world!
        foobar!

    The following commands are available:

     - ``hello ``: Reply with "world!"
     - ``foo``: Replay with "bar!"
     - ``P``: Returns the device parameter
     - ``P=something``: Set parameter to specified value

    """

    commands = {
        # Space as \x20 represents a custom 'terminator' for this command only
        # However, waiting for the timeout still applies
        Cmd("say_world", pattern=scanf("hello\x20")),
        Cmd("say_bar", pattern=scanf("foo")),
        Var("param", read_pattern=scanf("P"), write_pattern=scanf("P=%d")),
    }

    # An empty in_terminator triggers "timeout mode"
    # Otherwise, a ReadTimeout is considered an error.
    in_terminator = ""
    out_terminator = "\r\n"

    # Unusually long, for easier manual entry
    readtimeout = 2500

    def handle_error(self, request, error):
        return "An error occurred: " + repr(error)
Ejemplo n.º 5
0
class JulaboStreamInterfaceV2(StreamInterface):
    """Julabos can have different commands sets depending on the version number of the hardware.

    This protocol matches that for: FP50-HE (unconfirmed).
    """

    protocol = "julabo-version-2"

    commands = {
        Var('temperature',
            read_pattern='^IN_PV_00$',
            doc='The bath temperature.'),
        Var('external_temperature',
            read_pattern='^IN_PV_01$',
            doc='The external temperature.'),
        Var('heating_power',
            read_pattern='^IN_PV_02$',
            doc='The heating power.'),
        Var('set_point_temperature',
            read_pattern='^IN_SP_00$',
            doc='The temperature setpoint.'),
        Cmd('set_set_point',
            '^OUT_SP_00 ([0-9]*\.?[0-9]+)$',
            argument_mappings=(float, )),
        # Read pattern for high limit is different from version 1
        Var('temperature_high_limit',
            read_pattern='^IN_SP_03$',
            doc='The high limit - usually set in the hardware.'),
        # Read pattern for low limit is different from version 1
        Var('temperature_low_limit',
            read_pattern='^IN_SP_04$',
            doc='The low limit - usually set in the hardware.'),
        Var('version', read_pattern='^VERSION$', doc='The Julabo version.'),
        Var('status', read_pattern='^STATUS$', doc='The Julabo status.'),
        Var('is_circulating',
            read_pattern='^IN_MODE_05$',
            doc='Whether it is circulating.'),
        Cmd('set_circulating',
            '^OUT_MODE_05 (0|1)$',
            argument_mappings=(int, )),
        Var('internal_p',
            read_pattern='^IN_PAR_06$',
            doc='The internal proportional.'),
        Cmd('set_internal_p',
            '^OUT_PAR_06 ([0-9]*\.?[0-9]+)$',
            argument_mappings=(float, )),
        Var('internal_i',
            read_pattern='^IN_PAR_07$',
            doc='The internal integral.'),
        Cmd('set_internal_i',
            '^OUT_PAR_07 ([0-9]*)$',
            argument_mappings=(int, )),
        Var('internal_d',
            read_pattern='^IN_PAR_08$',
            doc='The internal derivative.'),
        Cmd('set_internal_d',
            '^OUT_PAR_08 ([0-9]*)$',
            argument_mappings=(int, )),
        Var('external_p',
            read_pattern='^IN_PAR_09$',
            doc='The external proportional.'),
        Cmd('set_external_p',
            '^OUT_PAR_09 ([0-9]*\.?[0-9]+)$',
            argument_mappings=(float, )),
        Var('external_i',
            read_pattern='^IN_PAR_11$',
            doc='The external integral.'),
        Cmd('set_external_i',
            '^OUT_PAR_11 ([0-9]*)$',
            argument_mappings=(int, )),
        Var('external_d',
            read_pattern='^IN_PAR_12$',
            doc='The external derivative.'),
        Cmd('set_external_d',
            '^OUT_PAR_12 ([0-9]*)$',
            argument_mappings=(int, )),
    }

    in_terminator = '\r'
    out_terminator = '\n'  # Different from version 1
class JulaboStreamInterfaceV2(StreamInterface):
    """Julabos can have different commands sets depending on the version number of the hardware.

    This protocol matches that for: FP50-HE (unconfirmed).
    """

    protocol = "julabo-version-2"

    commands = {
        Var("temperature", read_pattern="^IN_PV_00$", doc="The bath temperature."),
        Var(
            "external_temperature",
            read_pattern="^IN_PV_01$",
            doc="The external temperature.",
        ),
        Var("heating_power", read_pattern="^IN_PV_02$", doc="The heating power."),
        Var(
            "set_point_temperature",
            read_pattern="^IN_SP_00$",
            doc="The temperature setpoint.",
        ),
        Cmd(
            "set_set_point",
            r"^OUT_SP_00 ([0-9]*\.?[0-9]+)$",
            argument_mappings=(float,),
        ),
        # Read pattern for high limit is different from version 1
        Var(
            "temperature_high_limit",
            read_pattern="^IN_SP_03$",
            doc="The high limit - usually set in the hardware.",
        ),
        # Read pattern for low limit is different from version 1
        Var(
            "temperature_low_limit",
            read_pattern="^IN_SP_04$",
            doc="The low limit - usually set in the hardware.",
        ),
        Var("version", read_pattern="^VERSION$", doc="The Julabo version."),
        Var("status", read_pattern="^STATUS$", doc="The Julabo status."),
        Var(
            "is_circulating",
            read_pattern="^IN_MODE_05$",
            doc="Whether it is circulating.",
        ),
        Cmd("set_circulating", "^OUT_MODE_05 (0|1)$", argument_mappings=(int,)),
        Var("internal_p", read_pattern="^IN_PAR_06$", doc="The internal proportional."),
        Cmd(
            "set_internal_p",
            r"^OUT_PAR_06 ([0-9]*\.?[0-9]+)$",
            argument_mappings=(float,),
        ),
        Var("internal_i", read_pattern="^IN_PAR_07$", doc="The internal integral."),
        Cmd("set_internal_i", "^OUT_PAR_07 ([0-9]*)$", argument_mappings=(int,)),
        Var("internal_d", read_pattern="^IN_PAR_08$", doc="The internal derivative."),
        Cmd("set_internal_d", "^OUT_PAR_08 ([0-9]*)$", argument_mappings=(int,)),
        Var("external_p", read_pattern="^IN_PAR_09$", doc="The external proportional."),
        Cmd(
            "set_external_p",
            r"^OUT_PAR_09 ([0-9]*\.?[0-9]+)$",
            argument_mappings=(float,),
        ),
        Var("external_i", read_pattern="^IN_PAR_11$", doc="The external integral."),
        Cmd("set_external_i", "^OUT_PAR_11 ([0-9]*)$", argument_mappings=(int,)),
        Var("external_d", read_pattern="^IN_PAR_12$", doc="The external derivative."),
        Cmd("set_external_d", "^OUT_PAR_12 ([0-9]*)$", argument_mappings=(int,)),
    }

    in_terminator = "\r"
    out_terminator = "\n"  # Different from version 1