CAN Bus
CAN Message
- class pyrbs.canbus.message.can_message.CanMessage(_rbs, ch_id, arb_id, frame_desc=None, core_can_message=None)
Bases:
CallbackA Can Message Object that by default is crated from a .dbc or .arxml file at start
- Parameters:
_rbs (PyRbs)
ch_id (int) – The CAN channel id
arb_id (int) – The arbbitration id of the can message
frame_desc (dict) – Normalized frame metadata exported by pyrbs_core
core_can_message (CoreCanMessage | None)
from pyrbs import PyRbs, CanMessage rbs = PyRbs() example_msg: CanMessage = rbs.can_messages.get("CAN1.0x100")
- __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, message, signal_metadata, core_signal=None)
Bases:
CallbackA Can Signal Object that by default is crated from a .dbc or .arxml file at start
- Parameters:
_rbs (PyRbs)
signal_desc (canmatrix.Signal) – The signal description
identifier (str) – A string identifier used for callback identification “CAN1.256.Status_01”
message (CanMessage)
signal_metadata (dict)
core_signal (CoreCanSignalSigned | CoreCanSignalUnsigned | None)
from pyrbs import PyRbs, CanSignal rbs = PyRbs() example_sig: CanSignal = rbs.can_signal.get("CAN1.0x100.Status_01")
- attach_core_signal(core_signal)
- Parameters:
core_signal (CoreCanSignalSigned | CoreCanSignalUnsigned)
- Return type:
None
- 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, *, register_with_core=True)
Bases:
object- Parameters:
_rbs (PyRbs)
config (CanChannelConfig) – The configuration will be generated from the settings in ./config/* for example a CAN.toml or CAN1.toml file
register_with_core (bool)
- get_message(id)
Get a can message assignet to the channel by its arb_id or name
- Parameters:
id (str | int)
- Return type: