modbus-serial
Advanced tools
Comparing version 7.2.0 to 7.2.1
@@ -26,3 +26,2 @@ "use strict"; | ||
var addConnctionAPI = function(Modbus) { | ||
var cl = Modbus.prototype; | ||
@@ -65,3 +64,3 @@ | ||
// check if we have options | ||
if (typeof(next) === "undefined" && typeof(options) === "function") { | ||
if (typeof next === "undefined" && typeof options === "function") { | ||
next = options; | ||
@@ -92,3 +91,3 @@ options = {}; | ||
// check if we have options | ||
if (typeof(next) === "undefined" && typeof(options) === "function") { | ||
if (typeof next === "undefined" && typeof options === "function") { | ||
next = options; | ||
@@ -100,2 +99,5 @@ options = {}; | ||
var TcpPort = require("../ports/tcpport"); | ||
if (this._timeout) { | ||
options.timeout = this._timeout; | ||
} | ||
this._port = new TcpPort(ip, options); | ||
@@ -116,3 +118,3 @@ | ||
// check if we have options | ||
if (typeof(next) === "undefined" && typeof(options) === "function") { | ||
if (typeof next === "undefined" && typeof options === "function") { | ||
next = options; | ||
@@ -123,3 +125,5 @@ options = {}; | ||
var TcpRTUBufferedPort = require("../ports/tcprtubufferedport"); | ||
if (this._timeout) { options.timeout = this._timeout; } | ||
if (this._timeout) { | ||
options.timeout = this._timeout; | ||
} | ||
this._port = new TcpRTUBufferedPort(ip, options); | ||
@@ -140,3 +144,3 @@ | ||
// check if we have options | ||
if (typeof(next) === "undefined" && typeof(options) === "function") { | ||
if (typeof next === "undefined" && typeof options === "function") { | ||
next = options; | ||
@@ -148,2 +152,5 @@ options = {}; | ||
var TelnetPort = require("../ports/telnetport"); | ||
if (this._timeout) { | ||
options.timeout = this._timeout; | ||
} | ||
this._port = new TelnetPort(ip, options); | ||
@@ -164,3 +171,3 @@ | ||
// check if we have options | ||
if (typeof(next) === "undefined" && typeof(options) === "function") { | ||
if (typeof next === "undefined" && typeof options === "function") { | ||
next = options; | ||
@@ -187,3 +194,3 @@ options = {}; | ||
// check if we have options | ||
if (typeof(next) === "undefined" && typeof(options) === "function") { | ||
if (typeof next === "undefined" && typeof options === "function") { | ||
next = options; | ||
@@ -213,3 +220,3 @@ options = {}; | ||
// check if we have options | ||
if (typeof(next) === "undefined" && typeof(options) === "function") { | ||
if (typeof next === "undefined" && typeof options === "function") { | ||
next = options; | ||
@@ -216,0 +223,0 @@ options = {}; |
{ | ||
"name": "modbus-serial", | ||
"version": "7.2.0", | ||
"version": "7.2.1", | ||
"description": "A pure JavaScript implemetation of MODBUS-RTU (Serial and TCP) for NodeJS.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -36,3 +36,3 @@ "use strict"; | ||
// options | ||
if (typeof(options) === "undefined") options = {}; | ||
if (typeof options === "undefined") options = {}; | ||
modbus.port = options.port || MODBUS_PORT; | ||
@@ -54,2 +54,3 @@ | ||
modbus._client = new net.Socket(); | ||
if (options.timeout) this._client.setTimeout(options.timeout); | ||
@@ -61,3 +62,7 @@ // register the port data event | ||
modbusSerialDebug({ action: "receive tcp rtu buffered port", data: data, buffer: modbus._buffer }); | ||
modbusSerialDebug({ | ||
action: "receive tcp rtu buffered port", | ||
data: data, | ||
buffer: modbus._buffer | ||
}); | ||
@@ -77,3 +82,3 @@ // check if buffer include a complete modbus answer | ||
// check data length | ||
if (bufferLength < (MIN_MBAP_LENGTH + EXCEPTION_LENGTH)) return; | ||
if (bufferLength < MIN_MBAP_LENGTH + EXCEPTION_LENGTH) return; | ||
@@ -88,12 +93,17 @@ // loop and check length-sized buffer chunks | ||
modbusSerialDebug( | ||
{ protocolID: protocolID, msgLength: msgLength, bufferLength: bufferLength, cmd: cmd }); | ||
modbusSerialDebug({ | ||
protocolID: protocolID, | ||
msgLength: msgLength, | ||
bufferLength: bufferLength, | ||
cmd: cmd | ||
}); | ||
if (protocolID === 0 && | ||
if ( | ||
protocolID === 0 && | ||
cmd !== 0 && | ||
msgLength >= EXCEPTION_LENGTH && | ||
(i + MIN_MBAP_LENGTH + msgLength) <= bufferLength) { | ||
i + MIN_MBAP_LENGTH + msgLength <= bufferLength | ||
) { | ||
// add crc and emit | ||
modbus._emitData((i + MIN_MBAP_LENGTH), msgLength); | ||
modbus._emitData(i + MIN_MBAP_LENGTH, msgLength); | ||
return; | ||
@@ -119,2 +129,8 @@ } | ||
this._client.on("timeout", function() { | ||
modbus.openFlag = false; | ||
modbusSerialDebug("TcpRTUBufferedPort port: TimedOut"); | ||
handleCallback(new Error("TcpRTUBufferedPort Connection Timed Out.")); | ||
}); | ||
/** | ||
@@ -161,3 +177,7 @@ * Check if port is open. | ||
// debug | ||
modbusSerialDebug({ action: "parsed tcp buffered port", buffer: buffer, transactionId: modbus._transactionIdRead }); | ||
modbusSerialDebug({ | ||
action: "parsed tcp buffered port", | ||
buffer: buffer, | ||
transactionId: modbus._transactionIdRead | ||
}); | ||
} else { | ||
@@ -195,3 +215,6 @@ modbusSerialDebug({ action: "emit data to short", data: data }); | ||
if (data.length < MIN_DATA_LENGTH) { | ||
modbusSerialDebug("expected length of data is to small - minimum is " + MIN_DATA_LENGTH); | ||
modbusSerialDebug( | ||
"expected length of data is to small - minimum is " + | ||
MIN_DATA_LENGTH | ||
); | ||
return; | ||
@@ -215,3 +238,4 @@ } | ||
// get next transaction id | ||
this._transactionIdWrite = (this._transactionIdWrite + 1) % MAX_TRANSACTIONS; | ||
this._transactionIdWrite = | ||
(this._transactionIdWrite + 1) % MAX_TRANSACTIONS; | ||
@@ -218,0 +242,0 @@ // send buffer to slave |
@@ -28,3 +28,3 @@ "use strict"; | ||
// options | ||
if (typeof(options) === "undefined") options = {}; | ||
if (typeof options === "undefined") options = {}; | ||
this.port = options.port || TELNET_PORT; // telnet server port | ||
@@ -49,2 +49,3 @@ | ||
this._client = new net.Socket(); | ||
if (options.timeout) this._client.setTimeout(options.timeout); | ||
@@ -59,6 +60,21 @@ // register the port data event | ||
var bufferLength = self._buffer.length; | ||
modbusSerialDebug("on data expected length:" + expectedLength + " buffer length:" + bufferLength); | ||
modbusSerialDebug( | ||
"on data expected length:" + | ||
expectedLength + | ||
" buffer length:" + | ||
bufferLength | ||
); | ||
modbusSerialDebug({ action: "receive tcp telnet port", data: data, buffer: self._buffer }); | ||
modbusSerialDebug(JSON.stringify({ action: "receive tcp telnet port strings", data: data, buffer: self._buffer })); | ||
modbusSerialDebug({ | ||
action: "receive tcp telnet port", | ||
data: data, | ||
buffer: self._buffer | ||
}); | ||
modbusSerialDebug( | ||
JSON.stringify({ | ||
action: "receive tcp telnet port strings", | ||
data: data, | ||
buffer: self._buffer | ||
}) | ||
); | ||
@@ -76,7 +92,13 @@ // check data length | ||
if (functionCode === self._cmd && i + expectedLength <= bufferLength) { | ||
if ( | ||
functionCode === self._cmd && | ||
i + expectedLength <= bufferLength | ||
) { | ||
self._emitData(i, expectedLength); | ||
return; | ||
} | ||
if (functionCode === (0x80 | self._cmd) && i + EXCEPTION_LENGTH <= bufferLength) { | ||
if ( | ||
functionCode === (0x80 | self._cmd) && | ||
i + EXCEPTION_LENGTH <= bufferLength | ||
) { | ||
self._emitData(i, EXCEPTION_LENGTH); | ||
@@ -106,2 +128,8 @@ return; | ||
this._client.on("timeout", function() { | ||
self.openFlag = false; | ||
modbusSerialDebug("TelnetPort port: TimedOut"); | ||
handleCallback(new Error("TelnetPort Connection Timed Out.")); | ||
}); | ||
/** | ||
@@ -166,4 +194,7 @@ * Check if port is open. | ||
TelnetPort.prototype.write = function(data) { | ||
if(data.length < MIN_DATA_LENGTH) { | ||
modbusSerialDebug("expected length of data is to small - minimum is " + MIN_DATA_LENGTH); | ||
if (data.length < MIN_DATA_LENGTH) { | ||
modbusSerialDebug( | ||
"expected length of data is to small - minimum is " + | ||
MIN_DATA_LENGTH | ||
); | ||
return; | ||
@@ -212,8 +243,10 @@ } | ||
modbusSerialDebug(JSON.stringify({ | ||
action: "send tcp telnet port strings", | ||
data: data, | ||
unitid: this._id, | ||
functionCode: this._cmd | ||
})); | ||
modbusSerialDebug( | ||
JSON.stringify({ | ||
action: "send tcp telnet port strings", | ||
data: data, | ||
unitid: this._id, | ||
functionCode: this._cmd | ||
}) | ||
); | ||
}; | ||
@@ -220,0 +253,0 @@ |
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
219313
5783