UNPKG

weblab-instrument

Version:
1,040 lines (993 loc) 79.6 kB
/** * Module use to communicate with GWINSTEK's DSO through Ethernet or USB * * @module instrument-com */ /* eslint no-restricted-syntax: 0 */ /* eslint no-await-in-loop: 0 */ import cmdObj from './sys/afg-command.json'; const EventEmitter = require('events').EventEmitter; const debug = require('debug'); const log = debug('afg:log'); const sysConstant = require('./sys/sysConstant.js'); const syscmd = require('./afg/system.js'); const am = require('./afg/am.js'); const fm = require('./afg/fm.js'); const pm = require('./afg/pm.js'); const sweep = require('./afg/sweep.js'); const channel = require('./afg/channel.js'); const usbDev = require('./dev/devUsb.js'); const base = require('./dev/base.js'); const AGF_DELAY_CNT = 200; /** * Create all needed private properties and method * * @private * @constructor AfgObject * * @return {Object} Private method used to control DSO */ function AfgObject() { this.dev = new base.Dev(); this.sys = syscmd.initSysObj.call(this, 'sys'); this.ch1 = channel.initChanObj.call(this, 'ch1'); this.ch2 = channel.initChanObj.call(this, 'ch2'); this.am1 = am.initAMObj.call(this, 'am1'); this.am2 = am.initAMObj.call(this, 'am2'); this.fm1 = fm.initFMObj.call(this, 'fm1'); this.fm2 = fm.initFMObj.call(this, 'fm2'); this.pm1 = pm.initPMObj.call(this, 'pm1'); this.pm2 = pm.initPMObj.call(this, 'pm2'); this.sweep1 = sweep.initSweepObj.call(this, 'sweep1'); this.sweep2 = sweep.initSweepObj.call(this, 'sweep2'); this.cmdEvent = new EventEmitter(); this.commandObj = cmdObj; this.dev.commandObj = this.commandObj; return this; } /** * The class define all needed public properties and methods * * @class afgctrl * * */ function AfgControl(afgObj) { const afgctrl = {}; /** * The method belong to afgctrl class used to release device's resource. * * @method closeDev * @return {null} null * */ afgctrl.closeDev = function closeDev() { log('closeDev'); return new Promise(((resolve, reject) => { afgctrl.disconnect() .then(resolve) .catch((e) => { reject(e); }); })); }; /** * The method belong to afgctrl class used to connect to device, * connect method must be called and wait to complete before any afgctrl method. * * @method connect * * */ afgctrl.connect = function connect(dontCheckdev) { const self = this; return new Promise(((resolve, reject) => { function conn(e) { if (e) { reject(e); } else { resolve(); } } self.dev.usbConnect(conn, dontCheckdev); })); }.bind(afgObj); /** * The method belong to afgctrl class used to disconnect from device. * * @method disconnect * * */ afgctrl.disconnect = function disconnect() { log('disconnect'); const self = this; return new Promise(((resolve, reject) => { function disconnectDone(e) { if (e) { log('disconnect return'); log(e); reject(e); } else { resolve(); } } if (self.dev.state.conn !== 'disconnected') { self.dev.cmdSequence = []; if (self.dev.writeTimeoutObj !== null) { clearTimeout(self.dev.writeTimeoutObj); } self.dev.usbDisconnect(disconnectDone); } else { resolve(); } })); }.bind(afgObj); /** * */ afgctrl.getSetup = function getSetup() { const self = this; return new Promise(((resolve, reject) => { function getDone(e) { if (e) { reject(e); } else { resolve({ chProps: { ch1: { type: self.ch1.type.slice(), state: self.ch1.state, amplUnit: self.ch1.vunit, freq: self.ch1.freq, ampl: self.ch1.ampl, offset: self.ch1.offset, duty: self.ch1.duty, sym: self.ch1.sym, widt: self.ch1.width, modulation: { am: { state: self.am1.state, source: self.am1.source, depth: self.am1.depth, freq: self.am1.freq, shape: self.am1.type, }, fm: { state: self.fm1.state, source: self.fm1.source, deviation: self.fm1.deviation, freq: self.fm1.freq, shape: self.fm1.type, }, pm: { state: self.pm1.state, source: self.pm1.source, deviation: self.pm1.deviation, freq: self.pm1.freq, shape: self.pm1.type, }, }, sweep: { type: self.sweep1.type, source: self.sweep1.source, startfreq: self.sweep1.startfreq, stopfreq: self.sweep1.stopfreq, centerfreq: self.sweep1.centerfreq, span: self.sweep1.span, swptime: self.sweep1.swptime, markerfreq: self.sweep1.markerfreq, marker: self.sweep1.marker, state: self.sweep1.state, }, }, ch2: { type: self.ch2.type, state: self.ch2.state, amplUnit: self.ch2.vunit, freq: self.ch2.freq, ampl: self.ch2.ampl, offset: self.ch2.offset, duty: self.ch2.duty, sym: self.ch2.sym, widt: self.ch2.width, modulation: { am: { state: self.am2.state, source: self.am2.source, depth: self.am2.depth, freq: self.am2.freq, shape: self.am2.type, }, fm: { state: self.fm2.state, source: self.fm2.source, deviation: self.fm2.deviation, freq: self.fm2.freq, shape: self.fm2.type, }, pm: { state: self.pm2.state, source: self.pm2.source, deviation: self.pm2.deviation, freq: self.pm2.freq, shape: self.pm2.type, }, }, sweep: { type: self.sweep2.type, source: self.sweep2.source, startfreq: self.sweep2.startfreq, stopfreq: self.sweep2.stopfreq, centerfreq: self.sweep2.centerfreq, span: self.sweep2.span, swptime: self.sweep2.swptime, markerfreq: self.sweep2.markerfreq, marker: self.sweep2.marker, state: self.sweep2.state, }, }, }, }); } } const cmd = []; let i; const chID = ['ch1', 'ch2']; const amID = ['am1', 'am2']; const fmID = ['fm1', 'fm2']; const pmID = ['pm1', 'pm2']; const sweepID = ['sweep1', 'sweep2']; log('afg getSetup'); for (i = 0; i < self.dev.maxChNum; i += 1) { cmd.push({ id: chID[i], prop: 'FuncType', arg: '', cb: null, method: 'get' }); cmd.push({ id: chID[i], prop: 'Freq', arg: '', cb: null, method: 'get' }); cmd.push({ id: chID[i], prop: 'Ampl', arg: '', cb: null, method: 'get' }); cmd.push({ id: chID[i], prop: 'DCOffset', arg: '', cb: null, method: 'get' }); cmd.push({ id: chID[i], prop: 'RampSym', arg: '', cb: null, method: 'get' }); cmd.push({ id: chID[i], prop: 'OutputState', arg: '', cb: null, method: 'get' }); cmd.push({ id: chID[i], prop: 'PulseWidth', arg: '', cb: null, method: 'get' }); cmd.push({ id: chID[i], prop: 'SquDuty', arg: '', cb: null, method: 'get' }); cmd.push({ id: chID[i], prop: 'VoltageUnit', arg: '', cb: null, method: 'get' }); cmd.push({ id: amID[i], prop: 'AMInteFunc', arg: '', cb: null, method: 'get' }); cmd.push({ id: amID[i], prop: 'AMInteFreq', arg: '', cb: null, method: 'get' }); cmd.push({ id: amID[i], prop: 'AMSource', arg: '', cb: null, method: 'get' }); cmd.push({ id: amID[i], prop: 'AMState', arg: '', cb: null, method: 'get' }); cmd.push({ id: amID[i], prop: 'AMDepth', arg: '', cb: null, method: 'get' }); cmd.push({ id: fmID[i], prop: 'FMInteFunc', arg: '', cb: null, method: 'get' }); cmd.push({ id: fmID[i], prop: 'FMInteFreq', arg: '', cb: null, method: 'get' }); cmd.push({ id: fmID[i], prop: 'FMSource', arg: '', cb: null, method: 'get' }); cmd.push({ id: fmID[i], prop: 'FMState', arg: '', cb: null, method: 'get' }); cmd.push({ id: fmID[i], prop: 'FMDeviation', arg: '', cb: null, method: 'get' }); cmd.push({ id: pmID[i], prop: 'PMInteFunc', arg: '', cb: null, method: 'get' }); cmd.push({ id: pmID[i], prop: 'PMInteFreq', arg: '', cb: null, method: 'get' }); cmd.push({ id: pmID[i], prop: 'PMSource', arg: '', cb: null, method: 'get' }); cmd.push({ id: pmID[i], prop: 'PMState', arg: '', cb: null, method: 'get' }); cmd.push({ id: pmID[i], prop: 'PMDeviation', arg: '', cb: null, method: 'get' }); cmd.push({ id: sweepID[i], prop: 'SweepState', arg: '', cb: null, method: 'get' }); cmd.push({ id: sweepID[i], prop: 'SweepFrqStart', arg: '', cb: null, method: 'get' }); cmd.push({ id: sweepID[i], prop: 'SweepFrqStop', arg: '', cb: null, method: 'get' }); cmd.push({ id: sweepID[i], prop: 'SweepFrqCenter', arg: '', cb: null, method: 'get' }); cmd.push({ id: sweepID[i], prop: 'SweepFrqSpan', arg: '', cb: null, method: 'get' }); cmd.push({ id: sweepID[i], prop: 'SweepSpacing', arg: '', cb: null, method: 'get' }); cmd.push({ id: sweepID[i], prop: 'SweepTime', arg: '', cb: null, method: 'get' }); cmd.push({ id: sweepID[i], prop: 'SweepSource', arg: '', cb: null, method: 'get' }); cmd.push({ id: sweepID[i], prop: 'SweepMarker', arg: '', cb: null, method: 'get' }); cmd.push({ id: sweepID[i], prop: 'SweepMarkerFreq', arg: '', cb: null, method: 'get' }); } cmd[cmd.length - 1].cb = getDone; self.dev.cmdSequence = self.dev.cmdSequence.concat(cmd); self.cmdEvent.emit('cmdWrite', cmd); })); }.bind(afgObj); /** * */ afgctrl.setSetup = function setSetup(setup) { const self = this; return new Promise(((resolve, reject) => { function setDone(e) { if (e) { log('afg.setSetup error'); log(e); reject(e); } else { resolve(); } } const cmd = []; let i; const chID = ['ch1', 'ch2']; const amID = ['am1', 'am2']; const fmID = ['fm1', 'fm2']; const pmID = ['pm1', 'pm2']; const sweepID = ['sweep1', 'sweep2']; log('afg setSetup'); log(setup); cmd.push({ id: 'sys', prop: 'RST', arg: '', cb: null, method: 'set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); for (i = 0; i < self.dev.maxChNum; i += 1) { cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: chID[i], prop: 'FuncType', arg: setup.chProps[chID[i]].type.slice(0, -1), cb: null, method: 'set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: chID[i], prop: 'Freq', arg: setup.chProps[chID[i]].freq.slice(0, -1), cb: null, method: 'set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: chID[i], prop: 'Ampl', arg: setup.chProps[chID[i]].ampl.slice(0, -1), cb: null, method: 'set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: chID[i], prop: 'DCOffset', arg: setup.chProps[chID[i]].offset.slice(0, -1), cb: null, method: 'set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: chID[i], prop: 'RampSym', arg: setup.chProps[chID[i]].sym.slice(0, -1), cb: null, method: 'set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); if (setup.chProps[chID[i]].state.slice(0, -1) === '0') { cmd.push({ id: chID[i], prop: 'OutputState', arg: 'OFF', cb: null, method: 'set' }); } else { cmd.push({ id: chID[i], prop: 'OutputState', arg: 'ON', cb: null, method: 'set' }); } cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: chID[i], prop: 'SquDuty', arg: setup.chProps[chID[i]].duty.slice(0, -1), cb: null, method: 'set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: chID[i], prop: 'VoltageUnit', arg: setup.chProps[chID[i]].amplUnit.slice(0, -1), cb: null, method: 'set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: amID[i], prop: 'AMInteFunc', arg: setup.chProps[chID[i]].modulation.am.shape.slice(0, -1), cb: null, method: 'set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: amID[i], prop: 'AMInteFreq', arg: setup.chProps[chID[i]].modulation.am.freq.slice(0, -1), cb: null, method: 'set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: amID[i], prop: 'AMSource', arg: setup.chProps[chID[i]].modulation.am.source.slice(0, -1), cb: null, method: 'set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); if (setup.chProps[chID[i]].modulation.am.state.slice(0, -1) === '0') { cmd.push({ id: amID[i], prop: 'AMState', arg: 'OFF', cb: null, method: 'set' }); } else { cmd.push({ id: amID[i], prop: 'AMState', arg: 'ON', cb: null, method: 'set' }); } cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: amID[i], prop: 'AMDepth', arg: setup.chProps[chID[i]].modulation.am.depth.slice(0, -1), cb: null, method: ' set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: fmID[i], prop: 'FMInteFunc', arg: setup.chProps[chID[i]].modulation.fm.shape.slice(0, -1), cb: null, method: 'set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: fmID[i], prop: 'FMInteFreq', arg: setup.chProps[chID[i]].modulation.fm.freq.slice(0, -1), cb: null, method: 'set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: fmID[i], prop: 'FMSource', arg: setup.chProps[chID[i]].modulation.fm.source.slice(0, -1), cb: null, method: 'set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); if (setup.chProps[chID[i]].modulation.fm.state.slice(0, -1) === '0') { cmd.push({ id: fmID[i], prop: 'FMState', arg: 'OFF', cb: null, method: 'set' }); } else { cmd.push({ id: fmID[i], prop: 'FMState', arg: 'ON', cb: null, method: 'set' }); } cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: fmID[i], prop: 'FMDeviation', arg: setup.chProps[chID[i]].modulation.fm.deviation.slice(0, -1), cb: null, method: 'set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: pmID[i], prop: 'PMInteFunc', arg: setup.chProps[chID[i]].modulation.pm.shape.slice(0, -1), cb: null, method: 'set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: pmID[i], prop: 'PMInteFreq', arg: setup.chProps[chID[i]].modulation.pm.freq.slice(0, -1), cb: null, method: 'set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: pmID[i], prop: 'PMSource', arg: setup.chProps[chID[i]].modulation.pm.source.slice(0, -1), cb: null, method: 'set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); if (setup.chProps[chID[i]].modulation.pm.state.slice(0, -1) === '0') { cmd.push({ id: pmID[i], prop: 'PMState', arg: 'OFF', cb: null, method: 'set' }); } else { cmd.push({ id: pmID[i], prop: 'PMState', arg: 'ON', cb: null, method: 'set' }); } cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: pmID[i], prop: 'PMDeviation', arg: setup.chProps[chID[i]].modulation.pm.deviation.slice(0, -1), cb: null, method: 'set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); if (setup.chProps[chID[i]].sweep.state.slice(0, -1) === '0') { cmd.push({ id: sweepID[i], prop: 'SweepState', arg: 'OFF', cb: null, method: 'set' }); } else { cmd.push({ id: sweepID[i], prop: 'SweepState', arg: 'ON', cb: null, method: 'set' }); } cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: sweepID[i], prop: 'SweepFrqStart', arg: setup.chProps[chID[i]].sweep.startfreq.slice(0, -1), cb: null, method: 'set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: sweepID[i], prop: 'SweepFrqStop', arg: setup.chProps[chID[i]].sweep.stopfreq.slice(0, -1), cb: null, method: 'set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: sweepID[i], prop: 'SweepFrqCenter', arg: setup.chProps[chID[i]].sweep.centerfreq.slice(0, -1), cb: null, method: 'set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: sweepID[i], prop: 'SweepFrqSpan', arg: setup.chProps[chID[i]].sweep.span.slice(0, -1), cb: null, method: 'set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: sweepID[i], prop: 'SweepSpacing', arg: setup.chProps[chID[i]].sweep.type.slice(0, -1), cb: null, method: 'set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: sweepID[i], prop: 'SweepTime', arg: setup.chProps[chID[i]].sweep.swptime.slice(0, -1), cb: null, method: 'set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: sweepID[i], prop: 'SweepSource', arg: setup.chProps[chID[i]].sweep.source.slice(0, -1), cb: null, method: 'set' }); cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); if (setup.chProps[chID[i]].sweep.marker.slice(0, -1) === '0') { cmd.push({ id: sweepID[i], prop: 'SweepMarker', arg: 'OFF', cb: null, method: 'set' }); } else { cmd.push({ id: sweepID[i], prop: 'SweepMarker', arg: 'ON', cb: null, method: 'set' }); } cmd.push({ id: 'sys', prop: 'delay_for_a_while', arg: AGF_DELAY_CNT, cb: null, method: 'set' }); cmd.push({ id: sweepID[i], prop: 'SweepMarkerFreq', arg: setup.chProps[chID[i]].sweep.markerfreq.slice(0, -1), cb: null, method: 'set' }); } cmd[cmd.length - 1].cb = setDone; self.dev.cmdSequence = self.dev.cmdSequence.concat(cmd); // log(self.dev.cmdSequence); self.cmdEvent.emit('cmdWrite', cmd); })); }.bind(afgObj); /** * The method belong to afgctrl class used to load horizontal properties from device, * like time division, position .. etc. * * @method getChannel * @return {Object} chProperty * */ /** * Channel property of device. * * @property CHProperty * @type Object * @param {String} position Specify the distance with triggered pointer of the main window * @param {String} zposition Specify the distance with triggered pointer of the zoom window * @param {String} scale Specify the time divison of the main window * @param {String} zscale Specify the time divison of the zoom window * @param {String} mode Specify which mode device on * @param {String} expand Specify timebase expand by center or trigger position */ afgctrl.getChannel = function getChannel(chProp) { const self = this; const chNum = sysConstant.chID[chProp.ch]; return new Promise(((resolve, reject) => { function getDone(e) { if (e) { reject(e); } else { resolve(self[chProp.ch]); } } let cmd = []; log(`chNum =${chNum}`); log(`maxChNum =${self.dev.maxChNum}`); log(chProp); if (chNum === undefined) { reject(['AGF_DELAY_CNT', 'Parameter Error']); return; } if (chProp === undefined) { reject(['AGF_DELAY_CNT', 'Parameter Error']); } else { if (chProp.type !== undefined) { cmd.push({ id: chProp.ch, prop: 'FuncType', arg: chProp.type, cb: null, method: 'get' }); } if (chProp.freq !== undefined) { cmd.push({ id: chProp.ch, prop: 'Freq', arg: chProp.freq, cb: null, method: 'get' }); } if (chProp.ampl !== undefined) { cmd.push({ id: chProp.ch, prop: 'Ampl', arg: chProp.ampl, cb: null, method: 'get' }); } if (chProp.offset !== undefined) { cmd.push({ id: chProp.ch, prop: 'DCOffset', arg: chProp.offset, cb: null, method: 'get' }); } if (chProp.sym !== undefined) { cmd.push({ id: chProp.ch, prop: 'RampSym', arg: chProp.sym, cb: null, method: 'get' }); } if (chProp.load !== undefined) { cmd.push({ id: chProp.ch, prop: 'OutputLoad', arg: chProp.load, cb: null, method: 'get' }); } if (chProp.duty !== undefined) { cmd.push({ id: chProp.ch, prop: 'SquDuty', arg: chProp.load, cb: null, method: 'get' }); } if (chProp.vunit !== undefined) { cmd.push({ id: chProp.ch, prop: 'VoltageUnit', arg: chProp.vunit, cb: null, method: 'get' }); } if (chProp.state !== undefined) { cmd.push({ id: chProp.ch, prop: 'OutputState', arg: chProp.state, cb: null, method: 'get' }); } if (chProp.width !== undefined) { cmd.push({ id: chProp.ch, prop: 'PulseWidth', arg: chProp.vunit, cb: null, method: 'get' }); } if (cmd.length > 0) { cmd[cmd.length - 1].cb = getDone; self.dev.cmdSequence = self.dev.cmdSequence.concat(cmd); // log(self.dev.cmdSequence); self.cmdEvent.emit('cmdWrite', cmd); } else { cmd = [ { id: chProp.ch, prop: 'FuncType', arg: '', cb: null, method: 'get' }, { id: chProp.ch, prop: 'Freq', arg: '', cb: null, method: 'get' }, { id: chProp.ch, prop: 'Ampl', arg: '', cb: null, method: 'get' }, { id: chProp.ch, prop: 'DCOffset', arg: '', cb: null, method: 'get' }, { id: chProp.ch, prop: 'RampSym', arg: '', cb: null, method: 'get' }, { id: chProp.ch, prop: 'OutputLoad', arg: '', cb: null, method: 'get' }, { id: chProp.ch, prop: 'PulseWidth', arg: '', cb: null, method: 'get' }, { id: chProp.ch, prop: 'PulsePeriod', arg: '', cb: null, method: 'get' }, { id: chProp.ch, prop: 'VoltageUnit', arg: '', cb: null, method: 'get' }, { id: chProp.ch, prop: 'OutputState', arg: '', cb: getDone, method: 'get' }, ]; self.dev.cmdSequence = self.dev.cmdSequence.concat(cmd); self.cmdEvent.emit('cmdWrite', cmd); } } })); }.bind(afgObj); /** * The method belong to afgctrl class used to set horizontal properties to device, * like time division, position .. etc. * * @method setChannel * @param {Object} horProperty * */ /** * Channel property of device. * * @property chProperty * @type Object * @param {String} position Specify the distance with triggered pointer of the main window * @param {String} zposition Specify the distance with triggered pointer of the zoom window * @param {String} scale Specify the time divison of the main window * @param {String} zscale Specify the time divison of the zoom window * @param {String} mode Specify which mode device on * @param {String} expand Specify timebase expand by center or trigger position */ afgctrl.setChannel = function setChannel(chProp) { const self = this; const chNum = sysConstant.chID[chProp.ch]; return new Promise(((resolve, reject) => { const cmd = []; function setDone(e) { if (e) { reject(e); } else { resolve(); } } log(`chNum =${chNum}`); log(`maxChNum =${self.dev.maxChNum}`); log(chProp); if ((chNum === undefined) || (chNum >= self.dev.maxChNum)) { reject(['AGF_DELAY_CNT', 'Parameter Error']); return; } if (chProp === undefined) { reject(['AGF_DELAY_CNT', 'Parameter Error']); return; } if (chProp.type !== undefined) { cmd.push({ id: chProp.ch, prop: 'FuncType', arg: chProp.type, cb: null, method: 'set' }); } if (chProp.freq !== undefined) { cmd.push({ id: chProp.ch, prop: 'Freq', arg: chProp.freq, cb: null, method: 'set' }); } if (chProp.ampl !== undefined) { cmd.push({ id: chProp.ch, prop: 'Ampl', arg: chProp.ampl, cb: null, method: 'set' }); } if (chProp.sym !== undefined) { cmd.push({ id: chProp.ch, prop: 'RampSym', arg: chProp.sym, cb: null, method: 'set' }); } if (chProp.load !== undefined) { cmd.push({ id: chProp.ch, prop: 'OutputLoad', arg: chProp.load, cb: null, method: 'set' }); } if (chProp.offset !== undefined) { cmd.push({ id: chProp.ch, prop: 'DCOffset', arg: chProp.offset, cb: null, method: 'set' }); } if (chProp.duty !== undefined) { cmd.push({ id: chProp.ch, prop: 'SquDuty', arg: chProp.duty, cb: null, method: 'set' }); } if (chProp.vunit !== undefined) { cmd.push({ id: chProp.ch, prop: 'VoltageUnit', arg: chProp.vunit, cb: null, method: 'set' }); } if (chProp.state !== undefined) { cmd.push({ id: chProp.ch, prop: 'OutputState', arg: chProp.state, cb: null, method: 'set' }); } if (chProp.width !== undefined) { cmd.push({ id: chProp.ch, prop: 'PulseWidth', arg: chProp.width, cb: null, method: 'set' }); } if (cmd.length > 0) { cmd[cmd.length - 1].cb = setDone; self.dev.cmdSequence = self.dev.cmdSequence.concat(cmd); log(self.dev.cmdSequence); self.cmdEvent.emit('cmdWrite', cmd); } else { log('setHorizontal do nothing'); resolve(); } })); }.bind(afgObj); /** * The method belong to afgctrl class used to load horizontal properties from device, * like time division, position .. etc. * * @method getAM * @return {Object} amProperty * */ /** * Channel property of device. * * @property amProperty * @type Object * @param {String} position Specify the distance with triggered pointer of the main window * @param {String} zposition Specify the distance with triggered pointer of the zoom window * @param {String} scale Specify the time divison of the main window * @param {String} zscale Specify the time divison of the zoom window * @param {String} mode Specify which mode device on * @param {String} expand Specify timebase expand by center or trigger position */ afgctrl.getAM = function getAM(amProp) { const self = this; const chNum = sysConstant.chID[amProp.ch]; return new Promise(((resolve, reject) => { function getDone(e) { if (e) { reject(e); } else { resolve(self[amProp.ch]); } } let cmd = []; log('amProp ='); log(amProp); log(`chNum =${chNum}`); log(`maxChNum =${self.dev.maxChNum}`); log(amProp); if (chNum === undefined) { reject(['AGF_DELAY_CNT', 'Parameter Error']); return; } if (amProp === undefined) { reject(['AGF_DELAY_CNT', 'Parameter Error']); } else { if (amProp.type !== undefined) { cmd.push({ id: amProp.ch, prop: 'AMInteFunc', arg: amProp.type, cb: null, method: 'get' }); } if (amProp.freq !== undefined) { cmd.push({ id: amProp.ch, prop: 'AMInteFreq', arg: amProp.freq, cb: null, method: 'get' }); } if (amProp.source !== undefined) { cmd.push({ id: amProp.ch, prop: 'AMSource', arg: amProp.source, cb: null, method: 'get' }); } if (amProp.depth !== undefined) { cmd.push({ id: amProp.ch, prop: 'AMDepth', arg: amProp.depth, cb: null, method: 'get' }); } if (amProp.state !== undefined) { cmd.push({ id: amProp.ch, prop: 'AMState', arg: amProp.state, cb: null, method: 'get' }); } if (cmd.length > 0) { cmd[cmd.length - 1].cb = getDone; self.dev.cmdSequence = self.dev.cmdSequence.concat(cmd); // log(self.dev.cmdSequence); self.cmdEvent.emit('cmdWrite', cmd); } else { cmd = [ { id: amProp.ch, prop: 'AMInteFunc', arg: '', cb: null, method: 'get' }, { id: amProp.ch, prop: 'AMInteFreq', arg: '', cb: null, method: 'get' }, { id: amProp.ch, prop: 'AMSource', arg: '', cb: null, method: 'get' }, { id: amProp.ch, prop: 'AMDepth', arg: '', cb: null, method: 'get' }, { id: amProp.ch, prop: 'AMState', arg: '', cb: getDone, method: 'get' }, ]; self.dev.cmdSequence = self.dev.cmdSequence.concat(cmd); self.cmdEvent.emit('cmdWrite', cmd); } } })); }.bind(afgObj); /** * The method belong to afgctrl class used to set horizontal properties to device, * like time division, position .. etc. * * @method setChannel * @param {Object} horProperty * */ /** * Channel property of device. * * @property amProperty * @type Object * @param {String} position Specify the distance with triggered pointer of the main window * @param {String} zposition Specify the distance with triggered pointer of the zoom window * @param {String} scale Specify the time divison of the main window * @param {String} zscale Specify the time divison of the zoom window * @param {String} mode Specify which mode device on * @param {String} expand Specify timebase expand by center or trigger position */ afgctrl.setAM = function setAM(amProp) { const self = this; const chNum = sysConstant.chID[amProp.ch]; return new Promise(((resolve, reject) => { const cmd = []; function setDone(e) { if (e) { reject(e); } else { resolve(); } } if ((chNum === undefined) || (chNum >= self.dev.maxChNum)) { reject(['AGF_DELAY_CNT', 'Parameter Error']); return; } if (amProp === undefined) { reject(['AGF_DELAY_CNT', 'Parameter Error']); } else { if (amProp.type !== undefined) { cmd.push({ id: amProp.ch, prop: 'AMInteFunc', arg: amProp.type, cb: null, method: 'set' }); } if (amProp.freq !== undefined) { cmd.push({ id: amProp.ch, prop: 'AMInteFreq', arg: amProp.freq, cb: null, method: 'set' }); } if (amProp.source !== undefined) { cmd.push({ id: amProp.ch, prop: 'AMSource', arg: amProp.source, cb: null, method: 'set' }); } if (amProp.depth !== undefined) { cmd.push({ id: amProp.ch, prop: 'AMDepth', arg: amProp.depth, cb: null, method: 'set' }); } if (amProp.state !== undefined) { cmd.push({ id: amProp.ch, prop: 'AMState', arg: amProp.state, cb: null, method: 'set' }); } if (cmd.length > 0) { cmd[cmd.length - 1].cb = setDone; self.dev.cmdSequence = self.dev.cmdSequence.concat(cmd); // log(self.dev.cmdSequence); self.cmdEvent.emit('cmdWrite', cmd); } else { log('setAM do nothing'); resolve(); } } })); }.bind(afgObj); /** * The method belong to afgctrl class used to load horizontal properties from device, * like time division, position .. etc. * * @method getFM * @return {Object} fmProperty * */ /** * Channel property of device. * * @property fmProperty * @type Object * @param {String} position Specify the distance with triggered pointer of the main window * @param {String} zposition Specify the distance with triggered pointer of the zoom window * @param {String} scale Specify the time divison of the main window * @param {String} zscale Specify the time divison of the zoom window * @param {String} mode Specify which mode device on * @param {String} expand Specify timebase expand by center or trigger position */ afgctrl.getFM = function getFM(fmProp) { const self = this; const chNum = sysConstant.chID[fmProp.ch]; return new Promise(((resolve, reject) => { function getDone(e) { if (e) { reject(e); } else { resolve(self[fmProp.ch]); } } let cmd = []; if (chNum === undefined) { reject(['AGF_DELAY_CNT', 'Parameter Error']); return; } if (fmProp === undefined) { reject(['AGF_DELAY_CNT', 'Parameter Error']); } else { if (fmProp.type !== undefined) { cmd.push({ id: fmProp.ch, prop: 'FMInteFunc', arg: fmProp.type, cb: null, method: 'get' }); } if (fmProp.freq !== undefined) { cmd.push({ id: fmProp.ch, prop: 'FMInteFreq', arg: fmProp.freq, cb: null, method: 'get' }); } if (fmProp.source !== undefined) { cmd.push({ id: fmProp.ch, prop: 'FMSource', arg: fmProp.source, cb: null, method: 'get' }); } if (fmProp.deviation !== undefined) { cmd.push({ id: fmProp.ch, prop: 'FMDeviation', arg: fmProp.deviation, cb: null, method: 'get' }); } if (fmProp.state !== undefined) { cmd.push({ id: fmProp.ch, prop: 'FMState', arg: fmProp.state, cb: null, method: 'get' }); } if (cmd.length > 0) { cmd[cmd.length - 1].cb = getDone; self.dev.cmdSequence = self.dev.cmdSequence.concat(cmd); // log(self.dev.cmdSequence); self.cmdEvent.emit('cmdWrite', cmd); } else { cmd = [ { id: fmProp.ch, prop: 'FMInteFunc', arg: '', cb: null, method: 'get' }, { id: fmProp.ch, prop: 'FMInteFreq', arg: '', cb: null, method: 'get' }, { id: fmProp.ch, prop: 'FMSource', arg: '', cb: null, method: 'get' }, { id: fmProp.ch, prop: 'FMDeviation', arg: '', cb: null, method: 'get' }, { id: fmProp.ch, prop: 'FMState', arg: '', cb: getDone, method: 'get' }, ]; self.dev.cmdSequence = self.dev.cmdSequence.concat(cmd); self.cmdEvent.emit('cmdWrite', cmd); } } })); }.bind(afgObj); /** * The method belong to afgctrl class used to set horizontal properties to device, * like time division, position .. etc. * * @method setFM * @param {Object} horProperty * */ /** * Channel property of device. * * @property fmProperty * @type Object * @param {String} position Specify the distance with triggered pointer of the main window * @param {String} zposition Specify the distance with triggered pointer of the zoom window * @param {String} scale Specify the time divison of the main window * @param {String} zscale Specify the time divison of the zoom window * @param {String} mode Specify which mode device on * @param {String} expand Specify timebase expand by center or trigger position */ afgctrl.setFM = function setFM(fmProp) { const self = this; const chNum = sysConstant.chID[fmProp.ch]; return new Promise(((resolve, reject) => { const cmd = []; function setDone(e) { if (e) { reject(e); } else { resolve(); } } if ((chNum === undefined) || (chNum >= self.dev.maxChNum)) { reject(['AGF_DELAY_CNT', 'Parameter Error']); return; } if (fmProp === undefined) { reject(['AGF_DELAY_CNT', 'Parameter Error']); return; } if (fmProp.type !== undefined) { cmd.push({ id: fmProp.ch, prop: 'FMInteFunc', arg: fmProp.type, cb: null, method: 'set' }); } if (fmProp.freq !== undefined) { cmd.push({ id: fmProp.ch, prop: 'FMInteFreq', arg: fmProp.freq, cb: null, method: 'set' }); } if (fmProp.source !== undefined) { cmd.push({ id: fmProp.ch, prop: 'FMSource', arg: fmProp.source, cb: null, method: 'set' }); } if (fmProp.deviation !== undefined) { cmd.push({ id: fmProp.ch, prop: 'FMDevation', arg: fmProp.deviation, cb: null, method: 'set' }); } if (fmProp.state !== undefined) { cmd.push({ id: fmProp.ch, prop: 'FMState', arg: fmProp.state, cb: null, method: 'set' }); } if (cmd.length > 0) { cmd[cmd.length - 1].cb = setDone; self.dev.cmdSequence = self.dev.cmdSequence.concat(cmd); // log(self.dev.cmdSequence); self.cmdEvent.emit('cmdWrite', cmd); } else { log('setFM do nothing'); resolve(); } })); }.bind(afgObj); /** * The method belong to afgctrl class used to load horizontal properties from device, * like time division, position .. etc. * * @method getPM * @return {Object} fmProperty * */ /** * Channel property of device. * * @property pmProperty * @type Object * @param {String} position Specify the distance with triggered pointer of the main window * @param {String} zposition Specify the distance with triggered pointer of the zoom window * @param {String} scale Specify the time divison of the main window * @param {String} zscale Specify the time divison of the zoom window * @param {String} mode Specify which mode device on * @param {String} expand Specify timebase expand by center or trigger position */ afgctrl.getPM = function getPM(pmProp) { const self = this; const chNum = sysConstant.chID[pmProp.ch]; return new Promise(((resolve, reject) => { function getDone(e) { if (e) { reject(e); } else { resolve(self[pmProp.ch]); } } let cmd = []; if (chNum === undefined) { reject(['AGF_DELAY_CNT', 'Parameter Error']); return; } if (pmProp === undefined) { reject(['AGF_DELAY_CNT', 'Parameter Error']); return; } if (pmProp.type !== undefined) { cmd.push({ id: pmProp.ch, prop: 'PMInteFunc', arg: pmProp.type, cb: null, method: 'get' }); } if (pmProp.freq !== undefined) { cmd.push({ id: pmProp.ch, prop: 'PMInteFreq', arg: pmProp.freq, cb: null, method: 'get' }); } if (pmProp.source !== undefined) { cmd.push({ id: pmProp.ch, prop: 'PMSource', arg: pmProp.source, cb: null, method: 'get' }); } if (pmProp.deviation !== undefined) { cmd.push({ id: pmProp.ch, prop: 'PMDeviation', arg: pmProp.deviation, cb: null, method: 'get' }); } if (pmProp.state !== undefined) { cmd.push({ id: pmProp.ch, prop: 'PMState', arg: pmProp.state, cb: null, method: 'get' }); } if (cmd.length > 0) { cmd[cmd.length - 1].cb = getDone; self.dev.cmdSequence = self.dev.cmdSequence.concat(cmd); // log(self.dev.cmdSequence); self.cmdEvent.emit('cmdWrite', cmd); } else { cmd = [ { id: pmProp.ch, prop: 'PMInteFunc', arg: '', cb: null, method: 'get' }, { id: pmProp.ch, prop: 'PMInteFreq', arg: '', cb: null, method: 'get' }, { id: pmProp.ch, prop: 'PMSource', arg: '', cb: null, method: 'get' }, { id: pmProp.ch, prop: 'PMDeviation', arg: '', cb: null, method: 'get' }, { id: pmProp.ch, prop: 'PMState', arg: '', cb: getDone, method: 'get' }, ]; self.dev.cmdSequence = self.dev.cmdSequence.concat(cmd); self.cmdEvent.emit('cmdWrite', cmd); } })); }.bind(afgObj); /** * The method belong to afgctrl class used to set horizontal properties to device, * like time division, position .. etc. * * @method setFM * @param {Object} horProperty * */ /** * Channel property of device. * * @property fmProperty * @type Object * @param {String} position Specify the distance with triggered pointer of the main window * @param {String} zposition Specify the distance with triggered pointer of the zoom window * @param {String} scale Specify the time divison of the main window * @param {String} zscale Specify the time divison of the zoom window * @param {String} mode Specify which mode device on * @param {String} expand Specify timebase expand by center or trigger position */ afgctrl.setPM = function setPM(pmProp) { const self = this; const chNum = sysConstant.chID[pmProp.ch]; return new Promise(((resolve, reject) => { const cmd = []; function setDone(e) { if (e) { reject(e); } else { resolve(); } } if ((chNum === undefined) || (chNum >= self.dev.maxChNum)) { reject(['AGF_DELAY_CNT', 'Parameter Error']); return; } if (pmProp === undefined) { reject(['AGF_DELAY_CNT', 'Parameter Error']); return; } if (pmProp.type !== undefined) { cmd.push({ id: pmProp.ch, prop: 'PMInteFunc', arg: pmProp.type, cb: null, method: 'set' }); } if (pmProp.freq !== undefined) { cmd.push({ id: pmProp.ch, prop: 'PMInteFreq', arg: pmProp.freq, cb: null, method: 'set' }); } if (pmProp.source !== undefined) { cmd.push({ id: pmProp.ch, prop: 'PMSource', arg: pmProp.source, cb: null, method: 'set' }); } if (pmProp.deviation !== undefined) { cmd.push({ id: pmProp.ch, prop: 'PMDevation', arg: pmProp.deviation, cb: null, met