modbus-serial
Advanced tools
Comparing version 3.4.5 to 3.4.6
{ | ||
"name": "modbus-serial", | ||
"version": "3.4.5", | ||
"version": "3.4.6", | ||
"description": "A pure JavaScript implemetation of MODBUS-RTU (and TCP) for NodeJS.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -18,3 +18,3 @@ 'use strict'; | ||
var tmp; | ||
// calculate crc16 | ||
@@ -32,3 +32,3 @@ for (var i = 0; i < length; i++) { | ||
} | ||
return crc; | ||
@@ -49,3 +49,3 @@ } | ||
var crcIn = buf.readUInt16LE(buf.length - 2); | ||
// check buffer unit-id, command and crc | ||
@@ -63,10 +63,10 @@ return (buf[0] == modbus._id && | ||
this.ip = ip; | ||
// options | ||
if (typeof(options) == 'undefined') options = {}; | ||
this.port = options.port || C701_PORT; // C701 port | ||
// create a socket | ||
this._client = dgram.createSocket("udp4"); | ||
// wait for answer | ||
@@ -76,12 +76,12 @@ this._client.on('message', function(data) { | ||
if (modbus.length < 6) return; | ||
// check message length | ||
if (data.length < (116 + modbus.length)) return; | ||
// check the C701 packet magic | ||
if (data.readUInt16LE(2) != 602) return; | ||
// get the serial data from the C701 packet | ||
var buffer = data.slice(data.length - modbus._length); | ||
//check the serial data | ||
@@ -123,7 +123,7 @@ if (checkData(modbus, buffer)) { | ||
} | ||
// remember current unit and command | ||
this._id = data[0]; | ||
this._cmd = data[1]; | ||
// calculate expected answer length | ||
@@ -142,2 +142,3 @@ switch (this._cmd) { | ||
case 5: | ||
case 6: | ||
case 16: | ||
@@ -151,3 +152,3 @@ this._length = 6 + 2; | ||
} | ||
// build C701 header | ||
@@ -161,6 +162,6 @@ var buffer = new Buffer(data.length + 116); | ||
buffer.writeUInt16LE(data.length, 104); // serial data length | ||
// add serial line data | ||
data.copy(buffer, 116); | ||
// send buffer to C701 UDP to serial bridge | ||
@@ -167,0 +168,0 @@ this._client.send(buffer, 0, buffer.length, this.port, this.ip); |
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
1741
77861