CAN Bus

CAN Message

class pyrbs.canbus.message.can_message.CanMessage(_rbs, ch_id, arb_id, frame=None)

Bases: Callback

A Can Message Object that by default is crated from a .dbc or .arxml file at start

from pyrbs import PyRbs, CanMessage

rbs = PyRbs()
example_msg: CanMessage = rbs.can_messages.get("CAN1.0x100")
Parameters:
  • _rbs (PyRbs)

  • ch_id (int)

  • arb_id (int)

  • frame (Frame | None)

__getitem__(key: int) int
__getitem__(key: slice) bytes
__getitem__(key: str) CanSignal

Access message data bytes or signals using bracket notation.

Parameters:

key – Index (int), slice, or signal name (str)

Returns:

Single byte value when key is an int bytes: Byte sequence when key is a slice CanSignal: Signal object when key is a string

Return type:

int

Examples

# Get single byte at index 0
byte_value = example_msg[0]
# Returns: 255

# Get byte range using slice
byte_range = example_msg[0:4]
# Returns: b'\xff\x00\x12\x34'

# Get signal by name
speed_signal = example_msg["VehicleSpeed"]
# Returns: <CanSignal: VehicleSpeed>
__setitem__(key, value)

Set message data bytes using bracket notation.

Parameters:
  • key – Index (int) or slice for byte operations

  • value – Byte value (int 0-255) or bytes sequence

Examples

# Set single byte at index 0
example_msg[0] = 255

# Set multiple bytes using slice
example_msg[0:4] = b'\xff\x00\x12\x34'

# Set bytes from list
example_msg[2:4] = [0x12, 0x34]

Note

Signal assignment via string keys is not supported. Use signal.value or signal.raw to modify signal values.

Raises:
  • IndexError – If byte index is out of range

  • TypeError – If trying to assign with a string key

property data: bytes

The raw byes of the can message

property dir: Literal['Rx', 'Tx'] | None

The direction of the can message (“Rx”,”Tx”)

__repr__()

Return a dictionary representation when the CanMessage object is printed

Return type:

str

send(rawData=None, channel=None)

Sends the can message on the bus

rawData (Union[List, bytes]): if None the can message will be send as it is, the values of can signals will define the raw bytes output if a rawData input in form ob type bytes or List[int] is passed, the valus of can siganls will be updated from that input after sending

channel (int): if None the output will be on the assigned can channel of that can message, if a channel value is specified then the output will be send on that channel

Parameters:
  • rawData (List | bytes)

  • channel (int)

Return type:

None

CAN Signal

class pyrbs.canbus.signal.can_signal.CanSignal(_rbs, signal_desc, itemId)

Bases: Callback

A Can Signal Object that by default is crated from a .dbc or .arxml file at start

from pyrbs import PyRbs, CanSignal

rbs = PyRbs()
example_sig: CanSignal = rbs.can_messages.get("CAN1.0x100.example_sig")
Parameters:
  • signal_desc (Signal)

  • itemId (str)

signal_desc: Signal
itemId: str
dashboard_aliases: list[str]
property raw: int

the raw integer value, no conversions applied

property phys: float

the physical value representation, specified offset and factor applied

property value_desc: str

a string value that was specified for a specific integer value of a signal, sourced from a .dbc or .arxml file

property timestamp: float

the timestamp from the RX/TX event of the can message in seconds from rbs start

CAN Channel

class pyrbs.canbus.channel.can_channel.CanChannel(_rbs, config)

Bases: object

Parameters:
  • _rbs (PyRbs)

  • config (CanChannelConfig)

__getitem__(key)

get a can message

Return type:

CanMessage

list_messages()
Return type:

List

add_message()
Return type:

None

switch_on()
Return type:

None

switch_off()
Return type:

None

send_message(message)

Send a CAN message asynchronously.

callback(arbitration_id)

Decorator function for registering a callback function for a specific arbitration ID.

close()

close the CAN bus

get_message(id)
Parameters:

id (str | int)

Return type:

CanMessage