EtherNet/IP™ Adapter3.09.00
 
Loading...
Searching...
No Matches

◆ EI_API_CIP_addInstanceCustService()

uint32_t EI_API_CIP_addInstanceCustService ( T *  pCipNode_p,
uint16_t  classId_p,
uint16_t  instanceId_p,
EI_API_CIP_SCustomService_t pService_p 
)

Add custom service to the class instance.

This function adds one or more custom service/s to the class with the class and instance identifiers passed as parameters classId_p and instanceId_p. Compare to EI_API_CIP_addInstanceService gives the possibility to build response for remote request on side of application.

Remarks
Parameters
[in]pCipNode_pPointer to the CIP node.
[in]classId_pClass identifier.
[in]instanceId_pInstance identifier.
[in]pService_pPointer to custom service structure, see EI_API_CIP_SCustomService_t type definition.
Returns
EI_API_CIP_EError_t as uint32_t value.
Return values
EI_API_CIP_eERR_OKSuccess.
EI_API_CIP_eERR_NODE_INVALIDCIP node is invalid, possibly EI_API_CIP_NODE_new() was not called.
EI_API_CIP_eERR_CLASS_BLACKLISTOperation on the CIP object with specified identifier (class ID) are not allowed.
EI_API_CIP_eERR_CLASS_DOES_NOT_EXISTClass does not exists in CIP node dictionary.
EI_API_CIP_eERR_INSTANCE_DOES_NOT_EXISTInstance does not exist in CIP node dictionary.
EI_API_CIP_eERR_SERVICE_ALREADY_EXISTService already exist.
EI_API_CIP_eERR_SERVICE_INVALIDService is invalid, possibly NULL pointer.
EI_API_CIP_eERR_MEMALLOCMemory allocation error.
Example
#include "EI_API.h"
uint8_t EI_APP_DEVICE_PROFILE_RawGetSingle (const void *ptObj_p, void *ptConObj_p, EI_API_CIP_SBuffer_t *ptConsumeBuf_p, EI_API_CIP_SBuffer_t *ptProduceBuf_p)
{
// Check size of buffer against size of data to sent
if (4 + 232 < ptProduceBuf_p->maxData)
{
ptProduceBuf_p->pDataBuf[0] = 0x80 | 0x4B; // RESPONSE | RAW_GET_SINGLE;
ptProduceBuf_p->pDataBuf[1] = 0; // Reserved, always zero
ptProduceBuf_p->pDataBuf[2] = 0x00; // SUCCESS
ptProduceBuf_p->pDataBuf[3] = 0; // No Additional Status Data
ptProduceBuf_p->actData = 4; // Update actual number of bytes
for (int i = 0; i <= 232; i++)
{
ptProduceBuf_p->pDataBuf[4 + i] = i; // Update one data byte
ptProduceBuf_p->actData++; // Update actual number of bytes
}
ret = EI_API_CIP_SERVICE_eERR_RESPONSE; // Send response back with success.
}
else
{
ptProduceBuf_p->pDataBuf[0] = 0x80 | 0x4B; // RESPONSE | RAW_GET_SINGLE;
ptProduceBuf_p->pDataBuf[1] = 0; // Reserved, always zero
ptProduceBuf_p->pDataBuf[2] = 0x11; // DATA_TOO_LARGE
ptProduceBuf_p->pDataBuf[3] = 0; // No Additional Status Data
ptProduceBuf_p->actData = 4; // Update actual number of bytes
ret = EI_API_CIP_SERVICE_eERR_ERR_RESPONSE; // Send response back with error.
}
return ret;
}
void EI_APP_DEVICE_PROFILE_cipSetup (EI_API_CIP_NODE_T* pCipNode)
{
uint32_t errCode;
uint16_t classId = 0x010B;
// Create a class
errCode = EI_API_CIP_createClass(pCipNode, classId);
// Create instance in class with identifier classId
errCode = EI_API_CIP_createInstance(pCipNode, classId, 0x0001);
// Add custom service to instance 0x01 for the class with classId
service.code = 0x4B; // RAW_GET_SINGLE
service.fuServiceUser = NULL;
service.fuServiceStack = EI_APP_DEVICE_PROFILE_RawGetSingle;
errCode = EI_API_CIP_addInstanceCustService(pCipNode, classId, 0x0001, &service);
}
ETHIP_API uint32_t EI_API_CIP_createClass(T *pCipNode_p, uint16_t classId_p)
Create a CIP class.
Definition EI_API_CIP_stub.c:215
@ EI_API_CIP_SERVICE_eERR_INVALID
Definition EI_API_CIP_define.h:151
@ EI_API_CIP_SERVICE_eERR_ERR_RESPONSE
Definition EI_API_CIP_define.h:153
@ EI_API_CIP_SERVICE_eERR_RESPONSE
Definition EI_API_CIP_define.h:152
ETHIP_API uint32_t EI_API_CIP_addInstanceCustService(T *pCipNode_p, uint16_t classId_p, uint16_t instanceId_p, EI_API_CIP_SCustomService_t *pService_p)
Add custom service to the class instance.
Definition EI_API_CIP_stub.c:1006
ETHIP_API uint32_t EI_API_CIP_createInstance(T *pCipNode_p, uint16_t classId_p, uint16_t instanceId_p)
Creates a CIP instance.
Definition EI_API_CIP_stub.c:787
uint16_t maxData
Definition EI_API_CIP_define.h:204
uint8_t * pDataBuf
Definition EI_API_CIP_define.h:206
uint16_t actData
Definition EI_API_CIP_define.h:205
Consumer/Producer buffer structure declaration.
Definition EI_API_CIP_define.h:203
uint16_t code
Service Code Number.
Definition EI_API_CIP_define.h:228
EI_API_CIP_CBStack fuServiceStack
Function pointer to the callback required by stack.
Definition EI_API_CIP_define.h:229
EI_API_CIP_CBService fuServiceUser
Function pointer to the callback set by user.
Definition EI_API_CIP_define.h:230
Custom service structure declaration.
Definition EI_API_CIP_define.h:227
See also
EI_API_CIP_createClass EI_API_CIP_createInstance EI_API_CIP_EError_t