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
NWT.Stuff
OK Josef,

Not familiar with this software. Is this running on a PC ?

4096 corresponds to %ML0. I guess 4 values with give 4 x 16 bits which equates to the whole long integer (64 bit).  If you monitor %ML0 in Open PLC Monitor do you have a value > 0 ?   
Reply 0 0
Josef Bernhardt
Many Thanks,
I run this Modbus software under Windows.
https://sourceforge.net/projects/easymodbustcp/files/latest/download
I have read in from different addresses and get 0 all the time.
What more could I try?
Thanks in advance !
Reply 0 0
thiagoralves
I think you’re missing the point that NWT said about copying ML1024 to a location where you can read. You need to do this on your ladder logic. You can’t read ML1024 directly over modbus, it is out of bounds. Just create two variables on your ladder logic, one at ML1024 and another at ML0, then use the MOVE block to copy ML1024 to ML0. After that you will be able to read EPOC timestamp on ML0 via modbus
Reply 0 0
Josef Bernhardt
Hello Thiago,
thanks for the help, I'll give it a try!
Greetings to Josef
Reply 0 0
Josef Bernhardt
Hello Thiago,
I am currently trying this program, unfortunately I cannot read anything again!
Greetings to Josef
ScreenML1024.jpg 
Reply 0 0
Josef Bernhardt
Now it works
ScreenML1024.jpg 
Reply 0 0
NWT.Stuff
Hi Josef,

Whilst OpenSource Free Software is a great resource it is not uncommon for the software to be incomplete. It is a lot of work to implement all Modbus Functions (FCx) to the full range of registers so from experience I would test each Function and the full range of addressees.

What you are trying to do is read 64 bit Long Integers using the FC3 Function with EasyModbusTCP/UDP/RTU .NET.

I will download the PC software and test with Open PLC in the next week.

FYI I have had success with the FC3 Function (Read Holding Registers) using the following Modbus TCP Clients communicating with OpenPLC (However I have only tested %MW(16 bit) and %MD(32 bit) Registers)

Python on RPI & Linux Server
https://pypi.org/project/uModbus/
https://pypi.org/project/pyModbusTCP/

PHP on Linux Web Server
https://github.com/krakorj/phpmodbus

In your case I would start with the first 16bit register %MW0 (Modbus address 1024) and set an initial value in your PLC as shown below.

Josef1.jpg 

If you are getting a zero for %MW0 in this case I would suggest the EasyModbusTCP/UDP/RTU .NET software needs looking at in more detail.

Kevin

P.S. Both uModbus and phpmodbusTCP were incomplete from point of view of the complete modbus specification (but did enough for my requirements)


Reply 0 0
Josef Bernhardt
Hello Kevin,
Thank you very much for the extensive help
Greetings to Josef
Reply 0 0
Josef Bernhardt
One last try for today The variable% MW0 is unfortunately not displayed in the monitor from the Raspberry PI
%QW0 and %QW1 is OK


ScreenML1025_OK_with_PWM.jpg 

OpenplcWebMonitoring.jpg 
Reply 0 0
NWT.Stuff
Hi Josef,

I think I have been through this issue with Thiago before one time and he fixed it for me.

Try TYP "UINT" for %MW0 and not TYP "WORD"

This is one example of that works fine for me from OpenPLC monitoring and Modbus access.

Josef2.jpg 
Reply 0 0
thiagoralves
The reason why you’re having trouble reading %ML0 is because it is made out of 4 regular 16-bit registers. You need to read Modbus Holding Registers 4096 to 4099 and concatenate them all together to get the whole 64-bit integer in %ML0. Some Modbus software can do that for you automatically as long as you specify that the location is a 64-bit (long) integer.
Reply 1 0
Josef Bernhardt
Hello everybody,
I would like to thank you again very much for your help.
Here is a small example.
On the occasion I found a nice Modbus test program for C # that can be compiled with the free development environment Sharp Develop.
With ML1024 I assume that the UNIX timestamp is meant.
https://www.epochconverter.com/
Many greetings
Josef Bernhardt

SPS-Programm.jpg 


ModbusTestprogramm.jpg 
Reply 0 0
thiagoralves
All good. This shows that you’re reading them correctly. Now you need to concatenate the fields for each long variable to get the full number. And about your question, yes, ML1024 is the Unix timestamp (epoch) adjusted for your timezone 
Reply 1 0
Josef Bernhardt
Hello Thiago,
thanks again for help. Are there any other interesting variables that can be accessed?
Many greetings
Joseph
Reply 0 0
thiagoralves
Are there any other interesting variables that can be accessed?

Nope
Reply 1 0
Reply