Welcome to the Revolution Pi with Python

Program your Revolution Pi of Kunbus GmbH with Python!

Python module

This module provides you with various functions to access the hardware of the Revolution Pi with your Python program. It does not matter whether you come from the PLC sector and program cyclically or event-based as an application developer of e.g. Raspberry Pi.

PLC System for software, network and MQTT

With our RevPiPyPLC system you can make fast IO-Checks over the network, upload your control program, start it at system start and transfer all IO data via MQTT. Or simply write data from any Python system to the process image.

And there are no license fees!

Example for a flipflop with RevPiModIO

Cyclic

# -*- 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()
More examples

Blog

Version 2.7.2

Adjusts the address of the relay contact on the Connect 4. An LED was switched instead of the relay. Adjusts the properties of .core.A1 – .core.A5 on Connect 4. The colors of the LEDs were not according to the constants revpimodio2. GREEN, . RED, . BLUE switched. Outputs a clear indication on the Connect 4 …

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 With the new context managers, the IOs can be more easily …