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QAAQ,SAAW,WACtB,MAAM,WAAE,GAAe,QAAQ,cAE/B,OAAO,EAAW,MACtB,EAEA,OAAO,QAAQ,SAAW,QAAQ,oBAClC,IACI,OAAO,QAAQ,gBAAkB,QAAQ,0BAC7C,CAAE,MAAO,GAAO,CAChB,OAAO,QAAQ,QAAU,QAAQ,mBACjC,OAAO,QAAQ,mBAAqB,QAAQ,8BAC5C,OAAO,QAAQ,WAAa,QAAQ,sBACpC,OAAO,QAAQ,SAAW,QAAQ,oBAElC,OAAO,QAAQ,UAAY,QAAQ,uBACnC,IACI,OAAO,QAAQ,aAAe,QAAQ,yBAC1C,CAAE,MAAO,GAAO,CAChB,OAAO,QAAQ,QAAU,OAAO","file":"/npm/modbus-serial@8.0.23-no-serial-port/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/modbus-serial@8.0.23-no-serial-port/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\n/**\n * Copyright (c) 2015-2017, Yaacov Zamir <kobi.zamir@gmail.com>\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES\n * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\n * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR\n * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\n * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\n * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF\n * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF  THIS SOFTWARE.\n */\n\n/* Add bit operation functions to Buffer\n */\nrequire(\"./utils/buffer_bit\")();\nconst crc16 = require(\"./utils/crc16\");\nconst modbusSerialDebug = require(\"debug\")(\"modbus-serial\");\n\nconst events = require(\"events\");\nconst EventEmitter = events.EventEmitter || events;\n\nconst PORT_NOT_OPEN_MESSAGE = \"Port Not Open\";\nconst PORT_NOT_OPEN_ERRNO = \"ECONNREFUSED\";\n\nconst BAD_ADDRESS_MESSAGE = \"Bad Client Address\";\nconst BAD_ADDRESS_ERRNO = \"ECONNREFUSED\";\n\nconst TRANSACTION_TIMED_OUT_MESSAGE = \"Timed out\";\nconst TRANSACTION_TIMED_OUT_ERRNO = \"ETIMEDOUT\";\n\nconst modbusErrorMessages = [\n    \"Unknown error\",\n    \"Illegal function (device does not support this read/write function)\",\n    \"Illegal data address (register not supported by device)\",\n    \"Illegal data value (value cannot be written to this register)\",\n    \"Slave device failure (device reports internal error)\",\n    \"Acknowledge (requested data will be available later)\",\n    \"Slave device busy (retry request again later)\",\n    \"Negative acknowledge (slave device cannot perform programming functions)\",\n    \"Memory parity error (slave device detected a parity error in memory)\",\n    \"Unknown error\",\n    \"Gateway path unavailable (misconfigured gateway)\",\n    \"Gateway target device failed to respond (retry request again later)\"\n];\n\nconst PortNotOpenError = function() {\n    Error.captureStackTrace(this, this.constructor);\n    this.name = this.constructor.name;\n    this.message = PORT_NOT_OPEN_MESSAGE;\n    this.errno = PORT_NOT_OPEN_ERRNO;\n};\n\nconst BadAddressError = function() {\n    Error.captureStackTrace(this, this.constructor);\n    this.name = this.constructor.name;\n    this.message = BAD_ADDRESS_MESSAGE;\n    this.errno = BAD_ADDRESS_ERRNO;\n};\n\nconst TransactionTimedOutError = function() {\n    this.name = this.constructor.name;\n    this.message = TRANSACTION_TIMED_OUT_MESSAGE;\n    this.errno = TRANSACTION_TIMED_OUT_ERRNO;\n};\n\nconst SerialPortError = function() {\n    this.name = this.constructor.name;\n    this.message = null;\n    this.errno = \"ECONNREFUSED\";\n};\n\n/**\n * @fileoverview ModbusRTU module, exports the ModbusRTU class.\n * this class makes ModbusRTU calls fun and easy.\n *\n * Modbus is a serial communications protocol, first used in 1979.\n * Modbus is simple and robust, openly published, royalty-free and\n * easy to deploy and maintain.\n */\n\n/**\n * Parse the data for a Modbus -\n * Read Coils (FC=02, 01)\n *\n * @param {Buffer} data the data buffer to parse.\n * @param {Function} next the function to call next.\n */\nfunction _readFC2(data, next) {\n    const length = data.readUInt8(2);\n    const contents = [];\n\n    for (let i = 0; i < length; i++) {\n        let reg = data[i + 3];\n\n        for (let j = 0; j < 8; j++) {\n            contents.push((reg & 1) === 1);\n            reg = reg >> 1;\n        }\n    }\n\n    if (next)\n        next(null, { \"data\": contents, \"buffer\": data.slice(3, 3 + length) });\n}\n\n/**\n * Parse the data for a Modbus -\n * Read Input Registers (FC=04, 03)\n *\n * @param {Buffer} data the data buffer to parse.\n * @param {Function} next the function to call next.\n */\nfunction _readFC3or4(data, next) {\n    const length = data.readUInt8(2);\n    const contents = [];\n\n    for (let i = 0; i < length; i += 2) {\n        const reg = data.readUInt16BE(i + 3);\n        contents.push(reg);\n    }\n\n    if (next)\n        next(null, { \"data\": contents, \"buffer\": data.slice(3, 3 + length) });\n}\n\n/**\n * Parse the data for a Modbus (Enron) -\n * Read Registers (FC=04, 03)\n *\n * @param {Buffer} data the data buffer to parse.\n * @param {Function} next the function to call next.\n */\nfunction _readFC3or4Enron(data, next) {\n    const length = data.readUInt8(2);\n    const contents = [];\n\n    for (let i = 0; i < length; i += 4) {\n        const reg = data.readUInt32BE(i + 3);\n        contents.push(reg);\n    }\n\n    if (next)\n        next(null, { \"data\": contents, \"buffer\": data.slice(3, 3 + length) });\n}\n\n/**\n * Parse the data for a Modbus -\n * Force Single Coil (FC=05)\n *\n * @param {Buffer} data the data buffer to parse.\n * @param {Function} next the function to call next.\n */\nfunction _readFC5(data, next) {\n    const dataAddress = data.readUInt16BE(2);\n    const state = data.readUInt16BE(4);\n\n    if (next)\n        next(null, { \"address\": dataAddress, \"state\": (state === 0xff00) });\n}\n\n/**\n * Parse the data for a Modbus -\n * Preset Single Registers (FC=06)\n *\n * @param {Buffer} data the data buffer to parse.\n * @param {Function} next the function to call next.\n */\nfunction _readFC6(data, next) {\n    const dataAddress = data.readUInt16BE(2);\n    const value = data.readUInt16BE(4);\n\n    if (next)\n        next(null, { \"address\": dataAddress, \"value\": value });\n}\n\n/**\n * Parse the data for a Modbus (Enron) -\n * Preset Single Registers (FC=06)\n *\n * @param {Buffer} data the data buffer to parse.\n * @param {Function} next the function to call next.\n */\nfunction _readFC6Enron(data, next) {\n    const dataAddress = data.readUInt16BE(2);\n    const value = data.readUInt32BE(4);\n\n    if (next)\n        next(null, { \"address\": dataAddress, \"value\": value });\n}\n\n/**\n * Parse the data for a Modbus -\n * Preset Multiple Registers (FC=15, 16)\n *\n * @param {Buffer} data the data buffer to parse.\n * @param {Function} next the function to call next.\n */\nfunction _readFC16(data, next) {\n    const dataAddress = data.readUInt16BE(2);\n    const length = data.readUInt16BE(4);\n\n    if (next)\n        next(null, { \"address\": dataAddress, \"length\": length });\n}\n\n/**\n * Parse the data for a Modbus -\n * Report server ID (FC=17)\n *\n * @param {Buffer} data the data buffer to parse.\n * @param {Function} next the function to call next.\n */\nfunction _readFC17(data, next) {\n    const length = parseInt(data.readUInt8(2));\n    const serverId = parseInt(data.readUInt8(3));\n    const running = data.readUInt8(4) === 0xFF;\n    let additionalData;\n    if (length > 2) {\n        additionalData = Buffer.alloc(length - 2);\n        // copy additional data\n        data.copy(additionalData, 0, 5, data.length - 2);\n    } else {\n        additionalData = Buffer.alloc(0);\n    }\n\n    if (next)\n        next(null, { serverId: serverId, running: running, additionalData: additionalData });\n}\n\n/**\n * Parse  the data fro Modbus -\n * Read File Records\n *\n * @param {Buffer4} buffer\n * @param {Function} next\n */\nfunction _readFC20(data,  next) {\n    const fileRespLength = parseInt(data.readUInt8(2));\n    const result = [];\n    for (let i = 5; i < fileRespLength + 5; i++) {\n        const reg = data.readUInt8(i);\n        result.push(reg);\n    }\n    if(next)\n        next(null, { \"data\": result, \"length\": fileRespLength });\n}\n\n/**\n * Parse the data for a Modbus -\n * Mask Write Register (FC=22)\n *\n * @param {Buffer} data the data buffer to parse.\n * @param {Function} next the function to call next.\n */\nfunction _readFC22(data, next) {\n    const dataAddress = data.readUInt16BE(2);\n    const andMask = data.readUInt16BE(4);\n    const orMask = data.readUInt16BE(6);\n\n    if (next)\n        next(null, { \"address\": dataAddress, \"andMask\": andMask, \"orMask\": orMask });\n}\n\n/**\n * Parse the data for a Modbus -\n * Read Device Identification (FC=43)\n *\n * @param {Buffer} data the data buffer to parse.\n * @param {Modbus} modbus the client in case we need to read more device information\n * @param {Function} next the function to call next.\n */\nfunction _readFC43(data, modbus, next) {\n    const address = parseInt(data.readUInt8(0));\n    const readDeviceIdCode = parseInt(data.readUInt8(3));\n    const conformityLevel = parseInt(data.readUInt8(4));\n    const moreFollows = parseInt(data.readUInt8(5));\n    const nextObjectId = parseInt(data.readUInt8(6));\n    const numOfObjects = parseInt(data.readUInt8(7));\n\n    let startAt = 8;\n    const result = {};\n    // The modbus specification states that numOfObjects is the number of\n    // objects in the response, but the example on page 45 shows the total\n    // number over all responses. Therefore be careful about reading more data than available\n    for (let i = 0; i < numOfObjects && startAt < data.length; i++) {\n        const objectId = parseInt(data.readUInt8(startAt));\n        const objectLength = parseInt(data.readUInt8(startAt + 1));\n        const startOfData = startAt + 2;\n        result[objectId] = data.toString(\"ascii\", startOfData, startOfData + objectLength);\n        startAt = startOfData + objectLength;\n    }\n\n    // is it saying to follow and did you previously get data\n    // if you did not previously get data go ahead and halt to prevent an infinite loop\n    if (moreFollows && numOfObjects) {\n        const cb = function(err, data) {\n            data.data = Object.assign(data.data, result);\n            return next(err, data);\n        };\n        modbus.writeFC43(address, readDeviceIdCode, nextObjectId, cb);\n    } else if (next) {\n        next(null, { data: result, conformityLevel });\n    }\n}\n\n/**\n * Parse the data for a Modbus -\n * Read Device Identification (FC=43)\n *\n * @param {Buffer} data the data buffer to parse.\n * @param {Modbus} modbus the client in case we need to read more device information\n * @param {Function} next the function to call next.\n */\nfunction _readCustomFC(data, _modbus, next) {\n    const length = data.length - 4; // address, fn code, crc\n    const contents = [];\n\n    for (let i = 0; i < length; i++) {\n        const byte = data.readUInt8(i + 2);\n        contents.push(byte);\n    }\n\n    if (next)\n        next(null, { \"data\": contents, \"buffer\": data.slice(2, 2 + length) });\n}\n\n/**\n * Wrapper method for writing to a port with timeout. <code><b>[this]</b></code> has the context of ModbusRTU\n * @param {Buffer} buffer The data to send\n * @private\n */\nfunction _writeBufferToPort(buffer, transactionId) {\n    const transaction = this._transactions[transactionId];\n\n    if (transaction) {\n        transaction._timeoutFired = false;\n        transaction._timeoutHandle = _startTimeout(this._timeout, transaction);\n\n        // If in debug mode, stash a copy of the request payload\n        if (this._debugEnabled) {\n            transaction.request = Uint8Array.prototype.slice.call(buffer);\n            transaction.responses = [];\n        }\n    }\n\n    this._port.write(buffer);\n}\n\n/**\n * Starts the timeout timer with the given duration.\n * If the timeout ends before it was cancelled, it will call the callback with an error.\n * @param {number} duration the timeout duration in milliseconds.\n * @param {Function} next the function to call next.\n * @return {number} The handle of the timeout\n * @private\n */\nfunction _startTimeout(duration, transaction) {\n    if (!duration) {\n        return undefined;\n    }\n    return setTimeout(function() {\n        transaction._timeoutFired = true;\n        if (transaction.next) {\n            const err = new TransactionTimedOutError();\n            if (transaction.request && transaction.responses) {\n                err.modbusRequest = transaction.request;\n                err.modbusResponses = transaction.responses;\n            }\n            transaction.next(err);\n        }\n    }, duration);\n}\n\n/**\n * Cancel the given timeout.\n *\n * @param {number} timeoutHandle The handle of the timeout\n * @private\n */\nfunction _cancelTimeout(timeoutHandle) {\n    clearTimeout(timeoutHandle);\n}\n\n/**\n * Handle incoming data from the Modbus port.\n *\n * @param {Buffer} data The data received\n * @private\n */\nfunction _onReceive(data) {\n    const modbus = this;\n    let error;\n\n    // set locale helpers variables\n    const transaction = modbus._transactions[modbus._port._transactionIdRead];\n\n    // the _transactionIdRead can be missing, ignore wrong transaction it's\n    if (!transaction) {\n        return;\n    }\n\n    if (transaction.responses) {\n        /* Stash what we received */\n        transaction.responses.push(Uint8Array.prototype.slice.call(data));\n    }\n\n    /* What do we do next? */\n    const next = function(err, res) {\n        if (transaction.next) {\n            /* Include request/response data if enabled */\n            if (transaction.request && transaction.responses) {\n                if (err) {\n                    err.modbusRequest = transaction.request;\n                    err.modbusResponses = transaction.responses;\n                }\n\n                if (res) {\n                    res.request = transaction.request;\n                    res.responses = transaction.responses;\n                }\n            }\n\n            /* Pass the data on */\n            return transaction.next(err, res);\n        }\n    };\n\n    /* cancel the timeout */\n    _cancelTimeout(transaction._timeoutHandle);\n    transaction._timeoutHandle = undefined;\n\n    /* check if the timeout fired */\n    if (transaction._timeoutFired === true) {\n        // we have already called back with an error, so don't generate a new callback\n        return;\n    }\n\n    /* check incoming data\n     */\n\n    /* check minimal length\n     */\n    if (!transaction.lengthUnknown && data.length < 5) {\n        error = \"Data length error, expected \" +\n            transaction.nextLength + \" got \" + data.length;\n        next(new Error(error));\n        return;\n    }\n\n    /* check message CRC\n     * if CRC is bad raise an error\n     */\n    const crcIn = data.readUInt16LE(data.length - 2);\n    if (crcIn !== crc16(data.slice(0, -2))) {\n        error = \"CRC error\";\n        next(new Error(error));\n        return;\n    }\n\n    // if crc is OK, read address and function code\n    const address = data.readUInt8(0);\n    const code = data.readUInt8(1);\n\n    /* check for modbus exception\n     */\n    if (data.length >= 5 &&\n        code === (0x80 | transaction.nextCode)) {\n        const errorCode = data.readUInt8(2);\n        if (transaction.next) {\n            error = new Error(\"Modbus exception \" + errorCode + \": \" + (modbusErrorMessages[errorCode] || \"Unknown error\"));\n            error.modbusCode = errorCode;\n            next(error);\n        }\n        return;\n    }\n\n    /* check enron options are valid\n     */\n    if (modbus._enron) {\n        const example = {\n            enronTables: {\n                booleanRange: [1001, 1999],\n                shortRange: [3001, 3999],\n                longRange: [5001, 5999],\n                floatRange: [7001, 7999]\n            }\n        };\n\n        if (typeof modbus._enronTables === \"undefined\" ||\n                modbus._enronTables.shortRange.length !== 2 ||\n                modbus._enronTables.shortRange[0] >= modbus._enronTables.shortRange[1]) {\n            next(new Error(\"Enron table definition missing from options. Example: \" + JSON.stringify(example)));\n            return;\n        }\n    }\n\n    /* check message length\n     * if we do not expect this data\n     * raise an error\n     */\n    if (!transaction.lengthUnknown && data.length !== transaction.nextLength) {\n        error = \"Data length error, expected \" +\n            transaction.nextLength + \" got \" + data.length;\n        next(new Error(error));\n        return;\n    }\n\n    /* check message address\n     * if we do not expect this message\n     * raise an error\n     */\n    if (Number(address) !== Number(transaction.nextAddress)) {\n        error = \"Unexpected data error, expected \" +\n              \"address \" + transaction.nextAddress + \" got \" + address;\n        if (transaction.next)\n            next(new Error(error));\n        return;\n    }\n\n    /* check message code\n     * if we do not expect this message\n     * raise an error\n     */\n    if (code !== transaction.nextCode) {\n        error = \"Unexpected data error, expected \" +\n            \"code \" + transaction.nextCode + \" got \" + code;\n        if (transaction.next)\n            next(new Error(error));\n        return;\n    }\n\n    /* parse incoming data\n     */\n    try {\n        switch (code) {\n            case 1:\n            case 2:\n                // Read Coil Status (FC=01)\n                // Read Input Status (FC=02)\n                _readFC2(data, next);\n                break;\n            case 3:\n            case 4:\n                // Read Input Registers (FC=04)\n                // Read Holding Registers (FC=03)\n                if (modbus._enron && !(transaction.nextDataAddress >= modbus._enronTables.shortRange[0] && transaction.nextDataAddress <= modbus._enronTables.shortRange[1])) {\n                    _readFC3or4Enron(data, next);\n                } else {\n                    _readFC3or4(data, next);\n                }\n                break;\n            case 5:\n                // Force Single Coil\n                _readFC5(data, next);\n                break;\n            case 6:\n                // Preset Single Register\n                if (modbus._enron && !(transaction.nextDataAddress >= modbus._enronTables.shortRange[0] && transaction.nextDataAddress <= modbus._enronTables.shortRange[1])) {\n                    _readFC6Enron(data, next);\n                } else {\n                    _readFC6(data, next);\n                }\n                break;\n            case 15:\n            case 16:\n                // Force Multiple Coils\n                // Preset Multiple Registers\n                _readFC16(data, next);\n                break;\n            case 17:\n                _readFC17(data, next);\n                break;\n            case 20:\n                _readFC20(data, transaction.next);\n                break;\n            case 22:\n                _readFC22(data, next);\n                break;\n            case 43:\n                // read device identification\n                _readFC43(data, modbus, next);\n        }\n        if ((code >= 65 && code <= 72) || (code >= 100 && code <= 110)) {\n            _readCustomFC(data, transaction.nextCode, next);\n        }\n    } catch (e) {\n        if (transaction.next) {\n            next(e);\n        }\n    }\n}\n\n/**\n * Handle SerialPort errors.\n *\n * @param {Error} error The error received\n * @private\n */\nfunction _onError(e) {\n    const err = new SerialPortError();\n    err.message = e.message;\n    err.stack = e.stack;\n    this.emit(\"error\", err);\n}\n\nclass ModbusRTU extends EventEmitter {\n    /**\n     * Class making ModbusRTU calls fun and easy.\n     *\n     * @param {SerialPort} port the serial port to use.\n     */\n    constructor(port) {\n        super();\n\n        // the serial port to use\n        this._port = port;\n\n        // state variables\n        this._transactions = {};\n        this._timeout = null; // timeout in msec before unanswered request throws timeout error\n        this._unitID = 1;\n\n        // Flag to indicate whether debug mode (pass-through of raw\n        // request/response) is enabled.\n        this._debugEnabled = false;\n\n        this._onReceive = _onReceive.bind(this);\n        this._onError = _onError.bind(this);\n    }\n\n    /**\n     * Open the serial port and register Modbus parsers\n     *\n     * @param {Function} callback the function to call next on open success\n     *      of failure.\n     */\n    open(callback) {\n        const modbus = this;\n\n        // open the serial port\n        modbus._port.open(function(error) {\n            if (error) {\n                modbusSerialDebug({ action: \"port open error\", error: error });\n                /* On serial port open error call next function */\n                if (callback)\n                    callback(error);\n            } else {\n                /* init ports transaction id and counter */\n                modbus._port._transactionIdRead = 1;\n                modbus._port._transactionIdWrite = 1;\n\n                /* On serial port success\n                 * (re-)register the modbus parser functions\n                 */\n                modbus._port.removeListener(\"data\", modbus._onReceive);\n                modbus._port.on(\"data\", modbus._onReceive);\n\n                /* On serial port error\n                 * (re-)register the error listener function\n                 */\n                modbus._port.removeListener(\"error\", modbus._onError);\n                modbus._port.on(\"error\", modbus._onError);\n\n                /* Hook the close event so we can relay it to our callers. */\n                modbus._port.once(\"close\", modbus.emit.bind(modbus, \"close\"));\n\n                /* On serial port open OK call next function with no error */\n                if (callback)\n                    callback(error);\n            }\n        });\n    }\n\n    get isDebugEnabled() {\n        return this._debugEnabled;\n    }\n\n    set isDebugEnabled(enable) {\n        enable = Boolean(enable);\n        this._debugEnabled = enable;\n    }\n\n    get isOpen() {\n        if (this._port) {\n            return this._port.isOpen;\n        }\n\n        return false;\n    }\n\n    /**\n     * Clears the timeout for all pending transactions.\n     * This essentially cancels all pending requests.\n     */\n    _cancelPendingTransactions() {\n        if (Object.keys(this._transactions).length > 0) {\n            Object.values(this._transactions).forEach((transaction) => {\n                if (transaction._timeoutHandle) {\n                    _cancelTimeout(transaction._timeoutHandle);\n                }\n            });\n        }\n    }\n\n    /**\n     * Close the serial port\n     *\n     * @param {Function} callback the function to call next on close success\n     *      or failure.\n     */\n    close(callback) {\n        // close the serial port if exist\n        if (this._port) {\n            this._port.removeAllListeners(\"data\");\n            this._port.close(callback);\n        } else {\n            // nothing needed to be done\n            callback();\n        }\n    }\n\n    /**\n     * Destroy the serial port\n     *\n     * @param {Function} callback the function to call next on close success\n     *      or failure.\n     */\n    destroy(callback) {\n        // cancel all pending requests as we're closing the port\n        this._cancelPendingTransactions();\n\n        // close the serial port if exist and it has a destroy function\n        if (this._port && this._port.destroy) {\n            this._port.removeAllListeners(\"data\");\n            this._port.destroy();\n            callback();\n        } else {\n            // nothing needed to be done\n            callback();\n        }\n    }\n\n    /**\n     * Write a Modbus \"Read Coil Status\" (FC=01) to serial port.\n     *\n     * @param {number} address the slave unit address.\n     * @param {number} dataAddress the Data Address of the first coil.\n     * @param {number} length the total number of coils requested.\n     * @param {Function} next the function to call next.\n     */\n    writeFC1(address, dataAddress, length, next) {\n        this.writeFC2(address, dataAddress, length, next, 1);\n    }\n\n    /**\n     * Write a Modbus \"Read Input Status\" (FC=02) to serial port.\n     *\n     * @param {number} address the slave unit address.\n     * @param {number} dataAddress the Data Address of the first digital input.\n     * @param {number} length the total number of digital inputs requested.\n     * @param {Function} next the function to call next.\n     */\n    writeFC2(address, dataAddress, length, next, code) {\n        // check port is actually open before attempting write\n        if (this.isOpen !== true) {\n            if (next) next(new PortNotOpenError());\n            return;\n        }\n\n        // sanity check\n        if (typeof address === \"undefined\" || typeof dataAddress === \"undefined\") {\n            if (next) next(new BadAddressError());\n            return;\n        }\n\n        // function code defaults to 2\n        code = code || 2;\n\n        // set state variables\n        this._transactions[this._port._transactionIdWrite] = {\n            nextAddress: address,\n            nextCode: code,\n            nextLength: 3 + parseInt((length - 1) / 8 + 1) + 2,\n            next: next\n        };\n\n        const codeLength = 6;\n        const buf = Buffer.alloc(codeLength + 2); // add 2 crc bytes\n\n        buf.writeUInt8(address, 0);\n        buf.writeUInt8(code, 1);\n        buf.writeUInt16BE(dataAddress, 2);\n        buf.writeUInt16BE(length, 4);\n\n        // add crc bytes to buffer\n        buf.writeUInt16LE(crc16(buf.subarray(0, -2)), codeLength);\n\n        // write buffer to serial port\n        _writeBufferToPort.call(this, buf, this._port._transactionIdWrite);\n    }\n\n    /**\n     * Write a Modbus \"Read Holding Registers\" (FC=03) to serial port.\n     *\n     * @param {number} address the slave unit address.\n     * @param {number} dataAddress the Data Address of the first register.\n     * @param {number} length the total number of registers requested.\n     * @param {Function} next the function to call next.\n     */\n    writeFC3(address, dataAddress, length, next) {\n        this.writeFC4(address, dataAddress, length, next, 3);\n    }\n\n    /**\n     * Write a Modbus \"Read Input Registers\" (FC=04) to serial port.\n     *\n     * @param {number} address the slave unit address.\n     * @param {number} dataAddress the Data Address of the first register.\n     * @param {number} length the total number of registers requested.\n     * @param {Function} next the function to call next.\n     */\n    writeFC4(address, dataAddress, length, next, code) {\n        // check port is actually open before attempting write\n        if (this.isOpen !== true) {\n            if (next) next(new PortNotOpenError());\n            return;\n        }\n\n        // sanity check\n        if (typeof address === \"undefined\" || typeof dataAddress === \"undefined\") {\n            if (next) next(new BadAddressError());\n            return;\n        }\n\n        // function code defaults to 4\n        code = code || 4;\n\n        let valueSize = 2;\n        if (this._enron && !(dataAddress >= this._enronTables.shortRange[0] && dataAddress <= this._enronTables.shortRange[1])) {\n            valueSize = 4;\n        }\n\n        // set state variables\n        this._transactions[this._port._transactionIdWrite] = {\n            nextAddress: address,\n            nextDataAddress: dataAddress,\n            nextCode: code,\n            nextLength: 3 + (valueSize * length) + 2,\n            next: next\n        };\n\n        const codeLength = 6;\n        const buf = Buffer.alloc(codeLength + 2); // add 2 crc bytes\n\n        buf.writeUInt8(address, 0);\n        buf.writeUInt8(code, 1);\n        buf.writeUInt16BE(dataAddress, 2);\n        buf.writeUInt16BE(length, 4);\n\n        // add crc bytes to buffer\n        buf.writeUInt16LE(crc16(buf.subarray(0, -2)), codeLength);\n\n        // write buffer to serial port\n        _writeBufferToPort.call(this, buf, this._port._transactionIdWrite);\n    }\n\n    /**\n     * Write a Modbus \"Force Single Coil\" (FC=05) to serial port.\n     *\n     * @param {number} address the slave unit address.\n     * @param {number} dataAddress the Data Address of the coil.\n     * @param {number} state the boolean state to write to the coil (true / false).\n     * @param {Function} next the function to call next.\n     */\n    writeFC5(address, dataAddress, state, next) {\n        // check port is actually open before attempting write\n        if (this.isOpen !== true) {\n            if (next) next(new PortNotOpenError());\n            return;\n        }\n\n        // sanity check\n        if (typeof address === \"undefined\" || typeof dataAddress === \"undefined\") {\n            if (next) next(new BadAddressError());\n            return;\n        }\n\n        const code = 5;\n\n        // set state variables\n        this._transactions[this._port._transactionIdWrite] = {\n            nextAddress: address,\n            nextCode: code,\n            nextLength: 8,\n            next: next\n        };\n\n        const codeLength = 6;\n        const buf = Buffer.alloc(codeLength + 2); // add 2 crc bytes\n\n        buf.writeUInt8(address, 0);\n        buf.writeUInt8(code, 1);\n        buf.writeUInt16BE(dataAddress, 2);\n\n        if (state) {\n            buf.writeUInt16BE(0xff00, 4);\n        } else {\n            buf.writeUInt16BE(0x0000, 4);\n        }\n\n        // add crc bytes to buffer\n        buf.writeUInt16LE(crc16(buf.subarray(0, -2)), codeLength);\n\n        // write buffer to serial port\n        _writeBufferToPort.call(this, buf, this._port._transactionIdWrite);\n    }\n\n    /**\n     * Write a Modbus \"Preset Single Register \" (FC=6) to serial port.\n     *\n     * @param {number} address the slave unit address.\n     * @param {number} dataAddress the Data Address of the register.\n     * @param {number} value the value to write to the register.\n     * @param {Function} next the function to call next.\n     */\n    writeFC6(address, dataAddress, value, next) {\n        // check port is actually open before attempting write\n        if (this.isOpen !== true) {\n            if (next) next(new PortNotOpenError());\n            return;\n        }\n\n        // sanity check\n        if (typeof address === \"undefined\" || typeof dataAddress === \"undefined\") {\n            if (next) next(new BadAddressError());\n            return;\n        }\n\n        const code = 6;\n\n        let valueSize = 8;\n        if (this._enron && !(dataAddress >= this._enronTables.shortRange[0] && dataAddress <= this._enronTables.shortRange[1])) {\n            valueSize = 10;\n        }\n\n        // set state variables\n        this._transactions[this._port._transactionIdWrite] = {\n            nextAddress: address,\n            nextDataAddress: dataAddress,\n            nextCode: code,\n            nextLength: valueSize,\n            next: next\n        };\n\n        let codeLength = 6; // 1B deviceAddress + 1B functionCode + 2B dataAddress + (2B value | 4B value (enron))\n        if (this._enron && !(dataAddress >= this._enronTables.shortRange[0] && dataAddress <= this._enronTables.shortRange[1])) {\n            codeLength = 8;\n        }\n\n        const buf = Buffer.alloc(codeLength + 2); // add 2 crc bytes\n\n        buf.writeUInt8(address, 0);\n        buf.writeUInt8(code, 1);\n        buf.writeUInt16BE(dataAddress, 2);\n\n        if (Buffer.isBuffer(value)) {\n            value.copy(buf, 4);\n        } else if (this._enron && !(dataAddress >= this._enronTables.shortRange[0] && dataAddress <= this._enronTables.shortRange[1])) {\n            buf.writeUInt32BE(value, 4);\n        } else {\n            buf.writeUInt16BE(value, 4);\n        }\n\n        // add crc bytes to buffer\n        buf.writeUInt16LE(crc16(buf.subarray(0, -2)), codeLength);\n\n        // write buffer to serial port\n        _writeBufferToPort.call(this, buf, this._port._transactionIdWrite);\n    }\n\n    /**\n     * Write a Modbus \"Force Multiple Coils\" (FC=15) to serial port.\n     *\n     * @param {number} address the slave unit address.\n     * @param {number} dataAddress the Data Address of the first coil.\n     * @param {Array} array the array of boolean states to write to coils.\n     * @param {Function} next the function to call next.\n     */\n    writeFC15(address, dataAddress, array, next) {\n        // check port is actually open before attempting write\n        if (this.isOpen !== true) {\n            if (next) next(new PortNotOpenError());\n            return;\n        }\n\n        // sanity check\n        if (typeof address === \"undefined\" || typeof dataAddress === \"undefined\") {\n            if (next) next(new BadAddressError());\n            return;\n        }\n\n        const code = 15;\n        let i = 0;\n\n        // set state variables\n        this._transactions[this._port._transactionIdWrite] = {\n            nextAddress: address,\n            nextCode: code,\n            nextLength: 8,\n            next: next\n        };\n\n        const dataBytes = Math.ceil(array.length / 8);\n        const codeLength = 7 + dataBytes;\n        const buf = Buffer.alloc(codeLength + 2); // add 2 crc bytes\n\n        buf.writeUInt8(address, 0);\n        buf.writeUInt8(code, 1);\n        buf.writeUInt16BE(dataAddress, 2);\n        buf.writeUInt16BE(array.length, 4);\n        buf.writeUInt8(dataBytes, 6);\n\n        // clear the data bytes before writing bits data\n        for (i = 0; i < dataBytes; i++) {\n            buf.writeUInt8(0, 7 + i);\n        }\n\n        for (i = 0; i < array.length; i++) {\n            // buffer bits are already all zero (0)\n            // only set the ones set to one (1)\n            if (array[i]) {\n                buf.writeBit(1, i, 7);\n            }\n        }\n\n        // add crc bytes to buffer\n        buf.writeUInt16LE(crc16(buf.subarray(0, -2)), codeLength);\n\n        // write buffer to serial port\n        _writeBufferToPort.call(this, buf, this._port._transactionIdWrite);\n    }\n\n    /**\n     * Write a Modbus \"Preset Multiple Registers\" (FC=16) to serial port.\n     *\n     * @param {number} address the slave unit address.\n     * @param {number} dataAddress the Data Address of the first register.\n     * @param {Array} array the array of values to write to registers.\n     * @param {Function} next the function to call next.\n     */\n    writeFC16(address, dataAddress, array, next) {\n        // check port is actually open before attempting write\n        if (this.isOpen !== true) {\n            if (next) next(new PortNotOpenError());\n            return;\n        }\n\n        // sanity check\n        if (typeof address === \"undefined\" || typeof dataAddress === \"undefined\") {\n            if (next) next(new BadAddressError());\n            return;\n        }\n\n        const code = 16;\n\n        // set state variables\n        this._transactions[this._port._transactionIdWrite] = {\n            nextAddress: address,\n            nextCode: code,\n            nextLength: 8,\n            next: next\n        };\n\n        let dataLength = array.length;\n        if (Buffer.isBuffer(array)) {\n            // if array is a buffer it has double length\n            dataLength = array.length / 2;\n        }\n\n        const codeLength = 7 + 2 * dataLength;\n        const buf = Buffer.alloc(codeLength + 2); // add 2 crc bytes\n\n        buf.writeUInt8(address, 0);\n        buf.writeUInt8(code, 1);\n        buf.writeUInt16BE(dataAddress, 2);\n        buf.writeUInt16BE(dataLength, 4);\n        buf.writeUInt8(dataLength * 2, 6);\n\n        // copy content of array to buf\n        if (Buffer.isBuffer(array)) {\n            array.copy(buf, 7);\n        } else {\n            for (let i = 0; i < dataLength; i++) {\n                buf.writeUInt16BE(array[i], 7 + 2 * i);\n            }\n        }\n\n        // add crc bytes to buffer\n        buf.writeUInt16LE(crc16(buf.subarray(0, -2)), codeLength);\n\n        // write buffer to serial port\n        _writeBufferToPort.call(this, buf, this._port._transactionIdWrite);\n    }\n\n    /**\n     * Write a Modbus \"Report Server ID\" (FC=17) to serial port.\n     *\n     * @param {number} address the slave unit address.\n     * @param {Function} next the function to call next.\n     */\n    writeFC17(address, da, l, next) {\n        // check port is actually open before attempting write\n        if (this.isOpen !== true) {\n            if (next) next(new PortNotOpenError());\n            return;\n        }\n\n        const code = 17;\n\n        // set state variables\n        this._transactions[this._port._transactionIdWrite] = {\n            nextAddress: address,\n            nextCode: code,\n            lengthUnknown: true,\n            next: next\n        };\n\n        const codeLength = 2;\n        const buf = Buffer.alloc(codeLength + 2); // add 2 crc bytes\n\n        buf.writeUInt8(address, 0);\n        buf.writeUInt8(code, 1);\n\n        // add crc bytes to buffer\n        buf.writeUInt16LE(crc16(buf.subarray(0, -2)), codeLength);\n\n        // write buffer to serial port\n        _writeBufferToPort.call(this, buf, this._port._transactionIdWrite);\n    }\n\n\n    /**\n     * Write  mODBUS \"Read Device Identification\" (FC=20) to serial port\n     * @param {number} address the slave unit address.\n     * @param {Function} next;\n     */\n    writeFC20(address, fileNumber, recordNumber, next) {\n        if (this.isOpen !== true) {\n            if (next) next(new PortNotOpenError());\n            return;\n        }\n        // sanity check\n        if (typeof address === \"undefined\") {\n            if (next) next(new BadAddressError());\n            return;\n        }\n        // function code defaults to 20\n        const code = 20;\n        const codeLength = 10;\n        const byteCount = 7;\n        const chunck = 100;\n\n        this._transactions[this._port._transactionIdWrite] = {\n            nextAddress: address,\n            nextCode: code,\n            lengthUnknown: true,\n            next: next\n        };\n        const buf = Buffer.alloc(codeLength + 2); // add 2 crc bytes\n        buf.writeUInt8(address, 0);\n        buf.writeUInt8(code, 1);\n        buf.writeUInt8(byteCount, 2);\n        buf.writeUInt8(6, 3); // ReferenceType\n        buf.writeUInt16BE(fileNumber, 4);\n        buf.writeUInt16BE(recordNumber, 6);\n        buf.writeUInt8(chunck, 9);\n        buf.writeUInt16LE(crc16(buf.subarray(0, -2)), codeLength);\n        _writeBufferToPort.call(this, buf, this._port._transactionIdWrite);\n    }\n\n    /**\n     * Write a Modbus \"Mask Write Register\" (FC=22) to serial port.\n     *\n     * @param {number} address the slave unit address.\n     * @param {number} dataAddress the Data Address of the register.\n     * @param {number} andMask the AND mask value.\n     * @param {number} orMask the OR mask value.\n     * @param {Function} next the function to call next.\n     */\n    writeFC22(address, dataAddress, andMask, orMask, next) {\n        if (this.isOpen !== true) {\n            if (next) next(new PortNotOpenError());\n            return;\n        }\n\n        if (typeof address === \"undefined\" || typeof dataAddress === \"undefined\") {\n            if (next) next(new BadAddressError());\n            return;\n        }\n\n        const code = 22;\n        const codeLength = 8;\n\n        this._transactions[this._port._transactionIdWrite] = {\n            nextAddress: address,\n            nextCode: code,\n            nextLength: codeLength + 2,\n            next: next\n        };\n        const buf = Buffer.alloc(codeLength + 2); // add 2 crc bytes\n        buf.writeUInt8(address, 0);\n        buf.writeUInt8(code, 1);\n        buf.writeUInt16BE(dataAddress, 2);\n        buf.writeUInt16BE(andMask, 4);\n        buf.writeUInt16BE(orMask, 6);\n        buf.writeUInt16LE(crc16(buf.slice(0, -2)), codeLength);\n        _writeBufferToPort.call(this, buf, this._port._transactionIdWrite);\n    }\n\n    /**\n     * Write a Modbus \"Custom Function Code\" (FC=65-72, 100-110) to serial port.\n     *\n     * @param {number} address the slave unit address.\n     * @param {number} functionCode the custom function code.\n     * @param {Buffer} data the array of bytes to send.\n     * @param {Function} next the function to call next.\n     */\n    writeCustomFC(address, functionCode, data, next) {\n        if (this.isOpen !== true) {\n            if (next) next(new PortNotOpenError());\n            return;\n        }\n\n        if (typeof address === \"undefined\" || typeof functionCode === \"undefined\") {\n            if (next) next(new BadAddressError());\n            return;\n        }\n\n        const code = functionCode;\n        const codeLength = 2 + data.length;\n\n        this._transactions[this._port._transactionIdWrite] = {\n            nextAddress: address,\n            nextCode: code,\n            lengthUnknown: true,\n            next: next\n        };\n        const buf = Buffer.alloc(codeLength + 2); // add 2 crc bytes\n        buf.writeUInt8(address, 0);\n        buf.writeUInt8(code, 1);\n        let pos = 2;\n        for(const byte of data) {\n            buf.writeUInt8(byte, pos);\n            pos += 1;\n        }\n        buf.writeUInt16LE(crc16(buf.slice(0, -2)), codeLength);\n        _writeBufferToPort.call(this, buf, this._port._transactionIdWrite);\n    }\n\n    /**\n     * Write a Modbus \"Read Device Identification\" (FC=43) to serial port.\n     *\n     * @param {number} address the slave unit address.\n     * @param {number} deviceIdCode the read device access code.\n     * @param {number} objectId the array of values to write to registers.\n     * @param {Function} next the function to call next.\n     */\n    writeFC43(address, deviceIdCode, objectId, next) {\n        // check port is actually open before attempting write\n        if (this.isOpen !== true) {\n            if (next) next(new PortNotOpenError());\n            return;\n        }\n\n        const code = 0x2B; // 43\n\n        // set state variables\n        this._transactions[this._port._transactionIdWrite] = {\n            nextAddress: address,\n            nextCode: code,\n            lengthUnknown: true,\n            next: next\n        };\n        const codeLength = 5;\n        const buf = Buffer.alloc(codeLength + 2); // add 2 crc bytes\n        buf.writeUInt8(address, 0);\n        buf.writeUInt8(code, 1);\n        buf.writeUInt8(0x0E, 2); // 16 MEI Type\n        buf.writeUInt8(deviceIdCode, 3);\n        buf.writeUInt8(objectId, 4);\n        // add crc bytes to buffer\n        buf.writeUInt16LE(crc16(buf.subarray(0, -2)), codeLength);\n        // write buffer to serial port\n        _writeBufferToPort.call(this, buf, this._port._transactionIdWrite);\n    }\n}\n\n// add the connection shorthand API\nrequire(\"./apis/connection\")(ModbusRTU);\n\n// add the promise API\nrequire(\"./apis/promise\")(ModbusRTU);\n\n// add worker API\nrequire(\"./apis/worker\")(ModbusRTU);\n\n// exports\nmodule.exports = ModbusRTU;\n\nmodule.exports.getPorts = function getPorts() {\n    const { SerialPort } = require(\"serialport\");\n\n    return SerialPort.list();\n};\n\nmodule.exports.TestPort = require(\"./ports/testport\");\ntry {\n    module.exports.RTUBufferedPort = require(\"./ports/rtubufferedport\");\n} catch (err) { }\nmodule.exports.TcpPort = require(\"./ports/tcpport\");\nmodule.exports.TcpRTUBufferedPort = require(\"./ports/tcprtubufferedport\");\nmodule.exports.TelnetPort = require(\"./ports/telnetport\");\nmodule.exports.C701Port = require(\"./ports/c701port\");\n\nmodule.exports.ServerTCP = require(\"./servers/servertcp\");\ntry {\n    module.exports.ServerSerial = require(\"./servers/serverserial\");\n} catch (err) { }\nmodule.exports.default = module.exports;\n"]}