RevPiModIO 20ms Exceeded - Can not hold cycle time

Moderator: RevPiModIO

Post Reply
waischa
Posts: 10
Joined: 06 Jun 2023, 11:30

RevPiModIO 20ms Exceeded - Can not hold cycle time

Post by waischa »

Hi all,

I have encountered this problem:

Code: Select all

/usr/lib/python3/dist-packages/revpimodio2/helper.py:617: RuntimeWarning: cycle time of 20 ms exceeded - can not hold cycle time!
  RuntimeWarning
Why is this happening? My code has been running for 3 days straight until this error began to pop up and then proceed to freeze my entire RevPi. I cannot click, keyboard doesn't work but I am able to ping RevPi.

Is this a RevPi memory problem, meaning i need to refresh it from time to time to prevent the freeze? Any guidance is appreciated.

Thank you! :)
User avatar
RevPiModIO
KUNBUS
Posts: 333
Joined: 20 Jan 2017, 08:44
Contact:

Re: RevPiModIO 20ms Exceeded - Can not hold cycle time

Post by RevPiModIO »

Hi waisha.

It looks like a resource problem on the RevPi. Of course, when the CPU is busy and the system starts to be unoperable, revpimodio2 can of course no longer maintain the cycle time and these warnings are issued.

We now have to find out what is happening there.

- In the command line, for example, you could use `htop` to display CPU and RAM consumption. Then you can also find the responsible process.

If it is your Python program, I suspect that several times `revpimodio2. RevPiModIO(autorefresh=True)` is called. Only a single RevPiModIO instance may exist, old instances must be terminated cleanly by calling `.exit()`.

Bad example:

Code: Select all

import revpimodio2
from time import sleep

for i in range(5):
	rpi = revpimodio2.RevPiModIO(autorefresh=True)
	
	rpi.io.O_1.value = True
	sleep(10)
	rpi.io.O_1.value = False
	sleep(10)
	
	# Now the important part, which will free the resources
	rpi.exit()
The example is supposed to make the output O_1 flash, but if you did not call `rpi.exit()` at the end, more and more instances would be created that remain active in memory and the CPU through the `autorefresh`.

That's how it should be done

Code: Select all

import revpimodio2
from time import sleep

# Do this just once in your program and use this object
rpi = revpimodio2.RevPiModIO(autorefresh=True)

for i in range(5):
	rpi.io.O_1.value = True
	sleep(10)
	rpi.io.O_1.value = False
	sleep(10)
	
# At the end of the program call exit to make sure all data is written to process image
rpi.exit()
python3-RevPiModIO - https://revpimodio.org/ || Der RevPi ist das Beste, was passieren konnte!
waischa
Posts: 10
Joined: 06 Jun 2023, 11:30

Re: RevPiModIO 20ms Exceeded - Can not hold cycle time

Post by waischa »

Hi,
- In the command line, for example, you could use `htop` to display CPU and RAM consumption. Then you can also find the responsible process.
I have tried to type `htop` in the command prompt but nothing pop up, it just goes to the next line and nothing else.

Next, my autorefresh is indeed out of the loop, it was only called once in the beginning.

This is my code in short:

Code: Select all

rpi=revpimodio2.RevPiModIO(autorefresh=True)

rpi.handlesignalend()
rpi.core.green.value = 0
rpi.core.red.value = 1
rpi.core.green2.value = 0
rpi.core.red2.value = 1
rpi.exitsignal.wait(0.5)
rpi.core.a1green.value = 1
rpi.core.a1red.value = 0
rpi.core.a2green.value = 1
rpi.core.a2red.value = 0

while True:
	Server()
	Client()
	Read_SP()
	time.sleep(0.5)
I am unsure how autorefresh work completely, do I have to apply the autorefresh to all the IO I have in the program?
varioPLC
Posts: 2
Joined: 16 Aug 2024, 13:21

Re: RevPiModIO 20ms Exceeded - Can not hold cycle time

Post by varioPLC »

Hi there,
I've faced this problem 2 weeks after running the PLC program. 50 ms (later also 100 ms) exceeded in cycle function.
The error shows no space to write logfile, that's why the program freezes.

I'm using a revpi connect 4 to to read and control DIOs and AIOs, beside connecting to a measuring device via RS232 through USB port.
I'm also using node-red as GUI, which communicate to the device via Mosbus virtual device.

In my python program i'm using revpimodio2.Cycletools as ct.
In ct.first some variables are defined and some config files are loaded, which shows no errors.
in ct.last all IOs are set to default values.

the cycle function calling several predefined functions, that are synched by ct.variables, to guarantee the order of executing the function in cycles. Anyways four of the functions are running in parallel to control DIO and AIO connected devices.

all functions' structure is based on PLC cyclic concerns as used in PLC structured text programming, i.e using if conditions in python as case switch in steps.

the last line of the script:
revpimodio.run_plc(mainfunction, cycletime=100)

by calling htop in comandline i see 2 revpi_server.py running, each using 14-15% of CPU. node_red around 11%.
all four cores of cpu are in range of 16 to 23%

other tasks using very low % of cpu.

The warning is writen in logfile when the program tries to read values from IOs, write them to MariaDB, load to Azur, then clean MariaDB, in a 3 min intervals.

the process of reading values, writing to DB and Azure and cleaning the DB are in case switch steps seperated by ct.set_tofc(5), 1 min. during these processes, other functions are waiting, rather than reading from sensors in 200ms interval.

The questions are:
1. why two revpi_server.py are running?
2. all tasks are satisfied, despite Runtimewarning of cycle time exceeded, still warning to log file!
3. why warning (not a real error) leading to freezing the program

Thanks in advance for any comment and solution.
Post Reply