serialtools.database module
- class serialtools.database.ByteSpec(name: str, *, length: int | str | None = None, allowed_values: Sequence[bytes] | bytes | int | None = None)
Bases:
object
- Paramref length:
Either the number of bytes or the name of a previous byte spec which specifies the length of this byte spec
- class serialtools.database.Database(message_spec: Sequence[ByteSpec], signals: Sequence[Signal], *, endianness: Endianness, word_length_in_bits: int = 8)
Bases:
object
- encode_range(address: int, length_in_bytes: int, value: Callable[[Signal], int | float | str]) bytes
Encode all signals which are completely within the given range
- endianness: Endianness
The byte order
- class serialtools.database.Endianness(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
Enum
- BIG = 1
- LITTLE = 2
- class serialtools.database.Message(db: Database, timestamp: datetime | None, values: Mapping[str, bytes])
Bases:
object
- class serialtools.database.Reader(bus: serial.Serial | ReadFromFileBus | WriteToFileBus, db: Database)
Bases:
object
- ignore_bytes_between_messages
Each instance of this class represents a setting which can be changed in a config file.
This class implements the descriptor protocol to return
value
if an instance of this class is accessed as an instance attribute. If you want to get this object you need to access it as a class attribute.
- class serialtools.database.Signal(name: str, type: Type, address: int, *, bits: int | None = None, startbit: int = 0, scale: float = 1, offset: float = 0, unit: str = '')
Bases:
object
- Paramref name:
The name of the signal
- Paramref type:
The data type, e.g. INT, UINT, FLOAT
- Paramref address:
The address which is used to request this value from the battery
- Paramref bits:
The size of this signal in bits, defaults to
Database.word_length_in_bits
- Paramref startbit:
If the word identified by
address
contains several smaller values the startbit specifies where the signal starts inside of the word- Paramref scale:
A factor which is multiplied to the raw value received on the bus in order to get a value of
unit
- Paramref offset:
A summand which is added to the raw value received on the bus in order to get a value of
unit
- Paramref unit:
The unit of the value
When decoding data from bytes received on the bus to human readable floats in the given unit the raw value is first multiplied with
scale
and thenoffset
is added to it as in cantools.