New Parameter for Connect and Open
Posted: Mon Aug 15, 2022 2:35 pm
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);
}