ngocauto_siemensplc
v1.2.8
Published
This is package by Ngoc automation
Downloads
37
Readme
ngocauto_siemensplc
ngocauto_siemensplc is a library allows to connect with Siemens PLCs include S7-300, S7-400, S7-1200 and S7-1500
This software using for ngocautomation community platform Support: (Zalo VietNam) +84904701605, g_mail: [email protected]
How to Installation
Using npm to install:
- Step 1: install nodes7
npm i nodes7
- Step 2: install ngocauto siemens plc
npm i ngocauto_siemensplc
- Step 3: install loadash
npm i lodash
How to use
- Read data: The readed data will store in the Variable save PLC tags value - plc_tag
- Note 1: PLC need to enable PUT/GET function to connect
- Note 2: if you want to connect with DB (datablock), it need to disable "Optimized block access" function (Right click on the DB block > Attributes > Optimized block access )
/////////////////////////////////////////////////////////////////////////
// CONNECT REPORT SERVER TO PLC //
/////////////////////////////////////////////////////////////////////////
// 1. PLC parameter setting
var PLC_IP = '192.168.0.1'; // PLC IP address
var Slot_ID = 1; // S71200/1500 = 1, S7300/400 = 2
var scanTime = 1; // Scan time (second)
var plc_tag = ""; // Variable save PLC tags value
var tagval_show = true; // Show tag value (true = yes, false = no)
//2. PLC tag defined
var config_tag = {
Q_Valve1: 'M10.0',
Product_Count: 'MW100',
Flow_In: 'MR102',
};
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//3. System code (Fixed for all project)
var s7plc = require('ngocauto_siemensplc/ngocauto_siemensplc.js');
s7plc.val_Setup(PLC_IP, Slot_ID, config_tag, tagval_show);
s7plc.para_Load();
setInterval(() => plc_tag = s7plc.tag_read(),scanTime*1000);
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Exampla with Data Block tag (DB)
/////////////////////////////////////////////////////////////////////////
// CONNECT REPORT SERVER TO PLC //
/////////////////////////////////////////////////////////////////////////
// 1. PLC parameter setting
var PLC_IP = '192.168.0.1'; // PLC IP address
var Slot_ID = 1; // S71200/1500 = 1, S7300/400 = 2
var scanTime = 1; // Scan time (second)
var plc_tag = ""; // Variable save PLC tags value
var tagval_show = true; // Show tag value (true = yes, false = no)
//2. PLC tag defined
var config_tag = {
Q_Valve1: 'DB1,X0.0', // tag bool
Q_Valve2: 'DB1,X0.1', // tag bit
Product_Count: 'DB1,INT2', // tag integer
Flow_In: 'DB1,REAL4', // tag Real
Flow_Total: 'DB1,DINT8', // tag double integer
Tank_Level: 'DB1,REAL12' // tag real
};
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//3. System code (Fixed for all project)
var s7plc = require('nodes7/ngocautores/s7plc.js');
s7plc.val_Setup(PLC_IP, Slot_ID, config_tag, tagval_show);
s7plc.para_Load();
setInterval(() => plc_tag = s7plc.tag_read(),scanTime*1000);
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Write tag value to PLC
- in this Example - function write value 456 to tag name 'Procduct_Count'
- Note: Tag Product_Count need to define first (at config_tag)
// Write data to PLC by tag name
var s7plc_write = require('ngocauto_siemensplc/ngocauto_siemensplc.js');
s7plc_write.nat_tag_Write('Product_Count',456);
Write multipe tags to PLC
- in this Example - function write 3 tag ('Q_Valve1', 'Product_Count', 'Flow_In') with 3 value (true, 123, 456.78) as array
- Note: Tag Product_Count need to define first (at config_tag)
// Write data to PLC by tag array
var s7plc_write = require('ngocauto_siemensplc/ngocauto_siemensplc.js');
// Tag name and tag value define
var tag_name = ['Q_Valve1', 'Product_Count', 'Flow_In']
var tag_val = [true, 123, 456.78]
s7plc_write.nat_tag_Write(tag_name,tag_val);
Addressing Examples:
- M10.0 - Bit M10.0
- Q0.0 - Bit Q0.0
- MR30 - MD30 as REAL
- MW100 - MW30 as integer
- 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