weblab-instrument
Version:
communication with instrument through usb
147 lines (139 loc) • 3.45 kB
JavaScript
const propMethod = require('../dev/propMethod.js');
// const debug = require('debug');
// const log = debug('afg_channel:log');
function Channel() {
this.type = 'SIN';
this.load = 'DEF';
this.ampl = '1';
this.offset = '0';
this.freq = '1E+6';
this.state = 'OFF';
this.vunit = 'VPP';
this.sym = '5E+1';
this.width = '1E+3';
this.duty = '5E+1';
}
Channel.prototype.cmdHandler = {
FuncType: {
setHelper(chObj, arg) {
chObj.type = arg;
},
getHandler(chObj, res) {
res = res.slice(0, -1);
chObj.type = res.toString();
return true;
},
},
Freq: {
setHelper(chObj, arg) {
chObj.freq = arg;
return true;
},
getHandler(chObj, res) {
res = res.slice(0, -1);
chObj.freq = res.toString();
return true;
},
},
Ampl: {
setHelper(chObj, arg) {
chObj.ampl = arg;
return true;
},
getHandler(chObj, res) {
res = res.slice(0, -1);
chObj.ampl = res.toString();
return true;
},
},
DCOffset: {
setHelper(chObj, arg) {
chObj.offset = arg;
},
getHandler(chObj, res) {
res = res.slice(0, -1);
chObj.offset = res.toString();
return true;
},
},
RampSym: {
setHelper(chObj, arg) {
chObj.sym = arg;
return true;
},
getHandler(chObj, res) {
res = res.slice(0, -1);
chObj.sym = res.toString();
return true;
},
},
OutputState: {
setHelper(chObj, arg) {
chObj.state = arg;
},
getHandler(chObj, res) {
res = res.slice(0, -1);
chObj.state = res.toString();
return true;
},
},
OutputLoad: {
setHelper(chObj, arg) {
chObj.load = arg;
},
getHandler(chObj, res) {
res = res.slice(0, -1);
chObj.load = res.toString();
return true;
},
},
PulseWidth: {
setHelper(chObj, arg) {
chObj.width = arg;
},
getHandler(chObj, res) {
res = res.slice(0, -1);
chObj.width = res.toString();
return true;
},
},
SquDuty: {
setHelper(chObj, arg) {
chObj.duty = arg;
return true;
},
getHandler(chObj, res) {
res = res.slice(0, -1);
chObj.duty = res.toString();
return true;
},
},
VoltageUnit: {
setHelper(chObj, arg) {
chObj.vunit = arg;
},
getHandler(chObj, res) {
res = res.slice(0, -1);
chObj.vunit = res.toString();
return true;
},
},
};
Channel.prototype.setToDefault = function setToDefault(chObj) {
chObj.type = 'SIN';
chObj.load = 'DEF';
chObj.ampl = '1';
chObj.offset = '0';
chObj.freq = '1E+6';
chObj.state = 'OFF';
chObj.vunit = 'VPP';
chObj.sym = '5E+1';
chObj.width = '1E+3';
chObj.duty = '5E+1';
};
exports.initChanObj = function initChanObj(id) {
const chanCmd = new Channel();
chanCmd.id = id;
chanCmd.prop = propMethod.CreatMethod.call(this, id);
return chanCmd;
};