Download project
This sample project deals with the programming interface of the CANopen master and CANopen slave communication stack.
The project contains examples for SDO, NMT, diagnostics, and the dynamic configuration of communication parameters
(baud rate, network ID, node ID), and many more.
This sample project contains different examples for using the programming interface of the CANopen master
and CANopen slave stack. Topics that are handled include the following:
The project includes a CANopen master and a CANopen slave stack that communicate with each other via CANbus.
Two interconnected CAN interfaces are needed for commissioning the project.
It is easiest to implement this with CODESYS Control Win V3 and a PEAK PCAN-USB Pro or two PEAK PCAN USB adapters.
For this to work, the runtime system component "CmpPCANBasicDrv" must be entered in the configuration file.
For more information, refer to the CODESYS online help.
The project can also be operated on any controller with two CAN interfaces by means of an update device of the PLC.
The project is divided into three areas:
ChangeBaudrate
: Dynamic change of baud rate in runtime mode by means of reconfigureEnableDisableCANbus
: Dynamic activation and deactivation of a CANbus in runtime mode by means of reconfigureGetCANbus
: Generic search of an engineered CANbus instance by means of the device diagnosis libraryDiagnostics
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
NMT_Example
: 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 or block transfer) via CiA405.SDO_READ_DATA
SegmentedAndBlockWriteExample
: Writing if an object of any length via SDO (segmented or block transfer) via CiA405.SDO_WRITE_DATA
General API functions
CANopenManagerAPI
: Demonstrates the use of all methods and properties of the CANopenManager
instanceCANopenManagerEventHandler
: Exemplary implementation of a CANopen event handlerCANopenRemoteDeviceAPI
: Demonstrates the use of all methods and properties of a CANopenRemoteDevice
instanceDiagnostics
GetLocalDeviceInfoExample
: Demonstrates the reading of the CANopen state as well as the node IDNetwork management
ChangeNodeIDExample
: Change of the node ID in runtime modeNMTExample
: Change of the local CANopen stateObject directory
ReadObjectExample1
: Reading of an object from the local object directoryReadObjectExample2
: Alternative example of ReadObjectExample1
WriteObjectExample1
: Writing an object to the object directoryWriteObjectExample2
: Alternative example of WriteObjectExample1
CountObjects
: Traversing of the complete object directory by means of _3SCSS.ObjectIterator
GetPDOInfo
: Additional example of traversing the object directoryObjectDictionaryEventHandler
: Exemplary implementation of an object directory event handler System requirements and restrictions | Info |
---|---|
Programming System | CODESYS Development System Version 3.5.14.0 or higher |
Runtime System | CODESYS Control Version 3.5.14.0 |
Required Accessories | Two CAN interfaces from the company PEAK-System Technik GmbH (e.g.two PCAN-USB or one PCAN-USB Pro) |