Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/strolch-li/strolch-plc
A software PLC based on Strolch's runtime
https://github.com/strolch-li/strolch-plc
electronics java plc plc-controller plc-programming raspberry-pi raspberry-pi-3 strolch webapp
Last synced: 3 months ago
JSON representation
A software PLC based on Strolch's runtime
- Host: GitHub
- URL: https://github.com/strolch-li/strolch-plc
- Owner: strolch-li
- License: apache-2.0
- Created: 2020-01-26T12:43:57.000Z (almost 5 years ago)
- Default Branch: develop
- Last Pushed: 2024-07-30T11:46:49.000Z (5 months ago)
- Last Synced: 2024-09-29T00:45:30.696Z (3 months ago)
- Topics: electronics, java, plc, plc-controller, plc-programming, raspberry-pi, raspberry-pi-3, strolch, webapp
- Language: Java
- Homepage: https://strolch.li/plc.html
- Size: 630 KB
- Stars: 2
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Strolch as a software PLC
[![Contributors](https://img.shields.io/github/contributors/strolch-li/strolch-plc)](https://github.com/strolch-li/strolch-plc/graphs/contributors)
[![License](https://img.shields.io/github/license/strolch-li/strolch-plc)](https://github.com/strolch-li/strolch-plc/blob/master/LICENSE)A soft real time PLC written in Strolch running on Strolch
Checkout the documentation at https://strolch.li/plc/
## Features
Strolch PLC supports the following features:
* Notification model
* Raspberry Pi GPIO Input and Output addresses
* I2C Input and Output addresses over PCF8574 chips
* DataLogic Scanner connection
* Virtual addresses
* WebUI to observer and manipulate the addresses
* WebSocket connection to Strolch Agent for notifying of changes
* Simple two key addressing of hardware addresses to store semantics, e.g. `Convey01 - MotorOn`, instead of `i2cInput.dev01.0.0`## PlcService
PlcServices are sub classes of `PlcService`. You can register for notifications, send keys and delay actions:import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import li.strolch.plc.core.PlcHandler;
import li.strolch.plc.core.PlcService;
import li.strolch.plc.model.PlcAddress;
public class ConveyorPlcService extends PlcService {
public static final int BOX_TRANSFER_DURATION = 30;
private static final String R_CONVEYOR_01 = "Conveyor01";
private static final String A_START_BUTTON = "StartButton";
private static final String T_MOTOR_ON = "MotorOn";
private static final String T_MOTOR_OFF = "MotorOff";
private static final String A_BOX_DETECTED = "BoxDetected";
private boolean motorOn;
private ScheduledFuture> motorStopTask;
public ConveyorPlcService(PlcHandler plcHandler) {
super(plcHandler);
}
@Override
public void handleNotification(PlcAddress address, Object value) {
String action = address.action;boolean active = (boolean) value;
if (action.equals(A_START_BUTTON)) {
if (active) {
logger.info("Start button pressed. Starting motors...");
send(R_CONVEYOR_01, T_MOTOR_ON);
this.motorOn = true;
scheduleStopTask();
}
} else if (action.equals(A_BOX_DETECTED)) {
if (active && this.motorOn) {
logger.info("Container detected, refreshing stop task...");
scheduleStopTask();
}
} else {
logger.info("Unhandled notification " + address.toKeyAddress());
}
}
private void scheduleStopTask() {
if (this.motorStopTask != null)
this.motorStopTask.cancel(false);
this.motorStopTask = schedule(this::stopMotor, BOX_TRANSFER_DURATION, TimeUnit.SECONDS);
}
private void stopMotor() {
send(R_CONVEYOR_01, T_MOTOR_OFF);
}
@Override
public void register() {
this.plcHandler.register(R_CONVEYOR_01, A_START_BUTTON, this);
this.plcHandler.register(R_CONVEYOR_01, A_BOX_DETECTED, this);
super.register();
}
@Override
public void unregister() {
this.plcHandler.unregister(R_CONVEYOR_01, A_START_BUTTON, this);
this.plcHandler.unregister(R_CONVEYOR_01, A_BOX_DETECTED, this);
super.unregister();
}This example registered for changes to the keys `Conveyor01 - StartButton` and
`Conveyor01 - BoxDetected`. When the start button is pressed, then it sends the
keys `Conveyor01 - MotorOn` and schedules the motor off action with a delay of
30s.This class should then be registered in the `PlcServiceInitializer`:
public class CustomPlcServiceInitializer extends PlcServiceInitializer {
public CustomPlcServiceInitializer(ComponentContainer container, String componentName) {
super(container, componentName);
}
@Override
protected List getPlcServices(PlcHandler plcHandler) {
ArrayList plcServices = new ArrayList<>();
StartupPlcService startupPlcService = new StartupPlcService(plcHandler);
ConveyorPlcService conveyorPlcService = new ConveyorPlcService(plcHandler);
plcServices.add(conveyorPlcService);
plcServices.add(startupPlcService);
return plcServices;
}As one can see, there is little fuss for writing business logic, state is
persisted automatically so it is visible in the UI, and the PlcServices can
handle their state as needed.## PlcAddress
PlcAddresses store the value of a hardware address:
The two parameters `resource` and `action` are the local keys for the address,
while `address` is used to find the actual connection and the address on that
connection.## PlcTelegram
PlcTelegrams are used to store keys with a default value. For example it is
easier to understand `Conveyor01 - MotorOn` instead of `Conveyor01 - Motor` with the value true or false.
## PlcLogicalDevice
Multiple PlcAddresses can be grouped together into a PlcLogicalDevice for
visualization on the UI. In logistics a single conveyor might have multiple
sensors and actors, e.g. the conveyor's motor, a light barrier and a scanner,
grouping them together makes it easier for debugging.
## PlcConnections
PlcConnections are used to model the actual hardware connections and define with
which class the connection is to be established. The following shows some of the implementations:
## Virtual Addresses
In some cases, especially in conjunction with a Strolch Agent as the main
server, it is necessary to also have virtual addresses, with which to perform
notifications. The following shows examples:
## More Information
Find more to Strolch PLC at our website: https://strolch.li/plc.html