Rajesh Anand
I'm using raspberry Pi 3B model running openPLC. How do i know about the instruction cycles for which I'm writing the code? Or can i see the scan time after running a piece of code since i want to know how much cycles it takes exactly to run certain code.

And it's an ARM Cortex processor which uses 1.2GHz clock frequency. If i i run some code, will it process on four cores simultaneously or it will process in individual cores?

Will I be able to do correlate instruction cycles with structured language text program (like if a certain piece of structure language code amounts to certain instruction cycle)?
Quote 0 0
thiagoralves
OpenPLC runs on top of Linux (a non-deterministic OS), not on bare metal. Therefore it is impossible to predict exactly how many cpu cycles are used. Multi core performance is only achieved on multi threads. OpenPLC runs parallel threads to handle network communications (modbus, DNP3, etc). The main logic runs sequentially in a single thread. There is no reason to parallelize the main logic.
Quote 0 0
Rajesh Anand
I have a few more questions,

1. Is it possible to see the scan time in OpenPLC v3 on the browser where we upload the program and is there any way to calculate analytically the instruction cycles based on the code we write in Structured text language? (I found a library called OSCAT which has a function scan time, can I use that function here for calculating the scan time of my program?)
2. How do I communicate with raspberry pi (running OpenPLC) using Modbus TCP from ScadaBR as I have to use it as an HMI? (I will have to create a simple function in ScadaBR and then use it in openPLC for configuring it as modbus slave?)

Any suggestions would be helpful. Thanks in advance.
Quote 0 0
thiagoralves
1. On OpenPLC the scan time is always a fixed value, determined by the program's task configuration. Therefore, if you set your task cyclic time to T#20ms, your scan time will be 20ms always. Usually the processing of your Structured Text instructions is a lot faster (normally takes up a few nanoseconds). For the time remaining, OpenPLC does some I/O operations or sleeps until it reaches the end of the cycle time. That's exactly how most PLCs on the market behave.

2. Open ScadaBR, go to Datasources (icon on the top menu bar) and add a new datasource using Modbus IP protocol. Fill out the information on the next screen about your new datasource (name, RPi IP address, port 502, tcp keep-alive, etc) and then save your settings. After that, on the same screen you will be able to add data points, which are single variables connected to the PLC memory via Modbus. Once you set up all your data points, you will be able to see on ScadaBR the value of each data point in real time.
Quote 0 0
Rajesh Anand
1. On OpenPLC the scan time is always a fixed value, determined by the program's task configuration. Therefore, if you set your task cyclic time to T#20ms, your scan time will be 20ms always. Usually, the processing of your Structured Text instructions is a lot faster (normally takes up a few nanoseconds). For the time remaining, OpenPLC does some I/O operations or sleeps until it reaches the end of the cycle time. That's exactly how most PLCs on the market behave.


1. I would like to see how much cycle time it will take to start the new cycle based on my code. If my complete instructions are executed and waiting for the next cycle time, is there any way to check/monitor the total time it takes to start new a new cycle (idle time and processing time). If I reduce the scan time even further, how do I see for how much time OpenPLC sleeps till the cycle restarts?
Effectively can I see the processing time, idle time (when the processing is completed before the next cycle starts) within OpenPLC?

2. Is there any correlation between the time taken to process my instructions in openPLC with the instruction cycle provided by the CPU of RPi 3b ( Broadcom BCM2837).

On a separate note, how to run the OpenPLC as modbus TCP slave so that I can look at the status of the coils from another modbus TCP master. (because, there seems to be only option available for adding slaves to open PLC).
  
Thanks
Quote 0 0
thiagoralves
There is no straightforward way to do what you want. You will have to instrument OpenPLC core code and measure the timings. DyamoRIO https://www.dynamorio.org/ might be a good option to add instrumentation mechanisms. Otherwise, if you just want ballpark measurements, you can wrap the main routines on /webserver/core/main.cpp with timers and measure how much time each one of them takes to run.
Quote 0 0
Rajesh Anand
1. How do I wrap the main routine within the /webserver/core/main.cpp? I found the program which is a part of OpenPLC Software Stack (main file for the OpenPLC). Should I have to add my program (in the structured text) inside the main loop? Sorry, I don't know about it.

2. How about I monitor OpenPLC as a slave and monitor from my PC through Modbus TCP?
Quote 0 0
thiagoralves
CPU Instruction count is not something you can do through structured text or modbus. You will have to add features to the core of OpenPLC to be able to do that. What I'm telling you is to write some lines of code in C to measure the amount of time spent on each task inside main.cpp => https://github.com/thiagoralves/OpenPLC_v3/blob/master/webserver/core/main.cpp  (lines 255 to 276). If you don't know how to code in C you won't be able to do this.
Quote 0 0
Rajesh Anand
Oh okay, thank you 🙂
Quote 0 0
Rajesh Anand
On the separate note, how do I use the Modbus poll (master) to monitor the OpenPLC coils and registers? I'm using RPi with Unipi.

1. How do I use the registers inside the program for data in openPLC, any register names for it?
2. How do I read or write the coils and registers (after writing my program) through Modbus? (As I can see openplc has option for connecting Modbus slaves only)
Quote 0 0
thiagoralves
0. Open Radzio Modbus Master Simulator, File -> New. Then Connection -> Settings -> Modbus TCP -> on the IP address field, type in the IP of your Raspberry Pi. Then click Connection -> Connect and you're online.
1. Check http://www.openplcproject.com/scada . There are no register names, all Modbus registers and coils are mapped to specific OpenPLC locations.
2. You can't specifically read or write to external Modbus registers from your program on OpenPLC. You just add a slave device and it does the reading and writing for you automatically.
Quote 0 0
Rajesh Anand
Okay. I will try that.

I installed OpenPLC v3 in another RPi 3b. When i rebooted the RPi boots and stop with a blank screen and cursor is blinking on the top left end. I couldnt do any operations on that. Is it possible that some files be corrupted and any suggestions what could be the issue and how do i solve it?

Thanks. 
Quote 0 0
thiagoralves
Probably your filesystem got corrupted, probably due to a faulty SD card. Reflash your Pi with a fresh Raspbian image. If the problem persists, replace your SD card.
Quote 0 0
Rajesh Anand
It boots to this, saying "Welcome to Pixel powered by raspbian" and then the black screen with the cursor blinks. Still the issue might be with the file system?.

The above happens when i power it through Micro USB. But when I power it through GPIO, RPi doesnt gets powered ON. The fuse should be intact right as it powers through one mode atleast?
Quote 0 0
thiagoralves
Yes, if it is not booting there are great chances your filesystem got corrupted. Now that you're mentioned about powering the Pi through GPIO pins, I imagine that the SD card corruption might have been caused by improperly powering your Pi. There is no regulation or fuse protection on the GPIO to protect from over-voltage or current spikes. If an incorrect voltage is applied, or a current spike occurs on the line, you can permanently damage your Raspberry Pi. Check this article: https://magpi.raspberrypi.org/articles/power-supply
Quote 0 0