Manually Updating PLC Time Without NTP Using Cyclic Code

Hello,

If there is a difference between the PLC time and the actual time, I manually reset it in Info-Data/Time.

I do not want to use NTP. instead, I want to implement a Cyclic code that directly updates the time by inputting it manually.

Is there a library available that can help implement this functionality?

Thank you.

The set functions from the AsTime library can be used, if NTP is not activated.

Im testing new KARLI, AI service that powers our conversational help. here is the answer and suggestions. Feel free to comment :slight_smile:


Hello,

To implement a cyclic code that directly updates the time by manually inputting it, you can use the AsTime library. This library provides function blocks and functions for handling time-related operations, including setting the system time.

Steps to Implement Cyclic Time Update:

  1. Add the AsTime Library to Your Project:
  • In Automation Studio, go to the Logical View.
  • Right-click on the Libraries node and select Add Library.
  • Search for and add the AsTime library.
  1. Create a Function Block for Setting the Time:
  • Use the DTSetTime function block from the AsTime library to set the system time.
  • This function block allows you to set the current time using the DATE_AND_TIME data type.
  1. Implement Cyclic Time Update:
  • Create a cyclic task class with a suitable cycle time (e.g., 1 second).
  • In the cyclic task, read the manually input time from a global variable or a user interface.
  • Use the DTSetTime function block to update the system time with the manually input time.

Example Code:

(* Define a global variable to hold the manually input time *)
VAR
    manualTime: DATE_AND_TIME;
END_VAR

(* Cyclic task to update the system time *)
PROGRAM CyclicTimeUpdate
VAR
    setTimeFB: DTSetTime;  (* Instance of the DTSetTime function block *)
END_VAR

(* Read the manually input time from a global variable or user interface *)
manualTime := GetManualTimeFromUI();

(* Set the system time using the DTSetTime function block *)
setTimeFB(IN := manualTime);

Explanation:

  • manualTime: This variable holds the time that is manually input by the user.
  • setTimeFB: This is an instance of the DTSetTime function block.
  • GetManualTimeFromUI: This is a placeholder function that you need to implement to read the time from a user interface or another source.

Further Information:

By following these steps, you can create a cyclic task that updates the system time based on manually input values without using NTP.

1 Like