This article introduces objects, instances and attributes these are about to MAC Address and how to set/get the value of MAC address through Host application
APPLICABLE PRODUCTS
AB6605、AB6675、AB6604、AB6674、AB6603、AB6673
PRE-REQUISITES (Mandatory)
This article simply introduces how to set/get MAC address of CompactCom 40 devices, More information about MAC address can refer to user manual :
《Anybus CompactCom 40 - Software Design Guide》
《Anybus CompactCom 40 - Host Application Implementation Guide》
《Anybus CompactCom 40 - PROFINET IRT Network Guide》
IN THIS ARTICLE
This section lists the specific major sections in this article. This could be for example if there are more than one way to solve the problem this lists the different ways and a link to the section describing that particular way.
- Introduce Objects , instances , attributes about MAC address
- Set value of MAC address
- Get value of MAC address
To Introduce Objects, instances and attributes are about MAC address
- Anybus CompactCom40 module have preprogrammed with a valid MAC address. The preprogrammed MAC address can be read through accessing instance #1~3 of Network Ethernet Object (0Ch). MAC address of Port#1~2 only are valid in PROFINET.More information can refer to section 5 of unit 13 of manual 《Anybus CompactCom 40 - PROFINET IRT Network Guide》.
- The preprogrammed MAC address can be overwritten with new MAC address that's in Ethernet Host Object (F9h) ,if new MAC address are assigned to a PROFINET device ,these address have to be consecutive.
Set value of MAC address
- Enable Ethernet Host Object (F9h):Set value of ETN_OBJ_ENABLE with TRUE in \abcc_adapt\abcc_obj_cfg.h.
- Set value of ETN_IA_MAC_ADDRESS_ENABLE with TRUE and set value of ETN_IA_MAC_ADDRESS_VALUE with new address.
-
If the module is a PROFINET device, then define ETN_IA_PORT1_MAC_ADDRESS_ENABLE, ETN_IA_PORT1_MAC_ADDRESS_ENABLE, Set values of ETN_IA_PORT1_MAC_ADDRESS_VALUE、ETN_IA_PORT1_MAC_ADDRESS_VALUE with new addresses.
- The module will use new address after module initiated.
Get value of MAC address
- Define function ABCC_CmdSeqCmdStatusType GetDeviceMAC(ABP_MsgType* psMsg ) in \example_app\appl_abcc_handler.c ,The datatype of return value must be ABCC_CmdSeqCmdStatusType.
-
typedef enum ABCC_CmdSeqCmdStatus
{
ABCC_SEND_COMMAND,//Execute this command
ABCC_SKIP_COMMAND,//Skip this command
ABCC_CMD_ABORT_SEQ//Abort the command sequencer
}
ABCC_CmdSeqCmdStatusType; -
/*------------------------------------------------------------------------------
** Get Device MAC.
**------------------------------------------------------------------------------
*/
static ABCC_CmdSeqCmdStatusType GetDeviceMAC( ABP_MsgType* psMsg)
{
if((appl_fNwSupportsEthernetMAC)&&(appl_fNwGetEthernetMAC))
{
/*
**0x0c :Network Ethernet Object (0Ch)
**1:Instance code 1
**1:Attribute code 1
*/
ABCC_GetAttribute( psMsg, 0x0C, 1, 1, ABCC_GetNewSourceId() );
return ( ABCC_SEND_COMMAND );
}
else
return ( ABCC_SKIP_COMMAND );
}
-
-
Define function static ABCC_CmdSeqRespStatusType HandleGetDeviceMACResponse( ABP_MsgType* psMsg ) to handle MAC address that's read from module.The datatype of return value must be ABCC_CmdSeqRespStatusType.
-
typedef enum ABCC_CmdSeqRespStatus
{
ABCC_EXEC_NEXT_COMMAND,//execute next command
ABCC_EXEC_CURR_COMMAND,//excute this command again
ABCC_RESP_ABORT_SEQ//abort this command sequence
}
ABCC_CmdSeqRespStatusType; - ABCC_CmdSeqRespStatusType HandleGetDeviceMACResponse( ABP_MsgType* psMsg ),for example, the function print MAC address to log.
-
/*------------------------------------------------------------------------------
** Handler Device MAC.
**------------------------------------------------------------------------------
*/
static ABCC_CmdSeqRespStatusType HandleGetDeviceMACResponse( ABP_MsgType* psMsg )
{
UINT8 bException;
if( ABCC_VerifyMessage( psMsg ) != ABCC_EC_NO_ERROR )
{
APPL_UnexpectedError();
return( ABCC_EXEC_NEXT_COMMAND );
}
/*
**user handler MAC
*/
/********eg:printf to log*******/
for(int i=0;i<6;i++)
{
if(i==0)
{
ABCC_PORT_DebugPrint( ( "Device MAC address is[0x%02X ", psMsg->abData[i] ) );
}
else if(i>0&&i<5)
{
ABCC_PORT_DebugPrint( ( "0x%02X ", psMsg->abData[i] ) );
}
else if(i==5)
{
ABCC_PORT_DebugPrint( ( "0x%02X]:\n\n", psMsg->abData[i] ) );
}
}
return ( ABCC_EXEC_NEXT_COMMAND );//ABCC_EXEC_NEXT_COMMAND
}
-
- If the module is PROFINET device ,then define functions to get port#1~2 MAC address.
-
/*------------------------------------------------------------------------------
** Get Port1 MAC.
**------------------------------------------------------------------------------
*/
static ABCC_CmdSeqCmdStatusType GetPort1MAC( ABP_MsgType* psMsg)
{
UINT16 iNetworkType;
BOOL f_isPROFINET=0;
iNetworkType=ABCC_NetworkType();
if((iNetworkType==ABP_NW_TYPE_PIR)||
(iNetworkType==ABP_NW_TYPE_PRT))
{
f_isPROFINET=1;
}
if((appl_fNwSupportsEthernetMAC)&&(appl_fNwGetEthernetMAC)&&(f_isPROFINET))
{
ABCC_GetAttribute( psMsg, 0x0C, 1, 2, ABCC_GetNewSourceId() ); //port1 MAC
return ( ABCC_SEND_COMMAND );
}
else
return ( ABCC_SKIP_COMMAND );
}
/*------------------------------------------------------------------------------
** Get Port2 MAC.
**------------------------------------------------------------------------------
*/
static ABCC_CmdSeqCmdStatusType GetPort2MAC( ABP_MsgType* psMsg) //port2 MAC
{
UINT16 iNetworkType;
BOOL f_isPROFINET=0;
iNetworkType=ABCC_NetworkType();
if((iNetworkType==ABP_NW_TYPE_PIR)||
(iNetworkType==ABP_NW_TYPE_PRT))
{
f_isPROFINET=1;
}
if((appl_fNwSupportsEthernetMAC)&&(appl_fNwGetEthernetMAC)&&(f_isPROFINET))
{
ABCC_GetAttribute( psMsg, 0x0C, 1, 3, ABCC_GetNewSourceId());
return ( ABCC_SEND_COMMAND );
}
else
return ( ABCC_SKIP_COMMAND );
} - Response handle function
-
/*------------------------------------------------------------------------------
** Handler Port1 MAC.
**------------------------------------------------------------------------------
*/
static ABCC_CmdSeqRespStatusType HandleGetport1MACResponse( ABP_MsgType* psMsg )
{
UINT8 bException;
if( ABCC_VerifyMessage( psMsg ) != ABCC_EC_NO_ERROR )
{
APPL_UnexpectedError();
return( ABCC_EXEC_NEXT_COMMAND );
}
/******
user handler MAC
******/
/********eg:printf to log*******/
for(int i=0;i<6;i++)
{
if(i==0)
{
ABCC_PORT_DebugPrint( ( "PORT1 MAC address is[0x%02X ", psMsg->abData[i] ) );
}
else if(i>0&&i<5)
{
ABCC_PORT_DebugPrint( ( "0x%02X ", psMsg->abData[i] ) );
}
else if(i==5)
{
ABCC_PORT_DebugPrint( ( "0x%02X]:\n\n", psMsg->abData[i] ) );
}
}
return ( ABCC_EXEC_NEXT_COMMAND );//ABCC_EXEC_NEXT_COMMAND
/*------------------------------------------------------------------------------
** Handler Port2 MAC.
**------------------------------------------------------------------------------
*/
static ABCC_CmdSeqRespStatusType HandleGetport2MACResponse( ABP_MsgType* psMsg )
{
UINT8 bException;
if( ABCC_VerifyMessage( psMsg ) != ABCC_EC_NO_ERROR )
{
APPL_UnexpectedError();
return( ABCC_EXEC_NEXT_COMMAND );
}
/******
user handler MAC
******/
/********eg:printf to log*******/
for(int i=0;i<6;i++)
{
if(i==0)
{
ABCC_PORT_DebugPrint( ( "PORT2 MAC address is[0x%02X ", psMsg->abData[i] ) );
}
else if(i>0&&i<5)
{
ABCC_PORT_DebugPrint( ( "0x%02X ", psMsg->abData[i] ) );
}
else if(i==5)
{
ABCC_PORT_DebugPrint( ( "0x%02X]:\n\n", psMsg->abData[i] ) );
}
}
return ( ABCC_EXEC_NEXT_COMMAND );//ABCC_EXEC_NEXT_COMMAND ABCC_RESP_ABORT_SEQ
}
-
- Define function void Sdef_GetDeviceMAC(void) to determine condition that is command executed.
-
void Sdef_GetDeviceMAC(void)
{
UINT16 iNetworkType;
iNetworkType=ABCC_NetworkType();
if(iNetworkType==ABP_NW_TYPE_CCL||
iNetworkType==ABP_NW_TYPE_COP||
iNetworkType==ABP_NW_TYPE_PDPV0||
iNetworkType==ABP_NW_TYPE_PDPV1||
iNetworkType==ABP_NW_TYPE_COP||
iNetworkType==ABP_NW_TYPE_DEV||
iNetworkType==ABP_NW_TYPE_RTU||
iNetworkType==ABP_NW_TYPE_CNT)
{
appl_fNwSupportsEthernetMAC=FALSE;
}
else
{
appl_fNwSupportsEthernetMAC=TRUE;
}
-
- Define command sequencer static const ABCC_CmdSeqType Sdef_GetDeviceMAC[] to contain all commands.
-
static const ABCC_CmdSeqType Sdef_GetDeviceMAC[] =
{
ABCC_CMD_SEQ( GetDeviceMAC, HandleGetDeviceMACResponse ),
ABCC_CMD_SEQ( GetPort1MAC, HandleGetport1MACResponse ),
ABCC_CMD_SEQ( GetPort2MAC, HandleGetport2MACResponse ),
ABCC_CMD_SEQ_END()
};
-
- Define function void APPL_GetDeviceMAC(void) to execute the command sequence.
-
void APPL_GetDeviceMAC(void)
{
if( appl_fUserInitDone == TRUE )
{
appl_fNwGetEthernetMAC=TRUE;
Sdef_GetDeviceMAC();
ABCC_AddCmdSeq(Sdef_GetDeviceMAC,NULL);
}
}
-
- call void APPL_GetDeviceMAC(void) function in main function ; void APPL_GetDeviceMAC(void) function called position as shown in following code.In this example, the execution command is determined by simulating external conditions triggering (such as HMI, device configuration of upper computer software, etc.).
-
while(eAbccHandlerStatus == APPL_MODULE_NO_ERROR )
{
eAbccHandlerStatus = APPL_HandleAbcc();
//set attribute after abbc init through UART1 Command protocal further information in usart.c
if(appl_fUserInitDone==TRUE&&Sdef_NewCommandFlag==1)
{
switch(Sdef_setcommand)
{
case Sdef_GetDeviceMAC_Cmd://Get module MAC
APPL_GetDeviceMAC();
Sdef_NewCommandFlag=0;
break;
default:
def_NewCommandFlag=0;
break;
}
}
-
- Message log
-
- add command to appl_asUserInitCmdSeq[]
-
static const ABCC_CmdSeqType appl_asUserInitCmdSeq[] =
{
ABCC_CMD_SEQ( UpdateIpAddress, NULL ),
ABCC_CMD_SEQ( UpdateNetmask, NULL ),
ABCC_CMD_SEQ( UpdateGateway, NULL ),
ABCC_CMD_SEQ( UpdateDhcp, NULL ),
ABCC_CMD_SEQ( UpdateNodeAddress, NULL ),
ABCC_CMD_SEQ( UpdateBaudRate, NULL ),
ABCC_CMD_SEQ( GetDeviceMAC, HandleGetDeviceMACResponse ),
ABCC_CMD_SEQ( GetPort1MAC, HandleGetport1MACResponse ),
ABCC_CMD_SEQ( GetPort2MAC, HandleGetport2MACResponse ),
ABCC_CMD_SEQ_END()
};
-
- Define function void APPL_GetDeviceMAC_InInit(void) to execute the command sequence
-
void APPL_GetDeviceMAC_InInit(void)
{
if( appl_fUserInitDone == FALSE )
{
appl_fNwGetEthernetMAC=TRUE;
Sdef_GetDeviceMAC();
}
}
-
- call void APPL_GetDeviceMAC_InInit(void) function in main() function.
-
while(eAbccHandlerStatus == APPL_MODULE_NO_ERROR )
{
APPL_GetDeviceMAC_InInit();
eAbccHandlerStatus = APPL_HandleAbcc();
}
-
- add command to appl_asUserInitCmdSeq[]
ADDITIONAL INFO
The example code are for reference only,not as the final functional implementation standard.More information can refer to user manual.
User manual download link:Anybus Files and Documentation