2.0.1 • Published 4 months ago
ngocauto_kepware v2.0.1
ngocauto_kepware
ngocauto_kepware is a library allows to connect with All PLCs to nodejs with Kepware OPC
This software using for ngocautomation community platform Support: (Zalo VietNam) +84904701605, g_mail: ngocautomation.info@gmail.com
How to Installation
Using npm to install:
- Step 1: install kepware package
npm install kepserverex-js
- Step 2: install ngocauto kepware module
npm i ngocauto_kepware
- 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: in the Example channel_name is Channel and device in kepware
/////////////////////////////////////////////////////////////////////////
// CONNECT REPORT SERVER TO PLC //
/////////////////////////////////////////////////////////////////////////
// 1. PLC parameter setting
var channel_name = 'Channel1.Device1'; // Channel and device in kepware
var host_IP = '127.0.0.1'; // Host IP, here using localhost
var port_ID = 5000; // Port of IoT gateway server in kepware
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 = {
tag_Bool : 'tag_Bool',
tag_Integer : 'tag_Integer',
tag_Real : 'tag_Real',
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//3. System code (Fixed for all project)
var plckepware = require('ngocauto_kepware/ngocauto_kepware.js');
plckepware.val_Setup(channel_name, host_IP,port_ID, config_tag, tagval_show);
plckepware.para_Load();
setInterval(() => plc_tag = plckepware.tagRead(),scanTime*1000);
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Write value "true" to tag name "tag_Bool" with time out 3s
setTimeout(() => {
plckepware.fn_Data_Write('tag_Bool',true);
}, 3000);
Write tag value to PLC
- in this Example - function write value true to tag name 'tag_Bool'
- Note: Tag tag_Bool need to define first (at config_tag)
plckepware.fn_Data_Write('tag_Bool',true);