This article shows how to read information stored in the Anybus CompactCom (ABCC) during initialization. That is done by retrieving attribute values from Anybus Module Objects using user's custom functions.
APPLICABLE PRODUCTS
Anybus CompactCom 30
Anybus CompactCom 40
PRE-REQUISITES
Anybus CompactCom 30 / 40
Host Application Example Code V3.x
SOLUTION DESCRIPTION
During the SETUP state of the ABCC driver state machine, the Host Application sends commands to the Anybus CompactCom.
You can embed your own custom command and response functions in order to read attributes from the Anybus Module Objects during that SETUP state. In the Host Application Example Code ≥ V3.x, this can be done using a command sequence.
Here are the necessary steps to follow :
EXAMPLE
We want to read out the serial number of our ABCC40 module during SETUP.
In Chapter 12 of the ABCC40-Software Design guide, we see that the serial number is the 3rd Attribute of Instance #1 in the Anybus Object (01h).
Now, let’s apply the two steps we saw earlier.
The functions we are going to implement are ReadSerialNumCmd() and ReadSerialNumResp(), therefore those need to be part of our forward declarations, along with the abcc_iSerialNumber variable, used to store the serial number value.
static ABCC_CmdSeqCmdStatusType ReadSerialNumCmd ( ABP_MsgType* psMsg );
static ABCC_CmdSeqRespStatusType ReadSerialNumResp ( ABP_MsgType* psMsg);
static UINT32 abcc_iSerialNumber;
FUNCTION IMPLEMENTATIONS
Command function : ReadSerialNumCmd()
static ABCC_CmdSeqRespStatusType ReadSerialNumCmd(ABP_MsgType* psMsg )
{
ABCC_GetAttribute( psMsg, ABP_OBJ_NUM_ANB, 1,
ABP_ANB_IA_SERIAL_NUM, ABCC_GetNewSourceId());
return( ABCC_SEND_COMMAND );
}
As you can see in the command function, the command used is the Get_Attribute command (ABCC_GetAttribute), which points to the Anybus object (ABP_OBJ_NUM_ANB), Instance #1, Attribute 3 (ABP_ANB_IA_SERIAL_NUM).
Response handler function : ReadSerialNumResp()
static ABCC_CmdSeqCmdStatusType ReadSerialNumResp(ABP_MsgType* psMsg)
{
ABCC_ASSERT_ERR(ABCC_VerifyMessage(psMsg) == ABCC_EC_NO_ERROR,
ABCC_SEV_WARNING, ABCC_EC_RESP_MSG_E_BIT_SET,
(UINT32)ABCC_GetErrorCode(psMsg));
ABCC_GetMsgData32(psMsg, &abcc_iSerialNumber, 0);
ABCC_PORT_DebugPrint(("RSP MSG_GET_MODULE_SERIAL_NUM: %X\n", abcc_iSerialNumber));
return(ABCC_EXEC_NEXT_COMMAND);
}
The response handler checks the validity of the response data. The data shouldn’t contain any errors and should have the correct type.
COMMAND SEQUENCER
Here, we simply add those functions to the appl_asUserInitCmdSeq[] command sequence. In the code we can see that appl_asUserInitCmdSeq[] already has a set of handler functions. We simply need to add ours, following the same format.
static const ABCC_CmdSeqType appl_asUserInitCmdSeq[] =
{
...
ABCC_CMD_SEQ(ReadSerialNumCmd, ReadSerialNumResp),
ABCC_CMD_SEQ_END()
};
That’s it!
Once we reboot our ABCC40, our functions are also run as part of the appl_asUserInitCmdSeq[] command sequence during the SETUP state, and we’re able to read the serial number of our module.
ADDITIONAL INFORMATION
You will find attached a .txt file containing these handler functions. In case you want to make use of it, the section titles in example_code/appl_abcc_handler.c have been included in order to direct you better as to where to paste the different declarations and methods in the code.
Based on this example, you can implement your own handler functions to read other attributes from an ABCC Module Object during initialization.
RELATED ARTICLES
How to read out information from an Anybus CompactCom at runtime?
How to change a parameter in an Anybus CompactCom during initialization?
How to change a parameter in an Anybus CompactCom at runtime?