IO refresh time exceeded

Moderator: RevPiModIO

Post Reply
AndreC7
Posts: 5
Joined: 29 Feb 2024, 11:57

IO refresh time exceeded

Post by AndreC7 »

Hello, we are having the issue below
1.png
Here is the code snippet that starts the problem.
First code is the class below.

Code: Select all

import os
import time
import threading
import io_functions as io
from datetime import datetime
from camera_control import CameraControl
from config_manager import ConfigManager

class TempController(threading.Thread):
    def __init__(self, camera_control : CameraControl, config_manager : ConfigManager, img_folder_path = '/home/pi/fotos/'):
        threading.Thread.__init__(self)
        self.img_folder_path = img_folder_path
        self.sirene_status = 0
        self.button_light_status = 0
        self.temperature_alarm = 0
        self.temperature_delta_alarm = 0
        self.camera_control = camera_control
        self.config_manager_sing = config_manager
    #===END OF __init__()

    def init(self):
        self.running = 1
        if not os.path.isdir(self.img_folder_path):
            try:
                os.makedirs(self.img_folder_path)
            except Exception as e:
                self.running = 0
                print(f'Erro ao criar diretorios. err:{e}')
                return
    #===END OF init()

    def run(self):
        while self.running:
            if(self.temperature_alarm or self.temperature_delta_alarm):
                if not self.sirene_status and not io.get_button_click():
                    io.liga_led_botao()
                    io.liga_sinaleiro()
                    self.sirene_status = 1
                    img = self.camera_control.get_ir_img()
                    file_name = self.create_image_name()
                    if(img):
                        with open(file_name, 'wb') as fp:
                            fp.write(img)

                if(io.get_button_click()):
                    if(self.temperature_alarm):
                        self.temperature_alarm = 0
                    if(self.temperature_delta_alarm):
                        self.camera_control.clean_temperature_list()
                        self.temperature_delta_alarm = 0
                    io.desliga_led_botao()
                    io.desliga_sinaleiro()
                    self.sirene_status = 0
            if(self.camera_control.get_temperature() > self.config_manager_sing.get_temperature_limit()):
                self.temperature_alarm = 1
            if(self.camera_control.get_temperature_delta() > self.config_manager_sing.get_temperature_delta()):
                self.temperature_delta_alarm = 1
            time.sleep(0.001)
    #===END OF run()
This above calls the class io_functions below, which after the load starts the warnings.

Code: Select all

import revpimodio2
import time

rodando = True
rpi = revpimodio2.RevPiModIO(autorefresh=True)
print("Initiating io_functions")

rpi.io.O_1.value = False
rpi.io.O_2.value = False
rpi.io.O_3.value = False

def liga_sinaleiro():
    rpi.io.O_1.value = True
    rpi.io.O_3.value = True
    return rpi.io.O_1.value
    
def desliga_sinaleiro():
    rpi.io.O_1.value = False
    rpi.io.O_3.value = False
    return rpi.io.O_1.value

def liga_led_botao():
    rpi.io.O_2.value = True
    return rpi.io.O_2.value
    
def desliga_led_botao():
    rpi.io.O_2.value = False
    return rpi.io.O_2.value

def get_button_click():
    return rpi.io.I_1.value
Some information:
1. we only call revpimodio2.RevPiModIO(autorefresh=True) once on the software
2. We tried to change cycle time to 50 and 100 but seems the same 20ms warning keeps appearing.

Any ideas?

Regards,
User avatar
RevPiModIO
KUNBUS
Posts: 335
Joined: 20 Jan 2017, 08:44
Contact:

Re: IO refresh time exceeded

Post by RevPiModIO »

Hi AndreC7!

The warning from RevPiModIO is thrown at you because the process in which your Python program is running is probably running out of resources. Since your main program runs every millisecond `time.sleep(0.001)` I suspect that the Python process runs with 100% CPU time on one core. As a result, RevPiModIO no longer has enough resources to update the process image within the specified times.

You could remove autorefresh from RevPiModIO by changing your code as in the example below. This means that you always synchronize the IOs at the time when you need the data and synchronize the access to the IOs with your main program. Keep in mind that the speed of the PiBridge, depending on the number of modules, is 6 milliseconds. A faster reading / writing of the IOs is not possible.

Code: Select all

import revpimodio2
import time

rodando = True
rpi = revpimodio2.RevPiModIO()
print("Initiating io_functions")

with rpi.io:
    rpi.io.O_1.value = False
    rpi.io.O_2.value = False
    rpi.io.O_3.value = False

def liga_sinaleiro():
    with rpi.io:
        rpi.io.O_1.value = True
        rpi.io.O_3.value = True
        return rpi.io.O_1.value
    
def desliga_sinaleiro():
    with rpi.io:
        rpi.io.O_1.value = False
        rpi.io.O_3.value = False
        return rpi.io.O_1.value

def liga_led_botao():
    with rpi.io:
        rpi.io.O_2.value = True
        return rpi.io.O_2.value
    
def desliga_led_botao():
    with rpi.io:
        rpi.io.O_2.value = False
        return rpi.io.O_2.value

def get_button_click():
    with rpi.io:
        return rpi.io.I_1.value
Greeting
Sven
python3-RevPiModIO - https://revpimodio.org/ || Der RevPi ist das Beste, was passieren konnte!
Post Reply