/node-snap7

node.js wrapper for snap7

Primary LanguageC++MIT LicenseMIT

node-snap7

NPM NPM

Current node-snap7 version: 0.2.3 Current snap7 version: 1.4.0

Build status: Linux Build Status Windows Build status

!!! node-snap7 is still a work in progress !!!

About

This is a node.js wrapper for snap7. Snap7 is an open source, 32/64 bit, multi-platform Ethernet communication suite for interfacing natively with Siemens S7 PLCs (See compatibility).

Installation

Install with:

npm install node-snap7

Requirements:

Building for Node.js 4.x or higher requires C++11 features so the minimum is VS2013 / gcc4.8

Special thanks to

  • Davide Nardella for creating snap7

How to use

API

Client Example

var snap7 = require('node-snap7');

var s7client = new snap7.S7Client();
s7client.ConnectTo('192.168.1.12', 0, 1, function(err) {
    if(err)
        return console.log(' >> Connection failed. Code #' + err + ' - ' + s7client.ErrorText(err));

    // Read the first byte from PLC process outputs...
    s7client.ABRead(0, 1, function(err, res) {
        if(err)
            return console.log(' >> ABRead failed. Code #' + err + ' - ' + s7client.ErrorText(err));

        // ... and write it to stdout
        console.log(res)
    });
});

Server Example

var snap7 = require('node-snap7');

var s7server = new snap7.S7Server();

// Set up event listener
s7server.on("event", function(event) {
    console.log(s7server.EventText(event));
});

// Create a new Buffer and register it to the server as DB1
var db1 = new Buffer(100).fill('ÿ');
s7server.RegisterArea(s7server.srvAreaDB, 1, db1);

// Start the server
s7server.StartTo('127.0.0.1');

// Close the server after 20s in this example
setTimeout(function() {
    s7server.Stop();
    s7server.UnregisterArea(s7server.srvAreaDB, 1);
}, 20000);

Licence & copyright

Copyright (c) 2016, Mathias Küsel

node-snap7 is licensed under the MIT license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.

node-snap7 builds on the excellent work of the snap7 framework from Davide Nardella. Snap7 is issued under the GPL/LGPLv3 (see ./deps/snap7/gpl.txt ./deps/snap7/lgpl-3.0.txt).