|Date and Time Function Blocks [message #1830025]
||Thu, 16 July 2020 02:40
| NOJA Power
Registered: May 2020
I downloaded the latest forte source and looked around in the function block modules but I didn't see anything in there for accessing system date and time information.
I'm wondering if you think it might be worth while adding some function blocks to the library to access system date and time information?
Use case examples:
- Perform an operation every Monday between 9:00pm and 9:15pm local time
- Latch unique monotonic time stamp with an operation
- Change a setting based on season (Summer, Autumn, Winter, Spring)
Here are 3 function block examples that might address use cases.
The Date Time function block can represent current system date and time in 4DIAC data types.
The Date Time function block is subject to clock change by NTP, Daylight Savings Time, user or other updates. Where a monotonic time is required, refer to Monotonic Time function block.
The Local Time function block can represent current system date and time in broken down time components.
The Local Time function block is subject to clock change by NTP, Daylight Savings Time, user or other updates. Where a monotonic time is required, refer to Monotonic Time function block.
Monotonic time can be described as:
- Clock that cannot be set and represents monotonic time since some unspecified starting point.
- A monotonic clock is a time source that will never jump forward or backward (due to NTP, Daylight Savings Time, user or other updates).
|Re: Date and Time Function Blocks [message #1830060 is a reply to message #1830025]
||Thu, 16 July 2020 14:10
| Martin Melik-Merkumians
Registered: March 2016
this need is already addressed via the NOW and NOW_MONOTONIC functions available, which give you either the date and current time (as far as I remember in your current locale) or a monotonic time from a specified point of time (depending on OS and hardware) which has no direct correlation to the current time.
The idea of all these different time based data types are the use cases you mentioned. You can get the current date and time via the NOW function, returning a DATE_AND_TIME which can be explicitly cast into other data types which represent dates, i.e. DATE and TIME_OF_DAY
The TIME data type is not a specific date, but a time span, so the NOW_MONOTONIC returns a TIME with the time span since the starting point for the monotonic time start.
This also leads to a problem with your first FB_NOJA_DateTime, which returns a DATE, DATE_AND_TIME, TIME_OF_DAY, and TIME. The TIME type is incompatible with the other ones as it is a time span. Also, the other outputs can be generated via DT_TO_XXX cast FBs, so no need for providing all of them. As far as I see, it seems that no cast FBs are available right now, but can be easily created by wrapping a cast operator into a FB.
So if you are in need for such an FB, the best solution from my point of view would be to wrap the NOW function into an FB with a single DATE_AND_TIME output.
For monotonic time you can wrap the NOW_MONOTONIC function into an FB with a single TIME output (which replaces your third FB).
For your second FB, I do not see a use case, as you can compare two DATE_AND_TIME, DATE, and TIME_OF_DAY and you can also calculate the differences between dates, and most of the other information is included in the output of NOW or can easily calculated from it.
If you need time spans (TIME) as numbers (ANY_INT or ANY_REAL), there is a set of conversion FBs available in modules\IEC61131-3\Conversion\TIME, which clearly specify which time-base is used for the conversion.
Powered by FUDForum
. Page generated in 0.02053 seconds