F_EcGetMailboxGatewayAddr

This function can be used to determine the IP address and the MAC address of an EtherCAT master device via its object ID. The return value of the function signals whether the call was successful and outputs the relevant error code in the event of an error.
If the addresses are required as a STRING, the F_CreateIPv4Addr and F_CreateMacAddr functions are available for conversion in the Tc2_System library.
Return value
METHOD F_EcGetMailboxGatewayAddr : HRESULTName | Type | Description |
|---|---|---|
F_EcGetMailboxGatewayAddr | HRESULT | Signals whether the call was successful and outputs the relevant error code in the event of an error. |
Inputs
VAR_INPUT
oidEcMaster : OTCID; // object ID of EtherCAT master
END_VARName | Type | Description |
|---|---|---|
oidEcMaster | OTCID | The object ID of the EtherCAT master device is specified at this input. If this is not known, it can be read out using FB_EcMasterObjectID. |
Outputs
VAR_OUTPUT
aIpAddress : T_IPv4AddrArr;
aMacAddress : ARRAY[0..5] OF BYTE;
END_VARName | Type | Description |
|---|---|---|
aIpAddress | T_IPv4AddrArr | Byte array of the (IPv4) Internet Protocol network address |
aMacAddress | ARRAY[0..5] OF BYTE | Byte array of the (IPv4) MAC address |
Sample of a call in ST:
PROGRAM MAIN_MailboxGateway
VAR
bRead : BOOL;
fbRead : FB_EcMasterObjectID;
nErrorID : UDINT;
hr : HRESULT;
aIpAddress : T_IPv4AddrArr;
sIpAddress : T_IPv4Addr;
aMacAddress : T_MacAddrArr;
sMacAddress : T_MacAddr;
END_VARIF bRead THEN
bRead := FALSE;
fbRead( sNetId:= '1.2.3.4.5.6', bExecute:= TRUE );
ELSE
fbRead( bExecute:= FALSE );
END_IF
IF fbRead.bError THEN
nErrorID := fbRead.nErrId;
END_IF
IF fbRead.oidEcMaster <> 0 THEN
hr := F_EcGetMailboxGatewayAddr(fbRead.oidEcMaster, aIpAddress=>aIpAddress, aMacAddress=>aMacAddress);
IF SUCCEEDED(hr) THEN
sIpAddress := F_CreateIPv4Addr(aIpAddress);
sMacAddress := F_CreateMacAddr(aMacAddress, '-', FALSE);
END_IF
END_IFRequirements
Development Environment | Target platform | PLC libraries to include |
|---|---|---|
TwinCAT v3.1.4026.16 | PC or CX (x86, x64, Arm®) | Tc2_EtherCAT >= 3.7.1.0 |