Unhandled Promise Rejection

Supporting Browser-based Javascript and Node.js
superninja
Phidgetsian
Posts: 8
Joined: Tue Aug 10, 2021 4:00 pm
Contact:

Re: Unhandled Promise Rejection

Post by superninja »

the phidget22 libs version for nodejs is 2.7.4 (installed with npm install)
User avatar
mparadis
Site Admin
Posts: 660
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: Unhandled Promise Rejection

Post 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.
superninja
Phidgetsian
Posts: 8
Joined: Tue Aug 10, 2021 4:00 pm
Contact:

Re: Unhandled Promise Rejection

Post 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!
User avatar
Patrick
Lead Developer
Posts: 634
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Unhandled Promise Rejection

Post by Patrick »

Make sure you're registering for the state change event before calling open, or you'll miss an initial event.

-Patrick
superninja
Phidgetsian
Posts: 8
Joined: Tue Aug 10, 2021 4:00 pm
Contact:

Re: Unhandled Promise Rejection

Post 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.
User avatar
Patrick
Lead Developer
Posts: 634
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Unhandled Promise Rejection

Post by Patrick »

Can you make sure that the HUB5000 is on the latest firmware?

-Patrick
superninja
Phidgetsian
Posts: 8
Joined: Tue Aug 10, 2021 4:00 pm
Contact:

Re: Unhandled Promise Rejection

Post 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 :(
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests