0.0.3 • Published 3 years ago

s7client-ts v0.0.3

Weekly downloads
4
License
MIT
Repository
-
Last release
3 years ago

S7Client-ts

Typescript port of S7Client, the Hi-Level API for node-snap7 to communicate with Siemens S7 PCLs (See compatibility).

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

Api Documentation

// TODO

Usage

npm install s7client-ts
import { S7Client, S7DbVarAreaDbRead } from 's7client-ts';

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


// DBA to read
const dbNr = 102;
const dbVars: S7DbVarAreaDbRead[] = [
  // { type: "CHAR", start: 0 },
  { type: "BOOL", start: 4, bit: 2 },
  { type: 'INT', start: 13 }
];

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

(async function () {
  console.log("connectind");
  await client.connect().catch((e) => console.log(e));
  console.log("connected", client.isConnected());

  // Read DB
  const res: S7DbVarAreaDbRead[] = 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

License & copyright