Code Monkey home page Code Monkey logo

s7client's Introduction

S7Client

npm Dependencies Known Vulnerabilities Greenkeeper badge Maintainability Test Coverage Donate

Hi-Level API for node-snap7 to communicate with Siemens S7 PCLs (See compatibility).

  • Promise based, async/await support
  • Returns javascript objects with parsed var objects
  • EventEmitter: (connect, disconnect, connect_error, value)
  • Optional auto reconnect

API Documentation

Blog post about my SIMATIC S7 Web HMI project.

Usage

npm install s7client
const {S7Client} = require('s7client');

// PLC Connection Settings
const plcSettings = {
  name: "LocalPLC",
  host: 'localhost',
  port: 9102,
  rack: 0,
  slot: 2
};

// DBA to read
let dbNr = 1;
let dbVars = [
  { type: "CHAR", start: 0 },
  { type: "BOOL", start: 2, bit: 0 },
  { type: 'INT', start: 3 }
];

let client = new S7Client(plcSettings);
client.on('error', console.error);

(async function() {
  await client.connect();

  // Read DB
  const res = await client.readDB(dbNr, dbVars);
  console.log(res);

  // Write multiple Vars
  await client.writeVars([{
    area: 'db', dbnr: 1, type: 'BOOL',
    start: 5, bit: 2,
    value: true
  }]);

  client.disconnect();
})();

Special thanks to

  • Davide Nardella for creating snap7
  • Mathias Küsel for creating node-snap7

License & copyright

s7client's People

Contributors

anthrogan avatar chrisdoernen avatar dependabot[bot] avatar diegosanz avatar greenkeeper[bot] avatar mathiask88 avatar psi-4ward avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

s7client's Issues

Cannot connect to Siemens Logo8

Hey there!

I was able to connect to our LOGO 8 via tools like http://www.frickelzeugs.de/logocontrol/

However via nodejs S7Client, I have no success.

This is my setup:

const { S7Client } = require('s7client')
const plcSettings = {
    name: "SLOGO8",
    host: '192.168.255.200',
    connectionCheckInterval: 20000,
    maxRetryDelay: 20000,
    alivePkgCycle: 20000,
}

const client = new S7Client(plcSettings)
client.on('error', console.error)

const start = async () => {
    await client.connect()
    // client.disconnect()
}

start()

This is my result:

(node:1597) UnhandledPromiseRejectionWarning: Error: SLOGO8:  ISO : An error occurred during recv TCP : Connection timed out    at S7Client._getErr (/mnt/c/Users/Martin Muzatko/dev/test/slogo/node_modules/s7client/src/index.js:325:12)    
    at /mnt/c/Users/Martin Muzatko/dev/test/slogo/node_modules/s7client/src/index.js:336:36
(node:1597) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:1597) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

When I try to connect to another port, I get at least:

``(node:1567) UnhandledPromiseRejectionWarning: TCP : Unreachable peer`

Thank you in advance!

read error for BOOL type

readVar / readVars read BOOL vars
the read result always value: 0, the actual value is true in PLC

but readDB result is true

Can not connect to sinamics drive

The snap 7 client connects to the sinamic drives but the getCpuInfo fails.

async connect() {
...
          resolve(this.getCpuInfo().then(cpuInfo => {
            this.emit('connect', cpuInfo);
            return cpuInfo
          }));
      
  }

An in-range update of debug is breaking the build 🚨

Version 3.2.0 of debug was just published.

Branch Build failing 🚨
Dependency debug
Current Version 3.1.0
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

debug is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes 3.2.0

A long-awaited release to debug is available now: 3.2.0.

Due to the delay in release and the number of changes made (including bumping dependencies in order to mitigate vulnerabilities), it is highly recommended maintainers update to the latest package version and test thoroughly.


Minor Changes

Patches

Credits

Huge thanks to @DanielRuf, @EirikBirkeland, @KyleStay, @Qix-, @abenhamdine, @alexey-pelykh, @DiegoRBaquero, @febbraro, @kwolfy, and @TooTallNate for their help!

Commits

The new version differs by 25 commits.

There are 25 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Error: S7PLC: CPU : Item not available

Hi,
with this code I get the following error: Error: S7PLC: CPU : Item not available, what can I do?
I really appraciate any kind of help.

const {S7Client} = require('S7Client');

const plcSettings = {
    host: '192.168.1.15',
    port: 102,
    rack: 0,
    slot: 2
  };
   

let client = new S7Client(plcSettings);
client.on('error', console.error);

(async function() {
    await client.connect()

    const res = await cpuInfo.readVar({area:"pa", type:"BOOL", start:8, bit: 0})
    console.log(res)

    client.disconnect();
})();

Dockerize?

It would be great if s7-client can be run on i.e. a Synology NAS, on Docker.

For this, we would need to include a DOCKERFILE and post it to the public Docker Registry.

Polling

I'm polling a PLC via setInterval once connected and passing data over socketio to a vue application.

Is there a more appropriate method to polling the PLC? Or is this the best way for "live" responses for a web front end?

Is writing/reading multiple bits inside a byte supported?

We have a usecase where we need to access single bits inside the same byte, e.g.

{
  type: "BOOL",
  start: 0,
  bit: 0,
  value: true
},
{
  type: "BOOL",
  start: 0,
  bit: 2,
  value: false
},

Is that even supported because in datatypes, line 36 the formatter allocates a whole byte for the boolean dbVar.
Thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.