Willkommen beim Revolution Pi mit Python

Programmiert eure Steuerung auf dem Revolution Pi der Kunbus GmbH mit Python!

Python3 Modul

Dieses Modul stellt euch diverse Funktionen zur Verfügung um die Hardware des RevolutionPi’s kinderleicht mit eurem Pythonprogramm anzusprechen. Dabei spielt es keine Rolle, ob ihr aus der SPS Sparte kommt und zyklisch programmiert oder eventbasiert als Anwendungsentwickler vom z.B. RaspberryPi.

PLC System für Software, Netzwerk und MQTT

Mit unserem RevPiPyPLC System könnt ihr über das Netzwerk schnelle IO-Checks machen, euer Steuerungsprogramm hochladen, bei Systemstart starten lassen und alle IO Daten per MQTT übertragen. Oder auch einfach von jedem beliebigen Python-System Daten in das Prozessabbild schreiben oder draus lesen.

Und das alles ohne weitere Lizenzkosten!

Beispiel mit RevPiModIO Flipflop (bistabile Kippstufe):

Zyklisch

# -*- coding: utf-8 -*-
"""Flip Flop control cycle."""
__author__ = "Sven Sager"
__copyright__ = "Copyright (C) 2021 Sven Sager"
__license__ = "GPLv3"

import revpimodio2


def main(ct: revpimodio2.Cycletools) -> None:
    """RevPiModIO will call this function every 50 milliseconds."""
    if ct.first:
        # This is True in first cycle only / on program start

        # Define all your variables inside the ct.var object
        ct.var.counter = 0

    # You can use sub routines to split the cycle into logical parts
    flip_flop(ct)  # Always pass the ct object

    # Show the health of your program, by flashing the green A1 led
    ct.core.a1green(ct.flag10c)

    # You may want to use the watchdog, so toggle it!
    ct.core.wd_toggle()

    if ct.last:
        # This is True in last cycle only / program exit
        print("I_7 goes {0} times to True".format(ct.var.counter))

        # Set save IO states before exit
        ct.core.a1green(False)
        ct.io.O_1(False)


def flip_flop(ct: revpimodio2.Cycletools):
    """
    This is the logic of a sub routine inside the cycle.

    If Input I_7 goes to true, it will invert the actual state
    of the Output O_1.
    """
    if ct.changed(ct.io.I_7, edge=revpimodio2.RISING):
        # ct.changed compares the state of I_7 with the last cycle
        ct.var.counter += 1
        ct.io.O_1(not ct.io.O_1())


revpimodio2.run_plc(main, cycletime=50)  # 50ms is the default

 

Events

# -*- coding: utf-8 -*-
"""Flip Flop control cycle."""
__author__ = "Sven Sager"
__copyright__ = "Copyright (C) 2021 Sven Sager"
__license__ = "GPLv3"

import revpimodio2

# Define global variables
counter = 0


def evt_i_7(name, value) -> None:
    """Event function for input I_7 will invert state of O_1."""
    global counter
    counter += 0
    rpi.io.O_1(not rpi.io.O_1())


def toggle_led_wd(name, value) -> None:
    """By changing the LED, we will start the next timer event."""

    # Show the health of your program, by flashing the green A1 led
    rpi.core.a1green(not rpi.core.a1green())

    # You may want to use the watchdog, so toggle it!
    rpi.core.wd_toggle()


def clean_up():
    """Will be called at the end of the program."""
    print("I_7 goes {0} times to True".format(counter))

    # Set save IO states before exit
    rpi.core.a1green(False)
    rpi.io.O_1(False)


# Create the RevPiModIO object
rpi = revpimodio2.RevPiModIO(autorefresh=True)

# This will catch exit signals and calls the clean_up function
rpi.handlesignalend(clean_up)

# Register an event function to input I_7 for changing state to True
rpi.io.I_7.reg_event(evt_i_7, edge=revpimodio2.RISING)

# Register a timer event to change state of A1 LED every 500 ms
rpi.core.a1green.reg_timerevent(toggle_led_wd, 500, prefire=True)

rpi.mainloop()
Weitere Beispiele

 

Blog

Version 2.7.0

Add context manager for ios Remove deprecated parameter ‚direct_output‘ from ModIO classes Check offset values of the devices for integers Check if the length of the previous IO overlaps with the new IO Add support for RO device Add context manager for modio instance Mit den neuen Kontextmanagern können die IOs einfacher mit eigenen Zyklen …

Version 2.6.1

Wichtiges Update Behebt einen Fehler bei Verwendung von autofrefresh und shared_procimg. Unter bestimmten Umständen konnte es passieren, dass ein Ausgang gesetzt wurde, jedoch der interne Puffer noch den falschen Wert zurück lieferte. Behebt einen Fehler bei Verwendung von autofrefresh und shared_procimg. Bei dem alle Ausgänge immer geschrieben wurden, auch wenn ein Device kein autorefresh aktiviert …