servers/servertcp_handler.js
function _handleWriteSingleRegister(requestBuffer, vector, unitID, callback) {
    var address = requestBuffer.readUInt16BE(2);
    var value = requestBuffer.readUInt16BE(4);

    if (_errorRequestBufferLength(requestBuffer)) {
        return;
    }

    // build answer
    var responseBuffer = Buffer.alloc(8);
    responseBuffer.writeUInt16BE(address, 2);
    responseBuffer.writeUInt16BE(value, 4);

    if (vector.setRegister) {
        var callbackInvoked = false;
        var cb = function(err) {
            if (err) {
                if (!callbackInvoked) {
                    callbackInvoked = true;
                    callback(err);
                }

                return;
            }

            if (!callbackInvoked) {
                modbusSerialDebug({ action: "FC6 response", responseBuffer: responseBuffer });

                callbackInvoked = true;
                callback(null, responseBuffer);
            }
        };

        try {
            if (vector.setRegister.length === 4) {
                vector.setRegister(address, value, unitID, cb);
            }
            else {
                var promiseOrValue = vector.setRegister(address, value, unitID);
                _handlePromiseOrValue(promiseOrValue, cb);
            }
        } catch(err) {
            cb(err);
        }
    }
}
function _handleWriteSingleRegister(requestBuffer, vector, unitID, callback) {
    var address = requestBuffer.readUInt16BE(2);
    var value = requestBuffer.readUInt16BE(4);

    if (_errorRequestBufferLength(requestBuffer)) {
        return;
    }

    // build answer
    var responseBuffer = Buffer.alloc(8);
    responseBuffer.writeUInt16BE(address, 2);
    responseBuffer.writeUInt16BE(value, 4);

    if (vector.setRegister) {
        var callbackInvoked = false;
        var cb = function(err) {
            if (err) {
                if (!callbackInvoked) {
                    callbackInvoked = true;
                    callback(err);
                }

                return;
            }

            if (!callbackInvoked) {
                modbusSerialDebug({ action: "FC6 response", responseBuffer: responseBuffer });

                callbackInvoked = true;
                callback(null, responseBuffer);
            }
        };

        try {
            if (vector.setRegister.length === 4) {
                vector.setRegister(address, value, unitID, cb);
            }
            else {
                var promiseOrValue = vector.setRegister(address, value, unitID);
                _handlePromiseOrValue(promiseOrValue, cb);
            }
        } catch(err) {
            cb(err);
        }
    }
}
function _handleWriteSingleRegister ( requestBuffer , vector , unitID , callback ) { var address = requestBuffer . readUInt16BE ( 2 ) ; var value = requestBuffer . readUInt16BE ( 4 ) ; if ( _errorRequestBufferLength ( requestBuffer ) ) { return ; } // build answer var responseBuffer = Buffer . alloc ( 8 ) ; responseBuffer . writeUInt16BE ( address , 2 ) ; responseBuffer . writeUInt16BE ( value , 4 ) ; if ( vector . setRegister ) { var callbackInvoked = false ; var cb = function ( err ) { if ( err ) { if ( ! callbackInvoked ) { callbackInvoked = true ; callback ( err ) ; } return ; } if ( ! callbackInvoked ) { modbusSerialDebug ( { action : "FC6 response" , responseBuffer : responseBuffer } ) ; callbackInvoked = true ; callback ( null , responseBuffer ) ; } } ; try { if ( vector . setRegister . length === 4 ) { vector . setRegister ( address , value , unitID , cb ) ; } else { var promiseOrValue = vector . setRegister ( address , value , unitID ) ; _handlePromiseOrValue ( promiseOrValue , cb ) ; } } catch ( err ) { cb ( err ) ; } } }
Function to handle FC6 request.

@param requestBuffer - request Buffer from client
@param vector - vector of functions for read and write
@param unitID - Id of the requesting unit
@param {function} callback - callback to be invoked passing {Buffer} response
@returns undefined
@private
Function to handle FC6 request .