Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

modbus-serial

Package Overview
Dependencies
Maintainers
1
Versions
123
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

modbus-serial - npm Package Compare versions

Comparing version 4.3.0 to 4.4.2

3

apis/promise.js

@@ -70,4 +70,5 @@ 'use strict';

// set unitID
// set/get timeout
cl.setTimeout = function(timeout) {this._timeout = timeout;};
cl.getTimeout = function() {return this._timeout;};

@@ -74,0 +75,0 @@ // convert functions to return promises

@@ -7,37 +7,22 @@ // create an empty modbus client

// open connection to a tcp line
client.connectTCP("192.168.1.115");
client.connectTCP("192.168.1.115", run);
// the global last_connection time for the watchdog
var last_connection = new Date();
// read 8 read holding registers starting at register 10
// (function use the unit id 1, we set earlier)
function run() {
// set unit id
client.setID(1);
/* check time of last_connection and restart-reading if needed
*/
var watchdog = function() {
var time_diff = new Date() - last_connection;
if (time_diff > 1000) {
console.log('Oyyy ... we did not get data for 1 sec, will try again.');
run();
}
}
// set a timout for requests default is null (no timeout)
client.setTimeout(1000);
/* if last request was good - send a read request evry 0.5 sec
* and update last_connection
*/
var run = function() {
console.log('Send a request for input registers.');
client.readInputRegisters(0, 10, function(err, data) {
if (!err) {
console.log(data.data);
last_connection = new Date();
setTimeout(run, 500);
}
client.readHoldingRegisters(10, 8)
.then(function(data) {
// we got an answer before watchdog timeout
console.log(data);
})
.catch(function (err) {
// watchdog was trigered
console.log(err);
});
}
/* run the watchdog
*/
setInterval(function() {
watchdog();
}, 500);

@@ -30,2 +30,3 @@ declare namespace ModbusRTU {

setTimeout(duration: number): void;
getTimeout(): number;

@@ -32,0 +33,0 @@ readCoils(dataAddress: number, length: number): Promise<ReadCoilResult>;

{
"name": "modbus-serial",
"version": "4.3.0",
"version": "4.4.2",
"description": "A pure JavaScript implemetation of MODBUS-RTU (and TCP) for NodeJS.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -197,2 +197,5 @@ # modbus-serial

// set a timout for requests default is null (no timeout)
client.setTimeout(1000);
// read 8 discrete inputs starting at input 10

@@ -214,2 +217,20 @@ // (function use the unit id 1, we set earlier)

----
##### .getID()
Returns the unit id
----
##### .setTimeout(duration)
Sets a timeout for the request
*duration {number}:*
Duration of the timeout
----
##### .getTimeout()
Returns the timeout for the request
----
##### .readCoils (address, length)

@@ -322,2 +343,9 @@ Writes "Read Coils" (FC=1) request to serial port.

----
##### .close(callback)
Closes a modbus connection using the given serial port.
*callback {function}:* (optional)
Called when a connection has been closed.
----
##### .writeFC1 (unit, address, length, callback)

@@ -324,0 +352,0 @@ Writes "Read coil status" (FC=01) request to serial port.

@@ -28,3 +28,3 @@ 'use strict';

describe('#setID', function () {
it('should set a timeout on modubusRtu instance', function () {
it('should set a unit id on modubusRtu instance', function () {
var someId = 1;

@@ -37,3 +37,3 @@ modbusRTU.setID(someId);

describe('#getID', function () {
it('should set a timeout on modubusRtu instance', function () {
it('should return the unit id of modubusRtu instance', function () {
var someId = 1;

@@ -52,2 +52,9 @@ modbusRTU._unitID = someId;

});
describe('#getTimeout', function () {
it('should return the timeout of modubusRtu instance', function () {
modbusRTU._timeout = 1000;
expect(modbusRTU.getTimeout()).to.be.equal(modbusRTU._timeout)
});
});
});

@@ -357,3 +357,2 @@ 'use strict';

describe('Promise', function() {

@@ -365,3 +364,3 @@ it('should reject with error if timeout is hit', function (done) {

.then(function () {
done(new Error('Failed should timeout'));
done(new Error('Call should timeout'));
})

@@ -368,0 +367,0 @@ .catch(function (err) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc