modbus-serial
Advanced tools
Comparing version 5.2.6 to 5.2.7
@@ -7,3 +7,4 @@ /* eslint-disable no-console, spaced-comment */ | ||
var client = new ModbusRTU(); | ||
var timeoutRef = null; | ||
var timeoutRunRef = null; | ||
var timeoutConnectRef = null; | ||
@@ -17,5 +18,2 @@ var networkErrors = ["ESOCKETTIMEDOUT", "ETIMEDOUT", "ECONNRESET", "ECONNREFUSED"]; | ||
// stop reading loop | ||
clearTimeout(timeoutRef); | ||
// close port | ||
@@ -26,3 +24,3 @@ client.close(); | ||
client = new ModbusRTU(); | ||
setTimeout(connect, 3000); | ||
timeoutConnectRef = setTimeout(connect, 1000); | ||
} | ||
@@ -32,4 +30,12 @@ } | ||
// open connection to a serial port | ||
//client.connectRTU("/dev/ttyUSB0", {baudrate: 9600}) | ||
function connect() { | ||
// clear pending timeouts | ||
clearTimeout(timeoutConnectRef); | ||
// if client already open, just run | ||
if (client.isOpen()) { | ||
run(); | ||
} | ||
// if client closed, open a new connection | ||
client.connectTCP("127.0.0.1", { port: 8502 }) | ||
@@ -55,2 +61,5 @@ .then(setClient) | ||
function run() { | ||
// clear pending timeouts | ||
clearTimeout(timeoutRunRef); | ||
// read the 4 registers starting at address 5 | ||
@@ -60,6 +69,7 @@ client.readHoldingRegisters(5, 4) | ||
console.log("Receive:", d.data); }) | ||
.then(function() { | ||
timeoutRunRef = setTimeout(run, 1000); }) | ||
.catch(function(e) { | ||
checkError(e); | ||
console.log(e.message); }) | ||
.then(function() { timeoutRef = setTimeout(run, 1000); }); | ||
console.log(e.message); }); | ||
} | ||
@@ -66,0 +76,0 @@ |
@@ -11,4 +11,4 @@ /* eslint-disable no-console, spaced-comment */ | ||
// open connection to a serial port | ||
//client.connectRTU("/dev/ttyUSB0", {baudrate: 9600}) | ||
client.connectTCP("127.0.0.1", { port: 8502 }) | ||
client.connectRTU("/dev/ttyUSB0", { baudrate: 115200 }) | ||
//client.connectTCP("modbus.local", { port: 502 }) | ||
.then(setClient) | ||
@@ -32,6 +32,6 @@ .then(function() { | ||
// run program | ||
run(); | ||
readRegisters(); | ||
} | ||
function run() { | ||
function readRegisters() { | ||
// read the 4 registers starting at address 5 | ||
@@ -43,2 +43,12 @@ client.readHoldingRegisters(5, 4) | ||
console.log(e.message); }) | ||
.then(readCoils); | ||
} | ||
function readCoils() { | ||
// read the 4 registers starting at address 5 | ||
client.readCoils(1, 20) | ||
.then(function(d) { | ||
console.log("Receive:", d.data); }) | ||
.catch(function(e) { | ||
console.log(e.message); }) | ||
.then(close); | ||
@@ -45,0 +55,0 @@ } |
10
index.js
@@ -141,3 +141,5 @@ "use strict"; | ||
this._port.write(buffer); | ||
transaction._timeoutHandle = _startTimeout(this._timeout, transaction.next); | ||
if (transaction) { | ||
transaction._timeoutHandle = _startTimeout(this._timeout, transaction.next); | ||
} | ||
} | ||
@@ -220,4 +222,6 @@ | ||
/* cancel the timeout */ | ||
_cancelTimeout(transaction._timeoutHandle); | ||
transaction._timeoutHandle = undefined; | ||
if (transaction) { | ||
_cancelTimeout(transaction._timeoutHandle); | ||
transaction._timeoutHandle = undefined; | ||
} | ||
@@ -224,0 +228,0 @@ /* check incoming data |
{ | ||
"name": "modbus-serial", | ||
"version": "5.2.6", | ||
"version": "5.2.7", | ||
"description": "A pure JavaScript implemetation of MODBUS-RTU (Serial and TCP) for NodeJS.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
165029
4223