EtherNet/IP - Sample Applications
Several sample applications are provided for port’s EtherNet/IP protocol stack. They show how to set up and use the stack. The following examples can be found in the folder goal/appl/goal_eip/
00_rpc_cc – communication core application (for multicore targets only)
01_simple_io – simple IO application
02_dlr_dhcp – simple IO application with DHCP and DLR support.
03_dhcp – simple IO application with DHCP support
04_parameter – sample application with parameter
05_acd_dhcp – simple IO application with Address Conflict Detection and DHCP
The sample application can be found in the file goal_app_eip.c, located in the example folders except 00_rpc_cc. It sets the serial number to 123456789 and creates several assemblies and defines connections.
Assembly Instance 150 is an Output Assembly. It contains data received from a PLC. The first byte will be mirrored to the target’s LEDs. The second byte will be mirrored to second byte of Assembly Instance 100.
Assembly Instance 100 is an Input Assembly. It contains data that is sent to the PLC. Before it is sent the status of the target’s buttons are mapped to the first byte and the second byte of Assembly Instance 150 is mirrored.
The application folders also contain an EDS file that can be used by an EtherNet/IP Scanner.
By altering goal_app_eip.c changes to the assembly instances created, their size or what is done with their data are possible.
Default Identity
The identity Information of the CC is configured after startup and can be changed via API. It uses the following default values:
Table: Default identity values
Vendor ID | 1114 (port GmbH) |
Device Type | 43 (Generic Device (keyable)) |
Product Code | 1 |
Revision | 1.1 |
Product Name | EtherNet/IP Adapter |
At first start up or after a factory reset the device
either issues DHCP requests to obtain an IP address. The device is only operable after a valid IP configuration was received from a DHCP server, if DHCP support is enabled;
or returns to the default IP address defined by
GOAL_CONFIG_NET_ADDR_IP_DEFAULT
(default value: 192.168.0.100), if DHCP support is not enabled.
Configuring the sample application
Changing MAC Address
The default value of the board MAC address is 02:00:00:00:00:01.
Single-Core
MAC address can be changed by the application using the function goal_miEthCfgMacAddr()
. This function keeps the user MAC address and applies it automatically, when Ethernet handler is open by GOAL in stage GOAL_STAGE_ETH_PRE
.
Setting the MAC is done in appl_init()
in general, as shown in the following example.
Code: example for configuring the user MAC
#define APPL_ETH_MAC_ADDR { 0x45, 0x33, 0xab, 0x00, 0x00, 0xFF }
GOAL_STATUS_T appl_init
void
)
{
GOAL_ETH_MAC_ADDR_T macAddress = GOAL_ETH_MAC_ADDR; /* mac address */
/* Configure the user MAC */
res = goal_miEthCfgMacAddr(0, GOAL_MI_ID, &macAddress);
if (GOAL_RES_ERR(res)) {
goal_logErr("failed to set MAC");
}
return res;
}
Board hardware, like DIP switches or NVS, will not be available when calling appl_init()
. If the user MAC requires one of these features, calling goal_miEthCfgMacAddr()
in another startup stage of GOAL is also possible. But the user has to register the stage callback by goal_mainStageReg()
first.
Please note GOAL - Programmer´s Manual for further information.
Multi-Core
MAC address can be changed either by Communication Core as described in section Single-Core or by Application Core as followed.
Modifications in Communication Core project
Set GOAL_CONFIG_MEDIA_MI_ETH=1
in project configuration to delay opening the ETH interface until protocol instance is going to be created from AC.
Modifications in Application Core project
Call goal_miEthCfgMacAddr()
in appl_setup
prior creating the network protocol instance.
Code: example for configuring the interface MAC from AC
#define APPL_ETH_MAC_ADDR { 0x45, 0x33, 0xab, 0x00, 0x00, 0xFF }
GOAL_STATUS_T appl_setup(
void
)
{
GOAL_STATUS_T res; /* result */
GOAL_ETH_MAC_ADDR_T mac = APPL_ETH_MAC_ADDR; /* mac address */
/* set Interface MAC at CC */
goal_miEthCfgMacAddr(0, GOAL_MA_ID_ETH, &mac);
Changing IP Address
Some of the applications providing a DHCP client. In order to change the IP address of these applications, please reconfigure the DHCP server.
All other applications start with a static IP address, which is extracted from stored GOAL CM-variables by bootup. If no valid IP address has been set in GOAL’s CM-variables before, GOAL_CONFIG_NET_ADDR_IP_DEFAULT
is used instead. Please see Network handling for further information.
Changing the IP address via CIP is always possible. The TCP/IP Interface Object Attribute 3 has to be set to 0 (use static IP Address). Afterwards the IP address of the device is configurable by TCP/IP Interface Object Attribute 5.