How to change a parameter in an Anybus CompactCom at runtime?

23 Nov 2022

This article shows how to change some parameters in the Anybus CompactCom (ABCC) at runtime. That is done by writing attribute values to 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

While you can embed your own custom commands to set some attributes in the Anybus Module Objects during its initialization, you may also choose to set some parameters at runtime.

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

 

Note, however, that only attributes with a Set or Get/Set access rights can be changed, since we will be sending a Set_Attribute command for that purpose.

Attributes with only a Get access right cannot be overridden.

 

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 change the Provider specific information of our ABCC40 module during the WAIT_PROCESS state..

In Chapter 12 of the ABCC40-Software Design guide, we see that the Provider specific information is the 11th Attribute of Instance #1 in the Anybus Object (01h). The default value of that attribute is 0x0000.

 

kb4_1.png

kb4_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[].

 

The function we are going to implement is UpdateProviderInfo(), therefore, it needs to be part of our forward declarations.

static ABCC_CmdSeqCmdStatusType UpdateProviderInfo(ABP_MsgType* psMsg);

 

And since for the Set_Attribute command, there is no response data from the module, we put a NULL in place of the response handler for our command function in the appl_asUserRunCmdSeq[] command sequence.

 
static const ABCC_CmdSeqType appl_asUserRunCmdSeq[] =
{
ABCC_CMD_SEQ(UpdateProviderInfo, NULL),
ABCC_CMD_SEQ_END()
};

 

 

FUNCTION IMPLEMENTATION

 
 
Command function : UpdateProviderInfo()

 

static ABCC_CmdSeqCmdStatusType UpdateProviderInfo(ABP_MsgType* psMsg)
{
ABCC_SetMsgHeader(psMsg,
ABP_OBJ_NUM_ANB,
1,
ABP_ANB_IA_PROVIDER_INFO,
ABP_CMD_SET_ATTR,
2,
ABCC_GetNewSourceId());
ABCC_SetMsgData16(psMsg, 0xCAFE, 0);
return(ABCC_SEND_COMMAND);
}

 

As you can see in the command function, the command used is the Set_Attribute service (ABP_CMD_SET_ATTR), which points to the Anybus object (ABP_OBJ_NUM_ANB), Instance #1, Attribute 11 (ABP_ANB_IA_PROVIDER_INFO). Notice that ABCC_SetMsgHeader() sets the input arguments to the ABCC message header correctly and he data (0xCAFE) is copied to the message data buffer separately using ABCC_SetMsgData16().

 

Note that, just like ABCC_SetMsgData16(), other functions like ABCC_SetMsgData8(), ABCC_SetMsgData32(), ABCC_SetMsgData64() and ABCC_SetMsgString() are also available for usage, depending of the data type of the attributes you want to write.

 

 

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 are able to change the current Provider specific information of the module. You can see the output on the image below.

 

kb4_3.png

 

Please note that, since we don’t get any response data from the module for that function, we have added other handler functions to the appl_asUserRunCmdSeq[] command sequence to read out the current value of the Provider specific information attribute before and after changing it.

 

 

ADDITIONAL INFORMATION

It's worth noting that there are several functions implemented in the appl_asUserInitCmdSeq[] command sequence to set some network specific configuration parameters (node address, IP address, etc) of the module during its initialization. Therefore, you can use them as inspiration to write up your own functions, and add them to a custom command sequence that you can call at runtime to set other parameters of the ABCC.

 

 

RELATED ARTICLES

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