thiagoralves
Hi all,

I just updated OpenPLC v3 code to support special functions. These are values related to internal PLC status and data. Currently only two special functions are implemented: current time (RTC) and number of scan cycles executed. These functions are located in memory at address %ML1024 onwards. To be more specific:

%ML1024   ->   Current time in seconds since Epoch

%ML1025   ->   Number of scan cycles executed since the runtime started

%ML1026   ->   Slave Devices communication error counter

Attached is a simple program that works with the current time special function. The program turns the lamp on if the current time is greater than 15:06pm on Nov, 1st, 2018.

Just keep in mind that this program will fail if you don't update your OpenPLC v3 installation with the newer code. On Windows, to update just run "Rebase OpenPLC" from start menu. On other systems you will have to manually update following the installation instructions again.
Reply 5 0
Bordini
Hello, I'm new to OpenPLC. I liked the post on the testRTC lib; I'm implementing a program and would like to use it, but I can not open the lib.
Reply 0 0
thiagoralves
It was made for a previous version of the editor. You can still open it if you target OpenPLC Editor shortcut to PLCOpenEditor.py instead of Beremiz.py
Reply 1 0
Krzysztof
Good morning,
I am new here and I'm under the impression of a great job!
I need to read the current system time and system tick. I have some problems. I run the program on Raspberry PI and read the register% ML1024 and% ML1025, but both values are 0. What am I doing wrong?
Reply 0 0
thiagoralves
How are you reading these registers? Your program is not using the Current_Time or Sys_Tick variables you created.
Reply 0 0
Krzysztof
Hello,
I implemented the fixes and launched the program in the simulator on the PC. Unfortunately, the problem still occurs.
Reply 0 0
thiagoralves
Two things: your DT variable format is wrong. It should be

DT#2018-11-1 15:06:00

with no dash (-) between the date and the time. That’s why you see a red line after it.

The second thing is that special functions are not supported on the simulator. They only work on the physical device, as this is a particular implementation of the runtime.
Reply 0 0
Krzysztof
When I removed dash, compiler returned error.
Reply 0 0
Krzysztof
So, I found discription of RTC
Quote:

(****************************************************************

RTC - Real-time clock

Q is a copy of IN.

When IN = FALSE, CDT is the current date and time as set by the
PLC driver.

When IN changes from FALSE to TRUE, PDT is stored. As long as IN is
TRUE, CDT is equal to PDT + the amount of time since PDT was loaded.

****************************************************************)

FUNCTION_BLOCK RTC
VAR_INPUT
IN : BOOL; (* 0 - current time, 1 - load time from


When set the RTC block without any parameters, the function block returns the current system data and time (in the documentation).
On simulation it work properly but on hardware not. Probably don't load system time on Runtime environment. Same situation like use %ML1024 register.
Reply 0 0
thiagoralves
This is a limitation of the runtime that I plan to fix later. That’s why I added the %ML1024 register so that you can still get current system time on the runtime. The %ML1024 register is a hack and is not available on the editor (that’s why on the simulation it is always showing zero), only in the actual hardware running the runtime. This register on the runtime holds the current EPOCH time in milliseconds. Then you just convert it to a Date Time variable and you have the same output as the RTC block you have in the simulation. Just keep in mind that the %ML1024 register already takes in consideration time zone and daylight saving time, so you don’t need to add or subtract hours depending on your time zone.
Reply 0 0
NWT.Stuff
I am very interested in exploring and using this functionality.  

I just can't work out how to create a readable project in the Editor from an .st & .xml file ?
Reply 0 0
thiagoralves
The .st file is the compiled version of your project. It is not possible to generate back the xml project file from an .st file.
Reply 0 0
NWT.Stuff
Ok thanks. Is it possible to import/read an xml project file into the OpenPLC editor ?
Reply 0 0
Josef Bernhardt
Hi Tiago,
is it possible to read the Registers
%ML1024   ->   Current time in seconds since Epoch

%ML1025   ->   Number of scan cycles executed since the runtime started

%ML1026   ->   Slave Devices communication error counter
from Raspberry over Modbus TCP
Best Regards
Josef
Reply 0 0
NWT.Stuff
Hi Josef,

I don't think so as you are out of the allowable %ML LINT Range for Modbus (%ML0 to %ML1023). https://www.openplcproject.com/reference/modbus/

However if you MOV or COP you're values into the allowable range then I think that would work 🙂

Kevin
Reply 0 0
Josef Bernhardt
Thank You for Info
when I read Data from PI from this Adress there are always 0.
ModbusML1024.jpg 
 
Reply 0 0
Reply