Message

The Message base class is intended to provide a wrapper around message class implementations independent of transport layer (like TCP/IP or CAN).

class pyolcb.Message(message_type: MessageTypeIndicator, data: bytes | bytearray = None, source: Address = None, destination: Address = None, frame_id: int = None)
classmethod from_can_message(message)

Convert a received frame into a Message.

Accepts a can.Message or a pyolcb.frame.Frame (anything with arbitration_id, data and is_extended_id). Returns None for CAN control frames and unknown MTIs. The destination of an addressed message or datagram is filled in as an alias-only Address.

Event

class pyolcb.Event(event_id: str | list[int] | int | bytes | bytearray, source: Address = None)

Datagram

class pyolcb.Datagram(data: bytes | bytearray, source: Address, destination: Address)

A datagram: up to 72 bytes sent reliably to one node, split across as many as nine CAN frames.

Parameters:
  • data (bytes | bytearray) – The datagram content. The first byte identifies the protocol (0x20 is Memory Configuration).

  • source (Address) – The sending node.

  • destination (Address) – The receiving node (its alias is required to build frames).

as_message_list()

Split the datagram into one Message per CAN frame, with the frame types set for only (None), first (1), middle (2) and final (-1) frames.

classmethod from_message_list(message_list: list[Message] | Message)

Reassemble a datagram from the messages carrying its frames, in order.

Message Types

The message_types module contains all currently defined message types, packaged into a MessageTypeIndicator class to properly handle different Interface types.

pyolcb.message_types.is_known_mti(mti: MessageTypeIndicator | int) bool

True if mti (an MTI object or its 16-bit value) is in the table above.

pyolcb.message_types.name_of(mti: MessageTypeIndicator | int) str

A readable name for an MTI, given as an object, its 16-bit value, or the 12-bit value from a CAN header. Unknown values come back as hex.