weblab-instrument
Version:
communication with instrument through usb
165 lines (152 loc) • 4.66 kB
JavaScript
const propMethod = require('../dev/propMethod.js');
// const debug = require('debug');
// const log = debug('lcr_meas:log');
function Measure() {
this.func = 'Cp-D';
this.FuncImpeAuto = 'OFF';
this.FuncImpeRange = 'AUTO';
this.FuncDcrRange = 'AUTO';
this.FuncRangeAuto = 'AUTO';
this.FuntMonitor1 = 'OFF';
this.FuntMonitor2 = 'OFF';
this.primary = '';
this.secondary = '';
this.cmp = 'OFF';
this.aux = 'OFF';
this.mon1 = '';
this.mon2 = '';
this.dcr = '';
}
Measure.prototype.cmdHandler = {
Fetch: {
getHandler() {
return true;
},
},
FetchImpedance: {
getHandler(MeasObj, res) {
// console.log("FetchImpedance");
// console.log(`func = ${MeasObj.func}`);
if (MeasObj.func !== 'DCR') {
const [primary, secondary, mon1, mon2] = res.split(',');
MeasObj.primary = primary;
MeasObj.secondary = secondary;
MeasObj.mon1 = mon1;
MeasObj.mon2 = mon2;
} else {
const [dcr] = res.split(',');
MeasObj.dcr = dcr;
}
return true;
},
},
FetchMain: {
getHandler(MeasObj, res) {
// console.log(`FetchImpedance return string = ${res}, length = ${res.length}`);
if (MeasObj.func !== 'DCR') {
const [primary, secondary] = res.slice(0, -1).split(',');
MeasObj.primary = primary;
MeasObj.secondary = secondary;
} else {
MeasObj.dcr = res.slice(0, -1);
}
return true;
},
},
FetchMonitor: {
getHandler(MeasObj, res) {
// console.log(`FetchImpedance return string = ${res}, length = ${res.length}`);
if (MeasObj.func !== 'DCR') {
const [mon1, mon2] = res.slice(0, -1).split(',');
MeasObj.mon1 = mon1;
MeasObj.mon2 = mon2;
} else {
MeasObj.dcr = res.slice(0, -1);
}
return true;
},
},
Function: {
setHelper(MeasObj, arg) {
MeasObj.func = arg;
return true;
},
getHandler(MeasObj, res) {
// console.log(`Function return string = ${res}`);
MeasObj.func = res.slice(0, -1);
return true;
},
},
FuncImpeAuto: {
setHelper(MeasObj, arg) {
MeasObj.FuncImpeAuto = arg;
return true;
},
getHandler(MeasObj, res) {
// console.log(`FuncImpeAuto return string = ${res}`);
MeasObj.FuncImpeAuto = res.slice(0, -1);
return true;
},
},
FuncImpeRange: {
setHelper(MeasObj, arg) {
MeasObj.FuncImpeRange = arg;
return true;
},
getHandler(MeasObj, res) {
// console.log(`FuncImpeRange return string = ${res}`);
MeasObj.FuncImpeRange = res.slice(0, -1);
return true;
},
},
FuncDcrRange: {
setHelper(MeasObj, arg) {
MeasObj.FuncDcrRange = arg;
return true;
},
getHandler(MeasObj, res) {
// console.log(`FuncDcrRange return string = ${res}`);
MeasObj.FuncDcrRange = res.slice(0, -1);
return true;
},
},
FuncRangeAuto: {
setHelper(MeasObj, arg) {
MeasObj.FuncRangeAuto = arg;
return true;
},
getHandler(MeasObj, res) {
// console.log(`FuncRangeAuto return string = ${res}`);
MeasObj.FuncRangeAuto = res.slice(0, -1);
return true;
},
},
FuntMonitor1: {
setHelper(MeasObj, arg) {
MeasObj.FuntMonitor1 = arg;
return true;
},
getHandler(MeasObj, res) {
// console.log(`Function FuntMonitor1 return string = ${res}`);
MeasObj.FuntMonitor1 = res.slice(0, -1);
return true;
},
},
FuntMonitor2: {
setHelper(MeasObj, arg) {
MeasObj.FuntMonitor2 = arg;
return true;
},
getHandler(MeasObj, res) {
// console.log(`Function FuntMonitor2 return string = ${res}`);
MeasObj.FuntMonitor2 = res.slice(0, -1);
return true;
},
},
};
exports.initLcrMeasObj = function initLcrMeasObj(id) {
const measCmd = new Measure();
measCmd.id = id;
measCmd.prop = propMethod.CreatMethod.call(this, id);
return measCmd;
};