This SoftPLC framework allows for developing applications using the cyclic execution pattern typically found in PLCs. The guiding principle is to provide all that's needed for the application logic (such as IO states) as variable values. Application developers can therefore fully focus on creating the actual application logic without having to deal with low-level system details.
All that's required to be passed to the resulting binary is a configuration in YAML format. This file may even contain the PLC application logic in Lua (optional).
Example for two port expanders attached to the I2C bus of a Raspberry Pi:
tasks:
- name: main
interval: 25000 # us
programs:
- name: BlindLogic
type: Lua
script: |
local blind
-- called once before cyclic execution
function Init(gv) blind = Blind.new(BlindConfigFromMillis(500, 50000, 50000)) end
-- called every cycle
function Cycle(gv, now)
gv.outputs.blind_up, gv.outputs.blind_down =
blind:execute(now, gv.inputs.button_up, gv.inputs.button_down)
end
io:
- type: i2c
bus: /dev/i2c-1
components:
0x3b: # i2c address
type: pcf8574
direction: input
inputs:
0: button_up
1: button_down
0x20: # i2c address
type: max7311
direction: output
outputs:
0: blind_up
1: blind_down
Also see the introductory article on our website (more to come):
Supported featuers:
- Scheduler supporting an arbitrary number of tasks.
- Implementation of programs in C/C++ and Lua.
- I2C, ModBus, MQTT IO variables.
- A small standard library containing useful and tested logic blocks.
- A comprehensive build framework with multitude of tests.
- A statically linked binary with batteries included.
This project is licensed under the terms of the GNU Lesser General Public License v3.0.
Requirements:
- GNU Make
- Docker Compose (test environment)
- Python 3
- CMake 3.20+
- Ninja
- GCC 8+
- Valgrind
The Conan package manager will be installed in a Python 3 venv.
Currently, the following platforms are currently supported:
- Native (most likely this is x86_64)
- Raspberry Pi 4 (use Raspberry Pi 3 target)
- Raspberry Pi 3
- Raspberry Pi 2
Building:
make deps-install
: install required packages (Debian/Ubuntu Linux only)make conan-install
: install the conan package managermake conan-install-deps-native
: build and install dependencies for native platformmake conan-install-deps-rpi3
: build and install dependencies for Raspberry Pi 3 (and 4)make conan-install-deps-rpi2
: build and install dependencies for Raspberry Pi 2make native
: build tests for native platformmake test
: build and run tests locally directly on the build platformmake rpi3
: build for Raspberry Pi 3 (and 4) platformmake rpi2
: build for Raspberry Pi 2 platform
The following list is a living document mentioning what is planned in the future.
In central Europe, PLCs used in typical industrial automation scenarios are programmed according to the IEC 61131-3 standard. Therefore, on the middle or long run, we want to implement an interpreter which is capable of executing such logic.
For better analysis of what happened when and how often, we want to integrate a Prometheus Client, such as prometheus-cpp.
For inlined Lua application logic I want to implement a testing framework that allows for making formally sure that the contained application behaves as expected.
This interface allows for Starting/Stoping/Pausing the runtime dependening on commands received via different channels, such as MQTT and/or HTTP push mechanisms.
Changes in the values of global variable values (= events) invoke callbacks that can be registered with them:
- Variable value changed.
- Get all variable values.
This allows for easier interaction with interpreters and conversion between different time bases.
I wrote a couple of articles about the protocols mentioned in this project. Unfortunately, they are in German. But most likely, it is possible to translate them with some available online tools:
- Feldbussysteme unter Linux konfigurieren und einsetzen, Rainer Poisel, Linux Magazin 04/2018
- Hausautomatisierung auf Basis des MQTT-Protokolls, Rainer Poisel, Linux Magazin 07/2017
- Hausautomatisierung mit I2C-Buskomponenten, Rainer Poisel, Linux Magazin 12/2016