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 🙏

© 2025 – Pkg Stats / Ryan Hefner

siemensplc

v1.1.3

Published

Siemens node S7 PLC

Readme

SiemensPLC Integration

A Node.js project for interacting with Siemens PLCs using the nodes7 library. This project demonstrates how to connect, read, and write data to a Siemens PLC.


Table of Contents


Features

  • Connect to Siemens PLC: Supports configuration of host, port, rack, and slot.
  • Read Tags: Retrieve tag values from the PLC in real-time.
  • Write Tags: Update tag values programmatically.
  • Timer-Based Scanning: Automatically scan and log tag values at a specified interval.

Installation

  1. Step1 - Install node S7:
    npm i nodes7
  2. Step2 - Install siemens plc
    npm i siemensplc

Usage

1. Set up your PLC configuration:

Update the config object with your PLC's connection details:

const config = {
    port: 102, 
    host: '192.168.1.151', 
    rack: 0, 
    slot: 1, 
    debug: false
};

2. Define your tags:

Create a TagList.js file with the desired tag definitions:

// Danh sách tags
const tags = {
    tag1: 'MR100',
    tag2: 'MR104',
    tag3: 'M10.0',
    tag4: 'M10.1',
    tag5: 'M10.2',
    tag6: 'M10.3',
    tag7: 'DB1,X0.0',
};

// Xuất module tags để sử dụng trong các file khác
module.exports = tags;


// Examples:
// MR30 - MD30 as REAL
// DB10,LR32 - LREAL at byte offset 32 in DB10, for 1200/1500 only
// DB10,INT6 - DB10.DBW6 as INT
// DB10,I6 -same as above
// DB10,INT6.2 - DB10.DBW6 and DB10.DBW8 in an array with length 2
// DB10,X14.0 - DB10.DBX14.0 as BOOL
// DB10,X14.0.8 - DB10.DBB14 as an array of 8 BOOL
// PIW30 - PIW30 as INT
// DB10,S20.30 - String at offset 20 with length of 30 (actual array length 32 due to format of String type, length byte will be read/written)
// DB10,S20.30.3 - Array of 3 strings at offset 20, each with length of 30 (actual array length 32 due to format of String type, length byte will be read/written)
// DB10,C22.30 - Character array at offset 22 with length of 30 (best to not use this with strings as length byte is ignored)
// DB10,DT0 - Date and time
// DB10,DTZ0 - Date and time in UTC
// DB10,DTL0 - DTL in newer PLCs
// DB10,DTLZ0 - DTL in newer PLCs in UTC

3. Connect and run the PLC:

The main script initializes the connection, reads tag values, and writes updates as shown:

const SiemensPLC = require('SiemensPLC');
const tags = require('./TagList');

const tagscan = 1000; // Scanning interval (1 second)
const plc = new SiemensPLC();

plc.initiateConnection(config, tags, () => {
    console.log("PLC connection initialized.");
});

setInterval(() => {
    plc.readTags((values) => {
        console.log("PLC Values:", values);
    });
}, tagscan);

// Example: Write a value after 2 seconds
setTimeout(() => {
    plc.writeTag('tag5', true, () => {
        console.log("Write operation completed.");
    });
}, 2000);

Configuration

PLC Connection

| Key | Description | Default Value | |------------|-------------------------------------|---------------------| | port | Port number for the PLC connection | 102 | | host | IP address of the PLC | '192.168.1.151' | | rack | Rack number of the PLC | 0 | | slot | Slot number of the PLC | 1 | | debug | Enable/Disable debug logs | false |

Scanning Interval

Update the tagscan variable to change the scanning frequency:

const tagscan = 1000; // Time in milliseconds (1 second)

Examples

Reading PLC Values

PLC values are read periodically based on the tagscan interval:

plc.readTags((values) => {
    console.log("PLC Values:", values);
});

Writing a PLC Tag

Write a value to a specific tag:

plc.writeTag('tag5', true, () => {
    console.log("Write operation completed.");
});

Writing a Multipe tag

Write a value to multipe tags:

let tagwrite = {
    tag1: "true", // bool tag
    tag2: 10, // integer or real tag
    tag3: "someValue" // String tag
};

writeMultipleTags(tagwrite, () => {
    console.log("All values have been written successfully.");
});

Full Examples

const SiemensPLC = require('SiemensPLC');
const tags = require('./TagList');

// //////////////// CONFIGURATION SETTINGS ////////////////
const tagscan = 1000; // Tag scan interval --- 1s = 1000ms
const config = {port: 102, host: '192.168.1.151', rack: 0, slot: 1, debug: false}; 

// //////////////// SCAN TIMER ////////////////
function fn_Timer() {
    // 1. Read tag values
    plc.readTags((values) => {
        console.log("PLC Values:", values);
    });
}


// //////////////// SYSTEM FUNCTIONS - NO NEED TO MODIFY ////////////////
// Initialize PLC
const plc = new SiemensPLC();
plc.initiateConnection(config, tags, () => {
    console.log("PLC connection initialized.");
});
// Read PLC values every 1 second
setInterval(() => {
    fn_Timer();
}, tagscan);


// Example of writing a value after 2 seconds
setTimeout(() => {
    plc.writeTag('tag5', true, () => {
        console.log("Write operation completed.");
    });
}, 2000);

License

This project is licensed under the MIT License. See the LICENSE file for details.