This page provides the details of registering the custom read and write callbacks to objects of type Variable, Array and Record.
Create the custom object read callback function to be registered with object in the format given below.
uint8_t(*
EC_API_SLV_CBObjRead_t)(
void* pContext, uint16_t index, uint8_t subindex, uint32_t length, uint16_t* pData, uint8_t completeAccess);
uint8_t(* EC_API_SLV_CBObjRead_t)(void *pContext, uint16_t index, uint8_t subindex, uint32_t length, uint16_t *pData, uint8_t completeAccess)
Callback trigered by a SDO Upload operation.
Definition ecSlvApi_types.h:483
This callback function is called when the EtherCAT MainDevice sends the object read request (SDO upload request). It is the responsibility of the registered callback function to update the value pointed to by pData. pData is returned within the SDO Response datagram.
The code snippet is the sample custom read callback implementation.
uint8_t EC_SLV_APP_readObjectCb(void* pContext,uint16_t index_p,uint8_t subindex_p,uint32_t size_p,uint16_t MBXMEM * pData_p,uint8_t completeAccess_p)
{
OSAL_printf("SDO Upload: %s ==> Idx: 0x%04x:%d | Size: %d | access: %d\r\n", __func__,index_p, subindex_p, size_p, completeAccess_p);
if (completeAccess_p)
{
if (subindex_p == 0)
{
}
else if (subindex_p == 1)
{
}
else
{
OSAL_printf("Invalid SI for Complete Access -> 0x%04x:%d\r\n",index_p,subindex_p);
}
}
else
{
}
return (uint8_t)error;
}
enum EC_API_EError EC_API_EError_t
#define ABORT_NOERROR
No SDO error.
Definition ecSlvApiDef_CoE.h:158
Create the custom object write callback function to be registered with object in the format given below.
uint8_t(*
EC_API_SLV_CBObjWrite_t)(
void* pContext, uint16_t index, uint8_t subindex, uint32_t length, uint16_t* pData, uint8_t completeAccess);
uint8_t(* EC_API_SLV_CBObjWrite_t)(void *pContext, uint16_t index, uint8_t subindex, uint32_t length, uint16_t *pData, uint8_t completeAccess)
Callback trigered by a SDO Download operation.
Definition ecSlvApi_types.h:511
This callback function is called when the EtherCAT MainDevice sends the object write request (SDO download request). It is the responsibility of the callback function to copy the value pointed to by pData to the object entry.
The code snippet is the sample write callback implementation.
uint8_t EC_SLV_APP_writeObjectCb(void* pContext,uint16_t index_p,uint8_t subindex_p,uint32_t size_p,uint16_t MBXMEM * pData_p,uint8_t completeAccess_p)
{
OSAL_printf("SDO Download: %s ==> Idx: 0x%04x:%d | Size: %d | access: %d\r\n", __func__,index_p, subindex_p, size_p, completeAccess_p);
if (completeAccess_p)
{
if(subindex_p == 0)
{
}
else if(subindex_p == 1)
{
}
}
else
{
if(subindex_p!=0)
{
}
}
return (uint8_t)error;
}
Register these custom object read and write callbacks during the object creation. The code snippet below registers the custom read and write callbacks for a variable type object.
ptSubDevice,
0xYYYY,
"Name of Variable",
32,
EC_SLV_APP_readObjectCb,
pContext,
EC_SLV_APP_writeObjectCb,
pContext);
uint32_t EC_API_SLV_CoE_odAddVariable(EC_API_SLV_SHandle_t *pHandle, uint16_t index, char *pName, uint16_t type, uint16_t bitLen, uint16_t flags, EC_API_SLV_CBObjRead_t cbRead, void *pReadCtxt, EC_API_SLV_CBObjWrite_t cbWrite, void *pWriteCtxt)
This function creates a Base Data Type Object for the Object Dictionary.
Definition ecSlvApi_CoE.c:1606
#define ACCESS_READWRITE
Read/write in all states.
Definition ecSlvApiDef_CoE.h:134
#define DEFTYPE_UNSIGNED32
UNSIGNED32.
Definition ecSlvApiDef_CoE.h:46