OpenPLC is a PLC application I recently discovered. It has both an editor that can be used to create diagrams in different languages as well as a runtime environment that runs on Windows, Linux and MacOS. So, it runs on different platforms of which the Raspberry Pi is one. It converts the Raspberry Pi into a PLC, it uses all possible available GPIO pins as input or output.
This section describes 3 different topics of the OpenPLC runtime:
The build mechanism and how it works
Using the Raspberry Pi OpenPLC hardware layer
Using the new PSM method: Python Submodule (see this link on the OpenPLC forum where PSM is introduced)
First off, you have to download the OpenPLC runtime for Linux. Instructions are given here.
In short:
Make sure Git is installed
Clone the repository: git clone https://github.com/thiagoralves/OpenPLC_v3.git
Run the install script with the correct argument for the Raspberry Pi: ./install.sh rpi
The install script is nothing more than a bash script that calls another shell script, passes the arguments given (e.g. rpi) and routes the output both to the screen as well as to an output file install_log.txt.
This script analyses the argument(s) given. When no arguments are given an error message with some help info is thrown to the user and the script exits.
Based on the argument(s) given an if-elseif structure is iterated until the argument is recognised. In the case of the argument rpi the following is done (way of working is similar for other valid arguments):
Checks the Linux dependencies
Installs wiringPi (OpenPLC runtime on the Raspberry Pi uses wiringPi and its numbering to access the pins on the Raspberry Pi header)
Installs Python dependencies (some as sudo)
Installs necessary libraries (as sudo)
Installs a hardware layer file based upon the target using a script change_hardware_layer.sh (see further): the hardware layer file is copied from a directory related to the target given to the compilation environment where other files are taken during the compilation process.
Compiles all the files into an application called openplc, using the script compile_program.sh (see further)
Copies a startup script start_openplc.sh to the OpenPLC root directory to launch the OpenPLC runtime