/// ///////////////////// COMMANDS /////////////////////// var readCommand = function (commandOptions, cb) { var buf = Buffer.alloc(12) buf.writeUInt32LE(commandOptions.indexGroup, 0) buf.writeUInt32LE(commandOptions.indexOffset, 4) buf.writeUInt32LE(commandOptions.bytelength, 8) var options = { commandId: ID_READ, data: buf, cb: cb, symname: commandOptions.symname } runCommand.call(this, options) }
var deleteDeviceNotificationCommand = function (notificationHandle, cb) { var ads = this if (ads.connected) { var buf = Buffer.alloc(4) buf.writeUInt32LE(notificationHandle, 0) var options = { commandId: ID_DEL_NOTIFICATION, data: buf, cb: cb } runCommand.call(ads, options) } else if (typeof cb !== 'undefined') cb.call(ads) }
var writeCommand = function (commandOptions, cb) { var buf = Buffer.alloc(12 + commandOptions.bytelength) buf.writeUInt32LE(commandOptions.indexGroup, 0) buf.writeUInt32LE(commandOptions.indexOffset, 4) buf.writeUInt32LE(commandOptions.bytelength, 8) commandOptions.bytes.copy(buf, 12) var options = { commandId: ID_WRITE, data: buf, cb: cb, symname: commandOptions.symname } runCommand.call(this, options) }
var writeReadCommand = function (commandOptions, cb) { var buf = Buffer.alloc(16 + commandOptions.writeBuffer.length) buf.writeUInt32LE(commandOptions.indexGroup, 0) buf.writeUInt32LE(commandOptions.indexOffset, 4) buf.writeUInt32LE(commandOptions.readLength, 8) buf.writeUInt32LE(commandOptions.writeBuffer.length, 12) commandOptions.writeBuffer.copy(buf, 16) var options = { commandId: ID_READ_WRITE, data: buf, cb: cb, symname: commandOptions.symname } runCommand.call(this, options) }
buf.writeUInt32LE(ADSIGRP.GET_SYMHANDLE_BYNAME, index * 16 + 0); buf.writeUInt32LE(0x00000000, index * 16 + 4); buf.writeUInt32LE(4, index * 16 + 8); buf.writeUInt32LE(handle.name.length, index * 16 + 12); }); symHandleToRelease.writeUInt32LE(handle.symHandle, 0); ads.symHandlesToRelease.push(symHandleToRelease);
buf.writeUInt32LE( handle.indexGroup || ADSIGRP.RW_SYMVAL_BYHANDLE, index * 12 + 0 ); buf.writeUInt32LE(handle.symHandle, index * 12 + 4); buf.writeUInt32LE(handle.totalByteLength, index * 12 + 8);
header.writeUInt32LE(headerSize + options.data.length, offset) offset += 4 header.writeUInt32LE(options.data.length, offset) offset += 4 header.writeUInt32LE(0, offset) offset += 4 header.writeUInt32LE(++ads.invokeId, offset) offset += 4
handles.forEach(function(handle) { if (!handle.err){ buf.writeUInt32LE(handle.indexGroup || ADSIGRP.RW_SYMVAL_BYHANDLE,index) buf.writeUInt32LE(handle.indexOffset || handle.symhandle,index+4) buf.writeUInt32LE(handle.totalByteLength,index+8) index+=12
case 'DWORD': case 'UDINT': buf.writeUInt32LE(val, offset) break case 'DINT': datetime = new Date(datetime.setMinutes(datetime.getMinutes() - timeoffset)) buf.writeUInt32LE( datetime.getTime(), offset) break case 'DATE': datetime = new Date(datetime.setMinutes(datetime.getMinutes() - timeoffset)) buf.writeUInt32LE((datetime.getTime() / 1000), offset) break
buf.writeUInt32LE( handle.indexGroup || ADSIGRP.RW_SYMVAL_BYHANDLE, index * 12 + 0 ); buf.writeUInt32LE(handle.symHandle, index * 12 + 4); buf.writeUInt32LE(handle.totalByteLength, index * 12 + 8);
bufsymname.copy(buf,indexsynname,0,bufsymname.length) indexsynname+=bufsymname.length buf.writeUInt32LE(ADSIGRP.GET_SYMHANDLE_BYNAME,index+0) buf.writeUInt32LE(0x00000000,index+4) buf.writeUInt32LE(0x00000004,index+8) buf.writeUInt32LE(bufsymname.length,index+12) index+=16 symHandleToRelease.writeUInt32LE(handle.symhandle,0) ads.symHandlesToRelease.push(symHandleToRelease)
var addNotificationCommand = function (commandOptions, cb) { var buf = Buffer.alloc(40); buf.writeUInt32LE(commandOptions.indexGroup, 0) buf.writeUInt32LE(commandOptions.indexOffset, 4) buf.writeUInt32LE(commandOptions.bytelength, 8) buf.writeUInt32LE(commandOptions.transmissionMode, 12) buf.writeUInt32LE(commandOptions.maxDelay, 16) buf.writeUInt32LE(commandOptions.cycleTime * 10000, 20) buf.writeUInt32LE(0, 24) buf.writeUInt32LE(0, 28) buf.writeUInt32LE(0, 32) buf.writeUInt32LE(0, 36) var options = { commandId: ID_ADD_NOTIFICATION, data: buf, cb: cb, symname: commandOptions.symname } runCommand.call(this, options) }
handles.forEach(function(handle) { if (!handle.err){ buf.writeUInt32LE(handle.indexGroup || ADSIGRP.RW_SYMVAL_BYHANDLE,0) buf.writeUInt32LE(handle.indexOffset || handle.symhandle,4) buf.writeUInt32LE(handle.totalByteLength,8) index+=12 getBytesFromHandle(handle)