EtherCAT Slave
 
Loading...
Searching...
No Matches
Enumerations in Object Dictionary

Enumeration types can be defined in the Object Dictionary and these are hidden in the index range between 0x0800 and 0x0FFF. Enumeration type entries are composed by a value and by a name. Moreover, the enum bit size has to be provided. To create and configure the enumeration, these API functions are available: EC_API_SLV_CoE_odAddEnum and EC_API_SLV_CoE_configEnum.

Create and configure the new ENUM type

Use the function EC_API_SLV_CoE_odAddEnum to create the enum object. As input parameter it requires the SDK handle and the enumeration index. The index must be between 0x0800 and 0x0FFF, otherwise it will return an error code. The output parameter in an OBD object.

#define SLS_OBJIDX_FSOE_CONN_STATE 0x0800
//Create ENUM object
error = (EC_API_EError_t) EC_API_SLV_CoE_odAddEnum(ptSlave, SLS_OBJIDX_FSOE_CONN_STATE, &pApplicationInstance->pt0800EnumObj);
if (error != EC_API_eERR_NONE)
{
OSAL_printf("Object SLS_OBJIDX_FSOE_CONN_STATE Error code: 0x%08x\r\n", error);
}
@ EC_API_eERR_NONE
Definition ecSlvApiDef_error.h:45
enum EC_API_EError EC_API_EError_t

Use the function EC_API_SLV_CoE_configEnum to configure each enum entry. As input parameters, it requires the SDK handle, the enumeration object and then the entry value and entry name.

#define FSOE_CONN_ST_RESET 100
#define FSOE_CONN_ST_SESSION 101
#define FSOE_CONN_ST_CONNECTION 102
#define FSOE_CONN_ST_PARAMETER 103
#define FSOE_CONN_ST_DATA 104
#define FSOE_CONN_ST_FAILSAFE 105
EC_API_SLV_CoE_configEnum(ptSlave, pApplicationInstance->pt0800EnumObj, FSOE_CONN_ST_RESET, "Reset");
EC_API_SLV_CoE_configEnum(ptSlave, pApplicationInstance->pt0800EnumObj, FSOE_CONN_ST_SESSION, "Session");
EC_API_SLV_CoE_configEnum(ptSlave, pApplicationInstance->pt0800EnumObj, FSOE_CONN_ST_CONNECTION, "Connection");
EC_API_SLV_CoE_configEnum(ptSlave, pApplicationInstance->pt0800EnumObj, FSOE_CONN_ST_PARAMETER, "Parameter");
EC_API_SLV_CoE_configEnum(ptSlave, pApplicationInstance->pt0800EnumObj, FSOE_CONN_ST_DATA, "Data");
EC_API_SLV_CoE_configEnum(ptSlave, pApplicationInstance->pt0800EnumObj, FSOE_CONN_ST_FAILSAFE, "FailSafe");

Using the new ENUM type

The new enumeration type can now be used as type parameter for variable, array and record objects. Provide the enumeration index as type parameter and specify the enumeration bit length. The enumeration size can be up to 32 bits.

#define SLS_OBJIDX_FSOE_DIG_IO_MODULE 0xA000
#define SLS_OBJIDX_FSOE_CONN_STATE 0x0800
//Create FSoE Diagnosis object
error = (EC_API_EError_t)EC_API_SLV_CoE_odAddRecord(ptSlave,
SLS_OBJIDX_FSOE_DIG_IO_MODULE,
"FSoE Digital IO Module",
NULL,
NULL,
NULL,
NULL,
&pApplicationInstance->ptA000RecObj);
//Configure new SubIndex as enumeration type SLS_OBJIDX_FSOE_CONN_STATE and 16 bit length
error = (EC_API_EError_t)EC_API_SLV_CoE_configRecordSubIndex(ptSlave,
pApplicationInstance->ptA000RecObj,
1,
"Connection State",
SLS_OBJIDX_FSOE_CONN_STATE,
16,
if (error != EC_API_eERR_NONE)
{
OSAL_printf("Object 0xA000 SubIndex 1 Error code: 0x%08x\r\n", error);
goto Exit;
}
#define ACCESS_READ
Read only in all states.
Definition ecSlvApiDef_CoE.h:139

Finally set a value after initializing the stack with the EC_API_SLV_init.

/* use this code snippet after EC_API_SLV_init */
uint16_t connectionState = FSOE_CONN_ST_RESET;
EC_API_SLV_CoE_getObjectEntryByObject(ptSlave, pApplicationInstance_p->ptA000RecObj, 1, &ptObjEntry);
error = (EC_API_EError_t)EC_API_SLV_CoE_setObjectEntryData(ptSlave, ptObjEntry, sizeof(uint16_t), &connectionState);

Enumeration in TwinCAT

The enumeration subIndex can now be accessed by TwinCAT.

A000 object with subIndex 1 of enumeration type

The data dialog window shows a box with all possible enumeration values.

Enumeration box in TwinCAT