Application note 0564-07: virtual objects in PDOs

This document explains how to use virtual objects in PDOs.

 

Since library version 4.5p5 the CANopen stack provides the functionality to map virtual objects into PDOs, and that in both directions. As usual the application has to take care of the virtual objects and is fully responsible for the data.

 

If a virtual object is mapped to a PDO, the library calls either

 

coUserVirtualTpdoInd

 

when a PDO with virtual objects is going to be sent out, or

 

coUserVirtualRpdoInd

 

when a PDO with mapped virtual objects is received.

 

The application can then use these functions to either fill the PDO buffer with data to send or copy received data to a memory location or object.

 

The prototypes of the functions are:

 

RET_T coUserVirtualRpdoInd(UNSIGNED16 pdoNr, UNSIGNED8* pBuf CO_COMMA_LINE_PARA_DECL);

 

and

 

RET_T coUserVirtualTpdoInd(UNSIGNED16 pdoNr, UNSIGNED8* pBuf CO_COMMA_LINE_PARA_DECL);

 

The parameter pdoNr indicates the service number of the PDO. The parameter pBuf is a pointer to the actual PDO data. The application can fill the data on the corresponding location in the data. If the application fills locations which do not belong to a virtual mapped object, the library ignores that.

 

Please keep in mind that the application has to have knowledge of the PDO mapping, especially with dynamic mapping.

 

To enable this functionality, the define CONFIG_VIRTUAL_OBJECTS_PDO has to be set in addition to the define CONFIG_VIRTUAL_OBJECTS for virtual objects. Virtual objects that are mapped to PDOs need to be given the CO_MAP_PERM flag.

 

For an implementation example please see s24 in the examples folder.

 

Templates for coUserVirtualRpdoInd(..) and coUserVirtualTpdoInd(..) are in the file usr_301.c.