New Parameter for Connect and Open

Comments & issues
Post Reply
cvboucher
Phidgetsian
Posts: 13
Joined: Fri Oct 22, 2021 11:29 am
Contact:

New Parameter for Connect and Open

Post by cvboucher »

I'm working with a VINT hub and digital inputs (DAQ1301) with the JavaScript library (Blazor Webassembly). I'm using the NetworkConnection and DigitalInput classes. If the Network Server or digital input isn't available when my app starts, the call to connect and/or open fails but it doesn't keep trying. So I have to add logic in my JavaScript wrapper to keep trying. It would be nice to pass something like -1 to connect and open, and it would keep trying like it does if they become disconnected after connecting. Below is my workaround. Or is there a better way?

Code: Select all

var self = this;
try {
	var connected = false;
	while (connected == false) {
		await this.instance.connect()
			.then(function () {
				connected = true;
			}, async function (err) {
				var thisErr = `${err}`;
				await self.dotNetReference.invokeMethodAsync("OnError", thisErr);
				await new Promise(r => setTimeout(r, 5000));
			});
	}
} catch (ex) {
	var thisErr = `${ex}`;
	await self.dotNetReference.invokeMethodAsync("OnError", thisErr);
}

Code: Select all

var self = this;
try {
	var connected = false;
	while (connected == false) {
		await this.instance.open(phidget22.Phidget.DEFAULT_TIMEOUT)
			.then(function () {
				connected = true;
			}, async function (err) {
				var thisErr = `${err}`;
				await self.dotNetReference.invokeMethodAsync("OnError", thisErr);
				await new Promise(r => setTimeout(r, 5000));
			});
	}
} catch (ex) {
	var thisErr = `${ex}`;
	await self.dotNetReference.invokeMethodAsync("OnError", thisErr);
}
fraser
Engineering
Posts: 324
Joined: Thu Nov 19, 2009 4:41 pm
Contact:

Re: New Parameter for Connect and Open

Post by fraser »

open() can be called instead of open(phidget22.Phidget.DEFAULT_TIMEOUT), which will open it asynchronously. It will require attach events to know when it gets opened.
User avatar
Patrick
Lead Developer
Posts: 3403
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: New Parameter for Connect and Open

Post by Patrick »

This is a good point - there should be a way to call connect before the server is running. I'll have a look at how best to extend connect to support this - either as an option to connect(), or an entry in options to the constructor.

As for open - you just call it without the timeout to get this behaviour as Fraser said.

-Patrick
cvboucher
Phidgetsian
Posts: 13
Joined: Fri Oct 22, 2021 11:29 am
Contact:

Re: New Parameter for Connect and Open

Post by cvboucher »

Thanks for the feedback. I have it working now.
Post Reply

Who is online

Users browsing this forum: No registered users and 28 guests