Hallo,
ich hänge mich mal an diesen Thread dran, da ich das gleiche Problem habe.
ich habe das Bespiel von Sven Sager genommen um Phyton auszuprobieren...
Ich habe Anfangs das Beispiel unverändert getestet, es läuft. Bis auf der Fehler:
Code: Select all
warnings.warn(
/usr/lib/python3/dist-packages/revpimodio2/helper.py:627: RuntimeWarning: io refresh time of 20 ms exceeded!
Im Original wird in der Loop ein "wait" von 500ms ausgeführt. Ich bin, nach diesem Thread, davon ausgegangen, das der Fehler an diesem wait(0.5) liegt. Dam ist nicht so. Ich habe das wait umgestellt und der Fehler blieb.
Hier die Änderung (unten im start, die loop funktion):
Code: Select all
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#
# (c) Sven Sager, License: GPLv3
#
"""Combined events with mainloop() and own cyclic functions.
Let the LED A1 blink green during program is running. Switch on output O_1
if I_1 goes to True and switch off output O_1 if I_1 goes to True again.
piCtory Setup: RevPICore | DIO
"""
# ROGRAMMBESCHREIBUNG
# Das Programm soll den Ausgang O_1 auf True setzen, wenn I_1 auf True wechselt und diesen aktiv lassen.
# Wenn I_1 erneut auf True wechselt, soll O_1 wieder auf False gesetzt werden (FlipFlop Schaltung).
#
# Parallel soll während das Programm läuft, die LED A1 vom Core im Takt von 500 Millisekunden grün blinken!
#
import revpimodio2
import time
class MyRevPiApp():
"""Mainapp for RevPi."""
def __init__(self):
"""Init MyRevPiApp class."""
# Instantiate RevPiModIO
self.rpi = revpimodio2.RevPiModIO(autorefresh=True)
# Handle SIGINT / SIGTERM to exit program cleanly
self.rpi.handlesignalend(self.cleanup_revpi)
# Register event to toggle output O_1 with input I_1
self.rpi.io.I_1.reg_event(self.event_flipflop_o1, edge=revpimodio2.RISING)
def cleanup_revpi(self):
"""Cleanup function to leave the RevPi in a defined state."""
# Switch of LED and outputs before exit program
self.rpi.core.a1green.value = False
self.rpi.io.O_1.value = False
def event_flipflop_o1(self, ioname, iovalue):
"""Called if I_1 goes to True."""
# Switch on/off output O_1
self.rpi.io.O_1.value = not self.rpi.io.O_1.value
def start(self):
"""Start event system and own cyclic loop."""
# Start event system without blocking here
self.rpi.mainloop(blocking=False)
print("Application running.")
old_time = time.perf_counter()
while not self.rpi.exitsignal.is_set():
current_time = time.perf_counter()
elapsed_time = (current_time - old_time) * 1000
if elapsed_time > 500:
self.rpi.core.a1green.value = not self.rpi.core.a1green.value
old_time = current_time
print("Application has stopped.")
if __name__ == "__main__":
# Start RevPiApp app
root = MyRevPiApp()
root.start()
Woran kann das noch liegen?
MfG,
Heron