Skip to main content

CANopen library providing functionality to implement responder nodes

Project description

CANopen library to implement responder nodes.

Backends:

Synopsis

  • Pure python implementation

  • Under MIT license (2021 Günther Jena)

  • Source is hosted on GitHub.com

  • Tested on Python 3.7, 3.8, 3.9 and 3.10

  • Unit tested with pytest, coding style done with Black, static type checked with mypy, static code checked with Pylint, documented with Sphinx

  • Supporting CiA301 (EN 50325-4)

Feature List

  • Object dictionary

    • provides callbacks for validation, update, download and read

    • supports records, arrays and variables

  • EDS support

    • dynamically generation of EDS file

    • automatically provided via object 0x1021 (“Store EDS”)

  • up to 128 SDO servers

    • expetited, segmented and block transfer for up- and download

    • COB-IDs dynamically configurable

    • custom up- and download handlers supported

  • up to 512 TPDOs and 512 RPDOs

    • dynamically configurable

    • transmission types: synchronous (acyclic and every nth sync) and event driven

    • inhibit time supported

  • EMCY producer service

    • COB-ID dynamically configurable

    • inhibit time supported

  • Heartbeat producer service

    • dynamically configurable

  • NMT slave service

    • boot-up service

    • callback for state change provided

  • SYNC consumer service

    • COB-ID dynamically configurable

    • callback for received sync provided

  • CiA305 Layer Setting Service

    • fast scan supported

    • bitrate and node id configuring supported

    • identify remote responder supported

  • CAN interface abstraction

    • python-can fully supported

    • automatic CAN id filtering by subscripted services

  • Scheduling supporting threaded and async operation

TODO
  • build object dictionary via reading an EDS file

  • supporting MPDOs

  • TIME consumer service

  • Up- and download handler as io streams

Examples

Creating a node

import can
from durand import CANBusNetwork, Node, Variable, Record, DatatypeEnum

bus = can.Bus(bustype='socketcan', channel='vcan0')
network = CANBusNetwork(bus)

node = Node(network, node_id=0x01)

Congratulations! You have a CiA-301 compliant node running. Layer Setting Service is also supported out of the box.

Adding objects

od = node.object_dictionary

# add variable at index 0x2000
od[0x2000] = Variable(DatatypeEnum.UNSIGNED16, access='rw', value=10, name='Parameter 1')

# add record at index 0x2001
record = Record(name='Parameter Record')
record[1] = Variable(DatatypeEnum.UNSIGNED8, access='ro', value=0, name='Parameter 2a')
record[2] = Variable(DatatypeEnum.REAL32, access='rw', value=0, name='Parameter 2b')
od[0x2001] = record

Access values

The objects can be read and written directly by accessing the object dictionary:

print(f'Value of Parameter 1: {od.read(0x2000, 0)}')
od.write(0x2001, 1, value=0xAA)

Add callbacks

A more event driven approach is using of callbacks. Following callbacks are available:

  • validate_callbacks - called before a value in the object dictionary is going to be updated

  • update_callbacks - called when the value has been changed (via od.write or via CAN bus)

  • download_callbacks - called when the value has been changed via CAN bus

  • read_callback - called when a object is read (return value is used )

od.validate_callbacks[(0x2000, 0)].add(lambda v: v % 2 == 0)
od.update_callbacks[(0x2001, 2)].add(lambda v: print(f'Update for Parameter 2b: {v}'))
od.download_callbacks[(0x2000, 0)].add(lambda v: print(f'Download for Parmeter 1: {v}'))
od.set_read_callback(0x2001, 1, lambda: 17)

PDO mapping

PDOs can dynamically mapped via the SDO server or programmatically. The PDO indices start at 0.

node.tpdo[0].mapping = [(0x2001, 1), (0x2001, 2)]
node.tpdo[0].transmission_type = 1  # transmit on every SYNC

node.rpdo[0].mapping = [(0x2000, 0)]
node.tpdo[0].transmission_type = 255  # event driven (processed when received)

Install

pip install durand

Credits

This library would not be possible without:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

durand-0.4.9.tar.gz (35.4 kB view details)

Uploaded Source

Built Distribution

durand-0.4.9-py3-none-any.whl (30.6 kB view details)

Uploaded Python 3

File details

Details for the file durand-0.4.9.tar.gz.

File metadata

  • Download URL: durand-0.4.9.tar.gz
  • Upload date:
  • Size: 35.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for durand-0.4.9.tar.gz
Algorithm Hash digest
SHA256 a8c7d21fa4de1fb6123d8dd89fb833a7109d7801e22daf7b41b9e5cf576a300c
MD5 669dbf20806472890b326e96bd735559
BLAKE2b-256 23b14f5dcf222d5331fe97ffddd3fb72b887f8550fd60e61636f7a54a10873bb

See more details on using hashes here.

File details

Details for the file durand-0.4.9-py3-none-any.whl.

File metadata

  • Download URL: durand-0.4.9-py3-none-any.whl
  • Upload date:
  • Size: 30.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for durand-0.4.9-py3-none-any.whl
Algorithm Hash digest
SHA256 ffc35fcaf242113520f769502e4582564e25ccd96758be6e73c5d800d80a38fb
MD5 92623d4fa89867e914e22d9a64db8d8c
BLAKE2b-256 a24e2cea3d0192b44ceb02cfb428effc2e82a1fbab714bd627f0ac62ad60700b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page