Here is the code I'm using:
Code: Select all
function runExample() {
console.log('Running runExample');
var ch = new phidget22.VoltageInput();
ch.setIsHubPortDevice(true);
ch.setHubPort(0);
ch.onError = function (code, description) {
console.log("Error " + code + ": " + description);
};
ch.onAttach = () => {
console.log('attach');
/*ch.onSensorChange = (sensorValue, sensorUnit) => {
console.log(sensorValue);
}*/
};
ch.onSensorChange = (sensorValue, sensorUnit) => {
console.log(sensorValue);
}
ch.open().then(() => {
ch.setSensorType(phidget22.VoltageSensorType.PN_MOT2002_LOW);
}).catch(function (err) {
console.error(err);
});
}
var conn = new phidget22.Connection(8989, 'localhost');
conn.connect().then(runExample).catch(function (err) {
console.log('This function never runs');
console.error('Error during connect:', err);
});
2. While everything is working correctly and the connection is lost by closing the server I can see that it's automatically retrying and eventually succeeds after starting the server again but the onSensorChange is no longer called.
3. Every time the connection is established, I get a bunch of "Error 4103: Sensor value is ouside the valid range for this sensor." and onSensorChange is not being called. After around 10 seconds or so, sometime more, the errors stops and onSensorChange is called correctly.
Am I doing something wrong? What should I do in these situations if want the connection to recover?
Thanks