API#

specMech#

class yao.mech_controller.MechController(address, port=23, log=None)[source]#

Bases: object

Controller for the spectrograph mechanics.

The MechController handles the connection to the spectrograph mechanics microcontroller. A description of the communication protocol is available here.

Parameters:
  • address (str) – The IP address or host of the mech server.

  • port (int) – The port of the host of the mech server.

  • log (SDSSLogger | None) – A logger to which to write.

async close()[source]#

Closes the connection with specMech.

async get_stat(stat)[source]#

Returns the output of the report commands.

Parameters:

stat (str) – The report stat to recover. One of STATS.

Returns:

reply – The parsed command reply values.

Return type:

tuple[Any, …]

is_connected()[source]#

Checks if we are connected to the specMech.

async pneumatic_move(mechanism, open=True, command=None)[source]#

Opens/closes a pneumatic mechanism.

Parameters:
  • mechanism (str) – Either shutter, left, or right.

  • open (bool) – If True, opens the mechanism, otherwise closes it.

  • command (YaoCommand | None) – An actor command for outputs.

async pneumatic_status(mechanism)[source]#

Returns the open/closed status of a mechanism.

Parameters:

mechanism (str) –

Return type:

str

async read_data()[source]#

Awaits responses from specMech until the EOM character ‘>’ is seen.

Returns:

mech_reply – A SpecMechReply object with the reply received.

async send_data(command, timeout=None)[source]#

Sends the given string to the specMech and then awaits a response.

Currently when a command is sent the controller is locked and any new command is blocked until a reply for the currenly running command arrives or a timeout happens.

Parameters:
  • command (str) – A string that is sent to specMech.

  • timeout (float | None) – How long to wait for replies.

Returns:

replies – A tuple in which the first element is bytes array with the raw reply, and successive items are tuples with the data associated with each reply. If a timeout occurred before

async start()[source]#

Opens a connection with the given IP and port.

class yao.mech_controller.SpecMechReply(raw)[source]#

Bases: object

A valid response to a command to the specMech.

Parameters:

raw (bytes) –

static calculate_checksum(message)[source]#

Computes the checksum field for the NMEA protocol.

The checksum is simple, just an XOR of all the bytes between the $ and the * (not including the delimiters themselves), and written in hexadecimal.

Parameters:

message (bytes) –

static check_checksum(message)[source]#

Checks the checksum from a reply.

Parameters:

message (bytes) – The message to check. Must include the checksum *XX.

parse()[source]#

Parses the raw reply.

yao.mech_controller.check_reply(reply)[source]#

Checks a specMech reply.

Parameters:

reply (SpecMechReply) –

yao.mech_controller.STATS: dict[str, str] = {'environment': 're', 'motor-a': 'ra', 'motor-b': 'rb', 'motor-c': 'rc', 'motors': 'rd', 'orientation': 'ro', 'pneumatics': 'rp', 'specmech': 'rs', 'time': 'rt', 'vacuum': 'rv', 'version': 'rV'}#

Stat names accepted by the report command.