CAN Messages

OpenLCB over CAN

Classes for creating, manipulating, and parsing CAN frames as OpenLCB messages.

author:Dustin C. Hatch
author:Timothy C. Hatch
class openlcb.can.messages.AddressedMessage(**keywords)[source]

Represents a message sent to a single node

  • src_alias (int) – The alias of the node from which messages originate
  • dst_alias (int) – The alias of the node to which the message is sent

The node alias of the node sending the message


The alias of the node for which the message is intended

classmethod parse_frame(frame)[source]
class openlcb.can.messages.CANMessage(header='', body='')[source]

Base class for Controller Area Network messages

Calling str() on CANMessage instances returns a string containing the CAN frame.


The value of the header that would be sent in the frame


The value of the body that would be sent with the frame

classmethod from_sequence(seq)[source]

Convert a sequence (list, etc.) of strings to Message objects

Parameters:seq (sequence) – A sequence of OpenLCB frame strings
Yields :Instances of the CANMessage subclass
classmethod from_string(frame)[source]

Create a CANMessage instance from a frame string

Parameters:frame (str) – The complete CAN frame, including control characters
Returns:A new instance of the CANMessage subclass

Subclasses of CANMessage should not override this method, but rather parse_frame() instead.

classmethod parse_frame(frame)[source]

Parse a string containing a CAN frame into its parts

Returns dict:A dictionary containing the valuable message parts

Subclasses of CANMessage should override this method and provide their own unique logic for parsing the header and body into usable properties.

class openlcb.can.messages.ConsumerIdentified(**keywords)[source]
MTI = 103019
class openlcb.can.messages.DatagramReceived(**keywords)[source]
MTI = 30
class openlcb.can.messages.EventMessage(**keywords)[source]

Represents a message containing an event ID


The ID of the event identified in the message

classmethod parse_frame(frame)[source]
class openlcb.can.messages.GeneralDatagram(**keywords)[source]
MTI = 29
class openlcb.can.messages.GlobalMessage(**keywords)[source]

Represents a message sent to the entire bus

class openlcb.can.messages.IdentifyConsumers(**keywords)[source]
MTI = 98895
class openlcb.can.messages.IdentifyEventsAddressed(**keywords)[source]
MTI = 30
class openlcb.can.messages.IdentifyEventsGlobal(**keywords)[source]
MTI = 98999
class openlcb.can.messages.IdentifyProducers(**keywords)[source]
MTI = 98959
exception openlcb.can.messages.IncorrectMTI(mti, cls)[source]

Raised when creating a message from a string with the wrong MTI

exception openlcb.can.messages.InvalidMessage(frame)[source]

Raised when attempting to parse an improperly-formatted frame

class openlcb.can.messages.MessageWithBody(**keywords)[source]

Represents a message that contains a body


The full of the ID of the node sending the message

classmethod parse_frame(frame)[source]
class openlcb.can.messages.NodeAlias(alias)[source]

Utility class for handling node alias

  • Calling int on an instance of :py:class:NodeAlias will return

    the integer value.

  • Calling str on an instance of :py:class:NodeAlias will return a hexidecimal number.

class openlcb.can.messages.OpenLCBMessage(**keywords)[source]

Base class for all OpenLCB CAN messages

Parameters:src_alias (int) – The alias of the node from which messages originate

The node alias of the node sending the message


The message type indicator, as an integer. This value should be set by subclasses of CANMessage. See for a list of MTI allocations.

classmethod from_string(frame)[source]
classmethod parse_frame(frame)[source]
class openlcb.can.messages.RegisteredMessage[source]

Metaclass for OpenLCB message classes

Classes using RegisteredMessage as their metaclass will automatically have their MTIs registered, which creates a reverse mapping from MTI to class. This registration is required for parse_frame() to discover a message class based on the MTI and return an instance of it.

class openlcb.can.messages.StartDatagramFrame(**keywords)[source]
MTI = 28
class openlcb.can.messages.VerifiedNodeIDNumber(**keywords)[source]
MTI = 98487
class openlcb.can.messages.VerifyNodeIDNumberSimple(**keywords)[source]
MTI = 98471

Parse an OpenLCB Message from a CAN frame

Parameters:frame (str) – CAN frame as a string, including control characters
Returns:An instance of the class registered for the MTI specified in the frame

Previous topic

OpenLCB over CAN

Next topic

Node Communication

This Page