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.
npm i -S modbus-event// 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);
});return Function(options)
Main function of modbus-event
| 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 } | 
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);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) | 
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 | 
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 | 
MIT