How to read out information from an Anybus CompactCom at runtime?

22 Nov 2022

This article shows how to read information stored in the Anybus CompactCom (ABCC) at runtime. 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

You can embed your own custom command and response handler functions to read some information from the module at runtime.

In the Host Application Example Code ≥ V3.x, this can be done by implementing your own command sequence.

That implementation can be carried out in the example_code/appl_abcc_handler.c file.

Here are the necessary steps to follow:

  1. Define your command sequence.
  2. Implement the handler functions of the sequence.
  3. Call your command sequence in the application at the desired runtime state.

 

EXAMPLE

We want to read out the serial number and the current language of our ABCC40 module during the WAIT_PROCESS state.

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).

The language is the 9th Attribute of Instance #1 in the Anybus Object (01h).

 

kb2_1.png

kb2_2.png

 

Now, let’s apply the three steps we saw earlier.

 
 

COMMAND SEQUENCE DEFINITION

 

The command sequence we are going to implement is appl_asUserRunCmdSeq[].
static const ABCC_CmdSeqType appl_asUserRunCmdSeq[] =
{
ABCC_CMD_SEQ(ReadSerialNumCmd, ReadSerialNumResp),
ABCC_CMD_SEQ(ReadLangAttributeCmd, ReadLangAttributeResp),
ABCC_CMD_SEQ_END()
};

 

As you can see, it contains two sets of handler functions to read the serial number and the current language of the  module, respectively.

static ABCC_CmdSeqCmdStatusType ReadSerialNumCmd( ABP_MsgType* psMsg );
static ABCC_CmdSeqRespStatusType ReadSerialNumResp( ABP_MsgType* psMsg );

static ABCC_CmdSeqCmdStatusType ReadLangAttributeCmd(ABP_MsgType* psMsg );
static ABCC_CmdSeqRespStatusType ReadLangAttributeResp( ABP_MsgType* psMsg );

static UINT8 abcc_iLang;
static UINT32 abcc_iSerialNumber;

 

ReadSerialNumCmd() sends a Get_Attribute command to the module to read its serial number.

ReadSerialNumResp() handles the module's response to the serial number attribute query.

 

ReadLangAttributeCmd() sends a Get_Attribute command to the module to read its current language.

ReadLangAttributeResp() handles the module's response to the current language attribute query.

 

 

FUNCTION IMPLEMENTATIONS

 

Serial number functions

  

Command handler function : ReadSerialNumCmd()

static ABCC_CmdSeqRespStatusType ReadSerialNumCmd( ABP_MsgType* psMsg )
{  
    ABCC_GetAttribute( psMsg,
ABP_OBJ_NUM_ANB,
1, // instance number 1
       ABP_ANB_IA_SERIAL_NUM,
ABCC_GetNewSourceId()
);

    return( ABCC_SEND_COMMAND );
}

  

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);

 

 

Current language functions

 

Command handler function : ReadLangAttributeCmd() 

static ABCC_CmdSeqRespStatusType ReadLangAttributeCmd( ABP_MsgType* psMsg )
{
ABCC_GetAttribute( psMsg,
ABP_OBJ_NUM_ANB,
1, // instance number 1
ABP_ANB_IA_LANG,
ABCC_GetNewSourceId ()
);

return(ABCC_SEND_COMMAND);

}

  

Response handler function : ReadLangAttributeResp()

static ABCC_CmdSeqCmdStatusType ReadLangAttributeResp( ABP_MsgType* psMsg )
{
ABCC_ASSERT_ERR(ABCC_VerifyMessage( psMsg ) ==
ABCC_EC_NO_ERROR,
ABCC_SEV_WARNING, ABCC_EC_RESP_MSG_E_BIT_SET,
(UINT8) ABCC_GetErrorCode( psMsg ) );

ABCC_GetMsgData8( psMsg, &abcc_iLang, 0 );

ABCC_PORT_DebugPrint( ("RSP MSG_GET_MODULE_LANG: %X\n", abcc_iLang) );

return(ABCC_EXEC_NEXT_COMMAND);
}

 

As you can see, different function are being used in order to extract the data values out of the response messages, ABCC_GetMsgData32 for the serial number and ABCC_GetMsgData8 for the current language.  This takes account of the different data types of these attributes. 

Similar functions are also available, like ABCC_GetMsgData16(), ABCC_GetMsgData64() or ABCC_GetMsgString().

 

CALLING THE COMMAND SEQUENCE

 
The implementor has the possibility to call his command sequence in his application, specifying the state of the ABCC with the appl_eAnbState  variable. In the code snippet below, we call our command sequence during WAIT_PROCESS, and whenever the module enters that state, our handler functions will be executed.
 
...

if (appl_eAnbState = ABP_ANB_STATE_WAIT_PROCESS)
{
ABCC_AddCmdSeq(appl_asUserRunCmdSeq, NULL);
}

...
 
 
 
 

That’s it!

 

Once we reboot our ABCC40, our new command sequence, appl_asUserRunCmdSeq[] is called at runtime during the WAIT_PROCESS state, and we’re able to read the serial number, as well as the current language of our module. The current language of our module is English, and as you can see on the previous image taken from the ABCC40-Software Design guide, that corresponds to a value of 00h.

 

kb2_3.png

 

 

 

ADDITIONAL INFORMATION

 

RELATED ARTICLE

How to read out information from an Anybus CompactCom during initialization?
How to change a parameter in an Anybus CompactCom during initialization?
How to change a parameter in an Anybus CompactCom at runtime?