Download MicroCANopen Plus User Manual
Transcript
THE MICROCANOPEN PLUS PROTCOL STACK
Variables:
SDOCLIENT *pSC; // pointer to SDO client
UNSIGNED8 chn; // channel usage
UNSIGNED8 buf_SDO[4];
Setting up channel and starting request in the application:
chn = 0;
// Set up SDO channel 1 to talk to node 9 using buf_SDO data
pSC = MGR_InitSDOClient(1,CAN_ID_SDOREQUEST(MY_NODE_ID,9),
CAN_ID_SDORESPONSE(MY_NODE_ID,9),
&(buf_SDO[4]),4);
// Start read request of [0x1000,0x00] of remote node
MGR_SDOClientRead(pSC,0x1000,0x00);
chn = 1;
// chn is in use
The manager processing function MGR_ProcessMGR() has to be called
periodically. When the request is completed, it will call MGRCB_SDOComplete:
/***************************************************************
DOES:
Called when an SDO client transfer is completed
RETURNS: nothing
***************************************************************/
void MGRCB_SDOComplete (
UNSIGNED8 channel,
// SDO channel number in range of 1 to
// NR_OF_SDO_CLIENTS
UNSIGNED32 abort_code // status, error, abort code
)
{
// SDO Client example of non-blocking version
if (channel == 1)
{
if ((abort_code == SDOERR_READOK) ||
(abort_code == SDOERR_WRITEOK))
{
chn++; // signal OK
}
else
{
chn = 0xFF; // signal ABORT
}
}
}
In the application, we may react to our SDO status variable:
if (chn > 1)
if (chn = 0xFF)
[process SDO abort]
else
[start next request to node 9]
51