2.1.0 • Published 7 years ago

modbus-event v2.1.0

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

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

keydescriptiontypedefault
debugEnable verbosity for debuggin (very handy)booleanfalse
ipThe listenning IP of your Slave Modbusstring'127.0.0.1'
portThe listenning port of yout Slave Modbusnumber502
idThe SlaveID of your Slave Modbusnumber1
addressReading address rangeObject { 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:

keyvalue
runfunction(client, data, next)
onfunction(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:

argumentdescription
clientan instance of modbus-serial
dataobject containing all addresses and values
nexta 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:

updatefunction(type, address, newValue, oldValue)
triggers when any register is changedtype 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

2.1.0

7 years ago

2.0.3

7 years ago

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.2.2

8 years ago

1.2.1

8 years ago

1.1.9

8 years ago

1.1.8

8 years ago

1.1.7

8 years ago

1.1.6

8 years ago

1.1.5

8 years ago

1.1.4

8 years ago

1.1.3

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.10

8 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago