npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-beckhoff

v0.9.1

Published

AMS/ADS implementation for beckhoff PLCs

Downloads

26

Readme

node-beckhoff

Beckhoff ADS/AMS protocol implementation to use as Node.JS library

Heavily inspired on the Node.JS implementation of roccomuso (https://github.com/roccomuso/node-ads) and jisotalo (https://github.com/jisotalo/ads-client)

This library aims to be faster in handling read and write requests by caching the handles to the variables. The library uses async/await and Promises instead of the basic callbacks, so it's a little easier to read and follow.

The calls exposed to the user side provide Promises

Faster handling

Although implementation is still in javascript, execution speed is gained by storing fixed blocks of data (header) and storing handles in a SQLite database (default choice = in-memory)(storing on-disk is also possible but may have performance penalties, depending on the kind of storage used ). The drawback of this is that the application has to restart (or: re-fetch datatypes and symbols) after a PLC code-update.

Handles are stored after first use. When the application terminates, all handles are cleaned upon exit

Commands provided

  • getPlcInfo : read plc version
  • getPlcState : read current plc state
  • getPlcSymbols : read the list of plc symbols -> this step is necessary in order to read and write individual symbols
  • getPlcDataTypes : read the list of plc datatypes -> RPC functions are also being fetched _ (they can be used to execute functions rather than write data (still TODO))_
  • readPlcData : read the current value of a (list of) specified symbol(s) -> multiple symbols allowed
  • writePlcData : set the value of a specified symbol -> multiple symbols allowed
  • delPlcHandle : delete a read handle for a symbol -> multiple symbols allowed -> handles are fetched automatically upon read/write/notify
  • addPlcNotification : add a notification for a specific symbol -> multiple symbols allowed
  • delPlcNotification : remove notifications for a specific symbol -> multiple symbols allowed
  • getRpcMethodInfo : fetch info about rpc methods provided -> only 1 method allowed per call -> this requires updated plc datatypes and symbols
  • callPlcRpcMethod : call an rpc method on the plc -> only 1 method allowed per call
  • destroy : close connection to th PLC. Free used symbol + notify handles.

Example application

A sample console application is provided. This shows the (different) approach for node-ads users and will help new users get started.

Quick-start

const BeckhoffClient = require('node-beckhoff');
const settings = require(__dirname + '/settings.json');

const beckhoff = new BeckhoffClient(settings);

const tmpSettings = beckhoff.settings;

tmpSettings.plc.ip = 'plc-ip';
tmpSettings.remote.netid = 'plc-netid';
tmpSettings.develop.verbose = true;
tmpSettings.develop.debug = false;
beckhoff.settings = tmpSettings;

// fetch plc info
let data = await beckhoff.getPlcInfo();
console.log(JSON.stringify(data));

// fetch all symbols 
data = await beckhoff.getPlcSymbols();
//console.log(JSON.stringify(data)); -> this will produce quite some output
console.log('OK - ' + data.length);

let symbol = [
  { name : 'SENSORS.temp_outside' }
];
data = await beckhoff.readPlcData(symbol);
console.log(JSON.stringify(data));

symbol = [
  { name : 'SENSORS.temp_outside' },
  { name : 'SENSORS.temp_inside' }
];
data = await beckhoff.readPlcData(symbol);
console.log(JSON.stringify(data));

symbol = [
  { name : 'LIGHTS.light_outside', value : 1 }
];
data = await beckhoff.writePlcData(symbol);
console.log(JSON.stringify(data));

/*
 * symbol notifications
 */
beckhoff.on('notify', (data) => {
  console.log(JSON.stringify(data));
})

symbols = [
 // {name : "SENSORS.temp_inside",        mode: "cyclic",   delay : 5, cycle: 30},
  {name : "SENSORS.contact_front_door", mode: "onchange", delay : 5, cycle: 5}
];
data = await beckhoff.addPlcNotification(symbols);
console.log(JSON.stringify(data));

symbols = [
 // {name : "SENSORS.temp_inside"},
  {name : "SENSORS.contact_front_door"}
];
data = await beckhoff.delPlcNotification(symbols);
console.log(JSON.stringify(data));

symbols = [
 // {name : "SENSORS.temp_inside"},
  {name : "SENSORS.contact_front_door"}
];
data = await beckhoff.delPlcNotification(symbols);
console.log(JSON.stringify(data));

// in order to know the syntax for rpc calls on your plc,
// first do a 'getRpcMethodInfo' call
rpcCall = [
  {
    "name" : "LIGHTS.lgt_tabletop",
    "method" : "SET_VALUE", 
    "parm_in" : [{"parm" : "value", "value" : 1}]
  }
];
data = await beckhoff.callPlcRpcMethod(rpcCall);
console.log(JSON.stringify(data));

await beckhoff.destroy();