Skip to main content

Example: CANopen

Product: CODESYS CANopen Manager SL

This example deals with the programming interface of the communication stack of the CANopen Master and CANopen Slave. The project contains examples for SDO, NMT, diagnostics, and the dynamic configuration of communication parameters (baud rate, network ID, node ID), and many more.

Description

The project contains different examples for using the programming interface of the CANopen Master and CANopen Slave stack. Topics which are handled include the following:

  • SDO (expedited, segmented, block), access to the object dictionary

  • Network Management (NMT)

  • Diagnostics (CANopen state, EMCY)

  • Event handler for the object dictionary and CANopen manager state machine

  • Reconfigure: Dynamic changing of baud rate, network ID, and node ID

  • Access to the CAN configuration by means of the device diagnosis library

Additional information

The project includes a CANopen Master and a CANopen Slave stack which communicate with each other via CANbus. Two interconnected CAN interfaces are needed for commissioning the project. The easiest way to implement this is to use the CODESYS Control Win controller and a 2-channel USB-CAN adapter, such as PEAK PCAN-USB Pro or two 1-channel adapters.

For the communication to work, the respective runtime system component has to be entered in the configuration file.

For more information, see: Runtime Configuration.

The project can also be operated on any controller with two CAN interfaces by means of a device update of the PLC. The project is divided into three areas:

CANbus Examples

  • ChangeBaudrate: Dynamic change of baud rate in runtime mode by means of reconfiguration

  • EnableDisableCANbus: Dynamic activation and deactivation of a CANbus in runtime mode by means of reconfiguration

  • GetCANbus: Generic search of an engineered CANbus instance by means of the device diagnosis library

CANopen Master examples

Diagnostics

  • ReceiveEMCYFromAllDevicesExample: Reception of emergency messages by means of CiA405.RECV_EMCY

  • ReceiveEMCYFromOneDeviceExample: Reception of emergency messages for a specific device by means of CIA405.RECV_EMCY_DEV

  • GetCANopenKernelStateExample: Detection of the CANopen kernel state by means of CIA405.GET_CANOPEN_KERNEL_STATE

  • GetStateExample: Detection of the CANopen state of a slave by means of CIA405.GET_STATE

Network management

  • GetCANopenManagerNodeIDExample: Detection of the CANopenManager node ID by means of CiA405.

  • GET_CANOPEN_KERNEL_STATE: Sending of NMT requests by means of CIA405.NMT

SDO (acyclic data transfer)

  • ExpeditedReadExample: Reading of an object <= 4 bytes via SDO (expedited transfer) by means of CiA405.SDO_READ4

  • ExpeditedWriteExample: Writing of an object <= 4 bytes via SDO (expedited transfer) by means of CIA405.SDO_WRITE4

  • SegmentedAndBlockReadExample: Reading of an object of any length via SDO (segmented transfer or block transfer) by means of CiA405.SDO_READ_DATA

  • SegmentedAndBlockWriteExample: Writing if an object of any length via SDO (segmented transfer or block transfer) by means of CiA405.SDO_WRITE_DATA

General API functions

  • CANopenManagerAPI: Demonstrates the use of all methods and properties of the CANopenManager instance

  • CANopenManagerEventHandler: Exemplary implementation of a CANopen event handler

  • CANopenRemoteDeviceAPI: Demonstrates the use of all methods and properties of a CANopenRemoteDevice instance

CANopen Slave examples

Diagnostics

  • GetLocalDeviceInfoExample: Demonstrates the reading of the CANopen state as well as the node ID

Network management

  • ChangeNodeIDExample: Change of the node ID in runtime mode

  • NMTExample: Change of the local CANopen state

Object dictionary

  • ReadObjectExample1: Reading of an object from the local object dictionary

  • ReadObjectExample2: Alternative example of ReadObjectExample1

  • WriteObjectExample1: Writing the value of an object to the object dictionary

  • WriteObjectExample2: Alternative example of WriteObjectExample1

  • CountObjects: traverse over all objects of the object dictionary by means of _3SCSS.ObjectIterator

  • GetPDOInfo: Additional example of traversing the object dictionary

  • ObjectDictionaryEventHandler: Exemplary implementation of an object dictionary event handler

System requirements and restrictions

Programming system

CODESYS Development System (version 3.5.14.0 or higher)

Runtime system

CODESYS Control Win (version 3.5.14.0)

Add-on components

Two CAN interfaces

Note

_example_icon.png DOWNLOAD Project