CANopen Master Documentation
Version 6.06.04
Loading...
Searching...
No Matches
Demo application

A generic demo application, located inside the source/application/template-com/ directory, is used for all examples. Functions related to this demo have the prefix ComDemo. The following code snippet shows a stripped version of the main() function.

//---------------------------------------------------------------------------------------------------
// Initialize the CANopen Master demo application
//
//---------------------------------------------------------------------------------------------------
// this is the main loop of the embedded application
//
while (ComDemoAppRun() == true)
{
ComMgrProcess(ubNetV);
}
ComStatus_tv ComDemoAppInit(uint8_t ubNetV)
void ComDemoAppProcess(uint8_t ubNetV)
ComStatus_tv ComMgrProcess(uint8_t ubNetV)

CANopen demo initialization

A sample CANopen Master Stack initialization is implemented in the file source/application/template-com/com_demo_app.c

{
ComStatus_tv tvResultT;
//---------------------------------------------------------------------------------------------------
// Initialize the CANopen Master demo application, this is individual for every target
//
ComDemoAppInitTarget(tsComOptionsS[ubNetV].ubCanInterface, ubNetV, &tsComOptionsS[ubNetV]);
//---------------------------------------------------------------------------------------------------
// Initialize the CANopen Master stack with address 127 (default), bit-rate = 500K
//
tvResultT = ComMgrInit( tsComOptionsS[ubNetV].ubCanInterface, ubNetV, eCP_BITRATE_500K, tsComOptionsS[ubNetV].ubNodeId,
TMPL_COM_CONFIG);
//---------------------------------------------------------------------------------------------------
// add an individual object dictionary for this channel
//
tvResultT = ComDictAddList(ubNetV, &atsComDictMasterTableG[0]);
//---------------------------------------------------------------------------------------------------
// Initialize the CANopen Master stack services
//
//---------------------------------------------------------------------------------------------------
// start the CANopen master stack:
// this will issue the boot-up message of the CANopen master
//
tvResultT = ComMgrStart(ubNetV);
//---------------------------------------------------------------------------------------------------
// start master detection procedure
//
//---------------------------------------------------------------------------------------------------
// Set Heartbeat producer time for CANopen Master
//
tvResultT = ComNmtSetHbProdTime(ubNetV, tsComOptionsS[ubNetV].ulHeartbeatTime);
if (tvResultT != eCOM_ERR_NONE)
{
ComDemoAppConsoleError("Failed to set heartbeat producer time - ", tvResultT);
}
//---------------------------------------------------------------------------------------------------
// Set SYNC producer time for CANopen Master
//
#if COM_SYNC_SUPPORT > 0
tvResultT = ComSyncSetCycleTime(ubNetV, tsComOptionsS[ubNetV].ulSyncCycleTime);
if (tvResultT != eCOM_ERR_NONE)
{
ComDemoAppConsoleError("Failed to set SYNC producer time - ", tvResultT);
}
#endif
tsComOptionsS[ubNetV].btNetIsActive = true;
return tvResultT;
}
@ eCP_BITRATE_500K
Definition canpie.h:677
@ eCOM_ERR_NONE
Definition com_defs.h:155
int32_t ComStatus_tv
Definition com_defs.h:116
ComStatus_tv ComDemoAppInitServices(uint8_t ubNetV)
void ComDemoAppConsoleError(const char *szMessageV, ComStatus_tv tvStatusV)
ComStatus_tv ComDemoAppInitTarget(uint8_t ubCanIfV, uint8_t ubNetV, ComDemoAppOptions_ts *ptsOptionsV)
ComStatus_tv ComDictAddList(uint8_t ubNetV, ComDicEntry_ts *ptsDictListV)
ComDicEntry_ts atsComDictMasterTableG[]
ComStatus_tv ComMgrStart(uint8_t ubNetV)
Start the CANopen Master.
ComStatus_tv ComMgrInit(uint8_t ubCanIfV, uint8_t ubNetV, uint8_t ubBitrateNomSelV, uint8_t ubNodeIdV, uint32_t ulModeV)
ComStatus_tv ComNmtMasterDetection(uint8_t ubNetV, uint8_t ubBootupV)
Start NMT master detection.
ComStatus_tv ComNmtSetHbProdTime(uint8_t ubNetV, uint16_t uwTimeV)
Set producer heartbeat time.
ComStatus_tv ComSyncSetCycleTime(uint8_t ubNetV, uint32_t ulTimeV)

CANopen demo processing

A sample CANopen Master Stack data processing is implemented in the file source/application/template-com/com_demo_app.c

void ComDemoAppProcess(uint8_t ubNetV)
{
//---------------------------------------------------------------------------------------------------
// call handler for LSS only if LSS support is enabled
//
#if COM_LSS_SUPPORT > 0
#endif
#if TARGET_IS_WINDOWS > 0
MSG msg;
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
#endif
ComDemoAppIdle();
}
ComStatus_tv ComDemoLssProcess(uint8_t ubNetV)
ComStatus_tv ComDemoNmtProcess(uint8_t ubNetV)