lib/ljm-ffi.js
function createAsyncFunction(functionName, functionInfo) {
    return function asyncLJMFunction() {
        var userCB;
        function cb(err, res) {
            if(err) {
                console.error('Error Reported by Async Function', functionName);
            }
            
            // Create an object to be returned.
            var ljmError = res;
            var retObj = {
                'ljmError': ljmError,
            };
            if(ljmError !== 0) {
                retObj.errorInfo = modbus_map.getErrorInfo(ljmError);
            }

            // Fill the object being returned with data.
            parseAndStoreSyncFunctionArgs(functionInfo, funcArgs, retObj);

            // Execute the user's callback function.
            userCB(retObj);

            return;
        }

        // Check arg-length + 1 for the callback.
        if(arguments.length != (functionInfo.args.length + 1)) {
            var errStr = 'Invalid number of arguments.  Should be: ';
            errStr += functionInfo.args.length.toString() + '.  ';
            errStr += getFunctionArgNames(functionInfo).join(', ');
            errStr += ', ' + 'callback.';
            throw new LJMFFIError(errStr);
        // } else if(typeof(arguments[arguments.length]) !== 'function') {
        //     var errStr
        } else {
            if(typeof(arguments[functionInfo.args.length]) !== 'function') {
                userCB = function() {};
            } else {
                userCB = arguments[functionInfo.args.length];

            }

            // Create an array that will be filled with values to call the
            // LJM function with.
            var funcArgs = [];

            // Parse and fill the function arguments array with data.
            allocateAndFillSyncFunctionArgs(functionInfo, funcArgs, arguments);

            // Over-write the function callback in the arguments list.
            funcArgs[funcArgs.length] = cb;

            // Execute the asynchronous LJM function.
            var ljmFunction = liblabjack[functionName].async;
            ljmFunction.apply(this, funcArgs);

            return;
        }
    };
}
function createAsyncFunction(functionName, functionInfo) {
    return function asyncLJMFunction() {
        var userCB;
        function cb(err, res) {
            if(err) {
                console.error('Error Reported by Async Function', functionName);
            }
            
            // Create an object to be returned.
            var ljmError = res;
            var retObj = {
                'ljmError': ljmError,
            };
            if(ljmError !== 0) {
                retObj.errorInfo = modbus_map.getErrorInfo(ljmError);
            }

            // Fill the object being returned with data.
            parseAndStoreSyncFunctionArgs(functionInfo, funcArgs, retObj);

            // Execute the user's callback function.
            userCB(retObj);

            return;
        }

        // Check arg-length + 1 for the callback.
        if(arguments.length != (functionInfo.args.length + 1)) {
            var errStr = 'Invalid number of arguments.  Should be: ';
            errStr += functionInfo.args.length.toString() + '.  ';
            errStr += getFunctionArgNames(functionInfo).join(', ');
            errStr += ', ' + 'callback.';
            throw new LJMFFIError(errStr);
        // } else if(typeof(arguments[arguments.length]) !== 'function') {
        //     var errStr
        } else {
            if(typeof(arguments[functionInfo.args.length]) !== 'function') {
                userCB = function() {};
            } else {
                userCB = arguments[functionInfo.args.length];

            }

            // Create an array that will be filled with values to call the
            // LJM function with.
            var funcArgs = [];

            // Parse and fill the function arguments array with data.
            allocateAndFillSyncFunctionArgs(functionInfo, funcArgs, arguments);

            // Over-write the function callback in the arguments list.
            funcArgs[funcArgs.length] = cb;

            // Execute the asynchronous LJM function.
            var ljmFunction = liblabjack[functionName].async;
            ljmFunction.apply(this, funcArgs);

            return;
        }
    };
}
function createAsyncFunction ( functionName , functionInfo ) { return function asyncLJMFunction ( ) { var userCB ; function cb ( err , res ) { if ( err ) { console . error ( 'Error Reported by Async Function' , functionName ) ; } // Create an object to be returned. var ljmError = res ; var retObj = { 'ljmError' : ljmError , } ; if ( ljmError !== 0 ) { retObj . errorInfo = modbus_map . getErrorInfo ( ljmError ) ; } // Fill the object being returned with data. parseAndStoreSyncFunctionArgs ( functionInfo , funcArgs , retObj ) ; // Execute the user's callback function. userCB ( retObj ) ; return ; } // Check arg-length + 1 for the callback. if ( arguments . length != ( functionInfo . args . length + 1 ) ) { var errStr = 'Invalid number of arguments.  Should be: ' ; errStr += functionInfo . args . length . toString ( ) + '.  ' ; errStr += getFunctionArgNames ( functionInfo ) . join ( ', ' ) ; errStr += ', ' + 'callback.' ; throw new LJMFFIError ( errStr ) ; // } else if(typeof(arguments[arguments.length]) !== 'function') { //     var errStr } else { if ( typeof ( arguments [ functionInfo . args . length ] ) !== 'function' ) { userCB = function ( ) { } ; } else { userCB = arguments [ functionInfo . args . length ] ; } // Create an array that will be filled with values to call the // LJM function with. var funcArgs = [ ] ; // Parse and fill the function arguments array with data. allocateAndFillSyncFunctionArgs ( functionInfo , funcArgs , arguments ) ; // Over-write the function callback in the arguments list. funcArgs [ funcArgs . length ] = cb ; // Execute the asynchronous LJM function. var ljmFunction = liblabjack [ functionName ] . async ; ljmFunction . apply ( this , funcArgs ) ; return ; } } ; }
Define a function that creates functions that can call LJM asynchronously.
Define a function that creates functions that can call LJM asynchronously .