FB_GetHostAddrByName
The function block reads hosts (IPv4) Internet Protocol network address corresponding to a host name from a host database. The address is returned as string and byte array.
VAR_INPUT
VAR_INPUT
sNetID : T_AmsNetId;
sHostName : T_MaxString := '';
bExecute : BOOL;
tTimeout : TIME := DEFAULT_ADS_TIMEOUT;
END_VAR
sNetID: Here a string containing the TwinCAT network address of the TwinCAT computer can be given, where the command have to be executed. The string can also be empty (default) for the local computer.
sHostName: String containing host name. E.g. 'DataServer1'.
bExecute: The function block is activated by a positive edge at this input.
tTimeout: States the length of the timeout that may not be exceeded by execution of the command.
VAR_OUTPUT
VAR_OUTPUT
bBusy : BOOL;
bError : BOOL;
nErrID : UDINT;
sAddr : T_IPv4Addr := '';
arrAddr : T_IPv4AddrArr := 0, 0, 0, 0;
END_VAR
bBusy: When the function block is activated this output is set. It remains set until and acknowledgement is received.
bError: If an error should occur during the execution of the command, then this output is set, after the bBusy output has been reset.
nErrID: When the bError output is set, this variable supplies the ADS error code.
sAddr: String containing an (Ipv4) Internet Protocol dotted address. E.g. '172.16.7.199'
arrAddr: Byte array containing an (Ipv4) Internet Protocol dotted address.
Example in strutured text:
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 system type | PLC libraries to include |
---|---|---|
TwinCAT v2.10.0 Build > 1340 | PC or CX (x86, ARM) | TcUtilities.Lib |