Comparing version 3.1.2 to 3.1.3
'use strict' | ||
var SerialPort = require('serialport') | ||
const SerialPort = require('serialport') | ||
@@ -5,0 +5,0 @@ SerialPort.list(function (err, ports) { |
'use strict' | ||
let modbus = require('../../') | ||
let SerialPort = require('serialport') | ||
let socket = new SerialPort('/dev/ttyUSB1', { | ||
const modbus = require('../../') | ||
const SerialPort = require('serialport') | ||
const socket = new SerialPort('/dev/ttyUSB1', { | ||
baudRate: 115200, | ||
@@ -11,3 +11,3 @@ parity: 'even', | ||
}) | ||
let client = new modbus.client.RTU(socket, 0x01) | ||
const client = new modbus.client.RTU(socket, 0x01) | ||
@@ -14,0 +14,0 @@ socket.on('open', function () { |
'use strict' | ||
'use strict' | ||
let modbus = require('../..') | ||
let Serialport = require('serialport') | ||
let socket = new Serialport('COM6', { | ||
const modbus = require('../..') | ||
const Serialport = require('serialport') | ||
const socket = new Serialport('COM6', { | ||
baudRate: 19200, | ||
@@ -13,3 +13,3 @@ Parity: 'none', | ||
// set Slave PLC ID | ||
let client = new modbus.client.RTU(socket, 1) | ||
const client = new modbus.client.RTU(socket, 1) | ||
@@ -16,0 +16,0 @@ socket.on('connect', function () { |
@@ -1,4 +0,4 @@ | ||
let modbus = require('../../') | ||
let SerialPort = require('serialport') | ||
let socket = new SerialPort('/dev/ttyUSB0', { | ||
const modbus = require('../../') | ||
const SerialPort = require('serialport') | ||
const socket = new SerialPort('/dev/ttyUSB0', { | ||
baudrate: 115200, | ||
@@ -9,3 +9,3 @@ parity: 'even', | ||
let client = new modbus.client.RTU(socket, 1) | ||
const client = new modbus.client.RTU(socket, 1) | ||
@@ -12,0 +12,0 @@ socket.on('close', function () { |
'use strict' | ||
let modbus = require('../..') | ||
let Serialport = require('serialport') | ||
let socket = new Serialport('COM6', { | ||
const modbus = require('../..') | ||
const Serialport = require('serialport') | ||
const socket = new Serialport('COM6', { | ||
baudRate: 19200, | ||
@@ -13,3 +13,3 @@ Parity: 'none', | ||
// set Slave PLC ID | ||
let client = new modbus.client.RTU(socket, 1) | ||
const client = new modbus.client.RTU(socket, 1) | ||
@@ -16,0 +16,0 @@ socket.on('connect', function () { |
'use strict' | ||
let modbus = require('../..') | ||
let Serialport = require('serialport') | ||
let socket = new Serialport('COM6', { | ||
const modbus = require('../..') | ||
const Serialport = require('serialport') | ||
const socket = new Serialport('COM6', { | ||
baudRate: 19200, | ||
@@ -13,3 +13,3 @@ Parity: 'none', | ||
// set Slave PLC ID | ||
let client = new modbus.client.RTU(socket, 1) | ||
const client = new modbus.client.RTU(socket, 1) | ||
@@ -16,0 +16,0 @@ socket.on('connect', function () { |
'use strict' | ||
let modbus = require('../..') | ||
let Serialport = require('serialport') | ||
let socket = new Serialport('COM6', { | ||
const modbus = require('../..') | ||
const Serialport = require('serialport') | ||
const socket = new Serialport('COM6', { | ||
baudRate: 19200, | ||
@@ -13,3 +13,3 @@ Parity: 'none', | ||
// set Slave PLC ID | ||
let client = new modbus.client.RTU(socket, 1) | ||
const client = new modbus.client.RTU(socket, 1) | ||
@@ -16,0 +16,0 @@ socket.on('connect', function () { |
'use strict' | ||
let modbus = require('../..') | ||
let net = require('net') | ||
let socket = new net.Socket() | ||
let options = { | ||
const modbus = require('../..') | ||
const net = require('net') | ||
const socket = new net.Socket() | ||
const options = { | ||
'host': '127.0.0.1', | ||
'port': '8502' | ||
} | ||
let client = new modbus.client.TCP(socket) | ||
const client = new modbus.client.TCP(socket) | ||
let cycleDone = true | ||
@@ -21,23 +21,23 @@ | ||
let fc01 = client.readCoils(0, 40) | ||
let fc02 = client.readDiscreteInputs(0, 40) | ||
let fc03 = client.readHoldingRegisters(0, 100) | ||
let fc04 = client.readInputRegisters(0, 100) | ||
const fc01 = client.readCoils(0, 40) | ||
const fc02 = client.readDiscreteInputs(0, 40) | ||
const fc03 = client.readHoldingRegisters(0, 100) | ||
const fc04 = client.readInputRegisters(0, 100) | ||
let fc05StartAddress = Math.trunc(Math.random() * 1000) | ||
let fc05 = client.writeSingleCoil(fc05StartAddress, true) | ||
const fc05StartAddress = Math.trunc(Math.random() * 1000) | ||
const fc05 = client.writeSingleCoil(fc05StartAddress, true) | ||
let fc06StartAddress = Math.trunc(Math.random() * 100) | ||
let fc06Value = Math.trunc(Math.random() * 0xFFFF) | ||
let fc06 = client.writeSingleRegister(fc06StartAddress, fc06Value) | ||
const fc06StartAddress = Math.trunc(Math.random() * 100) | ||
const fc06Value = Math.trunc(Math.random() * 0xFFFF) | ||
const fc06 = client.writeSingleRegister(fc06StartAddress, fc06Value) | ||
let fc0FStartAddress = Math.trunc(Math.random() * 100) | ||
let fc0FBufferSize = Math.trunc(Math.random() * 100) | ||
let fc0F = client.writeMultipleCoils(fc0FStartAddress, Buffer.alloc(fc0FBufferSize * 2)) | ||
const fc0FStartAddress = Math.trunc(Math.random() * 100) | ||
const fc0FBufferSize = Math.trunc(Math.random() * 100) | ||
const fc0F = client.writeMultipleCoils(fc0FStartAddress, Buffer.alloc(fc0FBufferSize * 2)) | ||
let fc10StartAddress = Math.trunc(Math.random() * 100) | ||
let fc10BufferSize = Math.trunc(Math.random() * 100) | ||
let fc10 = client.writeMultipleCoils(fc10StartAddress, Buffer.alloc(fc10BufferSize * 2)) | ||
const fc10StartAddress = Math.trunc(Math.random() * 100) | ||
const fc10BufferSize = Math.trunc(Math.random() * 100) | ||
const fc10 = client.writeMultipleCoils(fc10StartAddress, Buffer.alloc(fc10BufferSize * 2)) | ||
let allFcs = Promise.all([fc01, fc02, fc03, fc04, fc05, fc06, fc0F, fc10]) | ||
const allFcs = Promise.all([fc01, fc02, fc03, fc04, fc05, fc06, fc0F, fc10]) | ||
@@ -44,0 +44,0 @@ allFcs.then(function () { |
'use strict' | ||
let modbus = require('../..') | ||
let net = require('net') | ||
let options = { | ||
const modbus = require('../..') | ||
const net = require('net') | ||
const options = { | ||
'host': '127.0.0.1', | ||
@@ -18,4 +18,4 @@ 'port': '8502' | ||
let socket = new net.Socket() | ||
let client = new modbus.client.TCP(socket) | ||
const socket = new net.Socket() | ||
const client = new modbus.client.TCP(socket) | ||
@@ -27,23 +27,23 @@ socket.on('end', function () { | ||
socket.on('connect', function () { | ||
let fc01 = client.readCoils(0, 40) | ||
let fc02 = client.readDiscreteInputs(0, 40) | ||
let fc03 = client.readHoldingRegisters(0, 100) | ||
let fc04 = client.readInputRegisters(0, 100) | ||
const fc01 = client.readCoils(0, 40) | ||
const fc02 = client.readDiscreteInputs(0, 40) | ||
const fc03 = client.readHoldingRegisters(0, 100) | ||
const fc04 = client.readInputRegisters(0, 100) | ||
let fc05StartAddress = Math.trunc(Math.random() * 1000) | ||
let fc05 = client.writeSingleCoil(fc05StartAddress, true) | ||
const fc05StartAddress = Math.trunc(Math.random() * 1000) | ||
const fc05 = client.writeSingleCoil(fc05StartAddress, true) | ||
let fc06StartAddress = Math.trunc(Math.random() * 100) | ||
let fc06Value = Math.trunc(Math.random() * 0xFFFF) | ||
let fc06 = client.writeSingleRegister(fc06StartAddress, fc06Value) | ||
const fc06StartAddress = Math.trunc(Math.random() * 100) | ||
const fc06Value = Math.trunc(Math.random() * 0xFFFF) | ||
const fc06 = client.writeSingleRegister(fc06StartAddress, fc06Value) | ||
let fc0FStartAddress = Math.trunc(Math.random() * 100) | ||
let fc0FBufferSize = Math.trunc(Math.random() * 100) | ||
let fc0F = client.writeMultipleCoils(fc0FStartAddress, Buffer.alloc(fc0FBufferSize * 2)) | ||
const fc0FStartAddress = Math.trunc(Math.random() * 100) | ||
const fc0FBufferSize = Math.trunc(Math.random() * 100) | ||
const fc0F = client.writeMultipleCoils(fc0FStartAddress, Buffer.alloc(fc0FBufferSize * 2)) | ||
let fc10StartAddress = Math.trunc(Math.random() * 100) | ||
let fc10BufferSize = Math.trunc(Math.random() * 100) | ||
let fc10 = client.writeMultipleCoils(fc10StartAddress, Buffer.alloc(fc10BufferSize * 2)) | ||
const fc10StartAddress = Math.trunc(Math.random() * 100) | ||
const fc10BufferSize = Math.trunc(Math.random() * 100) | ||
const fc10 = client.writeMultipleCoils(fc10StartAddress, Buffer.alloc(fc10BufferSize * 2)) | ||
let allFcs = Promise.all([fc01, fc02, fc03, fc04, fc05, fc06, fc0F, fc10]) | ||
const allFcs = Promise.all([fc01, fc02, fc03, fc04, fc05, fc06, fc0F, fc10]) | ||
@@ -50,0 +50,0 @@ allFcs.then(function () { |
'use strict' | ||
let modbus = require('../..') | ||
let net = require('net') | ||
let socket = new net.Socket() | ||
let options = { | ||
const modbus = require('../..') | ||
const net = require('net') | ||
const socket = new net.Socket() | ||
const options = { | ||
'host': '127.0.0.1', | ||
'port': '8502' | ||
} | ||
let client = new modbus.client.TCP(socket) | ||
const client = new modbus.client.TCP(socket) | ||
@@ -12,0 +12,0 @@ socket.on('connect', function () { |
@@ -5,6 +5,6 @@ #!/usr/bin/env node | ||
let net = require('net') | ||
let modbus = require('../..') | ||
let netServer = new net.Server() | ||
let server = new modbus.server.TCP(netServer) | ||
const net = require('net') | ||
const modbus = require('../..') | ||
const netServer = new net.Server() | ||
const server = new modbus.server.TCP(netServer) | ||
@@ -11,0 +11,0 @@ server.on('connection', function () { |
'use strict' | ||
let modbus = require('../../') | ||
let net = require('net') | ||
let socket = new net.Socket() | ||
let options = { | ||
const modbus = require('../../') | ||
const net = require('net') | ||
const socket = new net.Socket() | ||
const options = { | ||
'host': '127.0.0.1', | ||
'port': '8502' | ||
} | ||
let client = new modbus.client.TCP(socket) | ||
const client = new modbus.client.TCP(socket) | ||
@@ -12,0 +12,0 @@ socket.on('connect', function () { |
'use strict' | ||
let modbus = require('../../') | ||
let net = require('net') | ||
let socket = new net.Socket() | ||
let options = { | ||
const modbus = require('../../') | ||
const net = require('net') | ||
const socket = new net.Socket() | ||
const options = { | ||
'host': '127.0.0.1', | ||
'port': '8502' | ||
} | ||
let client = new modbus.client.TCP(socket) | ||
const client = new modbus.client.TCP(socket) | ||
socket.on('connect', function () { | ||
@@ -12,0 +12,0 @@ client.readDiscreteInputs(0, 12) |
'use strict' | ||
let modbus = require('../..') | ||
let net = require('net') | ||
let socket = new net.Socket() | ||
let options = { | ||
const modbus = require('../..') | ||
const net = require('net') | ||
const socket = new net.Socket() | ||
const options = { | ||
'host': '127.0.0.1', | ||
'port': '502' | ||
} | ||
let client = new modbus.client.TCP(socket) | ||
const client = new modbus.client.TCP(socket) | ||
@@ -12,0 +12,0 @@ socket.on('connect', function () { |
'use strict' | ||
let modbus = require('../..') | ||
let net = require('net') | ||
let socket = new net.Socket() | ||
let options = { | ||
const modbus = require('../..') | ||
const net = require('net') | ||
const socket = new net.Socket() | ||
const options = { | ||
'host': '127.0.0.1', | ||
'port': '8502' | ||
} | ||
let client = new modbus.client.TCP(socket) | ||
const client = new modbus.client.TCP(socket) | ||
@@ -12,0 +12,0 @@ socket.on('connect', function () { |
'use strict' | ||
var modbus = require('../..') | ||
var client = modbus.client.tcp.complete({ | ||
const modbus = require('../..') | ||
const client = modbus.client.tcp.complete({ | ||
'host': process.argv[2], | ||
@@ -10,9 +10,9 @@ 'port': process.argv[3], | ||
}).connect() | ||
var successCount = 0 | ||
var errorCount = 0 | ||
var reconnectCount = 0 | ||
var closedOnPurpose = false | ||
var firstTime = true | ||
let successCount = 0 | ||
let errorCount = 0 | ||
let reconnectCount = 0 | ||
let closedOnPurpose = false | ||
let firstTime = true | ||
var start = function () { | ||
const start = function () { | ||
console.log('Starting request...') | ||
@@ -52,3 +52,3 @@ | ||
var shutdown = function () { | ||
const shutdown = function () { | ||
closedOnPurpose = true | ||
@@ -55,0 +55,0 @@ |
'use strict' | ||
let net = require('net') | ||
let modbus = require('../..') | ||
let netServer = new net.Server() | ||
let holding = Buffer.alloc(10000) | ||
let server = new modbus.server.TCP(netServer, { | ||
const net = require('net') | ||
const modbus = require('../..') | ||
const netServer = new net.Server() | ||
const holding = Buffer.alloc(10000) | ||
const server = new modbus.server.TCP(netServer, { | ||
holding: holding | ||
@@ -9,0 +9,0 @@ }) |
'use strict' | ||
let modbus = require('../..') | ||
let net = require('net') | ||
let socket = new net.Socket() | ||
let options = { | ||
const modbus = require('../..') | ||
const net = require('net') | ||
const socket = new net.Socket() | ||
const options = { | ||
'host': '127.0.0.1', | ||
'port': '8502' | ||
} | ||
let client = new modbus.client.TCP(socket) | ||
const client = new modbus.client.TCP(socket) | ||
socket.on('connect', function () { | ||
var values = Buffer.from([0xff]) | ||
const values = Buffer.from([0xff]) | ||
@@ -15,0 +15,0 @@ client.writeMultipleCoils(13, values, 8) |
'use strict' | ||
let modbus = require('../..') | ||
let net = require('net') | ||
let socket = new net.Socket() | ||
let options = { | ||
const modbus = require('../..') | ||
const net = require('net') | ||
const socket = new net.Socket() | ||
const options = { | ||
'host': '127.0.0.1', | ||
'port': '8502' | ||
} | ||
let client = new modbus.client.TCP(socket) | ||
const client = new modbus.client.TCP(socket) | ||
@@ -12,0 +12,0 @@ socket.on('connect', function () { |
'use strict' | ||
let modbus = require('../..') | ||
let net = require('net') | ||
let socket = new net.Socket() | ||
let options = { | ||
const modbus = require('../..') | ||
const net = require('net') | ||
const socket = new net.Socket() | ||
const options = { | ||
'host': '127.0.0.1', | ||
'port': '8502' | ||
} | ||
let client = new modbus.client.TCP(socket) | ||
const client = new modbus.client.TCP(socket) | ||
@@ -12,0 +12,0 @@ socket.on('connect', function () { |
'use strict' | ||
let modbus = require('../..') | ||
let net = require('net') | ||
let socket = new net.Socket() | ||
let options = { | ||
const modbus = require('../..') | ||
const net = require('net') | ||
const socket = new net.Socket() | ||
const options = { | ||
'host': '192.168.56.101', | ||
'port': '502' | ||
} | ||
let client = new modbus.client.TCP(socket) | ||
const client = new modbus.client.TCP(socket) | ||
@@ -12,0 +12,0 @@ socket.on('connect', function () { |
{ | ||
"name": "jsmodbus", | ||
"version": "3.1.2", | ||
"version": "3.1.3", | ||
"description": "Implementation for the Serial/TCP Modbus protocol.", | ||
@@ -20,2 +20,3 @@ "author": "Stefan Poeter <stefan.poeter@cloud-automation.de>", | ||
"mocha": "^3.3.0", | ||
"nyc": "^13.1.0", | ||
"sinon": "2.2.0", | ||
@@ -26,3 +27,4 @@ "standard": "^8.5.0" | ||
"test": "standard && mocha test/*.test.js", | ||
"watch": "standard && mocha --watch test/*.test.js" | ||
"watch": "standard && mocha --watch test/*.test.js", | ||
"cov": "nyc mocha test/*.test.js" | ||
}, | ||
@@ -29,0 +31,0 @@ "license": "MIT", |
@@ -39,7 +39,7 @@ A simple an easy to use Modbus TCP client/server implementation. | ||
// create a tcp modbus client | ||
let Modbus = require('jsmodbus') | ||
let net = require('net') | ||
let socket = new net.Socket() | ||
let client = new Modbus.client.TCP(socket, unitId) | ||
let options = { | ||
const Modbus = require('jsmodbus') | ||
const net = require('net') | ||
const socket = new net.Socket() | ||
const client = new Modbus.client.TCP(socket, unitId) | ||
const options = { | ||
'host' : host | ||
@@ -56,9 +56,9 @@ 'port' : port | ||
// create a tcp modbus client | ||
let Modbus = require('jsmodbus') | ||
let SerialPort = require('serialport') | ||
let options = { | ||
const Modbus = require('jsmodbus') | ||
const SerialPort = require('serialport') | ||
const options = { | ||
baudRate: 57600 | ||
} | ||
let socket = new SerialPort("/dev/tty-usbserial1", options) | ||
let client = new Modbus.client.RTU(socket, address) | ||
const socket = new SerialPort("/dev/tty-usbserial1", options) | ||
const client = new Modbus.client.RTU(socket, address) | ||
``` | ||
@@ -99,6 +99,6 @@ | ||
let modbus = require('jsmodbus') | ||
let net = require('net') | ||
let server = new net.Server() | ||
let server = new modbus.server.TCP(server) | ||
const modbus = require('jsmodbus') | ||
const net = require('net') | ||
const server = new net.Server() | ||
const server = new modbus.server.TCP(server) | ||
@@ -105,0 +105,0 @@ server.listen(502) |
'use strict' | ||
let debug = require('debug')('buffer-utils') | ||
const debug = require('debug')('buffer-utils') | ||
@@ -31,10 +31,10 @@ // Buffer utilities to make simplify writing multiple coils | ||
startAddress = startAddress - 1 | ||
let startShift = startAddress % 8 | ||
let startByte = Math.floor(startAddress / 8) | ||
let endByte = Math.floor(endAddress / 8) | ||
const startShift = startAddress % 8 | ||
const startByte = Math.floor(startAddress / 8) | ||
const endByte = Math.floor(endAddress / 8) | ||
let size = endByte - startByte + 1 | ||
const size = endByte - startByte + 1 | ||
// Define a new buffer | ||
let buffer = Buffer.allocUnsafe(size) | ||
const buffer = Buffer.allocUnsafe(size) | ||
@@ -44,3 +44,3 @@ buffer[0] = outputs[0] << startShift | ||
let paddedBuffer = Buffer.concat([outputs, Buffer.alloc(1)], outputs.length + 1) | ||
const paddedBuffer = Buffer.concat([outputs, Buffer.alloc(1)], outputs.length + 1) | ||
@@ -70,5 +70,5 @@ for (let i = 1; i < size; i++) { | ||
startAddress = startAddress - 1 | ||
let startShift = startAddress % 8 | ||
let mask = 0xff >> (8 - startShift) | ||
let maskedOriginalByte = originalByte & mask | ||
const startShift = startAddress % 8 | ||
const mask = 0xff >> (8 - startShift) | ||
const maskedOriginalByte = originalByte & mask | ||
@@ -85,5 +85,5 @@ return outputByte + maskedOriginalByte | ||
static lastByte (endAddress, originalByte, outputByte) { | ||
let endShift = endAddress % 8 | ||
let mask = 0xff << endShift | ||
let maskedOriginalByte = originalByte & mask | ||
const endShift = endAddress % 8 | ||
const mask = 0xff << endShift | ||
const maskedOriginalByte = originalByte & mask | ||
@@ -94,3 +94,3 @@ return outputByte + maskedOriginalByte | ||
static bufferToArrayStatus (buffer) { | ||
let statusArray = [] | ||
const statusArray = [] | ||
let pos, curByteIdx, curByte | ||
@@ -112,4 +112,4 @@ if (!(buffer instanceof Buffer)) { | ||
static arrayStatusToBuffer (array) { | ||
let byteCount = array instanceof Array ? Math.ceil(array.length / 8) : 0 | ||
let buffer = Buffer.alloc(byteCount) | ||
const byteCount = array instanceof Array ? Math.ceil(array.length / 8) : 0 | ||
const buffer = Buffer.alloc(byteCount) | ||
@@ -116,0 +116,0 @@ if (!(array instanceof Array)) { |
@@ -7,5 +7,5 @@ 'use strict' | ||
let debug = require('debug')('client-request-handler') | ||
let UserRequest = require('./user-request.js') | ||
let ExceptionResponseBody = require('./response/exception.js') | ||
const debug = require('debug')('client-request-handler') | ||
const UserRequest = require('./user-request.js') | ||
const ExceptionResponseBody = require('./response/exception.js') | ||
@@ -43,3 +43,3 @@ /** Common Request Handler | ||
while (this._requests.length > 0) { | ||
let req = this._requests.shift() | ||
const req = this._requests.shift() | ||
req.reject({ | ||
@@ -66,3 +66,3 @@ 'err': OUT_OF_SYNC, | ||
register (request) { | ||
let userRequest = new UserRequest(request, this._timeout) | ||
const userRequest = new UserRequest(request, this._timeout) | ||
@@ -85,3 +85,3 @@ this._requests.push(userRequest) | ||
let userRequest = this._currentRequest | ||
const userRequest = this._currentRequest | ||
@@ -93,3 +93,3 @@ if (!userRequest) { | ||
let request = userRequest.request | ||
const request = userRequest.request | ||
@@ -157,3 +157,3 @@ /* check that response fc equals request id */ | ||
let payload = this._currentRequest.createPayload() | ||
const payload = this._currentRequest.createPayload() | ||
@@ -160,0 +160,0 @@ debug('flushing new request', payload) |
@@ -1,11 +0,11 @@ | ||
let debug = require('debug')('modbus-client') | ||
const debug = require('debug')('modbus-client') | ||
let ReadCoilsRequestBody = require('./request/read-coils.js') | ||
let ReadDiscreteInputsRequestBody = require('./request/read-discrete-inputs.js') | ||
let ReadHoldingRegistersRequestBody = require('./request/read-holding-registers.js') | ||
let ReadInputRegistersRequestBody = require('./request/read-input-registers.js') | ||
let WriteSingleCoilRequestBody = require('./request/write-single-coil.js') | ||
let WriteSingleRegisterRequestBody = require('./request/write-single-register.js') | ||
let WriteMultipleCoilsRequestBody = require('./request/write-multiple-coils.js') | ||
let WriteMultipleRegistersRequestBody = require('./request/write-multiple-registers.js') | ||
const ReadCoilsRequestBody = require('./request/read-coils.js') | ||
const ReadDiscreteInputsRequestBody = require('./request/read-discrete-inputs.js') | ||
const ReadHoldingRegistersRequestBody = require('./request/read-holding-registers.js') | ||
const ReadInputRegistersRequestBody = require('./request/read-input-registers.js') | ||
const WriteSingleCoilRequestBody = require('./request/write-single-coil.js') | ||
const WriteSingleRegisterRequestBody = require('./request/write-single-register.js') | ||
const WriteMultipleCoilsRequestBody = require('./request/write-multiple-coils.js') | ||
const WriteMultipleRegistersRequestBody = require('./request/write-multiple-registers.js') | ||
@@ -42,3 +42,3 @@ /** Common Modbus Client | ||
do { | ||
let response = this._responseHandler.shift() | ||
const response = this._responseHandler.shift() | ||
@@ -45,0 +45,0 @@ /* no message was parsed by now, come back later */ |
'use strict' | ||
let ModbusClient = require('./modbus-client.js') | ||
let ModbusRTUClientRequestHandler = require('./rtu-client-request-handler.js') | ||
let ModbusRTUClientResponseHandler = require('./rtu-client-response-handler.js') | ||
const ModbusClient = require('./modbus-client.js') | ||
const ModbusRTUClientRequestHandler = require('./rtu-client-request-handler.js') | ||
const ModbusRTUClientResponseHandler = require('./rtu-client-response-handler.js') | ||
@@ -12,6 +12,6 @@ /** This Client musst be initiated with a socket object that implements the event emitter | ||
* @example <caption>Create new Modbus/RTU Client</caption> | ||
* let Modbus = require('jsmodbus') | ||
* let SerialPort = require('serialport') | ||
* let socket = new SerialPort("/dev/tty/ttyUSB0", { "baudRate: 57600" }) | ||
* let client = new Modbus.client.RTU(socket, address) | ||
* const Modbus = require('jsmodbus') | ||
* const SerialPort = require('serialport') | ||
* const socket = new SerialPort("/dev/tty/ttyUSB0", { "baudRate: 57600" }) | ||
* const client = new Modbus.client.RTU(socket, address) | ||
* | ||
@@ -18,0 +18,0 @@ * @extends ModbusClient |
'use strict' | ||
let ModbusServer = require('./modbus-server.js') | ||
let ModbusServerClient = require('./modbus-server-client.js') | ||
let Request = require('./rtu-request.js') | ||
let Response = require('./rtu-response.js') | ||
const ModbusServer = require('./modbus-server.js') | ||
const ModbusServerClient = require('./modbus-server-client.js') | ||
const Request = require('./rtu-request.js') | ||
const Response = require('./rtu-response.js') | ||
@@ -12,3 +12,3 @@ class ModbusRTUServer extends ModbusServer { | ||
this._socket = socket | ||
let client = new ModbusServerClient(this, socket, Request, Response) | ||
const client = new ModbusServerClient(this, socket, Request, Response) | ||
this.emit('connection', client) | ||
@@ -15,0 +15,0 @@ } |
'use strict' | ||
let debug = require('debug')('modbus tcp client socket') | ||
let RequestHandler = require('./modbus-server-request-handler.js') | ||
let ResponseHandler = require('./modbus-server-response-handler.js') | ||
const debug = require('debug')('modbus tcp client socket') | ||
const RequestHandler = require('./modbus-server-request-handler.js') | ||
const ResponseHandler = require('./modbus-server-response-handler.js') | ||
@@ -31,3 +31,3 @@ class ModbusServerClient { | ||
do { | ||
let request = this._requestHandler.shift() | ||
const request = this._requestHandler.shift() | ||
@@ -34,0 +34,0 @@ if (!request) { |
'use strict' | ||
let debug = require('debug')('modbus-server-request-handler') | ||
const debug = require('debug')('modbus-server-request-handler') | ||
@@ -21,3 +21,3 @@ class RequestHandler { | ||
do { | ||
let request = this._requestClass.fromBuffer(this._buffer) | ||
const request = this._requestClass.fromBuffer(this._buffer) | ||
debug('request', request) | ||
@@ -24,0 +24,0 @@ |
'use strict' | ||
let debug = require('debug')('modbus tcp response handler') | ||
const debug = require('debug')('modbus tcp response handler') | ||
@@ -26,6 +26,6 @@ class ModbusServerResponseHandler { | ||
let ReadCoilsResponseBody = require('./response/read-coils.js') | ||
let responseBody = ReadCoilsResponseBody.fromRequest(request.body, this._server.coils) | ||
let response = this._responseClass.fromRequest(request, responseBody) | ||
let payload = response.createPayload() | ||
const ReadCoilsResponseBody = require('./response/read-coils.js') | ||
const responseBody = ReadCoilsResponseBody.fromRequest(request.body, this._server.coils) | ||
const response = this._responseClass.fromRequest(request, responseBody) | ||
const payload = response.createPayload() | ||
cb(payload) | ||
@@ -47,6 +47,6 @@ | ||
let ReadDiscreteInputsResponseBody = require('./response/read-discrete-inputs.js') | ||
let responseBody = ReadDiscreteInputsResponseBody.fromRequest(request.body, this._server.discrete) | ||
let response = this._responseClass.fromRequest(request, responseBody) | ||
let payload = response.createPayload() | ||
const ReadDiscreteInputsResponseBody = require('./response/read-discrete-inputs.js') | ||
const responseBody = ReadDiscreteInputsResponseBody.fromRequest(request.body, this._server.discrete) | ||
const response = this._responseClass.fromRequest(request, responseBody) | ||
const payload = response.createPayload() | ||
cb(payload) | ||
@@ -68,6 +68,6 @@ | ||
let ReadHoldingRegistersResponseBody = require('./response/read-holding-registers.js') | ||
let responseBody = ReadHoldingRegistersResponseBody.fromRequest(request.body, this._server.holding) | ||
let response = this._responseClass.fromRequest(request, responseBody) | ||
let payload = response.createPayload() | ||
const ReadHoldingRegistersResponseBody = require('./response/read-holding-registers.js') | ||
const responseBody = ReadHoldingRegistersResponseBody.fromRequest(request.body, this._server.holding) | ||
const response = this._responseClass.fromRequest(request, responseBody) | ||
const payload = response.createPayload() | ||
cb(payload) | ||
@@ -89,6 +89,6 @@ | ||
let ReadInputRegistersResponseBody = require('./response/read-input-registers.js') | ||
let responseBody = ReadInputRegistersResponseBody.fromRequest(request.body, this._server.input) | ||
let response = this._responseClass.fromRequest(request, responseBody) | ||
let payload = response.createPayload() | ||
const ReadInputRegistersResponseBody = require('./response/read-input-registers.js') | ||
const responseBody = ReadInputRegistersResponseBody.fromRequest(request.body, this._server.input) | ||
const response = this._responseClass.fromRequest(request, responseBody) | ||
const payload = response.createPayload() | ||
cb(payload) | ||
@@ -110,6 +110,6 @@ | ||
let WriteSingleCoilResponseBody = require('./response/write-single-coil.js') | ||
let responseBody = WriteSingleCoilResponseBody.fromRequest(request.body) | ||
const WriteSingleCoilResponseBody = require('./response/write-single-coil.js') | ||
const responseBody = WriteSingleCoilResponseBody.fromRequest(request.body) | ||
let address = request.body.address | ||
const address = request.body.address | ||
@@ -119,3 +119,3 @@ debug('Writing value %d to address %d', request.body.value, address) | ||
// find the byte that contains the coil to be written | ||
let oldValue = this._server.coils.readUInt8(Math.floor(address / 8)) | ||
const oldValue = this._server.coils.readUInt8(Math.floor(address / 8)) | ||
let newValue | ||
@@ -125,6 +125,6 @@ | ||
debug('illegal data value') | ||
let ExceptionResponseBody = require('./response/exception.js') | ||
const ExceptionResponseBody = require('./response/exception.js') | ||
/* illegal data value */ | ||
let responseBody = new ExceptionResponseBody(request.body.fc, 0x03) | ||
let response = this._responseClass.fromRequest(request, responseBody) | ||
const responseBody = new ExceptionResponseBody(request.body.fc, 0x03) | ||
const response = this._responseClass.fromRequest(request, responseBody) | ||
cb(response.createPayload()) | ||
@@ -144,6 +144,6 @@ return response | ||
debug('illegal data address') | ||
let ExceptionResponseBody = require('./response/exception.js') | ||
const ExceptionResponseBody = require('./response/exception.js') | ||
/* illegal data address */ | ||
let responseBody = new ExceptionResponseBody(request.body.fc, 0x02) | ||
let response = this._responseClass.fromRequest(request, responseBody) | ||
const responseBody = new ExceptionResponseBody(request.body.fc, 0x02) | ||
const response = this._responseClass.fromRequest(request, responseBody) | ||
cb(response.createPayload()) | ||
@@ -155,4 +155,4 @@ return response | ||
let response = this._responseClass.fromRequest(request, responseBody) | ||
let payload = response.createPayload() | ||
const response = this._responseClass.fromRequest(request, responseBody) | ||
const payload = response.createPayload() | ||
cb(payload) | ||
@@ -174,11 +174,11 @@ | ||
let WriteSingleRegisterResponseBody = require('./response/write-single-register.js') | ||
let responseBody = WriteSingleRegisterResponseBody.fromRequest(request.body) | ||
const WriteSingleRegisterResponseBody = require('./response/write-single-register.js') | ||
const responseBody = WriteSingleRegisterResponseBody.fromRequest(request.body) | ||
if (responseBody.address * 2 > this._server.holding.length) { | ||
debug('illegal data address') | ||
let ExceptionResponseBody = require('./response/exception.js') | ||
const ExceptionResponseBody = require('./response/exception.js') | ||
/* illegal data address */ | ||
let responseBody = new ExceptionResponseBody(request.body.fc, 0x02) | ||
let response = this._responseClass.fromRequest(request, responseBody) | ||
const responseBody = new ExceptionResponseBody(request.body.fc, 0x02) | ||
const response = this._responseClass.fromRequest(request, responseBody) | ||
cb(response.createPayload()) | ||
@@ -190,4 +190,4 @@ return response | ||
let response = this._responseClass.fromRequest(request, responseBody) | ||
let payload = response.createPayload() | ||
const response = this._responseClass.fromRequest(request, responseBody) | ||
const payload = response.createPayload() | ||
cb(payload) | ||
@@ -210,15 +210,15 @@ | ||
let { | ||
const { | ||
bufferToArrayStatus, | ||
arrayStatusToBuffer | ||
} = require('./buffer-utils.js') | ||
let WriteMultipleCoilsResponseBody = require('./response/write-multiple-coils.js') | ||
const WriteMultipleCoilsResponseBody = require('./response/write-multiple-coils.js') | ||
let responseBody = WriteMultipleCoilsResponseBody.fromRequest(request.body) | ||
let oldStatus = bufferToArrayStatus(this._server.coils) | ||
let requestCoilValues = bufferToArrayStatus(request.body.valuesAsBuffer) | ||
let start = request.body.address | ||
let end = start + request.body.quantity | ||
const responseBody = WriteMultipleCoilsResponseBody.fromRequest(request.body) | ||
const oldStatus = bufferToArrayStatus(this._server.coils) | ||
const requestCoilValues = bufferToArrayStatus(request.body.valuesAsBuffer) | ||
const start = request.body.address | ||
const end = start + request.body.quantity | ||
let newStatus = oldStatus.map((byte, i) => { | ||
const newStatus = oldStatus.map((byte, i) => { | ||
return (i >= start && i < end) ? requestCoilValues.shift() : byte | ||
@@ -231,4 +231,4 @@ }) | ||
let response = this._responseClass.fromRequest(request, responseBody) | ||
let payload = response.createPayload() | ||
const response = this._responseClass.fromRequest(request, responseBody) | ||
const payload = response.createPayload() | ||
cb(payload) | ||
@@ -251,11 +251,11 @@ | ||
let WriteMultipleRegistersResponseBody = require('./response/write-multiple-registers.js') | ||
let responseBody = WriteMultipleRegistersResponseBody.fromRequest(request.body) | ||
const WriteMultipleRegistersResponseBody = require('./response/write-multiple-registers.js') | ||
const responseBody = WriteMultipleRegistersResponseBody.fromRequest(request.body) | ||
if (((request.body.address * 2) + request.body.values.length) > this._server.holding.length) { | ||
debug('illegal data address') | ||
let ExceptionResponseBody = require('./response/exception.js') | ||
const ExceptionResponseBody = require('./response/exception.js') | ||
/* illegal data address */ | ||
let responseBody = new ExceptionResponseBody(request.body.fc, 0x10) | ||
let response = this._responseClass.fromRequest(request, responseBody) | ||
const responseBody = new ExceptionResponseBody(request.body.fc, 0x10) | ||
const response = this._responseClass.fromRequest(request, responseBody) | ||
cb(response.createPayload()) | ||
@@ -272,4 +272,4 @@ return response | ||
let response = this._responseClass.fromRequest(request, responseBody) | ||
let payload = response.createPayload() | ||
const response = this._responseClass.fromRequest(request, responseBody) | ||
const payload = response.createPayload() | ||
cb(payload) | ||
@@ -285,5 +285,5 @@ | ||
let ExceptionResponseBody = require('./response/exception.js') | ||
let responseBody = ExceptionResponseBody.fromRequest(request.body) | ||
let response = this._responseClass.fromRequest(request, responseBody) | ||
const ExceptionResponseBody = require('./response/exception.js') | ||
const responseBody = ExceptionResponseBody.fromRequest(request.body) | ||
const response = this._responseClass.fromRequest(request, responseBody) | ||
cb(response.createPayload()) | ||
@@ -290,0 +290,0 @@ return response |
@@ -1,2 +0,2 @@ | ||
let EventEmitter = require('events') | ||
const EventEmitter = require('events') | ||
@@ -3,0 +3,0 @@ class ModbusServer extends EventEmitter { |
'use strict' | ||
let ModbusClient = require('./modbus-client.js') | ||
let ModbusTCPClientRequestHandler = require('./tcp-client-request-handler.js') | ||
let ModbusTCPClientResponseHandler = require('./tcp-client-response-handler.js') | ||
const ModbusClient = require('./modbus-client.js') | ||
const ModbusTCPClientRequestHandler = require('./tcp-client-request-handler.js') | ||
const ModbusTCPClientResponseHandler = require('./tcp-client-response-handler.js') | ||
@@ -13,5 +13,5 @@ /** This client must be initiated with a net.Socket object. The module does not handle reconnections | ||
* @example <caption>Create new Modbus/TCP Client</caption> | ||
* let net = require('net') | ||
* let socket = new net.Socket() | ||
* let client = new Modbus.tcp.Client(socket) | ||
* const net = require('net') | ||
* const socket = new net.Socket() | ||
* const client = new Modbus.tcp.Client(socket) | ||
* | ||
@@ -18,0 +18,0 @@ * socket.connect({'host' : hostname, 'port' : 502 }) |
'use strict' | ||
let debug = require('debug')('modbus tcp server') | ||
let ModbusServer = require('./modbus-server') | ||
let ModbusServerClient = require('./modbus-server-client.js') | ||
let Request = require('./tcp-request.js') | ||
let Response = require('./tcp-response.js') | ||
const debug = require('debug')('modbus tcp server') | ||
const ModbusServer = require('./modbus-server') | ||
const ModbusServerClient = require('./modbus-server-client.js') | ||
const Request = require('./tcp-request.js') | ||
const Response = require('./tcp-response.js') | ||
@@ -19,3 +19,3 @@ class ModbusTCPServer extends ModbusServer { | ||
debug('new connection coming in') | ||
let client = new ModbusServerClient(this, socket, Request, Response) | ||
const client = new ModbusServerClient(this, socket, Request, Response) | ||
@@ -22,0 +22,0 @@ this.emit('connection', client) |
@@ -11,7 +11,7 @@ 'use strict' | ||
* @example <caption>Create new Modbus/TCP Client.</caption> | ||
* let Modbus = require('jsmodbus') | ||
* let net = require('net') | ||
* let socket = new new.Socket() | ||
* let client = new Modbus.client.TCP(socket, unitId) | ||
* let options = { | ||
* const Modbus = require('jsmodbus') | ||
* const net = require('net') | ||
* const socket = new new.Socket() | ||
* const client = new Modbus.client.TCP(socket, unitId) | ||
* const options = { | ||
* 'host' : host | ||
@@ -23,19 +23,19 @@ * 'port' : port | ||
*/ | ||
let ModbusTCPClient = require('./modbus-tcp-client.js') | ||
const ModbusTCPClient = require('./modbus-tcp-client.js') | ||
/** module:jsmodbus.client.RTU | ||
* @example <caption>Create new Modbus/RTU Client.</caption> | ||
* let Modbus = require('jsmodbus') | ||
* let SerialPort = require('serialport') | ||
* let socket = new SerialPort('/dev/tty/ttyUSB0', { baudRate: 57600 }) | ||
* let client = new Modbus.client.TCP(socket, address) | ||
* const Modbus = require('jsmodbus') | ||
* const SerialPort = require('serialport') | ||
* const socket = new SerialPort('/dev/tty/ttyUSB0', { baudRate: 57600 }) | ||
* const client = new Modbus.client.TCP(socket, address) | ||
*/ | ||
let ModbusRTUClient = require('./modbus-rtu-client.js') | ||
const ModbusRTUClient = require('./modbus-rtu-client.js') | ||
/** module:jsmodbus.server.TCP */ | ||
let ModbusTCPServer = require('./modbus-tcp-server.js') | ||
const ModbusTCPServer = require('./modbus-tcp-server.js') | ||
/** module:jsmodbus.server.RTU */ | ||
let ModbusRTUServer = require('./modbus-rtu-server.js') | ||
const ModbusRTUServer = require('./modbus-rtu-server.js') | ||
@@ -42,0 +42,0 @@ module.exports = { |
@@ -1,2 +0,2 @@ | ||
let ModbusRequestBody = require('./request-body.js') | ||
const ModbusRequestBody = require('./request-body.js') | ||
@@ -9,3 +9,3 @@ /** Write Single Coil Request Body | ||
try { | ||
let fc = buffer.readUInt8(0) | ||
const fc = buffer.readUInt8(0) | ||
@@ -37,3 +37,3 @@ if (fc > 0x2B) { | ||
createPayload () { | ||
let payload = Buffer.alloc(2) | ||
const payload = Buffer.alloc(2) | ||
@@ -40,0 +40,0 @@ payload.writeUInt8(this._fc, 0) // function code |
@@ -1,2 +0,2 @@ | ||
let ModbusRequestBody = require('./request-body.js') | ||
const ModbusRequestBody = require('./request-body.js') | ||
@@ -9,3 +9,3 @@ /** Read Coils Request Body | ||
try { | ||
let fc = buffer.readUInt8(0) | ||
const fc = buffer.readUInt8(0) | ||
@@ -16,4 +16,4 @@ if (fc !== 0x01) { | ||
let start = buffer.readUInt16BE(1) | ||
let quantity = buffer.readUInt16BE(3) | ||
const start = buffer.readUInt16BE(1) | ||
const quantity = buffer.readUInt16BE(3) | ||
@@ -61,3 +61,3 @@ return new ReadCoilsRequestBody(start, quantity) | ||
createPayload () { | ||
let payload = Buffer.alloc(5) | ||
const payload = Buffer.alloc(5) | ||
@@ -64,0 +64,0 @@ payload.writeUInt8(this._fc, 0) // function code |
@@ -1,2 +0,2 @@ | ||
let ModbusRequestBody = require('./request-body.js') | ||
const ModbusRequestBody = require('./request-body.js') | ||
@@ -9,3 +9,3 @@ /** Read Discrete Inputs Request Body | ||
try { | ||
let fc = buffer.readUInt8(0) | ||
const fc = buffer.readUInt8(0) | ||
@@ -16,4 +16,4 @@ if (fc !== 0x02) { | ||
let start = buffer.readUInt16BE(1) | ||
let quantity = buffer.readUInt16BE(3) | ||
const start = buffer.readUInt16BE(1) | ||
const quantity = buffer.readUInt16BE(3) | ||
@@ -62,3 +62,3 @@ return new ReadDiscreteInputsRequestBody(start, quantity) | ||
createPayload () { | ||
let payload = Buffer.alloc(5) | ||
const payload = Buffer.alloc(5) | ||
@@ -65,0 +65,0 @@ payload.writeUInt8(this._fc, 0) // function code |
@@ -1,2 +0,2 @@ | ||
let ModbusRequestBody = require('./request-body.js') | ||
const ModbusRequestBody = require('./request-body.js') | ||
@@ -9,5 +9,5 @@ /** Read Holding Registers Request Body | ||
try { | ||
let fc = buffer.readUInt8(0) | ||
let start = buffer.readUInt16BE(1) | ||
let count = buffer.readUInt16BE(3) | ||
const fc = buffer.readUInt8(0) | ||
const start = buffer.readUInt16BE(1) | ||
const count = buffer.readUInt16BE(3) | ||
@@ -61,3 +61,3 @@ if (fc !== 0x03) { | ||
createPayload () { | ||
let payload = Buffer.alloc(5) | ||
const payload = Buffer.alloc(5) | ||
payload.writeUInt8(this._fc, 0) // function code | ||
@@ -64,0 +64,0 @@ payload.writeUInt16BE(this._start, 1) // start address |
@@ -1,2 +0,2 @@ | ||
let ModbusRequestBody = require('./request-body.js') | ||
const ModbusRequestBody = require('./request-body.js') | ||
@@ -9,5 +9,5 @@ /** Read Input Registers Request Body | ||
try { | ||
let fc = buffer.readUInt8(0) | ||
let start = buffer.readUInt16BE(1) | ||
let count = buffer.readUInt16BE(3) | ||
const fc = buffer.readUInt8(0) | ||
const start = buffer.readUInt16BE(1) | ||
const count = buffer.readUInt16BE(3) | ||
@@ -57,3 +57,3 @@ if (fc !== 0x04) { | ||
createPayload () { | ||
let payload = Buffer.alloc(5) | ||
const payload = Buffer.alloc(5) | ||
@@ -60,0 +60,0 @@ payload.writeUInt8(this._fc, 0) // function code |
'use strict' | ||
let debug = require('debug')('request-body') | ||
const debug = require('debug')('request-body') | ||
@@ -19,34 +19,34 @@ /** Common Modbus Request Body | ||
try { | ||
let fc = buffer.readUInt8(0) | ||
const fc = buffer.readUInt8(0) | ||
if (fc === 0x01) { | ||
let ReadCoilsRequest = require('./read-coils.js') | ||
const ReadCoilsRequest = require('./read-coils.js') | ||
return ReadCoilsRequest.fromBuffer(buffer) | ||
} | ||
if (fc === 0x02) { | ||
let ReadDiscreteInputsRequest = require('./read-discrete-inputs.js') | ||
const ReadDiscreteInputsRequest = require('./read-discrete-inputs.js') | ||
return ReadDiscreteInputsRequest.fromBuffer(buffer) | ||
} | ||
if (fc === 0x03) { | ||
let ReadHoldingRegistersRequest = require('./read-holding-registers.js') | ||
const ReadHoldingRegistersRequest = require('./read-holding-registers.js') | ||
return ReadHoldingRegistersRequest.fromBuffer(buffer) | ||
} | ||
if (fc === 0x04) { | ||
let ReadInputRegistersRequest = require('./read-input-registers.js') | ||
const ReadInputRegistersRequest = require('./read-input-registers.js') | ||
return ReadInputRegistersRequest.fromBuffer(buffer) | ||
} | ||
if (fc === 0x05) { | ||
let WriteSingleCoilRequest = require('./write-single-coil.js') | ||
const WriteSingleCoilRequest = require('./write-single-coil.js') | ||
return WriteSingleCoilRequest.fromBuffer(buffer) | ||
} | ||
if (fc === 0x06) { | ||
let WriteSingleRegisterRequest = require('./write-single-register.js') | ||
const WriteSingleRegisterRequest = require('./write-single-register.js') | ||
return WriteSingleRegisterRequest.fromBuffer(buffer) | ||
} | ||
if (fc === 0x0f) { | ||
let WriteMultipleCoilsResponse = require('./write-multiple-coils.js') | ||
const WriteMultipleCoilsResponse = require('./write-multiple-coils.js') | ||
return WriteMultipleCoilsResponse.fromBuffer(buffer) | ||
} | ||
if (fc === 0x10) { | ||
let WriteMultipleRegistersResponse = require('./write-multiple-registers.js') | ||
const WriteMultipleRegistersResponse = require('./write-multiple-registers.js') | ||
return WriteMultipleRegistersResponse.fromBuffer(buffer) | ||
@@ -57,3 +57,3 @@ } | ||
debug('Illegal Function (fc %d)', fc) | ||
let ExceptionRequest = require('./exception.js') | ||
const ExceptionRequest = require('./exception.js') | ||
return new ExceptionRequest(fc, 0x01) | ||
@@ -60,0 +60,0 @@ } |
@@ -1,2 +0,2 @@ | ||
let ModbusRequestBody = require('./request-body.js') | ||
const ModbusRequestBody = require('./request-body.js') | ||
@@ -9,3 +9,3 @@ /** Write Multiple Coils Request Body | ||
try { | ||
let fc = buffer.readUInt8(0) | ||
const fc = buffer.readUInt8(0) | ||
@@ -16,6 +16,6 @@ if (fc !== 0x0F) { | ||
let address = buffer.readUInt16BE(1) | ||
let quantity = buffer.readUInt16BE(3) | ||
let numberOfBytes = buffer.readUInt8(5) | ||
let values = buffer.slice(6, 6 + numberOfBytes) | ||
const address = buffer.readUInt16BE(1) | ||
const quantity = buffer.readUInt16BE(3) | ||
const numberOfBytes = buffer.readUInt8(5) | ||
const values = buffer.slice(6, 6 + numberOfBytes) | ||
@@ -64,5 +64,5 @@ return new WriteMultipleCoilsRequestBody(address, values, quantity) | ||
for (let i = 0; i < this._quantity; i += 1) { | ||
let pos = i % 8 | ||
let curByteIdx = Math.floor(i / 8) | ||
let curByte = this._values.readUInt8(curByteIdx) | ||
const pos = i % 8 | ||
const curByteIdx = Math.floor(i / 8) | ||
const curByte = this._values.readUInt8(curByteIdx) | ||
@@ -77,3 +77,3 @@ this._valuesAsArray.push((curByte & Math.pow(2, pos)) > 0) | ||
this._valuesAsArray = this._values | ||
let len = Math.min(1968, this._values.length) | ||
const len = Math.min(1968, this._values.length) | ||
@@ -83,5 +83,5 @@ let curByte = 0 | ||
let cntr = 0 | ||
let bytes = Buffer.allocUnsafe(this._numberOfBytes) | ||
const bytes = Buffer.allocUnsafe(this._numberOfBytes) | ||
for (var i = 0; i < len; i += 1) { | ||
for (let i = 0; i < len; i += 1) { | ||
curByte += this._values[i] ? Math.pow(2, cntr) : 0 | ||
@@ -139,3 +139,3 @@ | ||
if (this._values instanceof Buffer) { | ||
let payload = Buffer.alloc(this._byteCount) | ||
const payload = Buffer.alloc(this._byteCount) | ||
payload.writeUInt8(this._fc, 0) // function code | ||
@@ -149,6 +149,6 @@ payload.writeUInt16BE(this._address, 1) // start address | ||
} else if (this._values instanceof Array) { | ||
let len = Math.min(1968, this._values.length) | ||
const len = Math.min(1968, this._values.length) | ||
let payload = Buffer.alloc(6 + this._numberOfBytes) | ||
let bytes = this._valuesAsBuffer | ||
const payload = Buffer.alloc(6 + this._numberOfBytes) | ||
const bytes = this._valuesAsBuffer | ||
@@ -155,0 +155,0 @@ payload.writeUInt8(this._fc, 0) // function code |
@@ -1,2 +0,2 @@ | ||
let ModbusRequestBody = require('./request-body.js') | ||
const ModbusRequestBody = require('./request-body.js') | ||
@@ -9,6 +9,6 @@ /** Write Multiple Registers Request Body | ||
try { | ||
let fc = buffer.readUInt8(0) | ||
let address = buffer.readUInt16BE(1) | ||
let numberOfBytes = buffer.readUInt8(5) | ||
let values = buffer.slice(6, 6 + numberOfBytes) | ||
const fc = buffer.readUInt8(0) | ||
const address = buffer.readUInt16BE(1) | ||
const numberOfBytes = buffer.readUInt8(5) | ||
const values = buffer.slice(6, 6 + numberOfBytes) | ||
@@ -105,3 +105,3 @@ if (fc !== 0x10) { | ||
createPayload () { | ||
let payload = Buffer.alloc(6 + this._numberOfBytes) | ||
const payload = Buffer.alloc(6 + this._numberOfBytes) | ||
payload.writeUInt8(this._fc, 0) // function code | ||
@@ -108,0 +108,0 @@ payload.writeUInt16BE(this._address, 1) // start address |
@@ -1,2 +0,2 @@ | ||
let ModbusRequestBody = require('./request-body.js') | ||
const ModbusRequestBody = require('./request-body.js') | ||
@@ -9,5 +9,5 @@ /** Write Single Coil Request Body | ||
try { | ||
let fc = buffer.readUInt8(0) | ||
let address = buffer.readUInt16BE(1) | ||
let value = buffer.readUInt16BE(3) === 0xff00 | ||
const fc = buffer.readUInt8(0) | ||
const address = buffer.readUInt16BE(1) | ||
const value = buffer.readUInt16BE(3) === 0xff00 | ||
@@ -57,3 +57,3 @@ if (fc !== 0x05) { | ||
createPayload () { | ||
let payload = Buffer.alloc(5) | ||
const payload = Buffer.alloc(5) | ||
@@ -60,0 +60,0 @@ payload.writeUInt8(this._fc, 0) // function code |
@@ -1,2 +0,2 @@ | ||
let ModbusRequestBody = require('./request-body.js') | ||
const ModbusRequestBody = require('./request-body.js') | ||
@@ -9,5 +9,5 @@ /** Write Single Register Request Body | ||
try { | ||
let fc = buffer.readUInt8(0) | ||
let address = buffer.readUInt16BE(1) | ||
let value = buffer.readUInt16BE(3) | ||
const fc = buffer.readUInt8(0) | ||
const address = buffer.readUInt16BE(1) | ||
const value = buffer.readUInt16BE(3) | ||
@@ -56,3 +56,3 @@ if (fc !== 0x06) { | ||
createPayload () { | ||
let payload = Buffer.alloc(5) | ||
const payload = Buffer.alloc(5) | ||
payload.writeUInt8(this._fc, 0) // function code | ||
@@ -59,0 +59,0 @@ payload.writeUInt16BE(this._address, 1) // output address |
@@ -1,2 +0,2 @@ | ||
let Messages = { | ||
const Messages = { | ||
0x01: 'ILLEGAL FUNCTION', | ||
@@ -13,3 +13,3 @@ 0x02: 'ILLEGAL DATA ADDRESS', | ||
let ModbusResponseBody = require('./response-body.js') | ||
const ModbusResponseBody = require('./response-body.js') | ||
@@ -27,4 +27,4 @@ /** Modbus Excepiton Response Body | ||
static fromBuffer (buffer) { | ||
let fc = buffer.readUInt8(0) | ||
let code = buffer.readUInt8(1) | ||
const fc = buffer.readUInt8(0) | ||
const code = buffer.readUInt8(1) | ||
return new ExceptionResponseBody(fc - 0x80, code) | ||
@@ -61,3 +61,3 @@ } | ||
createPayload () { | ||
let payload = Buffer.alloc(2) | ||
const payload = Buffer.alloc(2) | ||
payload.writeUInt8(this._fc, 0) | ||
@@ -64,0 +64,0 @@ payload.writeUInt8(this._code, 1) |
@@ -1,3 +0,3 @@ | ||
let debug = require('debug')('read-coils-response') | ||
let ModbusResponseBody = require('./response-body.js') | ||
const debug = require('debug')('read-coils-response') | ||
const ModbusResponseBody = require('./response-body.js') | ||
const { | ||
@@ -20,9 +20,9 @@ bufferToArrayStatus, | ||
static fromRequest (requestBody, coils) { | ||
let coilsStatus = bufferToArrayStatus(coils) | ||
const coilsStatus = bufferToArrayStatus(coils) | ||
let start = requestBody.start | ||
let end = start + requestBody.count | ||
const start = requestBody.start | ||
const end = start + requestBody.count | ||
// Extract the segment of coils status | ||
let coilsSegment = coilsStatus.slice(start, end) | ||
const coilsSegment = coilsStatus.slice(start, end) | ||
@@ -38,5 +38,5 @@ return new ReadCoilsResponseBody(coilsSegment, Math.ceil(coilsSegment.length / 8)) | ||
try { | ||
let fc = buffer.readUInt8(0) | ||
let byteCount = buffer.readUInt8(1) | ||
let coilStatus = buffer.slice(2, 2 + byteCount) | ||
const fc = buffer.readUInt8(0) | ||
const byteCount = buffer.readUInt8(1) | ||
const coilStatus = buffer.slice(2, 2 + byteCount) | ||
@@ -101,3 +101,3 @@ if (coilStatus.length !== byteCount) { | ||
createPayload () { | ||
let payload = Buffer.alloc(this.byteCount) | ||
const payload = Buffer.alloc(this.byteCount) | ||
@@ -104,0 +104,0 @@ payload.writeUInt8(this._fc, 0) |
@@ -1,2 +0,2 @@ | ||
let ModbusResponseBody = require('./response-body.js') | ||
const ModbusResponseBody = require('./response-body.js') | ||
const { | ||
@@ -18,9 +18,9 @@ bufferToArrayStatus, | ||
static fromRequest (requestBody, discreteInputs) { | ||
let discreteStatus = bufferToArrayStatus(discreteInputs) | ||
const discreteStatus = bufferToArrayStatus(discreteInputs) | ||
let start = requestBody.start | ||
let end = start + requestBody.count | ||
const start = requestBody.start | ||
const end = start + requestBody.count | ||
// Extract the segment of coils status | ||
let segmentStatus = discreteStatus.slice(start, end) | ||
const segmentStatus = discreteStatus.slice(start, end) | ||
@@ -36,5 +36,5 @@ return new ReadDiscreteInputsResponseBody(segmentStatus, Math.ceil(segmentStatus.length / 8)) | ||
try { | ||
let fc = buffer.readUInt8(0) | ||
let byteCount = buffer.readUInt8(1) | ||
let coilStatus = buffer.slice(2, 2 + byteCount) | ||
const fc = buffer.readUInt8(0) | ||
const byteCount = buffer.readUInt8(1) | ||
const coilStatus = buffer.slice(2, 2 + byteCount) | ||
@@ -98,3 +98,3 @@ if (coilStatus.length !== byteCount) { | ||
createPayload () { | ||
let payload = Buffer.alloc(this.byteCount) | ||
const payload = Buffer.alloc(this.byteCount) | ||
@@ -101,0 +101,0 @@ payload.writeUInt8(this._fc, 0) |
@@ -1,3 +0,3 @@ | ||
let ModbusResponseBody = require('./response-body.js') | ||
let debug = require('debug')('ReadHoldingRegistersResponseBody') | ||
const ModbusResponseBody = require('./response-body.js') | ||
const debug = require('debug')('ReadHoldingRegistersResponseBody') | ||
@@ -15,6 +15,6 @@ /** Read Holding Registers ResponseBody (Function Code 0x03) | ||
static fromRequest (requestBody, holdingRegisters) { | ||
let startByte = requestBody.start * 2 | ||
let endByte = (requestBody.start * 2) + (requestBody.count * 2) | ||
const startByte = requestBody.start * 2 | ||
const endByte = (requestBody.start * 2) + (requestBody.count * 2) | ||
let bufferSegment = holdingRegisters.slice(startByte, endByte) | ||
const bufferSegment = holdingRegisters.slice(startByte, endByte) | ||
@@ -31,5 +31,5 @@ /* TODO: check wheather holdingRegisters is big enough for this request */ | ||
static fromBuffer (buffer) { | ||
let fc = buffer.readUInt8(0) | ||
let byteCount = buffer.readUInt8(1) | ||
let payload = buffer.slice(2, 2 + byteCount) | ||
const fc = buffer.readUInt8(0) | ||
const byteCount = buffer.readUInt8(1) | ||
const payload = buffer.slice(2, 2 + byteCount) | ||
@@ -40,3 +40,3 @@ if (fc !== 0x03) { | ||
let values = [] | ||
const values = [] | ||
for (let i = 0; i < byteCount; i += 2) { | ||
@@ -102,3 +102,3 @@ values.push(payload.readUInt16BE(i)) | ||
if (this._values instanceof Array) { | ||
let payload = Buffer.alloc(this.byteCount) | ||
const payload = Buffer.alloc(this.byteCount) | ||
payload.writeUInt8(this._fc, 0) | ||
@@ -105,0 +105,0 @@ payload.writeUInt8(this._byteCount, 1) |
@@ -1,2 +0,2 @@ | ||
let ModbusResponseBody = require('./response-body.js') | ||
const ModbusResponseBody = require('./response-body.js') | ||
@@ -14,6 +14,6 @@ /** Read Input Registers Response Body (Function Code 0x04) | ||
static fromRequest (requestBody, inputRegisters) { | ||
let startByte = requestBody.start * 2 | ||
let endByte = startByte + (requestBody.count * 2) | ||
const startByte = requestBody.start * 2 | ||
const endByte = startByte + (requestBody.count * 2) | ||
let buf = inputRegisters.slice(startByte, endByte) | ||
const buf = inputRegisters.slice(startByte, endByte) | ||
@@ -28,5 +28,5 @@ return new ReadInputRegistersResponseBody(buf.length, buf) | ||
static fromBuffer (buffer) { | ||
let fc = buffer.readUInt8(0) | ||
let byteCount = buffer.readUInt8(1) | ||
let payload = buffer.slice(2, 2 + byteCount) | ||
const fc = buffer.readUInt8(0) | ||
const byteCount = buffer.readUInt8(1) | ||
const payload = buffer.slice(2, 2 + byteCount) | ||
@@ -37,3 +37,3 @@ if (fc !== 0x04) { | ||
let values = [] | ||
const values = [] | ||
for (let i = 0; i < byteCount; i += 2) { | ||
@@ -88,3 +88,3 @@ values.push(payload.readUInt16BE(i)) | ||
createPayload () { | ||
let payload = Buffer.alloc(this.byteCount) | ||
const payload = Buffer.alloc(this.byteCount) | ||
@@ -91,0 +91,0 @@ payload.writeUInt8(this._fc, 0) |
@@ -8,6 +8,6 @@ 'use strict' | ||
static fromBuffer (buffer) { | ||
let ReadCoilsResponse = require('./read-coils.js') | ||
const ReadCoilsResponse = require('./read-coils.js') | ||
try { | ||
let fc = buffer.readUInt8(0) | ||
const fc = buffer.readUInt8(0) | ||
@@ -14,0 +14,0 @@ if (fc === 0x01) { |
@@ -1,12 +0,12 @@ | ||
let debug = require('debug')('response-factory') | ||
const debug = require('debug')('response-factory') | ||
let ExceptionResponseBody = require('./exception.js') | ||
let ReadCoilsResponseBody = require('./read-coils.js') | ||
let ReadDiscreteInputsBody = require('./read-discrete-inputs.js') | ||
let ReadHoldingRegistersBody = require('./read-holding-registers.js') | ||
let ReadInputRegistersBody = require('./read-input-registers.js') | ||
let WriteSingleCoilBody = require('./write-single-coil.js') | ||
let WriteSingleRegisterBody = require('./write-single-register.js') | ||
let WriteMultipleCoilsBody = require('./write-multiple-coils.js') | ||
let WriteMultipleRegistersBody = require('./write-multiple-registers.js') | ||
const ExceptionResponseBody = require('./exception.js') | ||
const ReadCoilsResponseBody = require('./read-coils.js') | ||
const ReadDiscreteInputsBody = require('./read-discrete-inputs.js') | ||
const ReadHoldingRegistersBody = require('./read-holding-registers.js') | ||
const ReadInputRegistersBody = require('./read-input-registers.js') | ||
const WriteSingleCoilBody = require('./write-single-coil.js') | ||
const WriteSingleRegisterBody = require('./write-single-register.js') | ||
const WriteMultipleCoilsBody = require('./write-multiple-coils.js') | ||
const WriteMultipleRegistersBody = require('./write-multiple-registers.js') | ||
@@ -19,3 +19,3 @@ /** Response Factory | ||
try { | ||
let fc = buffer.readUInt8(0) | ||
const fc = buffer.readUInt8(0) | ||
@@ -22,0 +22,0 @@ debug('fc', fc, 'payload', buffer) |
@@ -1,2 +0,2 @@ | ||
let ModbusResponseBody = require('./response-body.js') | ||
const ModbusResponseBody = require('./response-body.js') | ||
@@ -14,4 +14,4 @@ /** WriteMultipleCoils Response Body (Function Code 0x0f) | ||
static fromRequest (requestBody) { | ||
let start = requestBody.address | ||
let quantity = requestBody.quantity | ||
const start = requestBody.address | ||
const quantity = requestBody.quantity | ||
@@ -22,5 +22,5 @@ return new WriteMultipleCoilsResponseBody(start, quantity) | ||
static fromBuffer (buffer) { | ||
let fc = buffer.readUInt8(0) | ||
let start = buffer.readUInt16BE(1) | ||
let quantity = buffer.readUInt16BE(3) | ||
const fc = buffer.readUInt8(0) | ||
const start = buffer.readUInt16BE(1) | ||
const quantity = buffer.readUInt16BE(3) | ||
@@ -53,3 +53,3 @@ if (fc !== 0x0f) { | ||
createPayload () { | ||
let payload = Buffer.alloc(this.byteCount) | ||
const payload = Buffer.alloc(this.byteCount) | ||
@@ -56,0 +56,0 @@ payload.writeUInt8(this._fc, 0) |
@@ -1,2 +0,2 @@ | ||
let ModbusResponseBody = require('./response-body.js') | ||
const ModbusResponseBody = require('./response-body.js') | ||
@@ -14,4 +14,4 @@ /** WriteMultipleRegisters Respone Body (Function code 0x10) | ||
static fromRequest (requestBody) { | ||
let start = requestBody.address | ||
let quantity = requestBody.quantity | ||
const start = requestBody.address | ||
const quantity = requestBody.quantity | ||
@@ -22,5 +22,5 @@ return new WriteMultipleRegistersResponseBody(start, quantity) | ||
static fromBuffer (buffer) { | ||
let fc = buffer.readUInt8(0) | ||
let start = buffer.readUInt16BE(1) | ||
let quantity = buffer.readUInt16BE(3) | ||
const fc = buffer.readUInt8(0) | ||
const start = buffer.readUInt16BE(1) | ||
const quantity = buffer.readUInt16BE(3) | ||
@@ -53,3 +53,3 @@ if (fc !== 0x10) { | ||
createPayload () { | ||
let payload = Buffer.alloc(this.byteCount) | ||
const payload = Buffer.alloc(this.byteCount) | ||
@@ -56,0 +56,0 @@ payload.writeUInt8(this._fc, 0) |
@@ -1,2 +0,2 @@ | ||
let ModbusResponseBody = require('./response-body.js') | ||
const ModbusResponseBody = require('./response-body.js') | ||
@@ -14,4 +14,4 @@ /** Write Single Coil Response Body | ||
static fromRequest (requestBody) { | ||
let address = requestBody.address | ||
let value = requestBody.value | ||
const address = requestBody.address | ||
const value = requestBody.value | ||
@@ -26,5 +26,5 @@ return new WriteSingleCoilResponseBody(address, value) | ||
static fromBuffer (buffer) { | ||
let fc = buffer.readUInt8(0) | ||
let address = buffer.readUInt16BE(1) | ||
let value = buffer.readUInt16BE(3) === 0xFF00 | ||
const fc = buffer.readUInt8(0) | ||
const address = buffer.readUInt16BE(1) | ||
const value = buffer.readUInt16BE(3) === 0xFF00 | ||
@@ -57,3 +57,3 @@ if (fc !== 0x05) { | ||
createPayload () { | ||
let payload = Buffer.alloc(this.byteCount) | ||
const payload = Buffer.alloc(this.byteCount) | ||
@@ -60,0 +60,0 @@ payload.writeUInt8(this._fc, 0) |
@@ -1,2 +0,2 @@ | ||
let ModbusResponseBody = require('./response-body.js') | ||
const ModbusResponseBody = require('./response-body.js') | ||
@@ -14,4 +14,4 @@ /** WriteSingleRegister Resonse Body (Function code 0x05) | ||
static fromRequest (requestBody) { | ||
let address = requestBody.address | ||
let value = requestBody.value | ||
const address = requestBody.address | ||
const value = requestBody.value | ||
@@ -22,5 +22,5 @@ return new WriteSingleRegisterResponseBody(address, value) | ||
static fromBuffer (buffer) { | ||
let fc = buffer.readUInt8(0) | ||
let address = buffer.readUInt16BE(1) | ||
let value = buffer.readUInt16BE(3) | ||
const fc = buffer.readUInt8(0) | ||
const address = buffer.readUInt16BE(1) | ||
const value = buffer.readUInt16BE(3) | ||
@@ -53,3 +53,3 @@ if (fc !== 0x06) { | ||
createPayload () { | ||
let payload = Buffer.alloc(5) | ||
const payload = Buffer.alloc(5) | ||
@@ -56,0 +56,0 @@ payload.writeUInt8(this._fc, 0) |
'use strict' | ||
let debug = require('debug')('rtu-client-request-handler') | ||
let ModbusRTURequest = require('./rtu-request.js') | ||
let ModbusClientRequestHandler = require('./client-request-handler.js') | ||
let CRC = require('crc') | ||
const debug = require('debug')('rtu-client-request-handler') | ||
const ModbusRTURequest = require('./rtu-request.js') | ||
const ModbusClientRequestHandler = require('./client-request-handler.js') | ||
const CRC = require('crc') | ||
@@ -30,3 +30,3 @@ /** Modbus/RTU Client Request Handler | ||
let request = new ModbusRTURequest(this._address, requestBody) | ||
const request = new ModbusRTURequest(this._address, requestBody) | ||
@@ -42,3 +42,3 @@ return super.register(request) | ||
let userRequest = this._currentRequest | ||
const userRequest = this._currentRequest | ||
@@ -50,6 +50,6 @@ if (!userRequest) { | ||
let buf = Buffer.concat([Buffer.from([response.address]), response.body.createPayload()]) | ||
const buf = Buffer.concat([Buffer.from([response.address]), response.body.createPayload()]) | ||
debug('create crc from response', buf) | ||
let crc = CRC.crc16modbus(buf) | ||
const crc = CRC.crc16modbus(buf) | ||
@@ -56,0 +56,0 @@ if (response.crc !== crc) { |
@@ -1,4 +0,4 @@ | ||
let debug = require('debug')('rtu-response-handler') | ||
let ModbusRTUResponse = require('./rtu-response.js') | ||
let ModbusClientResponseHandler = require('./client-response-handler.js') | ||
const debug = require('debug')('rtu-response-handler') | ||
const ModbusRTUResponse = require('./rtu-response.js') | ||
const ModbusClientResponseHandler = require('./client-response-handler.js') | ||
@@ -17,3 +17,3 @@ /** Modbus/RTU Client Response Handler | ||
do { | ||
let response = ModbusRTUResponse.fromBuffer(this._buffer) | ||
const response = ModbusRTUResponse.fromBuffer(this._buffer) | ||
@@ -20,0 +20,0 @@ if (!response) { |
@@ -1,4 +0,4 @@ | ||
let debug = require('debug')('rtu-request') | ||
let CRC = require('crc') | ||
let CommonRequestBody = require('./request/request-body.js') | ||
const debug = require('debug')('rtu-request') | ||
const CRC = require('crc') | ||
const CommonRequestBody = require('./request/request-body.js') | ||
@@ -68,9 +68,9 @@ class ModbusRTURequest { | ||
createPayload () { | ||
let bodyPayload = this._body.createPayload() | ||
const bodyPayload = this._body.createPayload() | ||
this._crc = CRC.crc16modbus(Buffer.concat([Buffer.from([this._address]), bodyPayload])) | ||
let crBu = Buffer.alloc(2) | ||
const crBu = Buffer.alloc(2) | ||
crBu.writeUInt16LE(this._crc) | ||
let idBuf = Buffer.from([this._address]) | ||
let payload = Buffer.concat([idBuf, bodyPayload, crBu]) | ||
const idBuf = Buffer.from([this._address]) | ||
const payload = Buffer.concat([idBuf, bodyPayload, crBu]) | ||
@@ -77,0 +77,0 @@ return payload |
@@ -1,4 +0,4 @@ | ||
let debug = require('debug')('rtu-response') | ||
let CRC = require('crc') | ||
let ResponseFactory = require('./response/response-factory.js') | ||
const debug = require('debug')('rtu-response') | ||
const CRC = require('crc') | ||
const ResponseFactory = require('./response/response-factory.js') | ||
@@ -24,7 +24,7 @@ class ModbusRTUResponse { | ||
let address = buffer.readUInt8(0) | ||
const address = buffer.readUInt8(0) | ||
debug('address', address, 'buffer', buffer) | ||
let body = ResponseFactory.fromBuffer(buffer.slice(1)) | ||
const body = ResponseFactory.fromBuffer(buffer.slice(1)) | ||
@@ -74,3 +74,3 @@ if (!body) { | ||
*/ | ||
let payload = Buffer.alloc(this.byteCount) | ||
const payload = Buffer.alloc(this.byteCount) | ||
payload.writeUInt8(this._address, 0) | ||
@@ -77,0 +77,0 @@ const bodyPayload = this._body.createPayload() |
'use strict' | ||
let debug = require('debug')('tcp-client-request-handler') | ||
let TCPRequest = require('./tcp-request.js') | ||
let ModbusClientRequestHandler = require('./client-request-handler.js') | ||
const debug = require('debug')('tcp-client-request-handler') | ||
const TCPRequest = require('./tcp-request.js') | ||
const ModbusClientRequestHandler = require('./client-request-handler.js') | ||
@@ -34,3 +34,3 @@ const OUT_OF_SYNC = 'OutOfSync' | ||
let tcpRequest = new TCPRequest(this._requestId, 0x00, requestBody.byteCount + 1, this._unitId, requestBody) | ||
const tcpRequest = new TCPRequest(this._requestId, 0x00, requestBody.byteCount + 1, this._unitId, requestBody) | ||
@@ -45,3 +45,3 @@ return super.register(tcpRequest) | ||
let userRequest = this._currentRequest | ||
const userRequest = this._currentRequest | ||
@@ -53,3 +53,3 @@ if (!userRequest) { | ||
let request = userRequest.request | ||
const request = userRequest.request | ||
@@ -56,0 +56,0 @@ /* check if response id equals request id */ |
@@ -1,4 +0,4 @@ | ||
let debug = require('debug')('tcp-response-handler') | ||
let TCPResponse = require('./tcp-response.js') | ||
let ModbusClientResponseHandler = require('./client-response-handler.js') | ||
const debug = require('debug')('tcp-response-handler') | ||
const TCPResponse = require('./tcp-response.js') | ||
const ModbusClientResponseHandler = require('./client-response-handler.js') | ||
@@ -24,3 +24,3 @@ /** Modbus/TCP Client Response Handler. | ||
do { | ||
let response = TCPResponse.fromBuffer(this._buffer) | ||
const response = TCPResponse.fromBuffer(this._buffer) | ||
@@ -27,0 +27,0 @@ if (!response) { |
@@ -1,3 +0,3 @@ | ||
let debug = require('debug')('tcp-request') | ||
let CommonRequestBody = require('./request/request-body.js') | ||
const debug = require('debug')('tcp-request') | ||
const CommonRequestBody = require('./request/request-body.js') | ||
@@ -18,6 +18,6 @@ /** Class representing a Modbus TCP Request */ | ||
let id = buffer.readUInt16BE(0) | ||
let protocol = buffer.readUInt16BE(2) | ||
let length = buffer.readUInt16BE(4) | ||
let unitId = buffer.readUInt8(6) | ||
const id = buffer.readUInt16BE(0) | ||
const protocol = buffer.readUInt16BE(2) | ||
const length = buffer.readUInt16BE(4) | ||
const unitId = buffer.readUInt8(6) | ||
@@ -27,3 +27,3 @@ debug('tcp header complete, id', id, 'protocol', protocol, 'length', length, 'unitId', unitId) | ||
let body = CommonRequestBody.fromBuffer(buffer.slice(7, 6 + length)) | ||
const body = CommonRequestBody.fromBuffer(buffer.slice(7, 6 + length)) | ||
@@ -95,4 +95,4 @@ if (!body) { | ||
createPayload () { | ||
let body = this._body.createPayload() | ||
let payload = Buffer.alloc(7 + this._body.byteCount) | ||
const body = this._body.createPayload() | ||
const payload = Buffer.alloc(7 + this._body.byteCount) | ||
@@ -99,0 +99,0 @@ payload.writeUInt16BE(this._id, 0) // transaction id |
@@ -1,3 +0,3 @@ | ||
let debug = require('debug')('tcp-response') | ||
let ResponseFactory = require('./response/response-factory.js') | ||
const debug = require('debug')('tcp-response') | ||
const ResponseFactory = require('./response/response-factory.js') | ||
@@ -29,6 +29,6 @@ /** Modbus/TCP Response | ||
try { | ||
let id = buffer.readUInt16BE(0) | ||
let protocol = buffer.readUInt16BE(2) | ||
let length = buffer.readUInt16BE(4) | ||
let unitId = buffer.readUInt8(6) | ||
const id = buffer.readUInt16BE(0) | ||
const protocol = buffer.readUInt16BE(2) | ||
const length = buffer.readUInt16BE(4) | ||
const unitId = buffer.readUInt8(6) | ||
@@ -38,3 +38,3 @@ debug('tcp header complete, id', id, 'protocol', protocol, 'length', length, 'unitId', unitId) | ||
let body = ResponseFactory.fromBuffer(buffer.slice(7, 7 + length - 1)) | ||
const body = ResponseFactory.fromBuffer(buffer.slice(7, 7 + length - 1)) | ||
@@ -110,3 +110,3 @@ if (!body) { | ||
*/ | ||
let payload = Buffer.alloc(this.byteCount) | ||
const payload = Buffer.alloc(this.byteCount) | ||
payload.writeUInt16BE(this._id, 0) | ||
@@ -113,0 +113,0 @@ payload.writeUInt16BE(this._protocol, 2) |
'use strict' | ||
let debug = require('debug')('user-request') | ||
const debug = require('debug')('user-request') | ||
@@ -5,0 +5,0 @@ /** Request created for the user. It contains the actual modbus request, |
/* global describe, it */ | ||
'use strict' | ||
let assert = require('assert') | ||
let bufferUtils = require('../src/buffer-utils.js') | ||
const assert = require('assert') | ||
const bufferUtils = require('../src/buffer-utils.js') | ||
describe('Buffer and status conversions.', function () { | ||
it('should convert 10 coils status to buffer 2 bytes', function () { | ||
let input = [0, 0, 0, 0, 1, 0, 1, 0, 1, 0] | ||
let expected = Buffer.from([0x50, 0x01]) | ||
let result = bufferUtils.arrayStatusToBuffer(input) | ||
const input = [0, 0, 0, 0, 1, 0, 1, 0, 1, 0] | ||
const expected = Buffer.from([0x50, 0x01]) | ||
const result = bufferUtils.arrayStatusToBuffer(input) | ||
@@ -17,5 +17,5 @@ assert.deepEqual(expected, result) | ||
it('should convert a buffer with hex to coils/discrete array status', function () { | ||
let input = Buffer.from([0x50, 0x01]) | ||
let expected = [0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0] | ||
let result = bufferUtils.bufferToArrayStatus(input) | ||
const input = Buffer.from([0x50, 0x01]) | ||
const expected = [0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0] | ||
const result = bufferUtils.bufferToArrayStatus(input) | ||
@@ -26,5 +26,5 @@ assert.deepEqual(expected, result) | ||
it('should convert a buffer with bin to coils/discrete array status', function () { | ||
let input = Buffer.from([0b01010000, 0b00000001]) | ||
let expected = [0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0] | ||
let result = bufferUtils.bufferToArrayStatus(input) | ||
const input = Buffer.from([0b01010000, 0b00000001]) | ||
const expected = [0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0] | ||
const result = bufferUtils.bufferToArrayStatus(input) | ||
@@ -35,3 +35,3 @@ assert.deepEqual(expected, result) | ||
it('should return empty array if buffer is not instance of Buffer', function () { | ||
let expected = [] | ||
const expected = [] | ||
@@ -52,3 +52,3 @@ let input = 0b0101000000000001 | ||
it('should return empty buffer if coils is not instance of Array', function () { | ||
let expected = Buffer.alloc(0) | ||
const expected = Buffer.alloc(0) | ||
@@ -73,7 +73,7 @@ let input = 0b0101000000000001 | ||
it('should return a short buffer', function () { | ||
let startAddress = 3 | ||
let endAddress = 7 | ||
let buffer = Buffer.from([0b00010001]) | ||
let expectedBuffer = Buffer.from([0b01000100]) | ||
let buf = bufferUtils.bufferShift(startAddress, endAddress, buffer) | ||
const startAddress = 3 | ||
const endAddress = 7 | ||
const buffer = Buffer.from([0b00010001]) | ||
const expectedBuffer = Buffer.from([0b01000100]) | ||
const buf = bufferUtils.bufferShift(startAddress, endAddress, buffer) | ||
@@ -84,7 +84,7 @@ assert(expectedBuffer.equals(buf)) | ||
it('should return a longer buffer', function () { | ||
let startAddress = 8 | ||
let endAddress = 17 | ||
let buffer = Buffer.from([0b11111111, 0b00000011]) | ||
let expectedBuffer = Buffer.from([0b10000000, 0b11111111, 0b00000001]) | ||
let buf = bufferUtils.bufferShift(startAddress, endAddress, buffer) | ||
const startAddress = 8 | ||
const endAddress = 17 | ||
const buffer = Buffer.from([0b11111111, 0b00000011]) | ||
const expectedBuffer = Buffer.from([0b10000000, 0b11111111, 0b00000001]) | ||
const buf = bufferUtils.bufferShift(startAddress, endAddress, buffer) | ||
@@ -95,10 +95,10 @@ assert(expectedBuffer.equals(buf)) | ||
it('should return a correct only byte', function () { | ||
let startAddress = 3 | ||
let endAddress = 7 | ||
let buffer = Buffer.from([0b00010001]) | ||
let buf = bufferUtils.bufferShift(startAddress, endAddress, buffer) | ||
let originalBuffer = Buffer.from([0b10101010]) | ||
const startAddress = 3 | ||
const endAddress = 7 | ||
const buffer = Buffer.from([0b00010001]) | ||
const buf = bufferUtils.bufferShift(startAddress, endAddress, buffer) | ||
const originalBuffer = Buffer.from([0b10101010]) | ||
let expectedByte = 0b01000110 | ||
let firstByte = bufferUtils.firstByte(startAddress, originalBuffer[0], buf[0]) | ||
const firstByte = bufferUtils.firstByte(startAddress, originalBuffer[0], buf[0]) | ||
@@ -108,3 +108,3 @@ assert.equal(firstByte, expectedByte) | ||
expectedByte = 0b11000110 | ||
let lastByte = bufferUtils.lastByte(endAddress, originalBuffer[0], firstByte) | ||
const lastByte = bufferUtils.lastByte(endAddress, originalBuffer[0], firstByte) | ||
@@ -115,12 +115,12 @@ assert.equal(lastByte, expectedByte) | ||
it('should return a correct buffer', function () { | ||
let startAddress = 10 | ||
let endAddress = 27 | ||
let buffer = Buffer.from([0b10011001, 0b10011001, 0b00000001]) | ||
let buf = bufferUtils.bufferShift(startAddress, endAddress, buffer) | ||
const startAddress = 10 | ||
const endAddress = 27 | ||
const buffer = Buffer.from([0b10011001, 0b10011001, 0b00000001]) | ||
const buf = bufferUtils.bufferShift(startAddress, endAddress, buffer) | ||
let originalBuffer = Buffer.from([0b10101010, 0b10101010, 0b10101010, 0b10101010, 0b10101010]) | ||
let expectedBuffer = Buffer.from([0b10101010, 0b00110010, 0b00110011, 0b10101011, 0b10101010]) | ||
const originalBuffer = Buffer.from([0b10101010, 0b10101010, 0b10101010, 0b10101010, 0b10101010]) | ||
const expectedBuffer = Buffer.from([0b10101010, 0b00110010, 0b00110011, 0b10101011, 0b10101010]) | ||
let startByte = Math.floor(startAddress / 8) | ||
let firstByte = bufferUtils.firstByte(startAddress, originalBuffer[startByte], buf[0]) | ||
const startByte = Math.floor(startAddress / 8) | ||
const firstByte = bufferUtils.firstByte(startAddress, originalBuffer[startByte], buf[0]) | ||
let expectedByte = 0b00110010 | ||
@@ -131,4 +131,4 @@ assert.equal(firstByte, expectedByte) | ||
let lb = Math.floor(endAddress / 8) | ||
let lastByte = bufferUtils.lastByte(endAddress, originalBuffer[originalBuffer.length - 1], buf[buf.length - 1]) | ||
const lb = Math.floor(endAddress / 8) | ||
const lastByte = bufferUtils.lastByte(endAddress, originalBuffer[originalBuffer.length - 1], buf[buf.length - 1]) | ||
expectedByte = 0b10101011 | ||
@@ -145,12 +145,12 @@ assert.equal(lastByte, expectedByte) | ||
it('should return another correct buffer', function () { | ||
let startAddress = 13 | ||
let endAddress = 20 | ||
let buffer = Buffer.from([0b11111111]) | ||
let buf = bufferUtils.bufferShift(startAddress, endAddress, buffer) | ||
const startAddress = 13 | ||
const endAddress = 20 | ||
const buffer = Buffer.from([0b11111111]) | ||
const buf = bufferUtils.bufferShift(startAddress, endAddress, buffer) | ||
let originalBuffer = Buffer.from([0b00000000, 0b00000000, 0b00000000, 0b00000000]) | ||
let expectedBuffer = Buffer.from([0b00000000, 0b11110000, 0b00001111, 0b00000000]) | ||
const originalBuffer = Buffer.from([0b00000000, 0b00000000, 0b00000000, 0b00000000]) | ||
const expectedBuffer = Buffer.from([0b00000000, 0b11110000, 0b00001111, 0b00000000]) | ||
let startByte = Math.floor(startAddress / 8) | ||
let firstByte = bufferUtils.firstByte(startAddress, originalBuffer[startByte], buf[0]) | ||
const startByte = Math.floor(startAddress / 8) | ||
const firstByte = bufferUtils.firstByte(startAddress, originalBuffer[startByte], buf[0]) | ||
let expectedByte = 0b11110000 | ||
@@ -161,4 +161,4 @@ assert.equal(firstByte, expectedByte) | ||
let lb = Math.floor(endAddress / 8) | ||
let lastByte = bufferUtils.lastByte(endAddress, originalBuffer[originalBuffer.length - 1], buf[buf.length - 1]) | ||
const lb = Math.floor(endAddress / 8) | ||
const lastByte = bufferUtils.lastByte(endAddress, originalBuffer[originalBuffer.length - 1], buf[buf.length - 1]) | ||
expectedByte = 0b00001111 | ||
@@ -165,0 +165,0 @@ assert.equal(lastByte, expectedByte) |
@@ -13,3 +13,3 @@ 'use strict' | ||
let request = function () { | ||
const request = function () { | ||
return client.readCoils(0, 13) | ||
@@ -28,3 +28,3 @@ } | ||
p.then(function () { | ||
let usedHeapSize = Math.floor(v8.getHeapStatistics().used_heap_size / 1e6) | ||
const usedHeapSize = Math.floor(v8.getHeapStatistics().used_heap_size / 1e6) | ||
@@ -31,0 +31,0 @@ console.log('Heap:', usedHeapSize, 'MB') |
@@ -5,9 +5,9 @@ 'use strict' | ||
let assert = require('assert') | ||
const assert = require('assert') | ||
let ModbusTCPRequest = require('../src/tcp-request.js') | ||
let ModbusTCPResponse = require('../src/tcp-response.js') | ||
let ReadCoilsRequest = require('../src/request/read-coils.js') | ||
let ReadCoilsResponse = require('../src/response/read-coils.js') | ||
let ModbusRequestBody = require('../src/request/request-body.js') | ||
const ModbusTCPRequest = require('../src/tcp-request.js') | ||
const ModbusTCPResponse = require('../src/tcp-response.js') | ||
const ReadCoilsRequest = require('../src/request/read-coils.js') | ||
const ReadCoilsResponse = require('../src/response/read-coils.js') | ||
const ModbusRequestBody = require('../src/request/request-body.js') | ||
@@ -17,5 +17,5 @@ describe('ReadCoils Tests.', function () { | ||
it('should create a buffer from a read coils message', function () { | ||
let response = new ReadCoilsResponse([1, 0, 1, 0, 1, 0, 1, 0, 1, 0], 2) | ||
let buffer = response.createPayload() | ||
let expected = Buffer.from([0x01, 0x02, 0x55, 0x01]) | ||
const response = new ReadCoilsResponse([1, 0, 1, 0, 1, 0, 1, 0, 1, 0], 2) | ||
const buffer = response.createPayload() | ||
const expected = Buffer.from([0x01, 0x02, 0x55, 0x01]) | ||
@@ -25,4 +25,4 @@ assert.deepEqual(expected, buffer) | ||
it('should create a message object from a buffer', function () { | ||
let buffer = Buffer.from([0x01, 0x02, 0x55, 0x01]) | ||
let message = ReadCoilsResponse.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x01, 0x02, 0x55, 0x01]) | ||
const message = ReadCoilsResponse.fromBuffer(buffer) | ||
@@ -35,7 +35,7 @@ assert.equal(0x01, message.fc) | ||
it('should mask out extra bits', function () { | ||
let requestBody = ModbusRequestBody.fromBuffer(Buffer.from([0x01, 0x00, 0x00, 0x00, 0x09])) | ||
let coils = Buffer.from([0xff, 0xff]) | ||
let response = ReadCoilsResponse.fromRequest(requestBody, coils) | ||
let buffer = response.createPayload() | ||
let expected = Buffer.from([0x01, 0x02, 0xff, 0x01]) | ||
const requestBody = ModbusRequestBody.fromBuffer(Buffer.from([0x01, 0x00, 0x00, 0x00, 0x09])) | ||
const coils = Buffer.from([0xff, 0xff]) | ||
const response = ReadCoilsResponse.fromRequest(requestBody, coils) | ||
const buffer = response.createPayload() | ||
const expected = Buffer.from([0x01, 0x02, 0xff, 0x01]) | ||
@@ -45,7 +45,7 @@ assert.deepEqual(expected, buffer) | ||
it('should return an individual coil if requested', function () { | ||
let requestBody = ModbusRequestBody.fromBuffer(Buffer.from([0x01, 0x00, 0x00, 0x00, 0x01])) | ||
let coils = Buffer.from([0xff, 0xff]) | ||
let response = ReadCoilsResponse.fromRequest(requestBody, coils) | ||
let buffer = response.createPayload() | ||
let expected = Buffer.from([0x01, 0x01, 0x01]) | ||
const requestBody = ModbusRequestBody.fromBuffer(Buffer.from([0x01, 0x00, 0x00, 0x00, 0x01])) | ||
const coils = Buffer.from([0xff, 0xff]) | ||
const response = ReadCoilsResponse.fromRequest(requestBody, coils) | ||
const buffer = response.createPayload() | ||
const expected = Buffer.from([0x01, 0x01, 0x01]) | ||
@@ -55,4 +55,4 @@ assert.deepEqual(expected, buffer) | ||
it('should return null on not enough buffer data', function () { | ||
let buffer = Buffer.from([0x01]) | ||
let message = ReadCoilsResponse.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x01]) | ||
const message = ReadCoilsResponse.fromBuffer(buffer) | ||
@@ -62,4 +62,4 @@ assert.ok(message === null) | ||
it('should return null on wrong function code', function () { | ||
let buffer = Buffer.from([0x02, 0x03, 0x0a, 0x00, 0x0c]) | ||
let message = ReadCoilsResponse.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x02, 0x03, 0x0a, 0x00, 0x0c]) | ||
const message = ReadCoilsResponse.fromBuffer(buffer) | ||
@@ -70,4 +70,4 @@ assert.ok(message === null) | ||
it('should return <55> when addres = 0 and count = 8 for coils <55 55 55>', function () { | ||
let coils = Buffer.from([0x55, 0x55, 0x55]) | ||
let requestBuffer = Buffer.from([ | ||
const coils = Buffer.from([0x55, 0x55, 0x55]) | ||
const requestBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -81,7 +81,7 @@ 0x00, 0x00, // protocol | ||
]) | ||
let request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
let responseBody = ReadCoilsResponse.fromRequest(request.body, coils) | ||
let response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
let payload = response.createPayload() | ||
let responseBuffer = Buffer.from([ | ||
const request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
const responseBody = ReadCoilsResponse.fromRequest(request.body, coils) | ||
const response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
const payload = response.createPayload() | ||
const responseBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -99,4 +99,4 @@ 0x00, 0x00, // protocol | ||
it('should return <55> when addres = 6 and count = 8 for coils <55 55 55>', function () { | ||
let coils = Buffer.from([0x55, 0x55, 0x55]) | ||
let requestBuffer = Buffer.from([ | ||
const coils = Buffer.from([0x55, 0x55, 0x55]) | ||
const requestBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -110,7 +110,7 @@ 0x00, 0x00, // protocol | ||
]) | ||
let request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
let responseBody = ReadCoilsResponse.fromRequest(request.body, coils) | ||
let response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
let payload = response.createPayload() | ||
let responseBuffer = Buffer.from([ | ||
const request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
const responseBody = ReadCoilsResponse.fromRequest(request.body, coils) | ||
const response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
const payload = response.createPayload() | ||
const responseBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -128,4 +128,4 @@ 0x00, 0x00, // protocol | ||
it('should return <55 01> when addres = 0 and count = 9 for coils <55 55 55>', function () { | ||
let coils = Buffer.from([0x55, 0x55, 0x55]) | ||
let requestBuffer = Buffer.from([ | ||
const coils = Buffer.from([0x55, 0x55, 0x55]) | ||
const requestBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -139,7 +139,7 @@ 0x00, 0x00, // protocol | ||
]) | ||
let request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
let responseBody = ReadCoilsResponse.fromRequest(request.body, coils) | ||
let response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
let payload = response.createPayload() | ||
let responseBuffer = Buffer.from([ | ||
const request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
const responseBody = ReadCoilsResponse.fromRequest(request.body, coils) | ||
const response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
const payload = response.createPayload() | ||
const responseBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -157,4 +157,4 @@ 0x00, 0x00, // protocol | ||
it('should return <2A> when addres = 1 and count = 7 for coils <55 55 55>', function () { | ||
let coils = Buffer.from([0x55, 0x55, 0x55]) | ||
let requestBuffer = Buffer.from([ | ||
const coils = Buffer.from([0x55, 0x55, 0x55]) | ||
const requestBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -168,7 +168,7 @@ 0x00, 0x00, // protocol | ||
]) | ||
let request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
let responseBody = ReadCoilsResponse.fromRequest(request.body, coils) | ||
let response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
let payload = response.createPayload() | ||
let responseBuffer = Buffer.from([ | ||
const request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
const responseBody = ReadCoilsResponse.fromRequest(request.body, coils) | ||
const response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
const payload = response.createPayload() | ||
const responseBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -186,4 +186,4 @@ 0x00, 0x00, // protocol | ||
it('should return <05> when addres = 0 and count = 4 for coils <55 55 55>', function () { | ||
let coils = Buffer.from([0x55, 0x55, 0x55]) | ||
let requestBuffer = Buffer.from([ | ||
const coils = Buffer.from([0x55, 0x55, 0x55]) | ||
const requestBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -197,7 +197,7 @@ 0x00, 0x00, // protocol | ||
]) | ||
let request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
let responseBody = ReadCoilsResponse.fromRequest(request.body, coils) | ||
let response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
let payload = response.createPayload() | ||
let responseBuffer = Buffer.from([ | ||
const request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
const responseBody = ReadCoilsResponse.fromRequest(request.body, coils) | ||
const response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
const payload = response.createPayload() | ||
const responseBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -215,4 +215,4 @@ 0x00, 0x00, // protocol | ||
it('should return <02> when addres = 1 and count = 3 for coils <55 55 55>', function () { | ||
let coils = Buffer.from([0x55, 0x55, 0x55]) | ||
let requestBuffer = Buffer.from([ | ||
const coils = Buffer.from([0x55, 0x55, 0x55]) | ||
const requestBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -226,7 +226,7 @@ 0x00, 0x00, // protocol | ||
]) | ||
let request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
let responseBody = ReadCoilsResponse.fromRequest(request.body, coils) | ||
let response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
let payload = response.createPayload() | ||
let responseBuffer = Buffer.from([ | ||
const request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
const responseBody = ReadCoilsResponse.fromRequest(request.body, coils) | ||
const response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
const payload = response.createPayload() | ||
const responseBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -247,5 +247,5 @@ 0x00, 0x00, // protocol | ||
it('should create a buffer from a read coils message', function () { | ||
let readCoilsRequest = new ReadCoilsRequest(10, 12) | ||
let buffer = readCoilsRequest.createPayload() | ||
let expected = Buffer.from([0x01, 0x00, 0x0a, 0x00, 0x0c]) | ||
const readCoilsRequest = new ReadCoilsRequest(10, 12) | ||
const buffer = readCoilsRequest.createPayload() | ||
const expected = Buffer.from([0x01, 0x00, 0x0a, 0x00, 0x0c]) | ||
@@ -255,4 +255,4 @@ assert.deepEqual(expected, buffer) | ||
it('should create a message object from a buffer', function () { | ||
let buffer = Buffer.from([0x01, 0x00, 0x0a, 0x00, 0x0c]) | ||
let message = ReadCoilsRequest.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x01, 0x00, 0x0a, 0x00, 0x0c]) | ||
const message = ReadCoilsRequest.fromBuffer(buffer) | ||
@@ -264,4 +264,4 @@ assert.equal(0x01, message.fc) | ||
it('should return null on not enough buffer data', function () { | ||
let buffer = Buffer.from([0x01, 0x00]) | ||
let message = ReadCoilsRequest.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x01, 0x00]) | ||
const message = ReadCoilsRequest.fromBuffer(buffer) | ||
@@ -271,4 +271,4 @@ assert.ok(message === null) | ||
it('should return null on wrong function code', function () { | ||
let buffer = Buffer.from([0x02, 0x00, 0x0a, 0x00, 0x0c]) | ||
let message = ReadCoilsRequest.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x02, 0x00, 0x0a, 0x00, 0x0c]) | ||
const message = ReadCoilsRequest.fromBuffer(buffer) | ||
@@ -275,0 +275,0 @@ assert.ok(message === null) |
@@ -5,5 +5,5 @@ 'use strict' | ||
let assert = require('assert') | ||
let ReadDiscreteInputsRequest = require('../src/request/read-discrete-inputs.js') | ||
let ReadDiscreteInputsResponse = require('../src/response/read-discrete-inputs.js') | ||
const assert = require('assert') | ||
const ReadDiscreteInputsRequest = require('../src/request/read-discrete-inputs.js') | ||
const ReadDiscreteInputsResponse = require('../src/response/read-discrete-inputs.js') | ||
@@ -13,5 +13,5 @@ describe('ReadDiscreteInputs Tests.', function () { | ||
it('should create a buffer from a read discrete inputs message', function () { | ||
let response = new ReadDiscreteInputsResponse([1, 0, 1, 0, 1, 0, 1, 0, 1, 0], 2) | ||
let buffer = response.createPayload() | ||
let expected = Buffer.from([0x02, 0x02, 0x55, 0x01]) | ||
const response = new ReadDiscreteInputsResponse([1, 0, 1, 0, 1, 0, 1, 0, 1, 0], 2) | ||
const buffer = response.createPayload() | ||
const expected = Buffer.from([0x02, 0x02, 0x55, 0x01]) | ||
@@ -21,4 +21,4 @@ assert.deepEqual(expected, buffer) | ||
it('should create a message object from a buffer', function () { | ||
let buffer = Buffer.from([0x02, 0x02, 0x55, 0x01]) | ||
let message = ReadDiscreteInputsResponse.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x02, 0x02, 0x55, 0x01]) | ||
const message = ReadDiscreteInputsResponse.fromBuffer(buffer) | ||
@@ -31,4 +31,4 @@ assert.equal(0x02, message.fc) | ||
it('should return null on not enough buffer data', function () { | ||
let buffer = Buffer.from([0x02]) | ||
let message = ReadDiscreteInputsResponse.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x02]) | ||
const message = ReadDiscreteInputsResponse.fromBuffer(buffer) | ||
@@ -38,4 +38,4 @@ assert.ok(message === null) | ||
it('should return null on wrong function code', function () { | ||
let buffer = Buffer.from([0x03, 0x03, 0x0a, 0x00, 0x0c]) | ||
let message = ReadDiscreteInputsResponse.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x03, 0x03, 0x0a, 0x00, 0x0c]) | ||
const message = ReadDiscreteInputsResponse.fromBuffer(buffer) | ||
@@ -48,5 +48,5 @@ assert.ok(message === null) | ||
it('should create a buffer from a discrete inputs message', function () { | ||
let readDiscreteInputsRequest = new ReadDiscreteInputsRequest(22, 33) | ||
let buffer = readDiscreteInputsRequest.createPayload() | ||
let expected = Buffer.from([0x02, 0x00, 0x16, 0x00, 0x21]) | ||
const readDiscreteInputsRequest = new ReadDiscreteInputsRequest(22, 33) | ||
const buffer = readDiscreteInputsRequest.createPayload() | ||
const expected = Buffer.from([0x02, 0x00, 0x16, 0x00, 0x21]) | ||
@@ -56,4 +56,4 @@ assert.deepEqual(expected, buffer) | ||
it('should create a message from a buffer', function () { | ||
let buffer = Buffer.from([0x02, 0x00, 0x16, 0x00, 0x21]) | ||
let message = ReadDiscreteInputsRequest.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x02, 0x00, 0x16, 0x00, 0x21]) | ||
const message = ReadDiscreteInputsRequest.fromBuffer(buffer) | ||
@@ -66,4 +66,4 @@ assert.ok(message !== null) | ||
it('should return null on not enough buffer data', function () { | ||
let buffer = Buffer.from([0x02, 0x00]) | ||
let message = ReadDiscreteInputsRequest.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x02, 0x00]) | ||
const message = ReadDiscreteInputsRequest.fromBuffer(buffer) | ||
@@ -73,4 +73,4 @@ assert.ok(message === null) | ||
it('should return null on wrong function code', function () { | ||
let buffer = Buffer.from([0x03, 0x00, 0x0a, 0x00, 0x0c]) | ||
let message = ReadDiscreteInputsRequest.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x03, 0x00, 0x0a, 0x00, 0x0c]) | ||
const message = ReadDiscreteInputsRequest.fromBuffer(buffer) | ||
@@ -77,0 +77,0 @@ assert.ok(message === null) |
@@ -5,4 +5,4 @@ 'use strict' | ||
let assert = require('assert') | ||
let ReadHoldingRegistersRequest = require('../src/request/read-holding-registers.js') | ||
const assert = require('assert') | ||
const ReadHoldingRegistersRequest = require('../src/request/read-holding-registers.js') | ||
@@ -15,5 +15,5 @@ describe('ReadHoldingRegisters Tests.', function () { | ||
it('should create a buffer from a read holding registers message', function () { | ||
let request = new ReadHoldingRegistersRequest(22, 33) | ||
let buffer = request.createPayload() | ||
let expected = Buffer.from([0x03, 0x00, 0x16, 0x00, 0x21]) | ||
const request = new ReadHoldingRegistersRequest(22, 33) | ||
const buffer = request.createPayload() | ||
const expected = Buffer.from([0x03, 0x00, 0x16, 0x00, 0x21]) | ||
@@ -23,4 +23,4 @@ assert.deepEqual(expected, buffer) | ||
it('should create a message from a buffer', function () { | ||
let buffer = Buffer.from([0x03, 0x00, 0x16, 0x00, 0x21]) | ||
let message = ReadHoldingRegistersRequest.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x03, 0x00, 0x16, 0x00, 0x21]) | ||
const message = ReadHoldingRegistersRequest.fromBuffer(buffer) | ||
@@ -33,4 +33,4 @@ assert.ok(message !== null) | ||
it('should return null on not enough buffer data', function () { | ||
let buffer = Buffer.from([0x03, 0x00]) | ||
let message = ReadHoldingRegistersRequest.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x03, 0x00]) | ||
const message = ReadHoldingRegistersRequest.fromBuffer(buffer) | ||
@@ -40,4 +40,4 @@ assert.ok(message === null) | ||
it('should return null on wrong function code', function () { | ||
let buffer = Buffer.from([0x04, 0x00, 0x0a, 0x00, 0x0c]) | ||
let message = ReadHoldingRegistersRequest.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x04, 0x00, 0x0a, 0x00, 0x0c]) | ||
const message = ReadHoldingRegistersRequest.fromBuffer(buffer) | ||
@@ -44,0 +44,0 @@ assert.ok(message === null) |
@@ -5,4 +5,4 @@ 'use strict' | ||
let assert = require('assert') | ||
let ReadInputRegistersRequest = require('../src/request/read-input-registers.js') | ||
const assert = require('assert') | ||
const ReadInputRegistersRequest = require('../src/request/read-input-registers.js') | ||
@@ -15,5 +15,5 @@ describe('ReadInputRegisters Tests.', function () { | ||
it('should create a buffer from a read input registers message', function () { | ||
let request = new ReadInputRegistersRequest(22, 33) | ||
let buffer = request.createPayload() | ||
let expected = Buffer.from([0x04, 0x00, 0x16, 0x00, 0x21]) | ||
const request = new ReadInputRegistersRequest(22, 33) | ||
const buffer = request.createPayload() | ||
const expected = Buffer.from([0x04, 0x00, 0x16, 0x00, 0x21]) | ||
@@ -23,4 +23,4 @@ assert.deepEqual(expected, buffer) | ||
it('should create a message from a buffer', function () { | ||
let buffer = Buffer.from([0x04, 0x00, 0x16, 0x00, 0x21]) | ||
let message = ReadInputRegistersRequest.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x04, 0x00, 0x16, 0x00, 0x21]) | ||
const message = ReadInputRegistersRequest.fromBuffer(buffer) | ||
@@ -33,4 +33,4 @@ assert.ok(message !== null) | ||
it('should return null on not enough buffer data', function () { | ||
let buffer = Buffer.from([0x04, 0x00]) | ||
let message = ReadInputRegistersRequest.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x04, 0x00]) | ||
const message = ReadInputRegistersRequest.fromBuffer(buffer) | ||
@@ -40,4 +40,4 @@ assert.ok(message === null) | ||
it('should return null on wrong function code', function () { | ||
let buffer = Buffer.from([0x05, 0x00, 0x0a, 0x00, 0x0c]) | ||
let message = ReadInputRegistersRequest.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x05, 0x00, 0x0a, 0x00, 0x0c]) | ||
const message = ReadInputRegistersRequest.fromBuffer(buffer) | ||
@@ -44,0 +44,0 @@ assert.ok(message === null) |
@@ -5,5 +5,5 @@ 'use strict' | ||
let assert = require('assert') | ||
let ResponseBody = require('../src/response/response-body.js') | ||
let ReadCoilsResponseBody = require('../src/response/read-coils.js') | ||
const assert = require('assert') | ||
const ResponseBody = require('../src/response/response-body.js') | ||
const ReadCoilsResponseBody = require('../src/response/read-coils.js') | ||
@@ -15,3 +15,3 @@ describe('Modbus Response Tests.', function () { | ||
it('should create request from buffer', function () { | ||
let buffer = Buffer.from([ | ||
const buffer = Buffer.from([ | ||
0x01, // fc | ||
@@ -23,3 +23,3 @@ 0x02, // byte count | ||
let response = ResponseBody.fromBuffer(buffer) | ||
const response = ResponseBody.fromBuffer(buffer) | ||
@@ -50,3 +50,3 @@ assert.ok(response !== null) | ||
it('should handle invalid buffer content', function () { | ||
let buffer = Buffer.from([ | ||
const buffer = Buffer.from([ | ||
0x01, // fc | ||
@@ -57,3 +57,3 @@ 0x02, // byte count | ||
let response = ReadCoilsResponseBody.fromBuffer(buffer) | ||
const response = ReadCoilsResponseBody.fromBuffer(buffer) | ||
@@ -60,0 +60,0 @@ assert.ok(response === null) |
'use strict' | ||
/* global describe, it, beforeEach */ | ||
let assert = require('assert') | ||
let sinon = require('sinon') | ||
let EventEmitter = require('events') | ||
let ReadCoilsRequest = require('../src/request/read-holding-registers.js') | ||
let ReadHoldingRegistersResponseBody = require('../src/response/read-holding-registers.js') | ||
let ModbusRTUResponse = require('../src/rtu-response.js') | ||
let ExceptionResponse = require('../src/response/exception.js') | ||
let ModbusRTUClientRequestHandler = require('../src/rtu-client-request-handler.js') | ||
const assert = require('assert') | ||
const sinon = require('sinon') | ||
const EventEmitter = require('events') | ||
const ReadCoilsRequest = require('../src/request/read-holding-registers.js') | ||
const ReadHoldingRegistersResponseBody = require('../src/response/read-holding-registers.js') | ||
const ModbusRTUResponse = require('../src/rtu-response.js') | ||
const ExceptionResponse = require('../src/response/exception.js') | ||
const ModbusRTUClientRequestHandler = require('../src/rtu-client-request-handler.js') | ||
@@ -27,4 +27,4 @@ describe('Modbus/RTU Client Request Tests', function () { | ||
it('should register an rtu request', function () { | ||
let handler = new ModbusRTUClientRequestHandler(socket, 4) | ||
let readCoilsRequest = new ReadCoilsRequest(0x4321, 0x0120) | ||
const handler = new ModbusRTUClientRequestHandler(socket, 4) | ||
const readCoilsRequest = new ReadCoilsRequest(0x4321, 0x0120) | ||
@@ -35,3 +35,3 @@ socket.emit('open') | ||
let promise = handler.register(readCoilsRequest) | ||
const promise = handler.register(readCoilsRequest) | ||
@@ -46,7 +46,7 @@ assert.ok(promise instanceof Promise) | ||
it('should register an rtu request and handle a response', function (done) { | ||
let ReadHoldingRegistersRequestBody = require('../src/request/read-holding-registers.js') | ||
let handler = new ModbusRTUClientRequestHandler(socket, 1) | ||
let request = new ReadHoldingRegistersRequestBody(0, 1) | ||
let response = new ReadHoldingRegistersResponseBody(1, Buffer.from([0x00, 0x32])) | ||
let rtuResponse = new ModbusRTUResponse(1, 0x91C9, response) | ||
const ReadHoldingRegistersRequestBody = require('../src/request/read-holding-registers.js') | ||
const handler = new ModbusRTUClientRequestHandler(socket, 1) | ||
const request = new ReadHoldingRegistersRequestBody(0, 1) | ||
const response = new ReadHoldingRegistersResponseBody(1, Buffer.from([0x00, 0x32])) | ||
const rtuResponse = new ModbusRTUResponse(1, 0x91C9, response) | ||
@@ -71,7 +71,7 @@ socket.emit('open') | ||
it('should register an rtu request and handle a exception response', function (done) { | ||
let ReadCoilsRequest = require('../src/request/read-coils.js') | ||
let handler = new ModbusRTUClientRequestHandler(socket, 4) | ||
let request = new ReadCoilsRequest(0x0000, 0x0008) | ||
let response = new ExceptionResponse(0x81, 0x01) | ||
let rtuResponse = new ModbusRTUResponse(4, 8352, response) | ||
const ReadCoilsRequest = require('../src/request/read-coils.js') | ||
const handler = new ModbusRTUClientRequestHandler(socket, 4) | ||
const request = new ReadCoilsRequest(0x0000, 0x0008) | ||
const response = new ExceptionResponse(0x81, 0x01) | ||
const rtuResponse = new ModbusRTUResponse(4, 8352, response) | ||
@@ -78,0 +78,0 @@ socket.emit('open') |
@@ -5,4 +5,4 @@ 'use strict' | ||
let assert = require('assert') | ||
let ModbusRTUClientResponseHandler = require('../src/rtu-client-response-handler.js') | ||
const assert = require('assert') | ||
const ModbusRTUClientResponseHandler = require('../src/rtu-client-response-handler.js') | ||
@@ -18,3 +18,3 @@ describe('Modbus/RTU Client Response Tests', function () { | ||
it('should handle a valid read coils response', function () { | ||
let responseBuffer = Buffer.from([ | ||
const responseBuffer = Buffer.from([ | ||
0x01, // address | ||
@@ -30,3 +30,3 @@ 0x01, // function code | ||
let response = handler.shift() | ||
const response = handler.shift() | ||
@@ -43,3 +43,3 @@ assert.ok(response !== null) | ||
it('should handle a exception', function () { | ||
let responseBuffer = Buffer.from([ | ||
const responseBuffer = Buffer.from([ | ||
0x01, // address | ||
@@ -53,3 +53,3 @@ 0x81, // exception code for fc 0x01 | ||
let response = handler.shift() | ||
const response = handler.shift() | ||
@@ -63,6 +63,6 @@ assert.ok(response !== undefined) | ||
it('should handle a chopped response', function () { | ||
let responseBufferA = Buffer.from([ | ||
const responseBufferA = Buffer.from([ | ||
0x01 // address | ||
]) | ||
let responseBufferB = Buffer.from([ | ||
const responseBufferB = Buffer.from([ | ||
0x01, // function code | ||
@@ -69,0 +69,0 @@ 0x02, // byte count |
/* global describe, it, beforeEach */ | ||
'use strict' | ||
let assert = require('assert') | ||
let Modbus = require('../') | ||
let EventEmitter = require('events') | ||
const assert = require('assert') | ||
const Modbus = require('../') | ||
const EventEmitter = require('events') | ||
@@ -8,0 +8,0 @@ describe('RTU Server Tests.', function () { |
@@ -5,6 +5,6 @@ 'use strict' | ||
let assert = require('assert') | ||
let Modbus = require('../') | ||
let sinon = require('sinon') | ||
let EventEmitter = require('events') | ||
const assert = require('assert') | ||
const Modbus = require('../') | ||
const sinon = require('sinon') | ||
const EventEmitter = require('events') | ||
@@ -25,5 +25,5 @@ describe('TCP Client Tests.', function () { | ||
describe('Read Coils Tests.', function () { | ||
let ReadCoilsResponseBody = require('../src/response/read-coils.js') | ||
const ReadCoilsResponseBody = require('../src/response/read-coils.js') | ||
it('should create request from buffer', function () { | ||
let buffer = Buffer.from([ | ||
const buffer = Buffer.from([ | ||
0x01, // fc | ||
@@ -35,3 +35,3 @@ 0x02, // byte count | ||
let response = ReadCoilsResponseBody.fromBuffer(buffer) | ||
const response = ReadCoilsResponseBody.fromBuffer(buffer) | ||
@@ -62,3 +62,3 @@ assert.ok(response !== null) | ||
it('should handle invalid buffer content', function () { | ||
let buffer = Buffer.from([ | ||
const buffer = Buffer.from([ | ||
0x01, // fc | ||
@@ -69,3 +69,3 @@ 0x02, // byte count | ||
let response = ReadCoilsResponseBody.fromBuffer(buffer) | ||
const response = ReadCoilsResponseBody.fromBuffer(buffer) | ||
@@ -75,3 +75,3 @@ assert.ok(response === null) | ||
it('should handle a invalid request (invalid quantity)', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
const client = new Modbus.client.TCP(socket) | ||
@@ -91,4 +91,4 @@ socket.emit('connect') | ||
it('should handle a valid request with a exception response', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
let response = Buffer.from([ | ||
const client = new Modbus.client.TCP(socket) | ||
const response = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -119,3 +119,3 @@ 0x00, 0x00, // protocol | ||
it('should handle a valid request with timeout', function (done) { | ||
let client = new Modbus.client.TCP(socket, 2, 100) // unit id = 2, timeout = 100ms | ||
const client = new Modbus.client.TCP(socket, 2, 100) // unit id = 2, timeout = 100ms | ||
@@ -135,3 +135,3 @@ socket.emit('connect') | ||
it('should handle a valid request while offline', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
const client = new Modbus.client.TCP(socket) | ||
@@ -147,3 +147,3 @@ client.readCoils(10, 11) | ||
it('should handle two valid request while offline', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
const client = new Modbus.client.TCP(socket) | ||
@@ -166,4 +166,4 @@ client.readCoils(10, 11) | ||
it('should handle two valid requests', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
let responseA = Buffer.from([ | ||
const client = new Modbus.client.TCP(socket) | ||
const responseA = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -178,3 +178,3 @@ 0x00, 0x00, // protocol | ||
]) | ||
let responseB = Buffer.from([ | ||
const responseB = Buffer.from([ | ||
0x00, 0x02, // transaction id | ||
@@ -211,4 +211,4 @@ 0x00, 0x00, // protocol | ||
it('should handle a valid request with an out of sync response', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
let response = Buffer.from([ | ||
const client = new Modbus.client.TCP(socket) | ||
const response = Buffer.from([ | ||
0x00, 0x02, // transaction id is WRONG!!!! | ||
@@ -239,4 +239,4 @@ 0x00, 0x00, // protocol | ||
it('should handle two valid request with an out of sync response', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
let response = Buffer.from([ | ||
const client = new Modbus.client.TCP(socket) | ||
const response = Buffer.from([ | ||
0x00, 0x02, // transaction id is WRONG!!!! | ||
@@ -274,4 +274,4 @@ 0x00, 0x00, // protocol | ||
it('should handle a valid request with an out of sync response (wrong fc)', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
let response = Buffer.from([ | ||
const client = new Modbus.client.TCP(socket) | ||
const response = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -302,4 +302,4 @@ 0x00, 0x00, // protocol | ||
it('should handle a valid request with a wrong protocol response', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
let response = Buffer.from([ | ||
const client = new Modbus.client.TCP(socket) | ||
const response = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -333,4 +333,4 @@ 0x00, 0x01, // protocol WRONG !!!! | ||
it('should handle a valid request', function (done) { | ||
let client = new Modbus.client.TCP(socket, 2) | ||
let response = Buffer.from([ | ||
const client = new Modbus.client.TCP(socket, 2) | ||
const response = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -364,3 +364,3 @@ 0x00, 0x00, // protocol | ||
it('should handle a invalid request (invalid start address)', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
const client = new Modbus.client.TCP(socket) | ||
@@ -380,3 +380,3 @@ socket.emit('connect') | ||
it('should handle a invalid request (invalid quantity)', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
const client = new Modbus.client.TCP(socket) | ||
@@ -398,4 +398,4 @@ socket.emit('connect') | ||
it('should handle a valid request', function (done) { | ||
let client = new Modbus.client.TCP(socket, 2) | ||
let response = Buffer.from([ | ||
const client = new Modbus.client.TCP(socket, 2) | ||
const response = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -429,3 +429,3 @@ 0x00, 0x00, // protocol | ||
it('should handle a invalid request (invalid start address)', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
const client = new Modbus.client.TCP(socket) | ||
@@ -445,3 +445,3 @@ socket.emit('connect') | ||
it('should handle a invalid request (invalid quantity)', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
const client = new Modbus.client.TCP(socket) | ||
@@ -463,4 +463,4 @@ socket.emit('connect') | ||
it('should handle a valid request', function (done) { | ||
let client = new Modbus.client.TCP(socket, 2) | ||
let response = Buffer.from([ | ||
const client = new Modbus.client.TCP(socket, 2) | ||
const response = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -494,3 +494,3 @@ 0x00, 0x00, // protocol | ||
it('should handle a invalid request (invalid start address)', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
const client = new Modbus.client.TCP(socket) | ||
@@ -510,3 +510,3 @@ socket.emit('connect') | ||
it('should handle a invalid request (invalid quantity)', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
const client = new Modbus.client.TCP(socket) | ||
@@ -528,4 +528,4 @@ socket.emit('connect') | ||
it('should handle a valid request', function (done) { | ||
let client = new Modbus.client.TCP(socket, 2) | ||
let response = Buffer.from([ | ||
const client = new Modbus.client.TCP(socket, 2) | ||
const response = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -558,3 +558,3 @@ 0x00, 0x00, // protocol | ||
it('should handle a invalid request (invalid start address)', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
const client = new Modbus.client.TCP(socket) | ||
@@ -576,4 +576,4 @@ socket.emit('connect') | ||
it('should handle a valid request', function (done) { | ||
let client = new Modbus.client.TCP(socket, 2) | ||
let response = Buffer.from([ | ||
const client = new Modbus.client.TCP(socket, 2) | ||
const response = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -606,3 +606,3 @@ 0x00, 0x00, // protocol | ||
it('should handle a invalid request (invalid start address)', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
const client = new Modbus.client.TCP(socket) | ||
@@ -622,3 +622,3 @@ socket.emit('connect') | ||
it('should handle a invalid request (invalid value, to big)', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
const client = new Modbus.client.TCP(socket) | ||
@@ -638,3 +638,3 @@ socket.emit('connect') | ||
it('should handle a invalid request (invalid value, float)', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
const client = new Modbus.client.TCP(socket) | ||
@@ -654,3 +654,3 @@ socket.emit('connect') | ||
it('should handle a invalid request (invalid value, negative)', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
const client = new Modbus.client.TCP(socket) | ||
@@ -672,4 +672,4 @@ socket.emit('connect') | ||
it('should handle a valid request (with array)', function (done) { | ||
let client = new Modbus.client.TCP(socket, 2) | ||
let response = Buffer.from([ | ||
const client = new Modbus.client.TCP(socket, 2) | ||
const response = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -702,4 +702,4 @@ 0x00, 0x00, // protocol | ||
it('should handle a valid request (with buffer)', function (done) { | ||
let client = new Modbus.client.TCP(socket, 2) | ||
let response = Buffer.from([ | ||
const client = new Modbus.client.TCP(socket, 2) | ||
const response = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -733,3 +733,3 @@ 0x00, 0x00, // protocol | ||
it('should handle a invalid request (invalid start address)', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
const client = new Modbus.client.TCP(socket) | ||
@@ -749,4 +749,4 @@ socket.emit('connect') | ||
it('should handle a invalid request (invalid array size)', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
let arr = [] | ||
const client = new Modbus.client.TCP(socket) | ||
const arr = [] | ||
@@ -770,4 +770,4 @@ for (let i = 0; i < (0x07b0 * 8) + 1; i += 1) { | ||
it('should handle a invalid request (invalid buffer size)', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
let buf = Buffer.alloc(0x07b1) | ||
const client = new Modbus.client.TCP(socket) | ||
const buf = Buffer.alloc(0x07b1) | ||
@@ -787,4 +787,4 @@ socket.emit('connect') | ||
it('should handle a invalid request (inconsistent buffer size)', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
let buf = Buffer.alloc(0x07a0 / 8) | ||
const client = new Modbus.client.TCP(socket) | ||
const buf = Buffer.alloc(0x07a0 / 8) | ||
@@ -806,4 +806,4 @@ socket.emit('connect') | ||
it('should handle a valid request (with array)', function (done) { | ||
let client = new Modbus.client.TCP(socket, 2) | ||
let response = Buffer.from([ | ||
const client = new Modbus.client.TCP(socket, 2) | ||
const response = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -836,4 +836,4 @@ 0x00, 0x00, // protocol | ||
it('should handle a valid request (with buffer)', function (done) { | ||
let client = new Modbus.client.TCP(socket, 2) | ||
let response = Buffer.from([ | ||
const client = new Modbus.client.TCP(socket, 2) | ||
const response = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -867,3 +867,3 @@ 0x00, 0x00, // protocol | ||
it('should handle a invalid request (invalid start address)', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
const client = new Modbus.client.TCP(socket) | ||
@@ -883,4 +883,4 @@ socket.emit('connect') | ||
it('should handle a invalid request (invalid array size)', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
let arr = [] | ||
const client = new Modbus.client.TCP(socket) | ||
const arr = [] | ||
@@ -904,4 +904,4 @@ for (let i = 0; i < (0x007b + 1); i += 1) { | ||
it('should handle a invalid request (invalid buffer size)', function (done) { | ||
let client = new Modbus.client.TCP(socket) | ||
let buf = Buffer.alloc((0x007b * 2) + 1) | ||
const client = new Modbus.client.TCP(socket) | ||
const buf = Buffer.alloc((0x007b * 2) + 1) | ||
@@ -908,0 +908,0 @@ socket.emit('connect') |
'use strict' | ||
/* global describe, it, beforeEach */ | ||
let assert = require('assert') | ||
let sinon = require('sinon') | ||
let EventEmitter = require('events') | ||
let TCPRequestHandler = require('../src/tcp-client-request-handler.js') | ||
let ReadCoilsRequest = require('../src/request/read-coils.js') | ||
const assert = require('assert') | ||
const sinon = require('sinon') | ||
const EventEmitter = require('events') | ||
const TCPRequestHandler = require('../src/tcp-client-request-handler.js') | ||
const ReadCoilsRequest = require('../src/request/read-coils.js') | ||
@@ -23,5 +23,5 @@ describe('TCP Modbus Request Tests', function () { | ||
it('should write a tcp request.', function () { | ||
let handler = new TCPRequestHandler(socket, 3) | ||
let readCoilsRequest = new ReadCoilsRequest(0xa0fa, 0x0120) | ||
let requestBuffer = Buffer.from([0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0x03, 0x01, 0xa0, 0xfa, 0x01, 0x20]) | ||
const handler = new TCPRequestHandler(socket, 3) | ||
const readCoilsRequest = new ReadCoilsRequest(0xa0fa, 0x0120) | ||
const requestBuffer = Buffer.from([0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0x03, 0x01, 0xa0, 0xfa, 0x01, 0x20]) | ||
@@ -33,3 +33,3 @@ socket.emit('connect') | ||
/* should flush the request right away */ | ||
let promise = handler.register(readCoilsRequest) | ||
const promise = handler.register(readCoilsRequest) | ||
@@ -36,0 +36,0 @@ assert.ok(promise instanceof Promise) |
/* globals describe, it */ | ||
'use strict' | ||
let assert = require('assert') | ||
let TCPRequest = require('../src/tcp-request.js') | ||
const assert = require('assert') | ||
const TCPRequest = require('../src/tcp-request.js') | ||
describe('TCP Request Tests', function () { | ||
it('should return a valid TCPRequest object for function 15', function () { | ||
let requestBuffer = Buffer.from([ | ||
const requestBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -21,3 +21,3 @@ 0x00, 0x00, // protocol | ||
let request = TCPRequest.fromBuffer(requestBuffer) | ||
const request = TCPRequest.fromBuffer(requestBuffer) | ||
assert.ok(request) | ||
@@ -24,0 +24,0 @@ assert.equal(request.id, 0x0001) |
@@ -5,4 +5,4 @@ 'use strict' | ||
let assert = require('assert') | ||
let TCPResponseHandler = require('../src/tcp-client-response-handler.js') | ||
const assert = require('assert') | ||
const TCPResponseHandler = require('../src/tcp-client-response-handler.js') | ||
@@ -19,3 +19,3 @@ describe('Modbus/TCP Client Response Handler Tests', function () { | ||
it('should handle a valid read coils response', function () { | ||
let responseBuffer = Buffer.from([ | ||
const responseBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -33,3 +33,3 @@ 0x00, 0x00, // protocol | ||
let response = handler.shift() | ||
const response = handler.shift() | ||
@@ -46,3 +46,3 @@ assert.ok(response !== null) | ||
it('should handle a exception', function () { | ||
let responseBuffer = Buffer.from([ | ||
const responseBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -58,3 +58,3 @@ 0x00, 0x00, // protocol | ||
let response = handler.shift() | ||
const response = handler.shift() | ||
@@ -72,3 +72,3 @@ assert.ok(response !== undefined) | ||
it('should handle a chopped response', function () { | ||
let responseBufferA = Buffer.from([ | ||
const responseBufferA = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -78,3 +78,3 @@ 0x00, 0x00, // protocol | ||
]) | ||
let responseBufferB = Buffer.from([ | ||
const responseBufferB = Buffer.from([ | ||
0x03, // unit id | ||
@@ -81,0 +81,0 @@ 0x01, // function code |
@@ -5,13 +5,13 @@ 'use strict' | ||
let assert = require('assert') | ||
let ReadCoilsResponseBody = require('../src/response/read-coils.js') | ||
let ReadDiscreteInputsResponseBody = require('../src/response/read-discrete-inputs.js') | ||
let ReadHoldingRegistersResponseBody = require('../src/response/read-holding-registers.js') | ||
let ReadInputRegistersResponseBody = require('../src/response/read-input-registers.js') | ||
let WriteSingleCoilResponseBody = require('../src/response/write-single-coil.js') | ||
let WriteSingleRegisterResponseBody = require('../src/response/write-single-register.js') | ||
let WriteMultipleCoilsResponseBody = require('../src/response/write-multiple-coils.js') | ||
let WriteMultipleRegistersResponseBody = require('../src/response/write-multiple-registers.js') | ||
let ModbusTCPResponse = require('../src/tcp-response.js') | ||
let ModbusTCPRequest = require('../src/tcp-request.js') | ||
const assert = require('assert') | ||
const ReadCoilsResponseBody = require('../src/response/read-coils.js') | ||
const ReadDiscreteInputsResponseBody = require('../src/response/read-discrete-inputs.js') | ||
const ReadHoldingRegistersResponseBody = require('../src/response/read-holding-registers.js') | ||
const ReadInputRegistersResponseBody = require('../src/response/read-input-registers.js') | ||
const WriteSingleCoilResponseBody = require('../src/response/write-single-coil.js') | ||
const WriteSingleRegisterResponseBody = require('../src/response/write-single-register.js') | ||
const WriteMultipleCoilsResponseBody = require('../src/response/write-multiple-coils.js') | ||
const WriteMultipleRegistersResponseBody = require('../src/response/write-multiple-registers.js') | ||
const ModbusTCPResponse = require('../src/tcp-response.js') | ||
const ModbusTCPRequest = require('../src/tcp-request.js') | ||
@@ -22,3 +22,3 @@ describe('Modbus/TCP Server Response Handler Tests', function () { | ||
it('should handle a valid read coils request', function () { | ||
let requestBuffer = Buffer.from([ | ||
const requestBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -33,11 +33,11 @@ 0x00, 0x00, // protocol | ||
let coils = Buffer.from([ | ||
const coils = Buffer.from([ | ||
0x01 | ||
]) | ||
let request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
let responseBody = ReadCoilsResponseBody.fromRequest(request.body, coils) | ||
let response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
let payload = response.createPayload() | ||
let responseBuffer = Buffer.from([ | ||
const request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
const responseBody = ReadCoilsResponseBody.fromRequest(request.body, coils) | ||
const response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
const payload = response.createPayload() | ||
const responseBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -56,3 +56,3 @@ 0x00, 0x00, // protocol | ||
it('should handle a valid read discrete inputs request', function () { | ||
let requestBuffer = Buffer.from([ | ||
const requestBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -67,11 +67,11 @@ 0x00, 0x00, // protocol | ||
let discreteInputs = Buffer.from([ | ||
const discreteInputs = Buffer.from([ | ||
0xff | ||
]) | ||
let request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
let responseBody = ReadDiscreteInputsResponseBody.fromRequest(request.body, discreteInputs) | ||
let response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
let payload = response.createPayload() | ||
let responseBuffer = Buffer.from([ | ||
const request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
const responseBody = ReadDiscreteInputsResponseBody.fromRequest(request.body, discreteInputs) | ||
const response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
const payload = response.createPayload() | ||
const responseBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -90,3 +90,3 @@ 0x00, 0x00, // protocol | ||
it('should handle a valid read holding registers request', function () { | ||
let requestBuffer = Buffer.from([ | ||
const requestBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -101,3 +101,3 @@ 0x00, 0x00, // protocol | ||
let holdingRegisters = Buffer.from([ | ||
const holdingRegisters = Buffer.from([ | ||
0xff, 0x10, | ||
@@ -109,7 +109,7 @@ 0x07, 0x08, | ||
let request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
let responseBody = ReadHoldingRegistersResponseBody.fromRequest(request.body, holdingRegisters) | ||
let response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
let payload = response.createPayload() | ||
let responseBuffer = Buffer.from([ | ||
const request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
const responseBody = ReadHoldingRegistersResponseBody.fromRequest(request.body, holdingRegisters) | ||
const response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
const payload = response.createPayload() | ||
const responseBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -129,3 +129,3 @@ 0x00, 0x00, // protocol | ||
it('should handle a valid read input registers request', function () { | ||
let requestBuffer = Buffer.from([ | ||
const requestBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -140,3 +140,3 @@ 0x00, 0x00, // protocol | ||
let inputRegisters = Buffer.from([ | ||
const inputRegisters = Buffer.from([ | ||
0xff, 0x10, | ||
@@ -148,7 +148,7 @@ 0x07, 0x08, | ||
let request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
let responseBody = ReadInputRegistersResponseBody.fromRequest(request.body, inputRegisters) | ||
let response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
let payload = response.createPayload() | ||
let responseBuffer = Buffer.from([ | ||
const request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
const responseBody = ReadInputRegistersResponseBody.fromRequest(request.body, inputRegisters) | ||
const response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
const payload = response.createPayload() | ||
const responseBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -168,3 +168,3 @@ 0x00, 0x00, // protocol | ||
it('should handle a valid write coil request', function () { | ||
let requestBuffer = Buffer.from([ | ||
const requestBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -179,7 +179,7 @@ 0x00, 0x00, // protocol | ||
let request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
let responseBody = WriteSingleCoilResponseBody.fromRequest(request.body) | ||
let response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
let payload = response.createPayload() | ||
let responseBuffer = Buffer.from([ | ||
const request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
const responseBody = WriteSingleCoilResponseBody.fromRequest(request.body) | ||
const response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
const payload = response.createPayload() | ||
const responseBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -197,3 +197,3 @@ 0x00, 0x00, // protocol | ||
it('should handle a valid write register request', function () { | ||
let requestBuffer = Buffer.from([ | ||
const requestBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -208,7 +208,7 @@ 0x00, 0x00, // protocol | ||
let request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
let responseBody = WriteSingleRegisterResponseBody.fromRequest(request.body) | ||
let response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
let payload = response.createPayload() | ||
let responseBuffer = Buffer.from([ | ||
const request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
const responseBody = WriteSingleRegisterResponseBody.fromRequest(request.body) | ||
const response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
const payload = response.createPayload() | ||
const responseBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -226,3 +226,3 @@ 0x00, 0x00, // protocol | ||
it('should handle a valid write multiple coils request', function () { | ||
let requestBuffer = Buffer.from([ | ||
const requestBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -239,7 +239,7 @@ 0x00, 0x00, // protocol | ||
let request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
let responseBody = WriteMultipleCoilsResponseBody.fromRequest(request.body) | ||
let response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
let payload = response.createPayload() | ||
let responseBuffer = Buffer.from([ | ||
const request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
const responseBody = WriteMultipleCoilsResponseBody.fromRequest(request.body) | ||
const response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
const payload = response.createPayload() | ||
const responseBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -257,3 +257,3 @@ 0x00, 0x00, // protocol | ||
it('should handle a valid write multiple registers request', function () { | ||
let requestBuffer = Buffer.from([ | ||
const requestBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -271,7 +271,7 @@ 0x00, 0x00, // protocol | ||
let request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
let responseBody = WriteMultipleRegistersResponseBody.fromRequest(request.body) | ||
let response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
let payload = response.createPayload() | ||
let responseBuffer = Buffer.from([ | ||
const request = ModbusTCPRequest.fromBuffer(requestBuffer) | ||
const responseBody = WriteMultipleRegistersResponseBody.fromRequest(request.body) | ||
const response = ModbusTCPResponse.fromRequest(request, responseBody) | ||
const payload = response.createPayload() | ||
const responseBuffer = Buffer.from([ | ||
0x00, 0x01, // transaction id | ||
@@ -278,0 +278,0 @@ 0x00, 0x00, // protocol |
/* global describe, it, beforeEach */ | ||
'use strict' | ||
let assert = require('assert') | ||
let Modbus = require('../') | ||
let EventEmitter = require('events') | ||
const assert = require('assert') | ||
const Modbus = require('../') | ||
const EventEmitter = require('events') | ||
@@ -8,0 +8,0 @@ describe('TCP Server Tests.', function () { |
@@ -5,4 +5,4 @@ 'use strict' | ||
let assert = require('assert') | ||
let WriteMultipleCoilsRequest = require('../src/request/write-multiple-coils.js') | ||
const assert = require('assert') | ||
const WriteMultipleCoilsRequest = require('../src/request/write-multiple-coils.js') | ||
@@ -16,5 +16,5 @@ describe('WriteMultipleCoils Tests.', function () { | ||
it('should create a buffer from a write multiple coils message', function () { | ||
let request = new WriteMultipleCoilsRequest(10, [1, 0, 1, 0, 0, 1, 0, 1, 1]) | ||
let buffer = request.createPayload() | ||
let expected = Buffer.from([0x0F, 0x00, 0x0a, 0x00, 0x09, 0x02, 0xa5, 0x01]) | ||
const request = new WriteMultipleCoilsRequest(10, [1, 0, 1, 0, 0, 1, 0, 1, 1]) | ||
const buffer = request.createPayload() | ||
const expected = Buffer.from([0x0F, 0x00, 0x0a, 0x00, 0x09, 0x02, 0xa5, 0x01]) | ||
@@ -27,4 +27,4 @@ assert.ok(request !== null) | ||
it('should create a message from a buffer', function () { | ||
let buffer = Buffer.from([0x0f, 0x00, 0x0a, 0x00, 0x09, 0x02, 0xa5, 0x01]) | ||
let message = WriteMultipleCoilsRequest.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x0f, 0x00, 0x0a, 0x00, 0x09, 0x02, 0xa5, 0x01]) | ||
const message = WriteMultipleCoilsRequest.fromBuffer(buffer) | ||
@@ -39,4 +39,4 @@ assert.ok(message !== null) | ||
it('should return null on not enough buffer data', function () { | ||
let buffer = Buffer.from([0x0f, 0x00]) | ||
let message = WriteMultipleCoilsRequest.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x0f, 0x00]) | ||
const message = WriteMultipleCoilsRequest.fromBuffer(buffer) | ||
@@ -46,4 +46,4 @@ assert.ok(message === null) | ||
it('should return null on wrong function code', function () { | ||
let buffer = Buffer.from([0x10, 0x00, 0x0a, 0xff, 0x00]) | ||
let message = WriteMultipleCoilsRequest.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x10, 0x00, 0x0a, 0xff, 0x00]) | ||
const message = WriteMultipleCoilsRequest.fromBuffer(buffer) | ||
@@ -50,0 +50,0 @@ assert.ok(message === null) |
@@ -5,4 +5,4 @@ 'use strict' | ||
let assert = require('assert') | ||
let WriteMultipleRegistersRequest = require('../src/request/write-multiple-registers.js') | ||
const assert = require('assert') | ||
const WriteMultipleRegistersRequest = require('../src/request/write-multiple-registers.js') | ||
@@ -16,5 +16,5 @@ describe('WriteMultipleRegisters Tests.', function () { | ||
it('should create a buffer from a write multiple registers message', function () { | ||
let request = new WriteMultipleRegistersRequest(10, [0x0001, 0x0002, 0x1234, 0x4321]) | ||
let buffer = request.createPayload() | ||
let expected = Buffer.from([0x10, 0x00, 0x0a, 0x00, 0x04, 0x08, 0x00, 0x01, 0x00, 0x02, 0x12, 0x34, 0x43, 0x21]) | ||
const request = new WriteMultipleRegistersRequest(10, [0x0001, 0x0002, 0x1234, 0x4321]) | ||
const buffer = request.createPayload() | ||
const expected = Buffer.from([0x10, 0x00, 0x0a, 0x00, 0x04, 0x08, 0x00, 0x01, 0x00, 0x02, 0x12, 0x34, 0x43, 0x21]) | ||
@@ -27,4 +27,4 @@ assert.ok(request !== null) | ||
it('should create a message from a buffer', function () { | ||
let buffer = Buffer.from([0x10, 0x00, 0x0a, 0x00, 0x04, 0x08, 0x00, 0x01, 0x00, 0x02, 0x12, 0x34, 0x43, 0x21]) | ||
let message = WriteMultipleRegistersRequest.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x10, 0x00, 0x0a, 0x00, 0x04, 0x08, 0x00, 0x01, 0x00, 0x02, 0x12, 0x34, 0x43, 0x21]) | ||
const message = WriteMultipleRegistersRequest.fromBuffer(buffer) | ||
@@ -39,4 +39,4 @@ assert.ok(message !== null) | ||
it('should return null on not enough buffer data', function () { | ||
let buffer = Buffer.from([0x0f, 0x00]) | ||
let message = WriteMultipleRegistersRequest.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x0f, 0x00]) | ||
const message = WriteMultipleRegistersRequest.fromBuffer(buffer) | ||
@@ -46,4 +46,4 @@ assert.ok(message === null) | ||
it('should return null on wrong function code', function () { | ||
let buffer = Buffer.from([0x11, 0x00, 0x0a, 0xff, 0x00]) | ||
let message = WriteMultipleRegistersRequest.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x11, 0x00, 0x0a, 0xff, 0x00]) | ||
const message = WriteMultipleRegistersRequest.fromBuffer(buffer) | ||
@@ -50,0 +50,0 @@ assert.ok(message === null) |
@@ -5,4 +5,4 @@ 'use strict' | ||
let assert = require('assert') | ||
let WriteSingleCoilRequest = require('../src/request/write-single-coil.js') | ||
const assert = require('assert') | ||
const WriteSingleCoilRequest = require('../src/request/write-single-coil.js') | ||
@@ -12,5 +12,5 @@ describe('WriteSingleCoil Tests.', function () { | ||
it('should create a buffer from a write single coil message', function () { | ||
let request = new WriteSingleCoilRequest(10, true) | ||
let buffer = request.createPayload() | ||
let expected = Buffer.from([0x05, 0x00, 0x0a, 0xff, 0x00]) | ||
const request = new WriteSingleCoilRequest(10, true) | ||
const buffer = request.createPayload() | ||
const expected = Buffer.from([0x05, 0x00, 0x0a, 0xff, 0x00]) | ||
@@ -20,4 +20,4 @@ assert.deepEqual(expected, buffer) | ||
it('should create a message from a buffer', function () { | ||
let buffer = Buffer.from([0x05, 0x00, 0x0a, 0xff, 0x00]) | ||
let message = WriteSingleCoilRequest.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x05, 0x00, 0x0a, 0xff, 0x00]) | ||
const message = WriteSingleCoilRequest.fromBuffer(buffer) | ||
@@ -30,4 +30,4 @@ assert.ok(message !== null) | ||
it('should return null on not enough buffer data', function () { | ||
let buffer = Buffer.from([0x05, 0x00]) | ||
let message = WriteSingleCoilRequest.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x05, 0x00]) | ||
const message = WriteSingleCoilRequest.fromBuffer(buffer) | ||
@@ -37,4 +37,4 @@ assert.ok(message === null) | ||
it('should return null on wrong function code', function () { | ||
let buffer = Buffer.from([0x06, 0x00, 0x0a, 0xff, 0x00]) | ||
let message = WriteSingleCoilRequest.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x06, 0x00, 0x0a, 0xff, 0x00]) | ||
const message = WriteSingleCoilRequest.fromBuffer(buffer) | ||
@@ -41,0 +41,0 @@ assert.ok(message === null) |
@@ -5,4 +5,4 @@ 'use strict' | ||
let assert = require('assert') | ||
let WriteSingleRegisterRequest = require('../src/request/write-single-register.js') | ||
const assert = require('assert') | ||
const WriteSingleRegisterRequest = require('../src/request/write-single-register.js') | ||
@@ -16,5 +16,5 @@ describe('WriteSingleRegister Tests.', function () { | ||
it('should create a buffer from a write single register message', function () { | ||
let request = new WriteSingleRegisterRequest(10, 0x1234) | ||
let buffer = request.createPayload() | ||
let expected = Buffer.from([0x06, 0x00, 0x0a, 0x12, 0x34]) | ||
const request = new WriteSingleRegisterRequest(10, 0x1234) | ||
const buffer = request.createPayload() | ||
const expected = Buffer.from([0x06, 0x00, 0x0a, 0x12, 0x34]) | ||
@@ -24,4 +24,4 @@ assert.deepEqual(expected, buffer) | ||
it('should create a message from a buffer', function () { | ||
let buffer = Buffer.from([0x06, 0x00, 0x0a, 0x12, 0x34]) | ||
let message = WriteSingleRegisterRequest.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x06, 0x00, 0x0a, 0x12, 0x34]) | ||
const message = WriteSingleRegisterRequest.fromBuffer(buffer) | ||
@@ -34,4 +34,4 @@ assert.ok(message !== null) | ||
it('should return null on not enough buffer data', function () { | ||
let buffer = Buffer.from([0x05, 0x00]) | ||
let message = WriteSingleRegisterRequest.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x05, 0x00]) | ||
const message = WriteSingleRegisterRequest.fromBuffer(buffer) | ||
@@ -41,4 +41,4 @@ assert.ok(message === null) | ||
it('should return null on wrong function code', function () { | ||
let buffer = Buffer.from([0x07, 0x00, 0x0a, 0xff, 0x00]) | ||
let message = WriteSingleRegisterRequest.fromBuffer(buffer) | ||
const buffer = Buffer.from([0x07, 0x00, 0x0a, 0xff, 0x00]) | ||
const message = WriteSingleRegisterRequest.fromBuffer(buffer) | ||
@@ -45,0 +45,0 @@ assert.ok(message === null) |
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
210323
4
89
6026