lib/device.js
function(address, writeData) {
		var writeInfo = {
			'isValid': false,
			'message': 'Unknown Reason',

			// Data to be written
			'address': undefined,
			'type': undefined,
			'numValues': undefined,
			'aValues': undefined,
			'errorAddress': undefined,
		};

		var info = self.constants.getAddressInfo(address, 'W');
		var isDirectionValid = info.directionValid == 1;
		var isBufferRegister = false;
		if(info.data) {
			if(info.data.isBuffer) {
				isBufferRegister = true;
			}
		}

		if (isDirectionValid && isBufferRegister) {
			writeInfo.isValid = true;

			// Save info
			writeInfo.address = info.address;
			writeInfo.type = info.type;

			var errorVal = new ref.alloc('int',1);
			errorVal.fill(0);
			
			writeInfo.errorAddress = errorVal;

			// Variable declarations:
			var aValues, offset, i;

			// Check to see if the input-data is of the type "buffer"
			if(Buffer.isBuffer(writeData)) {
				writeInfo.isValid = false;
				writeInfo.message = 'Buffer type is not supported';
			} else if(Array.isArray(writeData)) {
				writeInfo.numValues = writeData.length;
				aValues = new Buffer(writeData.length * ARCH_DOUBLE_NUM_BYTES);
				aValues.fill(0);
				offset = 0;
				for(i = 0; i < writeData.length; i++) {
					aValues.writeDoubleLE(writeData[i], offset);
					offset += ARCH_DOUBLE_NUM_BYTES;
				}
				writeInfo.aValues = aValues;
			} else if((typeof(writeData) === 'string') || (writeData instanceof String)) {
				writeInfo.numValues = writeData.length;
				aValues = new Buffer(writeData.length * ARCH_DOUBLE_NUM_BYTES);
				aValues.fill(0);
				offset = 0;
				for(i = 0; i < writeData.length; i++) {
					aValues.writeDoubleLE(writeData.charCodeAt(i), offset);
					offset += ARCH_DOUBLE_NUM_BYTES;
				}
				writeInfo.aValues = aValues;
			} else {
				// Un-supported type
				writeInfo.isValid = false;
				writeInfo.message = 'Invalid data type being written: ' + typeof(writeData) + '.';
			}
			writeInfo.numValues = writeData.length;
		} else {
			writeInfo.isValid = false;
			if (info.type == -1) {
				writeInfo.message = 'Invalid Address';
			} else if (info.directionValid === 0) {
				writeInfo.message = 'Invalid Read Attempt';
			} else if (!isBufferRegister) {
				writeInfo.message = 'Tried to read an array from a register that is not a buffer';
			}
		}
		return writeInfo;
	}
function(address, writeData) {
		var writeInfo = {
			'isValid': false,
			'message': 'Unknown Reason',

			// Data to be written
			'address': undefined,
			'type': undefined,
			'numValues': undefined,
			'aValues': undefined,
			'errorAddress': undefined,
		};

		var info = self.constants.getAddressInfo(address, 'W');
		var isDirectionValid = info.directionValid == 1;
		var isBufferRegister = false;
		if(info.data) {
			if(info.data.isBuffer) {
				isBufferRegister = true;
			}
		}

		if (isDirectionValid && isBufferRegister) {
			writeInfo.isValid = true;

			// Save info
			writeInfo.address = info.address;
			writeInfo.type = info.type;

			var errorVal = new ref.alloc('int',1);
			errorVal.fill(0);
			
			writeInfo.errorAddress = errorVal;

			// Variable declarations:
			var aValues, offset, i;

			// Check to see if the input-data is of the type "buffer"
			if(Buffer.isBuffer(writeData)) {
				writeInfo.isValid = false;
				writeInfo.message = 'Buffer type is not supported';
			} else if(Array.isArray(writeData)) {
				writeInfo.numValues = writeData.length;
				aValues = new Buffer(writeData.length * ARCH_DOUBLE_NUM_BYTES);
				aValues.fill(0);
				offset = 0;
				for(i = 0; i < writeData.length; i++) {
					aValues.writeDoubleLE(writeData[i], offset);
					offset += ARCH_DOUBLE_NUM_BYTES;
				}
				writeInfo.aValues = aValues;
			} else if((typeof(writeData) === 'string') || (writeData instanceof String)) {
				writeInfo.numValues = writeData.length;
				aValues = new Buffer(writeData.length * ARCH_DOUBLE_NUM_BYTES);
				aValues.fill(0);
				offset = 0;
				for(i = 0; i < writeData.length; i++) {
					aValues.writeDoubleLE(writeData.charCodeAt(i), offset);
					offset += ARCH_DOUBLE_NUM_BYTES;
				}
				writeInfo.aValues = aValues;
			} else {
				// Un-supported type
				writeInfo.isValid = false;
				writeInfo.message = 'Invalid data type being written: ' + typeof(writeData) + '.';
			}
			writeInfo.numValues = writeData.length;
		} else {
			writeInfo.isValid = false;
			if (info.type == -1) {
				writeInfo.message = 'Invalid Address';
			} else if (info.directionValid === 0) {
				writeInfo.message = 'Invalid Read Attempt';
			} else if (!isBufferRegister) {
				writeInfo.message = 'Tried to read an array from a register that is not a buffer';
			}
		}
		return writeInfo;
	}
function ( address , writeData ) { var writeInfo = { 'isValid' : false , 'message' : 'Unknown Reason' , // Data to be written 'address' : undefined , 'type' : undefined , 'numValues' : undefined , 'aValues' : undefined , 'errorAddress' : undefined , } ; var info = self . constants . getAddressInfo ( address , 'W' ) ; var isDirectionValid = info . directionValid == 1 ; var isBufferRegister = false ; if ( info . data ) { if ( info . data . isBuffer ) { isBufferRegister = true ; } } if ( isDirectionValid && isBufferRegister ) { writeInfo . isValid = true ; // Save info writeInfo . address = info . address ; writeInfo . type = info . type ; var errorVal = new ref . alloc ( 'int' , 1 ) ; errorVal . fill ( 0 ) ; writeInfo . errorAddress = errorVal ; // Variable declarations: var aValues , offset , i ; // Check to see if the input-data is of the type "buffer" if ( Buffer . isBuffer ( writeData ) ) { writeInfo . isValid = false ; writeInfo . message = 'Buffer type is not supported' ; } else if ( Array . isArray ( writeData ) ) { writeInfo . numValues = writeData . length ; aValues = new Buffer ( writeData . length * ARCH_DOUBLE_NUM_BYTES ) ; aValues . fill ( 0 ) ; offset = 0 ; for ( i = 0 ; i < writeData . length ; i ++ ) { aValues . writeDoubleLE ( writeData [ i ] , offset ) ; offset += ARCH_DOUBLE_NUM_BYTES ; } writeInfo . aValues = aValues ; } else if ( ( typeof ( writeData ) === 'string' ) || ( writeData instanceof String ) ) { writeInfo . numValues = writeData . length ; aValues = new Buffer ( writeData . length * ARCH_DOUBLE_NUM_BYTES ) ; aValues . fill ( 0 ) ; offset = 0 ; for ( i = 0 ; i < writeData . length ; i ++ ) { aValues . writeDoubleLE ( writeData . charCodeAt ( i ) , offset ) ; offset += ARCH_DOUBLE_NUM_BYTES ; } writeInfo . aValues = aValues ; } else { // Un-supported type writeInfo . isValid = false ; writeInfo . message = 'Invalid data type being written: ' + typeof ( writeData ) + '.' ; } writeInfo . numValues = writeData . length ; } else { writeInfo . isValid = false ; if ( info . type == - 1 ) { writeInfo . message = 'Invalid Address' ; } else if ( info . directionValid === 0 ) { writeInfo . message = 'Invalid Read Attempt' ; } else if ( ! isBufferRegister ) { writeInfo . message = 'Tried to read an array from a register that is not a buffer' ; } } return writeInfo ; }
A helper function for the writeArray and writeArraySync function to parse
or interpret the data to be written.
A helper function for the writeArray and writeArraySync function to parse or interpret the data to be written .