CommandEntry

class bapsf_motion.actors.motor_.CommandEntry(command: str, *, send: str, send_processor: ~typing.Callable[[~typing.Any], str] | None = None, recv: ~re.Pattern | None = None, recv_processor: ~typing.Callable[[str], ~typing.Any] | None = <function do_nothing>, two_way: bool = False, units: str | ~astropy.units.core.Unit | None = None, method_command: bool = False, buffered: bool = True)

Bases: UserDict

A dict containing all the necessary information to define a command that is sent to an ethernet based stepper motor.

Parameters:
  • command (str) – Name of the command. If the command entry is also a method command, then this must be the name of the class method to be called.

  • send (str) – The base str command that is sent to the motor.

  • send_processor (callable, optional) – A callable object that processes the command argument before the full command is sent to the motor. The callable must return a string that is concatenated with the send command to form the full command. If None, then the command is assumed to have no argument. (DEFAULT: None)

  • recv (re.Pattern, optional) – A re compiled pattern to expression match any received string from the sent command. If None, then no expression matching is performed on the returned string. If a pattern is defined, then the pattern must define a return group (i.e. '(?P<return>...)'). This return group is assumed to be the returned argument and will be further processed by the recv_processor. (DEFAULT: None)

  • recv_processor (callable, optional) – A callable object that will process the returned argument from the sent command. The returned command is always in the form of a string, so the processor must take a string and process that it into any desirable type. If None, then no processing is performed. (DEFAULT: do_nothing)

  • two_way (bool, optional) – The command both sends and receives arguments from the motor. (DEFAULT: False)

  • units (unit-like, optional) – An object that represents the units of the sent and/or returned arguments. These units will converted into astropy.units and will become the default units for any argument sent or received by this defined command. (DEFAULT: None)

  • method_command (bool) – If True, then the defined command is a method command. A method command is an advanced motor command (e.g. move_to) that requires multiple base commands to be performed in a particular sequence. Thus, the command argument defines the name of a class method that will be executed for this command. (DEFAULT: False)

Examples

An example of a typical motor command entry…

ce = CommandEntry(
    "speed",
    send="VE",
    send_processor=lambda value: f"{float(value):.4f}",
    recv=re.compile(r"VE=(?P<return>[0-9]+\.?[0-9]*)"),
    recv_processor=float,
    two_way=True,
    units=u.rev / u.s,
)

An example of a method based motor command entry. A method based command is reserved for more advanced commands that typically require multiple base commands to be sent in a particular sequence.

ce = CommandEntry(
    "move_to",
    send="",
    units=u.steps,
    method_command=True,
)

Attributes Summary

command

Name of the command.

Methods Summary

clear()

copy()

fromkeys(iterable[,Β value])

get(k[,d])

items()

keys()

pop(k[,d])

value.

popitem()

as a 2-tuple; but raise KeyError if D is empty.

setdefault(k[,d])

update([E,Β ]**F)

If E present and has a .keys() method, does:

values()

Attributes Documentation

command

Name of the command. If the command entry is also a method command, then this is the name of the class method to be called.

Methods Documentation

clear() None.  Remove all items from D.
copy()
classmethod fromkeys(iterable, value=None)
get(k[, d]) D[k] if k in D, else d.  d defaults to None.
items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
pop(k[, d]) v, remove specified key and return the corresponding

value. If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() (k, v), remove and return some (key, value) pair

as a 2-tuple; but raise KeyError if D is empty.

setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D
update([E, ]**F) None.  Update D from mapping/iterable E and F.
If E present and has a .keys() method, does:

for k in E.keys(): D[k] = E[k]

If E present and lacks .keys() method, does:

for (k, v) in E: D[k] = v

In either case, this is followed by:

for k, v in F.items(): D[k] = v

values() an object providing a view on D's values