Page 1 of 1

New Parameter for Connect and Open

Posted: Mon Aug 15, 2022 2:35 pm
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);
}

Re: New Parameter for Connect and Open

Posted: Tue Aug 16, 2022 7:20 am
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.

Re: New Parameter for Connect and Open

Posted: Fri Aug 19, 2022 11:24 am
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

Re: New Parameter for Connect and Open

Posted: Sat Aug 20, 2022 7:15 pm
by cvboucher
Thanks for the feedback. I have it working now.