FB_GetHostAddrByName
This function block can be used to read the (IPv4) Internet protocol network address for the specified host name. The address is returned as string and byte array.
Inputs
VAR_INPUT
sNetID : T_AmsNetId;
sHostName : T_MaxString := '';
bExecute : BOOL;
tTimeout : TIME := DEFAULT_ADS_TIMEOUT;
END_VAR
Name | Type | Description |
---|---|---|
sNetID | T_AmsNetID | The network address of the TwinCAT computer on which the command is to be executed can be specified here. For the local computer an empty string may be specified. |
sHostName | T_MaxString | Host name as a string. E.g.: 'DataServer1'. |
bExecute | BOOL | The function block is enabled by a positive edge at this input. |
tTimeout | TIME | States the length of the timeout that may not be exceeded by execution of the ADS command. |
Outputs
VAR_OUTPUT
bBusy : BOOL;
bError : BOOL;
nErrID : UDINT;
sAddr : T_IPv4Addr := '';
arrAddr : T_IPv4AddrArr :=[ 0, 0, 0, 0];
END_VAR
Name | Type | Description |
---|---|---|
bBusy | BOOL | When the function block is enabled, this output is set and remains set until a feedback is received. |
bError | BOOL | If an error occurs during the transmission of the command, this output is set after the bBusy output is reset. |
nErrID | UDINT | Returns the ADS error number when the bError output is set. |
sAddr | T_Ipv4AddrArr | Internet protocol network address (IPv4) as string. E.g.: '172.16.7.199' |
arrAddr | T_Ipv4AddrArr | Internet protocol network address as byte array |
Example:
PROGRAM MAIN
VAR
fbGet : FB_GetHostAddrByName;
bGet : BOOL := TRUE;
bError : BOOL;
nErrID : UDINT;
sIPv4 : T_IPv4Addr;(* Result: '87.106.8.100' *)
arrIPv4 : T_IPv4AddrArr;
state : BYTE;
END_VAR
CASE state OF
0:
IF bGet THEN
bGet := FALSE;
sIPv4 := '';
fbGet( bExecute:= FALSE );
fbGet( bExecute:= TRUE, sHostName := 'www.beckhoff.com' );
state := 1;
END_IF
1:
fbGet( bExecute:= FALSE, bError=>bError, nErrID=>nErrID, sAddr=>sIPv4, arrAddr=>arrIPv4 );
IF NOT fbGet.bBusy THEN
state := 0;
END_IF
END_CASE
Requirements
Development environment | Target platform | PLC libraries to be integrated (category group) |
---|---|---|
TwinCAT v3.1.0 | PC or CX (WES7/Win7/Win10: TC RT x86/x64, WEC6/7: TC RT x86, WEC7: TC CE7 ARMV7) | Tc2_Utilities (System) |