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.4.2 to 4.4.3

examples/talnet.py

125

index.js

@@ -127,4 +127,6 @@ 'use strict';

function _writeBufferToPort(buffer) {
var transaction = this._transactions[this._transactionId]
this._port.write(buffer);
this._timeoutHandle = _startTimeout(this._timeout, this._next);
transaction._timeoutHandle = _startTimeout(this._timeout, transaction.next);
}

@@ -170,9 +172,6 @@

// state variables
this._nextAddress = null; // unit address of current function call.
this._nextCode = null; // function code of current function call.
this._nextLength = 0; // number of bytes in current answer.
this._next = null; // the function to call on success or failure
this._transactions = {};
this._transactionId = 1;
this._timeout = null; // timeout in msec before unanswered request throws timeout error
this._timeoutHandle = null; // timeoutHandle to cancel active timeouts

@@ -211,8 +210,7 @@ this._unitID = 1;

// set locale helpers variables
var length = modbus._nextLength;
var next = modbus._next;
var transaction = modbus._transactions[modbus._transactionId];
/* cancel the timeout */
_cancelTimeout(modbus._timeoutHandle);
modbus._timeoutHandle = undefined;
_cancelTimeout(transaction._timeoutHandle);
transaction._timeoutHandle = undefined;

@@ -226,5 +224,5 @@ /* check incoming data

error = "Data length error, expected " +
length + " got " + data.length;
if (next)
next(error);
transaction.nextLength + " got " + data.length;
if (transaction.next)
transaction.next(error);
return;

@@ -239,4 +237,4 @@ }

error = "CRC error";
if (next)
next(error);
if (transaction.next)
transaction.next(error);
return;

@@ -252,6 +250,6 @@ }

if (data.length == 5 &&
code == (0x80 | modbus._nextCode)) {
code == (0x80 | transaction.nextCode)) {
error = "Modbus exception " + data.readUInt8(2);
if (next)
next(error);
if (transaction.next)
transaction.next(error);
return;

@@ -264,7 +262,7 @@ }

*/
if (data.length != length) {
if (data.length != transaction.nextLength) {
error = "Data length error, expected " +
length + " got " + data.length;
if (next)
next(error);
transaction.nextLength + " got " + data.length;
if (transaction.next)
transaction.next(error);
return;

@@ -277,15 +275,10 @@ }

*/
if (address != modbus._nextAddress || code != modbus._nextCode) {
if (address != transaction.nextAddress || code != transaction.nextCode) {
error = "Unexpected data error, expected " +
modbus._nextAddress + " got " + address;
if (next)
next(error);
transaction.nextAddress + " got " + address;
if (transaction.next)
transaction.next(error);
return;
}
// data is OK - clear state variables
modbus._nextAddress = null;
modbus._nextCode = null;
modbus._next = null;
/* parse incoming data

@@ -299,3 +292,3 @@ */

// Read Input Status (FC=02)
_readFC2(data, next);
_readFC2(data, transaction.next);
break;

@@ -306,11 +299,11 @@ case 3:

// Read Holding Registers (FC=03)
_readFC4(data, next);
_readFC4(data, transaction.next);
break;
case 5:
// Force Single Coil
_readFC5(data, next);
_readFC5(data, transaction.next);
break;
case 6:
// Preset Single Register
_readFC6(data, next);
_readFC6(data, transaction.next);
break;

@@ -321,3 +314,3 @@ case 15:

// Preset Multiple Registers
_readFC16(data, next);
_readFC16(data, transaction.next);
break;

@@ -374,6 +367,8 @@ }

// set state variables
this._nextAddress = address;
this._nextCode = code;
this._nextLength = 3 + parseInt((length - 1) / 8 + 1) + 2;
this._next = next;
this._transactions[this._transactionId] = {
nextAddress: address,
nextCode: code,
nextLength: 3 + parseInt((length - 1) / 8 + 1) + 2,
next: next
};

@@ -427,6 +422,8 @@ var codeLength = 6;

// set state variables
this._nextAddress = address;
this._nextCode = code;
this._nextLength = 3 + 2 * length + 2;
this._next = next;
this._transactions[this._transactionId] = {
nextAddress: address,
nextCode: code,
nextLength: 3 + 2 * length + 2,
next: next
};

@@ -467,6 +464,8 @@ var codeLength = 6;

// set state variables
this._nextAddress = address;
this._nextCode = code;
this._nextLength = 8;
this._next = next;
this._transactions[this._transactionId] = {
nextAddress: address,
nextCode: code,
nextLength: 8,
next: next
};

@@ -512,6 +511,8 @@ var codeLength = 6;

// set state variables
this._nextAddress = address;
this._nextCode = code;
this._nextLength = 8;
this._next = next;
this._transactions[this._transactionId] = {
nextAddress: address,
nextCode: code,
nextLength: 8,
next: next
};

@@ -553,6 +554,8 @@ var codeLength = 6; // 1B deviceAddress + 1B functionCode + 2B dataAddress + 2B value

// set state variables
this._nextAddress = address;
this._nextCode = code;
this._nextLength = 8;
this._next = next;
this._transactions[this._transactionId] = {
nextAddress: address,
nextCode: code,
nextLength: 8,
next: next
};

@@ -608,6 +611,8 @@ var dataBytes = Math.ceil(array.length / 8);

// set state variables
this._nextAddress = address;
this._nextCode = code;
this._nextLength = 8;
this._next = next;
this._transactions[this._transactionId] = {
nextAddress: address,
nextCode: code,
nextLength: 8,
next: next
};

@@ -614,0 +619,0 @@ var codeLength = 7 + 2 * array.length;

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

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

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

var MODBUS_PORT = 502; // modbus port
var MAX_TRANSACTIONS = 64; // maximum transaction to wait for

@@ -49,2 +50,5 @@ /**

// update transaction id
modbus._transactionId = data.readUInt16BE(0)
// emit a data signal

@@ -100,5 +104,8 @@ modbus.emit('data', buffer);

TcpPort.prototype.write = function (data) {
// get next transaction id
var transactionsId = (this._transactionId + 1) % MAX_TRANSACTIONS;
// remove crc and add mbap
var buffer = new Buffer(data.length + 6 - 2);
buffer.writeUInt16BE(1, 0);
buffer.writeUInt16BE(transactionsId, 0);
buffer.writeUInt16BE(0, 2);

@@ -105,0 +112,0 @@ buffer.writeUInt16BE(data.length - 2, 4);

@@ -58,4 +58,4 @@ 'use strict';

if (port._client._data.equals(new Buffer('0001000000061103006B0003', 'hex'))) {
port._client.receive(new Buffer('000100000006110366778899', 'hex'));
if (port._client._data.equals(new Buffer('0000000000061103006B0003', 'hex'))) {
port._client.receive(new Buffer('000000000006110366778899', 'hex'));
}

@@ -83,3 +83,3 @@ });

port.write(new Buffer('1103006B00037687', 'hex'));
expect(port._client._data.toString('hex')).to.equal('0001000000061103006b0003');
expect(port._client._data.toString('hex')).to.equal('0002000000061103006b0003');
});

@@ -86,0 +86,0 @@ });

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