From f3ee5153f1ed9aa1a47a4679036d6afaad80ddd3 Mon Sep 17 00:00:00 2001 From: FlyBooks <36462422+FlyBooks@users.noreply.github.com> Date: Sun, 16 Jun 2024 23:10:26 +0800 Subject: [PATCH] feat: buf.slice() method has been deprecated (#558) --- index.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 5225496..04242ac 100644 --- a/index.js +++ b/index.js @@ -755,7 +755,7 @@ class ModbusRTU extends EventEmitter { buf.writeUInt16BE(length, 4); // add crc bytes to buffer - buf.writeUInt16LE(crc16(buf.slice(0, -2)), codeLength); + buf.writeUInt16LE(crc16(buf.subarray(0, -2)), codeLength); // write buffer to serial port _writeBufferToPort.call(this, buf, this._port._transactionIdWrite); @@ -820,7 +820,7 @@ class ModbusRTU extends EventEmitter { buf.writeUInt16BE(length, 4); // add crc bytes to buffer - buf.writeUInt16LE(crc16(buf.slice(0, -2)), codeLength); + buf.writeUInt16LE(crc16(buf.subarray(0, -2)), codeLength); // write buffer to serial port _writeBufferToPort.call(this, buf, this._port._transactionIdWrite); @@ -871,7 +871,7 @@ class ModbusRTU extends EventEmitter { } // add crc bytes to buffer - buf.writeUInt16LE(crc16(buf.slice(0, -2)), codeLength); + buf.writeUInt16LE(crc16(buf.subarray(0, -2)), codeLength); // write buffer to serial port _writeBufferToPort.call(this, buf, this._port._transactionIdWrite); @@ -934,7 +934,7 @@ class ModbusRTU extends EventEmitter { } // add crc bytes to buffer - buf.writeUInt16LE(crc16(buf.slice(0, -2)), codeLength); + buf.writeUInt16LE(crc16(buf.subarray(0, -2)), codeLength); // write buffer to serial port _writeBufferToPort.call(this, buf, this._port._transactionIdWrite); @@ -996,7 +996,7 @@ class ModbusRTU extends EventEmitter { } // add crc bytes to buffer - buf.writeUInt16LE(crc16(buf.slice(0, -2)), codeLength); + buf.writeUInt16LE(crc16(buf.subarray(0, -2)), codeLength); // write buffer to serial port _writeBufferToPort.call(this, buf, this._port._transactionIdWrite); @@ -1058,7 +1058,7 @@ class ModbusRTU extends EventEmitter { } // add crc bytes to buffer - buf.writeUInt16LE(crc16(buf.slice(0, -2)), codeLength); + buf.writeUInt16LE(crc16(buf.subarray(0, -2)), codeLength); // write buffer to serial port _writeBufferToPort.call(this, buf, this._port._transactionIdWrite); @@ -1094,7 +1094,7 @@ class ModbusRTU extends EventEmitter { buf.writeUInt8(code, 1); // add crc bytes to buffer - buf.writeUInt16LE(crc16(buf.slice(0, -2)), codeLength); + buf.writeUInt16LE(crc16(buf.subarray(0, -2)), codeLength); // write buffer to serial port _writeBufferToPort.call(this, buf, this._port._transactionIdWrite); @@ -1136,7 +1136,7 @@ class ModbusRTU extends EventEmitter { buf.writeUInt16BE(fileNumber, 4); buf.writeUInt16BE(recordNumber, 6); buf.writeUInt8(chunck, 9); - buf.writeUInt16LE(crc16(buf.slice(0, -2)), codeLength); + buf.writeUInt16LE(crc16(buf.subarray(0, -2)), codeLength); _writeBufferToPort.call(this, buf, this._port._transactionIdWrite); } @@ -1172,7 +1172,7 @@ class ModbusRTU extends EventEmitter { buf.writeUInt8(deviceIdCode, 3); buf.writeUInt8(objectId, 4); // add crc bytes to buffer - buf.writeUInt16LE(crc16(buf.slice(0, -2)), codeLength); + buf.writeUInt16LE(crc16(buf.subarray(0, -2)), codeLength); // write buffer to serial port _writeBufferToPort.call(this, buf, this._port._transactionIdWrite); }