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 libraryvar modbusEvent = ;// Set constructor optionsvar 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 = ; // Executes some function in between the reading stageme; // Assign a listener eventme;
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 = ;
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
Contact-me
License
MIT