-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto-reconnecting guidance needed #156
Comments
https://github.com/GoogleChromeLabs/serial-terminal/blob/main/src/index.ts#L378 shows you how https://github.com/googlechromelabs/serial-terminal/ handles it. Note that you don't need - port = await event.target || event.port;
+ port = event.target || event.port; Can I try out your code somewhere? |
Thanks for such a quick reply @beaufortfrancois Here is what I'm working on a demo: https://github.com/devATdbsutdio/webserial_time_resetter/blob/main/public/src/serialManager.js
Some insights would be really helpful 🙏🏽 |
As written your code should work. I'm thinking the issue might be that trying to open the port as soon as it is detected is causing a race with another application on the system that probes serial ports or the operating system isn't actually quite ready for an application to try opening the port even though it's already delivered the notification that the port is available. If you add a small delay does that fix the problem? What operating system are you using? Note, checking |
@reillyeon Adding delays helped, so guessing it was the actual availability and race condition situation. BTW how do we avoid 2 times firing, gracefully, of those connect and disconnect events? |
Delay(s) helped there but I wonder if we can make it better in Chromium. |
@beaufortfrancois I was thinking the same (But didn't get time today to try). Will try it tomorrow. Something like this may be 🤔 : while (true){
try {
await port.open({ baudRate: baudrate});
if (port) break;
} catch(err){
// log ...
}
} |
Can you check about://device-log to see if the error from the operating system is really "device busy"? It would also be good to understand what other application on the system might be trying to communicate with the device as that could cause other problems if it puts the device in a weird state. I'm hesitant to hide the problem with a workaround in Chrome. |
So when I ran: var a = performance.now();
while (true){
try {
await port.open({ baudRate: baudrate});
if (port) break;
} catch(err){
// log ...
}
}
var b = performance.now();
if (port.writable && port.readable) serialConnected = true;
console.log('Serial Port is available again and re-connected & it took:' + (b - a)/1000 + 's approximately'); It took: 1sec or 1009 ms So. @reillyeon when I looked into the device log, on auto re-connect attempt, I saw the Error: Does it mean device busy err? Also I saw an interesting Phenomenon in macOS (my machine) and my Serial device is FTDI based:As we know, macOS already comes with FTDI drivers but I also have the VCP drivers from FTDI installed in my machine.
|
@reillyeon @beaufortfrancois would be nice to have an example in your guide that illustrates (with how and why):
|
FILE_ERROR_IN_USE means the device is busy. The behavior between the VCP driver and built-in driver makes it sound like at some point you granted your site access to both versions of the device. If you click the lock icon, clear all the serial port permissions for the site and only grant it permission using one of the two drivers does that improve the behavior? |
Hello @ALL I made a design choice in my software: It doesn't reconnect again automatically. The user has to manually reconnect the device if he/she disconnected the physical device accidentally. So basically I'm using this call back below to remove the serial object: navigator.serial.addEventListener("disconnect", (event) => {
// TODO: Remove |event.target| from the UI.
// If the serial port was opened, a stream error would be observed as well.
}); And nothing else. |
Right now it's not actually possible to properly implement example 3 from your comment above because when a port is reconnected there's no identifier for recognizing it as the device that was connected recently rather than another device that the site has permission to access. This will be solved by #128. |
I'm having a similar on macOS (Apple Silicon). The disconnect event fires just fine, but the connection event doesn't fire at all for any serial connections. Disconnect removes the paired device from the list of authorized/paired devices. Anytime I disconnect, I need to request device access again. |
As one might have guessed, it is not a bug report and an issue.
So I was looking into:
My intention:
1. what do you mean by Remove
event.target
...? I have just set my serial port object tonull
;2. What else is needed here to handle?
1. The intention is that the old serial port object shall now not remain null anymore.
2. And should open again.
So this is what I was doing:
But when I physically disconnect and reconnect back, I get:
DOMException: Failed to open serial port.
But the Serial port is not null (I checked).
I would highly appreciate if you guys can fill this section again in : https://web.dev/serial/ and the Explainer
Meanwhile it would be very kind and helpful, if someone can show me how this part should be properly handled.
Something to do with
bubbles
?Also these events are always firing twice !🤔
The text was updated successfully, but these errors were encountered: