Page 2 of 2

Re: Unhandled Promise Rejection

Posted: Wed Aug 18, 2021 3:59 am
by superninja
the phidget22 libs version for nodejs is 2.7.4 (installed with npm install)

Re: Unhandled Promise Rejection

Posted: Wed Aug 18, 2021 8:27 am
by mparadis
Just tested it with a HUB5000 on firmware version 1.0.53 and node package version 2.7.3 and it works with the following code:

Code: Select all

var phidget22 = require('phidget22');

function runExample() {
	var digitalInput0 = new phidget22.DigitalInput();

	digitalInput0.setIsHubPortDevice(true);
	digitalInput0.setHubPort(0);

	digitalInput0.onStateChange = function onDigitalInput0_StateChange(state) {
		console.log('State: ' + state.toString())
	};

	digitalInput0.open(5000).then(function() {

		setTimeout(function () {
			digitalInput0.close();
			process.exit(0);
		}, 5000);
	});
}

var conn = new phidget22.Connection(5661, '192.168.3.113');
conn.connect().then(runExample);
Another thing you should check- try opening it as a voltageInput object and make a note of what voltage you see when it's blocked or unblocked. If the sensitivity screw on the board is set to the wrong spot it might be causing issues. You should see a bit less than 5V when the sensor is blocked and close to 0V when the sensor is empty.

Re: Unhandled Promise Rejection

Posted: Wed Aug 18, 2021 8:38 am
by superninja
I just tested again - I still don't get an event on startup, but I can successfully call the getState() function immediately after the open function, and I don't get the 'Unknown or Invalid Value' error anymore, it gives me the correct state.

I will check the voltage and the sensitivity screw to see if that is affecting the initial event. But the firmware upgrade definitely solved the problem of reading the state at any time.

thanks a lot for the help!

Re: Unhandled Promise Rejection

Posted: Wed Aug 18, 2021 9:31 am
by Patrick
Make sure you're registering for the state change event before calling open, or you'll miss an initial event.

-Patrick

Re: Unhandled Promise Rejection

Posted: Wed Aug 18, 2021 3:24 pm
by superninja
Not sure how it worked before but it went back to giving the same error before, maybe a race condition?

Thanks Patrick, I doubled checked I was registering the state event before opening and indeed I am. Also, the code pasted by mparadis has the same behaviour.

I tested with a VoltageInput, and I get the following values (or similar), I think they are correct:
When nothing is in the sensor:
Voltage: 0.16006
Voltage: 0.16052
Voltage: 0.16098
When an object is in the sensor:
Voltage: 4.86435
Voltage: 4.8735
Voltage: 4.879

I'm running the exact code you pasted here, mparadis. Just to be 100% clear, what I'm expecting is to run the code and immediately have one output such as State: true/false, depending on the state.

What I get instead is no output at all, until I put an object in the sensor. Additionally, if I try to call getState after opening, I get the error 'Unknown or invalid value' as explained before.

Is this correct? What else can I try?? Thanks a lot to both of you for trying to help me out.

Re: Unhandled Promise Rejection

Posted: Thu Aug 19, 2021 11:20 am
by Patrick
Can you make sure that the HUB5000 is on the latest firmware?

-Patrick

Re: Unhandled Promise Rejection

Posted: Tue Aug 24, 2021 7:42 am
by superninja
Yes, I upgraded it as indicated previously by mparadis.
Firmware Version 1.0.53

I really don't understand why I'm getting different results than both of you :(