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.5.9

Important update It is strongly recommended to install this update when using .cycleloop! The .cycleloop did not maintain its defined cycle time under certain circumstances (different runtimes of the cycle function)! Depending on the case, the cycle function was executed too often or too seldom than expected. With this version, the cycle time is adhered …

Version 2.5.8

Important update Fixes errors when using shared_procimg when querying the output status, especially in .cycleloop(…). The status of set outputs was one cycle behind. So the values of the outputs in the next cycle were still at the old status. Offset check of the entire process image and omission of overlapping IOs. When using several …

Version 2.5.7

Important update Corrects errors in the length specifications of the memory areas from the process image if the piCtory configurations have gaps. This has been discovered so far with the “Modbus Master 150” module. The error means that the IOs of modules behind the incomplete module are not correctly synchronized. Flat: Switch button and relay …