How canopen-python/canopen works
Project type and purpose
• This is a Python library implementing the CANopen protocol (CiA-301) for use as a master (and limited slave) in testing and automation.
• It provides high-level abstractions for Network, Node, SDO, PDO, NMT, SYNC, EMCY, TIME, LSS, and object dictionary functionality.
File structure
• Top-level package “canopen/”: contains modules for each CANopen service:
• network.py – Network abstraction
• node/ – Node classes (LocalNode, RemoteNode, base Node)
• sdo/, pdo/, nmt.py, sync.py, emcy.py, timestamp.py, lss.py
• objectdictionary/ – EDS parsing, datatypes, EPF support
• profiles/ – CiA-402 profile support and test tools
• utils.py, variable.py
• Configuration and tooling:
• setup.py, pyproject.toml, MANIFEST.in – packaging
• .github/workflows, codecov.yml – CI/CD
• doc/ – Sphinx docs
• examples/ – usage scripts
• test/ – pytest and unittest test suite
• External dependency integration:
• python-can (“network.connect” passes parameters to python-can Bus)
README for additional insights
• Clarifies mission: simple Pythonic interface, master-oriented.
• Lists supported services: NMT, SDO client, PDO producer/consumer, SYNC, EMCY, TIME, LSS.
• Shows quick-start usage: instantiate Network, add RemoteNode, connect, perform SDO/PDO operations, start/stop SYNC, change NMT state.
a. Main components to include:
• CANopen Library Core
• Network Manager
• Node Manager (LocalNode, RemoteNode)
• Service Modules: SDO, PDO, NMT, SYNC, EMCY, TIME, LSS
• Object Dictionary Parser (EDS)
• Profile Support Layer (CiA-402)
• External Interfaces
• python-can Bus backend (hardware abstraction layer)
• CAN bus network (physical layer)
• Consumer Code / Examples / Tests
• User Application / Automation Scripts
• Test Harness
b. Relationships and interactions:
• User Application → invokes Library Core API
• Library Core → uses Network Manager to open python-can Bus
• Network Manager ↔ python-can Bus → sends/receives raw CAN frames
• Node Manager holds Node instances (Local or Remote)
• Service Modules attach to Node and Network to implement protocol flows:
• SDO client/server messages over CAN frames
• PDO mapping and transmission
• NMT state controls
• SYNC generation
• EMCY and TIME producer/consumer
• Object Dictionary → used by Node Manager and SDO/PDO modules
• Profiles layer builds on Object Dictionary for CiA-402 state machine
c. Architectural patterns/design principles:
• Modular layering: transport (python-can) → network abstraction → protocol services → application
• Plug-in extensibility: object dictionary loading (EDS), hardware backend customization
• Separation of concerns: each CANopen service in its own module
d. Relevant technologies/frameworks:
• Python 3.8+
• python-can for hardware interface
• Sphinx for documentation
• pytest/unittest for testing