Set NTP server connection
This FP instruction sets a destination NTP server to which a time synchronization request can be sent.
Input
IP address or host name (required parameter).
IP address
For an IP address, specify the keyword IPv4
or IPv6
at the beginning.
Syntax for IPv4: e.g. 'IPv4=111.122.133.144'
Syntax for IPv6: e.g. 'IPv6=1111:122:2:1555:0:0:1888'
Host name
Keyword: HOST
Syntax: e.g.'HOST=ntp.pidsx.com'
Output
Set to TRUE when the operation ends abnormally without execution, e.g. when sys_bIsEthernetInitializing is TRUE
When an error occurs, check the system variable sys_iEthernetConnectionErrorCode for the error code number.
This instruction is not available in interrupt programs.
The NTP server address is set in the CPU unit (built-in ET-LAN) according to sNTPServer.
The data that is already set in the system registers ( ) is invalid and the NTP time synchronisation request is executed at the time that is specified by this instruction.
The PLC returns to the settings from the system registers in the following cases:
The power is turned off.
You switch from PROG mode to RUN mode.
You switch to a different project.
The setting data will not be lost even if the instruction FP_IPV4_SET_ADDRESS is executed.
Before you execute the instruction, make sure that sys_bIsEthernetInitializing is FALSE. sys_bIsEthernetInitializing turns to TRUE when the instruction is executed. When you execute the instruction while sys_bIsEthernetInitializing is TRUE, an error occurs.
When this instruction has been executed successfully, the system variables sys_bIsCarry and sys_iEthernetConnectionErrorCode are reset.
When the instruction has not been executed successfully, check the execution result code in output nResult of the FP_NTP_SYNCHRONIZE instruction.
When an error occurs, check the system variable sys_iEthernetConnectionErrorCode for the error code number.
if a value specified for a parameter is outside the permissible range.
if the instruction is executed in an interrupt program
if the system is synchronizing the time with the NTP server.
if a value specified for a parameter is outside the permissible range.
if the instruction is executed in an interrupt program
if the system is synchronizing the time with the NTP server.
if the instruction is executed during the initialization of Ethernet, sys_iEthernetConnectionErrorCode is set to "11: Ethernet is being initialized".
All input and output variables used for programming this function have been declared in the POU header.The same POU header is used for all programming languages.
VAR
sNTPServer: STRING[32]:='IPv4=192.168.2.1';
bIsError: BOOL:=FALSE;
bEnable: BOOL:=FALSE;
END_VAR
When the system variable sys_bIsEthernetInitializing is FALSE and the variable bEnable is set to TRUE, the function is carried out.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 5 ;
NETWORK_BODY
B(B_CONTACT,,sys_bIsEthernetInitializing,6,1,8,3,N);
B(B_CONTACT,,bEnable,14,1,16,3,);
B(B_F,FP_NTP_SET_SERVER!,,22,0,33,4,,?DEN?DsNTPServer?AENO?AbError);
B(B_VARIN,,sNTPServer,20,2,22,4,);
B(B_VAROUT,,bIsError,33,2,35,4,);
L(1,0,1,5);
L(1,2,6,2);
L(8,2,14,2);
L(16,2,22,2);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 5 ;
NETWORK_BODY
L(1,0,1,5);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 5 ;
NETWORK_BODY
L(1,0,1,5);
END_NETWORK_BODY
END_NET_WORK
END_BODY
if NOT (sys_bIsEthernetInitializing) AND (bEnable) then
FP_NTP_SET_SERVER(sNTPServer := sNTPServer,
bError => bIsError);
end_if;