Request time synchronization from NTP server
This FP instruction sends a request to the NTP server to synchronize the time.
Input
Number of retries of requesting the time synchronization
Values: 0–20
Time synchronization interval
Values: 16–600
Output
Execution result code
16#FFFF |
In progress |
|
16#0 |
Normal completion |
|
16#10 |
Double startup error |
The instruction requesting the time synchronization is being executed. NOTE The double startup error does not occur when the instruction is executed with the number of retries being set to 0 to cancel the time synchronization request instruction. |
16#11 |
SNTP server address setting error |
ET-LAN setting, SNTP server address setting = "0.0.0.0" |
16#12 |
Disconnection error |
Ethernet is disconnected. |
16#13 |
Ethernet initialization active error |
No IP address has been assigned to the Ethernet unit sending the request. (sys_bIsEthernetIPAddressAssigned is FALSE) |
16#14 |
Number of retries setting error |
The specified number of retries is out of range. |
16#15 |
Retry interval setting error |
The specified retry interval is out of range. |
16#20 |
Response timeout error |
The response time of processing the time synchronization request exceeds the predefined time. NOTE This error also occurs when an NTP IP address is not resolved. |
16#30 |
Ethernet task response timeout |
This error occurs when no response is returned from the Ethernet task. |
This instruction is not available in interrupt programs.
If a time synchronization timeout is foreseeable, set nNumberOfRetries to a higher value.
For cancelling further attempts to synchronize the time, set nNumberOfRetries to 0. In this case, the execution result code is not stored in nResult.
The timeout period for one time synchronization attempt is fixed at 3 seconds.
When multiple time synchronization attempts are specified, a new request starts after the timeout period elapses (3 seconds) plus the processing interval (specified by nRetryInterval).
The total timeout period (seconds) for time synchronization is obtained with the following formula: nRetryInterval x 3 + (nRetryInterval x (nNumberOfRetries-1)). (Here, nNumberOfRetries is larger than 0.)
if the area specified using the index modifier exceeds the limit.
if the instruction is executed in an interrupt program
if the area specified using the index modifier exceeds the limit.
if the instruction is executed in an interrupt program
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
bRequestSynchronization: BOOL:=FALSE;
iNumberOfRetries: INT:=3;
iRetryInterval: INT:=20;
wResult: WORD:=0;
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,15,1,17,3,);
B(B_F,FP_NTP_SYNCHRONIZE!,,22,0,35,5,,?DEN?DnNumberOfRetries?DnRetryInterval?AENO?AnResult);
B(B_VARIN,,iNumberOfRetries,20,2,22,4,);
B(B_VAROUT,,wResult,35,2,37,4,);
B(B_VARIN,,iRetryInterval,20,3,22,5,);
L(1,0,1,5);
L(1,2,6,2);
L(8,2,15,2);
L(17,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_SYNCHRONIZE(nNumberOfRetries := iNumberOfRetries,
nRetryInterval := iRetryInterval,
nResult => wResult);
end_if;