WriteTopic#

class lsst.ts.salobj.topics.WriteTopic(*, salinfo, attr_name, min_seq_num=1, max_seq_num=2147483647, initial_seq_num=None)#

Bases: BaseTopic

Base class for topics that are written.

This includes controller events, controller telemetry, remote commands and ackcmd writers.

Parameters:
  • salinfo (SalInfo) – SAL component information

  • attr_name (str) – Topic name with attribute prefix. The prefix must be one of: cmd_, evt_, tel_, or (only for the ackcmd topic) ack_.

  • min_seq_num (int or None, optional) – Minimum value for the private_seqNum field. The default is 1. If None then private_seqNum is not set; this is needed for the ackcmd writer, which sets the field itself.

  • max_seq_num (int, optional) – Maximum value for private_seqNum, inclusive. The default is the maximum allowed positive value (private_seqNum is a 4-byte signed int). Ignored if min_seq_num is None.

  • initial_seq_num (int, optional) – Initial sequence number; if None use min_seq_num.

isopen#

Is this instance open? True until close or basic_close is called.

Type:

bool

default_force_output#

Default value for the force_output argument of write.

Type:

bool

Plus the attributes of

BaseTopic

Attributes Summary

data

Internally cached message.

has_data

Has data ever been set?

Methods Summary

basic_close()

A synchronous and possibly less thorough version of close.

close()

Shut down and release resources.

set(**kwargs)

Set one or more fields of message data self.data.

set_write(*[, force_output])

Set zero or more fields of self.data and write if any field changed or if output forced.

write()

Write the current data and return a copy of the data written.

Attributes Documentation

data#

Internally cached message.

Raises:

TypeError – If data is not an instance of DataType

Notes

Do not assume the data will be constant. You can make a copy using copy.copy(data).

has_data#

Has data ever been set?

Note: a value of true means at least one field has been set, not that all fields have been set.

Methods Documentation

basic_close()#

A synchronous and possibly less thorough version of close.

Intended for exit handlers and constructor error handlers.

Return type:

None

async close()#

Shut down and release resources.

Intended to be called by SalInfo.close(), since that tracks all topics.

Return type:

None

set(**kwargs)#

Set one or more fields of message data self.data.

This is useful when accumulating data for a topic in different bits of code. Have each bit of code call set to set the fields it knows about. Have the last bit of code call write to set the remaining fields and write the completed message.

If you have all the information for a topic in one place, it is simpler to call set_write to set all of the fields and write the message.

Parameters:

**kwargs (dict [str, any]) –

Dict of field name: new value for that field:

  • Any key whose value is None is checked for existence, but the value of the field is not changed.

  • If the field being set is an array then the value must be an array of the same length.

Returns:

did_change – True if self.data was changed, or if this was the first call to set.

Return type:

bool

Raises:
  • AttributeError – If the topic does not have the specified field.

  • ValueError – If the field cannot be set to the specified value.

Notes

If one or more fields cannot be set, the message data may be partially updated.

async set_write(*, force_output=None, **kwargs)#

Set zero or more fields of self.data and write if any field changed or if output forced.

Parameters:
  • force_output (bool, optional) – If True then write the event, even if no fields have changed. If None (the default), use the class default, which is True for all except ControllerEvent. (The default value is given by class constant default_force_output).

  • **kwargs (dict [str, any]) – The remaining keyword arguments are field name = new value for that field. See set for more information about values.

Returns:

result – The resulting data and some flags.

Return type:

SetWriteResult

Notes

The reason there are separate set_write and write methods is that write reliably writes the data, whereas the event version of set_write only writes the data if kwargs changes it, or if force_output is true.

async write()#

Write the current data and return a copy of the data written.

Returns:

data – The data that was written. This can be useful to avoid race conditions (as found in RemoteCommand).

Return type:

self.DataType

Raises:

RuntimeError – If not running.