i6-driver-modbus
v1.0.3-beta.5
Published
Modbus driver for i6
Downloads
4
Maintainers
Readme
i6-driver-modbus
Merupakan driver modbus TCP untuk i6. Dikembangkan dari node-modbus.
Install
$ npm install --save i6-driver-modbus
Contoh Pengunaan
Buat file tags.js yang berisi address list :
module.exports = [{
"name": "A",
"address": 40100,
"eu": "MT/Hrs",
"description": "",
"hi": "",
"lo": "",
"type": "real"
},
{
"name": "B",
"address": 40102,
"eu": "C",
"description": "",
"hi": 120,
"lo": 90,
"type": "real"
},
{
"name": "C",
"address": 40104,
"eu": "Toor",
"description": "",
"hi": 200,
"lo": "",
"type": "real"
},
{
"name": "3A",
"address": 30000,
"eu": "Toor",
"description": "",
"hi": 200,
"lo": "",
"type": "real"
},
{
"name": "3B",
"address": 30002,
"eu": "Toor",
"description": "",
"hi": 200,
"lo": "",
"type": "real"
},
{
"name": "3C",
"address": 30012,
"eu": "Toor",
"description": "",
"hi": 200,
"lo": "",
"type": "real"
},
]
Buat konfigurasi device pada file devices.js
module.exports = {
PLC1: {
name: 'PLC1',
host: '192.168.1.1',
update_interval: 500,
base_address: 0,
swap_byte: true
},
PLC2: {
name: 'PLC2',
host: '192.168.1.2',
update_interval: 500,
base_address: 0,
swap_byte: true
}
}
Kemudian, buat file utama dengan nama app.js
var modbus = require('i6-driver-modbus.');
var _ = require('lodash');
// Berisi tags / address list
var tags = require('./tags.js');
// Berisi konfigurasi device
var devices = require('./devices');
devices.PLC1.tags = tags;
devices.PLC2.tags = tags;
var PLC1 = new modbus(devices.PLC1);
var PLC2 = new modbus(devices.PLC2);
PLC1.on(PLC1.events.valueUpdate, (payload)=>{
_.each(payload.tags, function(tag){
console.log(tag.name + ' : ' + tag.value);
});
});
PLC2.on(PLC2.events.valueUpdate, (payload)=>{
_.each(payload.tags, function(tag){
console.log(tag.name + ' : ' + tag.value);
});
});