I'm trying to develop node.js webserver that interact with my phidgetAnalog 4-Output.
I've installed all the needed libraries according to the Phidget Getting started user guide.
I Create a conn object and try to run conn.connect() but the code keep on crashing to the point it doesn't even breaks in the catch(ex) block of my node.js code.
JS Library (phidget22) version: 1.7 (seems to be the latest)
I tried to go into the phidget22 npm package code and I trace the exception to the following line:
"...}, Vt.prototype.connect = function () {
if (this.connected === !0) return Promise.resolve(this);
--------------------------------------------------------
var t = this; // The code crashes on this line //
--------------------------------------------------------
return new Promise(function (e, n) {
..."
after running the above line of code, it crashes and reach the following catch block:
"...
} catch (s) {
n(new _t(V.UNEXPECTED, s.message));
}
});
..."
What am I doing wrong???
p.s.
I also wrote code in python that intercat with the same device and it works perfectly ON THE SAME development laptop.
my node.js code:
const initPhidgetChannel = () => {
try{
var libraryVersion = phidget22.Phidget.getLibraryVersion();
let conn = new phidget22.Connection(5661, 'localhost');
conn.connect().then(function() {
channel = new phidget22.VoltageOutput();
channel.open(2500).then(function() {
let enabled = channel.getEnabled();
console.log(`InitPhidgetChannel: Enabled: ${enabled}`);
return true;
}).catch(function (err) {
console.error(`Error during channel openning: ${err}`);
return false;
});
}).catch(function(err) {
console.error(`Error during connection: ${err}`);
return false;
});
}
catch(ex)
{
console.error(`PhidgetException: ${ex}`);
return false;
}
}