Skip to content

Latest commit

 

History

History
60 lines (39 loc) · 1.39 KB

File metadata and controls

60 lines (39 loc) · 1.39 KB

CANopen Master (Python)

This Python application demonstrates a CANopen master that communicates with the CANopen slave demo.

Overview

The application connects to a CANopen network and configures a slave node to:

  • Read button states via TPDO1 (Transmit PDO from slave perspective)
  • Control LEDs via RPDO1 (Receive PDO from slave perspective)
  • Mirror button states to LEDs in real-time

Requirements

  • Python 3.x
  • canopen library
  • SocketCAN interface (Linux) or compatible CAN adapter

Installation

Install dependencies using uv:

uv sync

Or using pip:

pip install canopen

When using pip it is recommend to create a virtual environment.

Usage

  1. Ensure your CAN interface is configured (e.g., can0 for SocketCAN)
  2. Run the application:
uv run python main.py

Or if using pip:

python main.py
  1. Press the buttons - you should see the LED light up
  2. Press Ctrl+C to stop the application

CAN Adapter Support

While this example uses SocketCAN, the canopen library supports various CAN adapters. See the python-canopen documentation for other supported interfaces.

Troubleshooting

  • Ensure the CAN interface is up: ip link set can0 up type can bitrate 250000
  • Verify the slave device is connected and powered
  • Check that the EDS file path is correct