All Projects → xtrinch → moka7-live

xtrinch / moka7-live

Licence: other
S7 PLC communication library for Java, based on Moka7

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to moka7-live

Industrial-Security-Auditing-Framework
ISAF aims to be a framework that provides the necessary tools for the correct security audit of industrial environments. This repo is a mirror of https://gitlab.com/d0ubl3g/industrial-security-auditing-framework.
Stars: ✭ 43 (+53.57%)
Mutual labels:  plc, s7
iot-master
物联大师是开源免费的物联网智能网关系统,集成了标准Modbus和主流PLC等多种协议,支持数据采集、公式计算、定时控制、自动控制、异常报警、流量监控、Web组态、远程调试等功能,适用于大部分物联网和工业互联网应用场景。
Stars: ✭ 119 (+325%)
Mutual labels:  plc, s7
vscode-st
Extension for VS Code to support Structured Text language.
Stars: ✭ 94 (+235.71%)
Mutual labels:  plc
IoT-system-PLC-data-to-InfluxDB
This project aim is to provide free software to fetch data from plcs (Siemens S7-300/400/1200/1500) and store it. Used stack is completly opensource. I used InfluDB as data storage, so application principle is following Big Data paradigm.
Stars: ✭ 26 (-7.14%)
Mutual labels:  plc
Iot Dc3
IOT DC3 is an open source, distributed Internet of Things (IOT) platform based on Spring Cloud. It is used for rapid development of IOT projects and management of IOT devices. It is a set of solutions for IOT system.
Stars: ✭ 195 (+596.43%)
Mutual labels:  plc
EasyModbusTCP.Java
EasyModbusTCP library for Java implementation
Stars: ✭ 76 (+171.43%)
Mutual labels:  plc
tgpkernel-s7-n
Custom Kernel for Samsung Galaxy S7 / S7 Edge running Samsung Firmware (Nougat) [EOL]
Stars: ✭ 20 (-28.57%)
Mutual labels:  s7
plccore
一个基于rt-thread的可编程控制器(PLC)运行时内核
Stars: ✭ 43 (+53.57%)
Mutual labels:  plc
s7client
Hi level API for node-snap7 to communication with Siemens S7 PLCs
Stars: ✭ 36 (+28.57%)
Mutual labels:  plc
Modbus-STM32-HAL-FreeRTOS
Modbus TCP and RTU, Master and Slave for STM32 using Cube HAL and FreeRTOS
Stars: ✭ 272 (+871.43%)
Mutual labels:  plc
ads-client
Unofficial Node.js ADS library for connecting to Beckhoff TwinCAT automation systems using ADS protocol.
Stars: ✭ 44 (+57.14%)
Mutual labels:  plc
TcBlack
Opnionated code formatter for TwinCAT.
Stars: ✭ 67 (+139.29%)
Mutual labels:  plc
node-drivers
Industrial protocol drivers in node.js
Stars: ✭ 20 (-28.57%)
Mutual labels:  plc
iec-checker
Static analysis of IEC 61131-3 programs
Stars: ✭ 36 (+28.57%)
Mutual labels:  plc
V2GInjector
V2GInjector - Tool to intrude a V2G PowerLine network, but also to capture and inject V2G packets
Stars: ✭ 79 (+182.14%)
Mutual labels:  plc
TwinRx
.NET library for connecting with Beckhoff TwinCAT PLC via Reactive Extensions (Rx)
Stars: ✭ 16 (-42.86%)
Mutual labels:  plc
SoftBeckhoff
Virtual Beckhoff PLC for local testing with docker support
Stars: ✭ 40 (+42.86%)
Mutual labels:  plc
openHAB-Simatic
openHAB binding for Siemens Simatic S7 PLC
Stars: ✭ 15 (-46.43%)
Mutual labels:  plc
plc-programmable-3d-simulation
Project for students who want to learn PLC programming but don't have access to real-world machines or constructions to learn programming on.
Stars: ✭ 49 (+75%)
Mutual labels:  plc
TF6100 Samples
Contains product samples for TF6100 TC3 OPC UA
Stars: ✭ 15 (-46.43%)
Mutual labels:  plc

Maven Central

moka7-live

This is a library built around moka7 created by Dave Nardella. Moka7 is is the Java port of Snap7 Client. It’s a pure Java implementation of the S7Protocol used to communicate with S7 PLCs.

Installation

Package can be installed via maven by adding the following to your pom.xml:

<dependency>
    <groupId>si.trina</groupId>
    <artifactId>moka7-live</artifactId>
    <version>0.0.11</version>
</dependency>

How to use

1. Create classes that implement interface PLCListener

2. Create PLC class instances for every PLC you wish to receive bit changes / read integers, bits from

import si.trina.moka7.live.PLC;
import com.sourceforge.snap7.moka7.S7;

/*
    args: 
        ** name of PLC
        ** IP of PLC
        ** byte array with length of db PLC->PC
        ** byte array with length of PC->PLC
        ** db (DataBase) number PLC->PC
        ** db (DataBase) number PC->PLC
        ** array of addresses of booleans to listen to changes to
*/
PLC plc1 = new PLC("Test PLC1","10.10.21.10",new byte[32],new byte[36],112,114,new double[]{0.1,0.2});


/*
    args: 
        ** name of PLC
        ** IP of PLC
        ** length of db PLC->PC
        ** length of PC->PLC
        ** db (DataBase) number PLC->PC
        ** db (DataBase) number PC->PLC
        ** array of addresses of booleans to listen to changes to
        ** rack number
        ** slot number
        ** area type of PLC->PC
        ** area type of PC->PLC
*/
PLC plc2 = new PLC("Test PLC2", "10.10.22.10", 18, 22, 45, 44, new double[]{0.1,0.2,0.3}, 0, 1, S7.AreaDB, S7AreaDB); 

3. Add classes that implement interface PLCListener to PLC's ArrayList<PLCListener> listener array

PLCListenerImplementation myListener = new PLCListenerImplementation();
plc1.listeners.add(myListener);
plc2.listeners.add(myListener);

4. Start a thread for each PLC instance

Thread t1 = new Thread(plc1).start();
Thread t2 = new Thread(plc2).start();

5. Receive bit changes from bits at addresses from last argument of PLC constructor

import si.trina.moka7.live.PLCListener;

public class PLCListenerImplementation implements PLCListener {
    @Override
    public void PLCBitChanged(int address, int pos, boolean val, String plcName) {
        switch (address) {
        case 0:
            switch (pos) {
            case 1:
                System.out.println("Bit at address 0.1 of PLC " + plcName + " changed to: " + val);
            }
        }
    }
}

6. Write shorts/integers/booleans to DB

/*
    args: 
        ** database to write to: from plc = true, from pc = false
        ** address to write to
        ** short/integer to write to db
*/
plc1.putInt(false, 12, (short)3);
plc1.putDInt(false, 12, 3);

/*
    args:
        ** database to write to: from plc = true, from pc = false
        ** address to write to
        ** bit offset at address to write to
        ** value to write
*/
plc1.putBool(false, 0, 1, true);
plc1.signalBoolean(false, 0, 1, true); // resets to false after 300ms

7. Read shorts/integers/booleans from DB

try {
    short aShort = plc1.getInt(true, 8); // 2 bytes
    int anInteger = plc1.getDInt(true, 8); // 4 bytes
    boolean aBoolean = plc1.getBool(true, 0, 2);
} catch (Exception e) { 
    e.printStackTrace(); 
}

Optional

Check communication status

Communication status can optionally be continuously checked with the help of a 'live bit'.

The following example settings set bit at address 0.0 in both DB's as the 'live bit', meaning it toggles it every 250ms and expects PLC to toggle it back every 500ms. Throws exception if it doesn't.

    plc1.liveBitEnabled = true;
    plc1.liveBitAddress = 0;
    plc1.liveBitPosition = 0;
    plc1.liveBitPCDuration = 250;
    plc1.liveBitPLCDuration = 500;

Misc

PLC connection status

Boolean indicating whether a PLC is connected or not can be found in PLC class' public variable connected.

Logging

All logging with various priorities inside the library is done with slf4j. Meaning, you need a logger binding (for example slf4j-simple) to see logs.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].