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.