node-modbus
Advanced tools
Comparing version 3.1.2 to 3.2.0
@@ -18,3 +18,4 @@ /** | ||
this.log.debug('handling read coils response.') | ||
this.log.debug('on read coils got PDU: ' + JSON.stringify(pdu) + ' request: ' + JSON.stringify(request)) | ||
this.log.debug('on read coils got PDU: ' + JSON.stringify(pdu) + ' pdu.length:' + pdu.length) | ||
this.log.debug(' request: ' + JSON.stringify(request)) | ||
@@ -21,0 +22,0 @@ if (pdu.length < 2) { |
@@ -18,3 +18,4 @@ /** | ||
this.log.debug('handling read discrete inputs response.') | ||
this.log.debug('on read discrete inputs got PDU: ' + JSON.stringify(pdu) + ' request: ' + JSON.stringify(request)) | ||
this.log.debug('on read discrete inputs got PDU: ' + JSON.stringify(pdu) + ' pdu.length:' + pdu.length) | ||
this.log.debug('request: ' + JSON.stringify(request)) | ||
@@ -27,5 +28,9 @@ if (pdu.length < 2) { | ||
let fc = pdu.readUInt8(0) | ||
if (fc !== 2) { | ||
request.defer.reject() | ||
return | ||
} | ||
let byteCount = pdu.readUInt8(1) | ||
let cntr = 0 | ||
let resp = { | ||
@@ -38,7 +43,2 @@ fc: fc, | ||
if (fc !== 2) { | ||
request.defer.reject() | ||
return | ||
} | ||
let h = 1 | ||
@@ -45,0 +45,0 @@ let cur = 0 |
@@ -18,2 +18,4 @@ /** | ||
this.log.debug('handling read holding registers response.') | ||
this.log.debug('on read holding registers got PDU: ' + JSON.stringify(pdu) + ' pdu.length:' + pdu.length) | ||
this.log.debug('request: ' + JSON.stringify(request)) | ||
@@ -26,4 +28,8 @@ if (pdu.length < 2) { | ||
let fc = pdu.readUInt8(0) | ||
if (fc !== 3) { | ||
request.defer.reject() | ||
return | ||
} | ||
let byteCount = pdu.readUInt8(1) | ||
let resp = { | ||
@@ -36,7 +42,2 @@ fc: fc, | ||
if (fc !== 3) { | ||
request.defer.reject() | ||
return | ||
} | ||
let registerCount = byteCount / 2 | ||
@@ -43,0 +44,0 @@ |
@@ -18,5 +18,5 @@ /** | ||
this.log.debug('handling read input registers response.') | ||
this.log.debug('on read input registers got PDU: ' + JSON.stringify(pdu) + ' pdu.length:' + pdu.length) | ||
this.log.debug('request: ' + JSON.stringify(request)) | ||
this.log.debug('on read input registers got PDU: ' + JSON.stringify(pdu) + ' request: ' + JSON.stringify(request)) | ||
if (pdu.length < 2) { | ||
@@ -28,4 +28,8 @@ request.defer.reject() | ||
let fc = pdu.readUInt8(0) | ||
if (fc !== 4) { | ||
request.defer.reject() | ||
return | ||
} | ||
let byteCount = pdu.readUInt8(1) | ||
let resp = { | ||
@@ -38,7 +42,2 @@ fc: fc, | ||
if (fc !== 4) { | ||
request.defer.reject() | ||
return | ||
} | ||
let registerCount = byteCount / 2 | ||
@@ -45,0 +44,0 @@ |
@@ -18,5 +18,5 @@ /** | ||
this.log.debug('handling multiple coils response.') | ||
this.log.debug('on write multiple coils got PDU: ' + JSON.stringify(pdu) + ' pdu.length:' + pdu.length) | ||
this.log.debug('request: ' + JSON.stringify(request)) | ||
this.log.debug('on write multiple coils got PDU: ' + JSON.stringify(pdu) + ' request: ' + JSON.stringify(request)) | ||
if (pdu.length < 5) { | ||
@@ -28,5 +28,9 @@ request.defer.reject() | ||
let fc = pdu.readUInt8(0) | ||
if (fc !== 15) { | ||
request.defer.reject() | ||
return | ||
} | ||
let startAddress = pdu.readUInt16BE(1) | ||
let quantity = pdu.readUInt16BE(3) | ||
let resp = { | ||
@@ -38,7 +42,2 @@ fc: fc, | ||
if (fc !== 15) { | ||
request.defer.reject() | ||
return | ||
} | ||
request.defer.resolve(resp) | ||
@@ -45,0 +44,0 @@ }.bind(this) |
@@ -18,5 +18,5 @@ /** | ||
this.log.debug('handling multiple registers response.') | ||
this.log.debug('on write multiple registers got PDU: ' + JSON.stringify(pdu) + ' pdu.length:' + pdu.length) | ||
this.log.debug('request: ' + JSON.stringify(request)) | ||
this.log.debug('on write multiple registers got PDU: ' + JSON.stringify(pdu) + ' request: ' + JSON.stringify(request)) | ||
if (pdu.length < 5) { | ||
@@ -28,5 +28,9 @@ request.defer.reject() | ||
let fc = pdu.readUInt8(0) | ||
if (fc !== 16) { | ||
request.defer.reject() | ||
return | ||
} | ||
let startAddress = pdu.readUInt16BE(1) | ||
let quantity = pdu.readUInt16BE(3) | ||
let resp = { | ||
@@ -38,7 +42,2 @@ fc: fc, | ||
if (fc !== 16) { | ||
request.defer.reject() | ||
return | ||
} | ||
request.defer.resolve(resp) | ||
@@ -45,0 +44,0 @@ }.bind(this) |
@@ -18,5 +18,5 @@ /** | ||
this.log.debug('handling write single coil response.') | ||
this.log.debug('on write single coil got PDU: ' + JSON.stringify(pdu) + ' pdu.length:' + pdu.length) | ||
this.log.debug('request: ' + JSON.stringify(request)) | ||
this.log.debug('on write single coil got PDU: ' + JSON.stringify(pdu) + ' request: ' + JSON.stringify(request)) | ||
if (pdu.length < 5) { | ||
@@ -28,5 +28,9 @@ request.defer.reject() | ||
let fc = pdu.readUInt8(0) | ||
if (fc !== 5) { | ||
request.defer.reject() | ||
return | ||
} | ||
let outputAddress = pdu.readUInt16BE(1) | ||
let outputValue = pdu.readUInt16BE(3) | ||
let resp = { | ||
@@ -38,7 +42,2 @@ fc: fc, | ||
if (fc !== 5) { | ||
request.defer.reject() | ||
return | ||
} | ||
request.defer.resolve(resp) | ||
@@ -45,0 +44,0 @@ }.bind(this) |
@@ -18,5 +18,5 @@ /** | ||
this.log.debug('handling write single register response.') | ||
this.log.debug('on write single register got PDU: ' + JSON.stringify(pdu) + ' pdu.length:' + pdu.length) | ||
this.log.debug('request: ' + JSON.stringify(request)) | ||
this.log.debug('on write single register got PDU: ' + JSON.stringify(pdu) + ' request: ' + JSON.stringify(request)) | ||
if (pdu.length < 5) { | ||
@@ -28,5 +28,9 @@ request.defer.reject() | ||
let fc = pdu.readUInt8(0) | ||
if (fc !== 6) { | ||
request.defer.reject() | ||
return | ||
} | ||
let registerAddress = pdu.readUInt16BE(1) | ||
let registerValue = pdu.readUInt16BE(3) | ||
let resp = { | ||
@@ -39,8 +43,2 @@ fc: fc, | ||
} | ||
if (fc !== 6) { | ||
request.defer.reject() | ||
return | ||
} | ||
request.defer.resolve(resp) | ||
@@ -59,3 +57,3 @@ }.bind(this) | ||
this.queueRequest(fc, pdu, { resolve: resolve, reject: reject }) | ||
this.queueRequest(fc, pdu, {resolve: resolve, reject: reject}) | ||
}.bind(this)) | ||
@@ -62,0 +60,0 @@ } |
@@ -133,4 +133,2 @@ /** | ||
let onData = function (pdu) { | ||
this.log.debug('received data PDU: ' + JSON.stringify(pdu)) | ||
if (!currentRequest) { | ||
@@ -140,4 +138,4 @@ this.log.debug('No current request.') | ||
} | ||
clearTimeout(currentRequest.timeout) | ||
this.log.debug('received data and clean timeout PDU: ' + JSON.stringify(pdu)) | ||
@@ -144,0 +142,0 @@ // check pdu for error |
@@ -17,3 +17,3 @@ /** | ||
let SerialPort = require('serialport') | ||
let crc = require('crc') | ||
let crc = require('js-crc') | ||
let serialport | ||
@@ -24,2 +24,4 @@ let timerID | ||
let expectedBytes = 0 | ||
let crcBytes = 2 | ||
let minLength = 0x80 | ||
let exeptionMessageLength = 5 | ||
@@ -117,3 +119,3 @@ | ||
if (pdu.length !== 0) { // at least one byte has been received | ||
this.log.debug('received data ' + JSON.stringify(pdu)) | ||
this.log.debug('received serial data ' + JSON.stringify(pdu)) | ||
@@ -126,5 +128,6 @@ if ((pdu.length + receivedBytes) <= receiveBuffer.length) { | ||
if (receivedBytes === exeptionMessageLength) { | ||
if (receiveBuffer[1] >= 0x80 && | ||
if (receiveBuffer[1] >= minLength && | ||
crc.crc16modbus(receiveBuffer.slice(0, receivedBytes)) === 0) { | ||
this.emit('data', receiveBuffer.slice(1, receivedBytes - 1)) | ||
this.emit('data', receiveBuffer.slice(1, receivedBytes - crcBytes)) | ||
receivedBytes = 0 | ||
} | ||
@@ -135,3 +138,4 @@ } else { | ||
if (crc.crc16modbus(receiveBuffer.slice(0, receivedBytes)) === 0) { | ||
this.emit('data', receiveBuffer.slice(1, receivedBytes - 1)) | ||
this.emit('data', receiveBuffer.slice(1, receivedBytes - crcBytes)) | ||
receivedBytes = 0 | ||
} | ||
@@ -150,4 +154,3 @@ } else { | ||
} else { | ||
this.log.debug('received bytes to lessfor use: ' + receivedBytes) | ||
this.emit('data', pdu) | ||
this.log.debug('received bytes to less to do more -> receivedBytes: ' + receivedBytes) | ||
} | ||
@@ -169,7 +172,11 @@ } else { | ||
let buf = Buffer.concat([base, pdu]) | ||
let crc16 = crc.crc16modbus(buf) | ||
let crc16 = crc.crc16(buf) | ||
let crcBuf = Buffer.allocUnsafe(2) | ||
crcBuf.writeUInt16LE(crc16, 0) | ||
let bufWithCRC = Buffer.concat([buf, crcBuf]) | ||
this.log.debug('buffer: ' + buf + ' crc16: ' + crc16) | ||
let bufWithCRC = Buffer.concat([buf, crc16]) | ||
this.log.debug('PDU in Endian-Type: ' + this.endianType + | ||
@@ -201,3 +208,3 @@ ' and LITTLE-ENDIAN CRC via ' + this.connectionType + ' : ' + JSON.stringify(bufWithCRC)) | ||
default: | ||
expectedBytes = 0 | ||
break | ||
@@ -204,0 +211,0 @@ } |
{ | ||
"name": "node-modbus", | ||
"version": "3.1.2", | ||
"version": "3.2.0", | ||
"tag": "3.2.0-alpha-1", | ||
"description": "Sum of implementations for the Serial/TCP Modbus protocol.", | ||
@@ -19,3 +20,3 @@ "author": "Klaus Landsdorf <klaus.landsdorf@bianco-royal.de>", | ||
"bluebird": "^3.4.6", | ||
"crc": "^3.4.4", | ||
"js-crc": "^0.1.0", | ||
"net": "^1.0.2", | ||
@@ -22,0 +23,0 @@ "serialport": "^4.0.7", |
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
85712
1703
+ Addedjs-crc@^0.1.0
+ Addedjs-crc@0.1.0(transitive)
- Removedcrc@^3.4.4
- Removedbase64-js@1.5.1(transitive)
- Removedbuffer@5.7.1(transitive)
- Removedcrc@3.8.0(transitive)
- Removedieee754@1.2.1(transitive)