WriteTopic#
- class lsst.ts.salobj.topics.WriteTopic(*, salinfo, attr_name, min_seq_num=1, max_seq_num=2147483647, initial_seq_num=None)#
Bases:
BaseTopicBase class for topics that are written.
This includes controller events, controller telemetry, remote commands and
ackcmdwriters.- Parameters:
salinfo (
SalInfo) – SAL component informationattr_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 (
intorNone, optional) – Minimum value for theprivate_seqNumfield. The default is 1. IfNonethenprivate_seqNumis not set; this is needed for the ackcmd writer, which sets the field itself.max_seq_num (
int, optional) – Maximum value forprivate_seqNum, inclusive. The default is the maximum allowed positive value (private_seqNumis a 4-byte signed int). Ignored ifmin_seq_numisNone.initial_seq_num (
int, optional) – Initial sequence number; ifNoneuse min_seq_num.
- isopen#
Is this instance open?
Trueuntilcloseorbasic_closeis called.- Type:
- Plus the attributes of
Attributes Summary
Methods Summary
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.dataand 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
datais not an instance ofDataType
Notes
Do not assume the data will be constant. You can make a copy using
copy.copy(data).
- has_data#
Has
dataever 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:
- async close()#
Shut down and release resources.
Intended to be called by SalInfo.close(), since that tracks all topics.
- Return type:
- 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
setto set the fields it knows about. Have the last bit of code callwriteto 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_writeto set all of the fields and write the message.- Parameters:
Dict of field name: new value for that field:
Any key whose value is
Noneis 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.datawas changed, or if this was the first call toset.- Return type:
- 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.dataand 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 constantdefault_force_output).**kwargs (
dict[str,any]) – The remaining keyword arguments are field name = new value for that field. Seesetfor more information about values.
- Returns:
result – The resulting data and some flags.
- Return type:
Notes
The reason there are separate
set_writeandwritemethods is thatwritereliably writes the data, whereas the event version ofset_writeonly writes the data ifkwargschanges it, or ifforce_outputis 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.