What's new
ES6 and old Node support
This release mainly bring more internal changes. A lot of internal code was refactored. Project was refactored with ES6, and transpiled to ES5 with babel. But i decided to drop support of legacy Node versions, so minimal required version of node is 5.
Got rid of timeouts
I finally got rid of this weird timeouts such as endPacketTimeout
and queueTimeout
. Now end of packet determines by predicted length of the packet, and some other assumptions. This works much faster and this approach much cleaner for end-user.
SerialPort as peerDependency
SerialPort now is peerDependency
. It means now you can choose any version you want. And you have to install it by yourself.
I tested this lib with SerialPort
2, 3, 4 and even 5 version, all works fine. But be careful, they have differences in option keys if you decided to upgrade.
Migration
Some of internal refactorings reflect to external api as well, here guide how to upgrade.
require('modbus-rtu')
exportsModbusMaster
instead ofMaster
// old
var modbus = require('modbus-rtu');
var master = new modbus.Master(serialPort);
// new
var ModbusMaster = require('modbus-rtu').ModbusMaster;
var master = new ModbusMaster(serialPort);
DATA_TYPES
now exports directly from packet:
// old
var modbus = require('modbus-rtu');
var master = new modbus.Master(serialPort);
master.readHoldingRegisters(1, 0, 4, modbus.Master.DATA_TYPES.UINT).then((data) => {
console.log(data);
});
// new, using ES6 Destructuring Syntax
const { ModbusMaster, DATA_TYPES } = require('modbus-rtu');
const master = new ModbusMaster(serialPort);
master.readHoldingRegisters(1, 0, 4, DATA_TYPES.UINT).then((data) => {
console.log(data);
});
- Error constructors stored in another place
Previously errors constructors could be obtained by requiringrequire('./modbus-rtu/errors')
, no they can be obtained by this pathrequire('./modbus-rtu/lib/errors')
.
Also exports was changed, now exported name equals to Error constructor name:
require('./modbus-rtu/errors').crc; -> require('./modbus-rtu/lib/errors').ModbusCrcError;
require('./modbus-rtu/errors').retryLimit; -> require('./modbus-rtu/lib/errors').ModbusRetryLimitExceed;
-
ModbusResponseTimeout error instead Bluebird timeout error.
In this version, if request exceed time limit, promise will be rejected withModbusResponseTimeout
from./modbus-rtu/lib/errors
instead of Bluebird error as in previous release. -
Accessing
/modbus-rtu/constants
directly is impossible. Use constructor options instead.