[go: nahoru, domu]

modbus-event

2.1.0 • Public • Published

modbus-event

Modbus-event is a TCP/IP Master, event-driven, implementation for modbus protocol. This package was built upon the great modbus-serial. Make sure to read the methods section to get the best out this module.

Installation

npm i -S modbus-event

Usage

// Require library
var modbusEvent = require('modbus-event');
// Set constructor options
var options = {
    debug : true, // default: false
    ip : '192.168.1.1', // default: '127.0.0.1'
    port : 777, // default: 502
    id : 2 // default: 1
};
var me = modbusEvent(options);
 
// Executes some function in between the reading stage
me.run(function(client, datas, next){
    client.writeCoil(1, 1).then(next);
});
 
// Assign a listener event
me.on('update', function(type, address, newValue, oldValue){
    console.log(type, address, newValue, oldValue);
});

Reference

require('modbus-event')

return Function(options)

Main function of modbus-event

Constructor argument: Options

key description type default
debug Enable verbosity for debuggin (very handy) boolean false
ip The listenning IP of your Slave Modbus string '127.0.0.1'
port The listenning port of yout Slave Modbus number 502
id The SlaveID of your Slave Modbus number 1
address Reading address range Object { init : initial address, length : address range } { init : 0, length : 10 }
Sample:
var options = {
    debug : true, // default: false
    ip : '192.168.1.1', // default: '127.0.0.1'
    port : 777, // default: 502
    id : 2 // default: 1
};
var me = modbusEvent(options);

require('modbus-event')(options)

return Object { run : fn, on : fn }

The constructor of modbus-event. Return the following functions:

key value
run function(client, data, next)
on function(event, callback)

require('modbus-event')(options)#run

type Function(client, data, next)

Executes arbitrary code when the serial channel is available. The function arguments are:

argument description
client an instance of modbus-serial
data object containing all addresses and values
next a function that you need to invoke when done

require('modbus-event')(options)#on

type Function(event, callback)

Assign an event and the respective callback. This are the available events:

update function(type, address, newValue, oldValue)
triggers when any register is changed type is the address indentifier ('coils', 'inputStatus', 'holdingReg', 'inputReg')
  address is the changed address in the moment
  newValue is the value before the update
  oldValue is the value after the update

Dependencies

modbus-serial

Contact-me

License

MIT

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.1.03latest

Version History

VersionDownloads (Last 7 Days)Published
2.1.03
2.0.32
2.0.22
2.0.12
2.0.03
1.2.23
1.2.12
1.1.92
1.1.82
1.1.72
1.1.62
1.1.52
1.1.42
1.1.32
1.1.22
1.1.12
1.1.02
1.0.102
1.0.92
1.0.82
1.0.72
1.0.62
1.0.52
1.0.42
1.0.32
1.0.22
1.0.12
1.0.02

Package Sidebar

Install

npm i modbus-event

Weekly Downloads

0

Version

2.1.0

License

MIT

Last publish

Collaborators

  • gsplitter
  • raphaelbs