-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
No close event emitted when a device is physically removed for an open port. #2043
Comments
Same problem on Windows 10 |
I can confirm the issue on macOS v10.15.1 |
I have the same issue. Platform: MacOS v10.15.2 Close event is not being triggered. |
We are periodically checking the status of the device with get as a work around for this issue. But this API behaves differently on different platforms:
|
For me the close event still fires on However it was very tricky to downgrade because npm kept installing 8.0.7, ignoring the lower version. In the end I pasted the |
See serialport/node-serialport#2043 No close event is emitted when physically removing the serial device.
It seems like responsibilities shifted around between versions and I don't fully follow that, so I can't propose a fix. Perhaps what I did find will help with fixing. when you unplug the cable, this code (in stream):
https://github.com/serialport/node-serialport/blob/master/packages/stream/lib/index.js#L388-L391
Note: it is also set in 2 other places above that, likely each needs to be double-checked. I also found this comment that relates (in binding-abstract)
...there is a similar comment for write. Perhaps that comment could be clarified once someone wraps their head around this. |
The issue persists in the latest version for me: Platform: MacOS v10.15.4 Close event is not being triggered after physical disconnect |
I tried the version |
I'm trying to downgrade to version
Any ideas on how to fix this? Platform: MacOS v10.15.4 |
Maybe downgrade your node version? Why are you downloading?
On Wed, Jun 10, 2020 at 8:54 AM Sebastian ***@***.***> wrote:
I'm trying to downgrade to version 7.1.5 which worked for me in the past,
but unfortunately I run into this error now:
> prebuild-install --tag-prefix @serialport/bindings@ || node-gyp rebuild
CXX(target) Release/obj.target/bindings/src/serialport.o
errorOut=prebuild-install WARN install No prebuilt binaries found (target=8.2.4 runtime=electron arch=x64 libc= platform=darwin)
../src/serialport.cpp:329:14: error: no matching member function for call to 'Set'
results->Set(Nan::New<v8::String>("cts").ToLocalChecked(), Nan::New<v8::Boolean>(data->cts));
~~~~~~~~~^~~
/Users/kuhlgert/.electron-gyp/8.2.4/include/node/v8.h:3611:37: note: candidate function not viable: requires 3 arguments, but 2 were provided
V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
^
/Users/kuhlgert/.electron-gyp/8.2.4/include/node/v8.h:3614:37: note: candidate function not viable: requires 3 arguments, but 2 were provided
V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
^
../src/serialport.cpp:330:14: error: no matching member function for call to 'Set'
results->Set(Nan::New<v8::String>("dsr").ToLocalChecked(), Nan::New<v8::Boolean>(data->dsr));
~~~~~~~~~^~~
/Users/kuhlgert/.electron-gyp/8.2.4/include/node/v8.h:3611:37: note: candidate function not viable: requires 3 arguments, but 2 were provided
V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
^
/Users/kuhlgert/.electron-gyp/8.2.4/include/node/v8.h:3614:37: note: candidate function not viable: requires 3 arguments, but 2 were provided
V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
^
../src/serialport.cpp:331:14: error: no matching member function for call to 'Set'
results->Set(Nan::New<v8::String>("dcd").ToLocalChecked(), Nan::New<v8::Boolean>(data->dcd));
~~~~~~~~~^~~
/Users/[username]/.electron-gyp/8.2.4/include/node/v8.h:3611:37: note: candidate function not viable: requires 3 arguments, but 2 were provided
V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
^
/Users/[username]/.electron-gyp/8.2.4/include/node/v8.h:3614:37: note: candidate function not viable: requires 3 arguments, but 2 were provided
V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
^
../src/serialport.cpp:378:14: error: no matching member function for call to 'Set'
results->Set(Nan::New<v8::String>("baudRate").ToLocalChecked(), Nan::New<v8::Integer>(data->baudRate));
~~~~~~~~~^~~
/Users/[username]/.electron-gyp/8.2.4/include/node/v8.h:3611:37: note: candidate function not viable: requires 3 arguments, but 2 were provided
V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
^
/Users/[username]/.electron-gyp/8.2.4/include/node/v8.h:3614:37: note: candidate function not viable: requires 3 arguments, but 2 were provided
V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
^
4 errors generated.
Any ideas on how to fix this?
Platform: MacOS v10.15.4
Electron: 8.2.4
Node version: 12.13.0
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2043 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAGK3SSOUCY55KS6J6H5HDRV57BRANCNFSM4LBI4EOA>
.
--
---
Francis Gulotta
[email protected]
|
I can also confirm that this occurs on the new version 9.0.0 (running on MacOS 10.15.2). |
I will try to downgrade node and see if that works. I can't download the prebuild libraries, so I would have to rebuild them and it seems that process is failing. Proper install only works for releases of serialport version 8.x and up |
I finally find some time to get working on the issue. Any particular node version you would recommend using @reconbot ? |
I’ve looked into this a bit more. On Windows the problem does not occur. I was trying to look into the code a bit and do some testing, I’m not totally sure but it seems like the Poller binding is not receiving any disconnect event. |
I think I have tracked down the problem. First, it seems that physically disconnecting something triggers a read. It doesn't trigger a disconnect at the low level code in
if (disconnectError) {
- err.disconnect = true
+ err.canceled = true
logger('disconnecting', err)
} With this, the disconnect function won't get called in node-serialport/packages/stream/lib/index.js Lines 387 to 393 in 45f83ab
And from what I can tell, it just gets stuck in an (asynchronous) loop and does nothing until you try to write, at which point the disconnect function is called and the closed event is emitted.
I tried just changing In
So this clearly was added on purpose, but since physical disconnects trigger in progress reads, I'm not sure what should be changed to maintain the current desired behavior (actual in progress reads erring with canceled equal to true), while adding the disconnect event for disconnects. @reconbot, thoughts on this? |
Same issue with 9.0.0 — node v10.17.0 and macOS 10.15.5 |
Same here with version 9.0.0 and node v13.12.0 and macOS 10.13.6. |
@reconbot Have you had a chance to look into this. If you have any suggestions I'd be happy to make a pull request. |
This was an oversight on the refactor. I've changed the code back per @dunkmann00. The test was also wrong. |
Thanks @reconbot! |
I published |
Working great, thanks again for fixing this! |
Issue is still present on here's my log
and the code (tested on Node.js 16.18.0 and 18.12.0, Windows 10, Windows 11) const { SerialPort } = require('serialport');
const config = {
pnpId: 'USB\\VID_067B&PID_2303\\11111111',
baudRate: 9600,
dataBits: 8,
stopBits: 1,
parity: 'none',
};
const path = 'COM3';
const port = new SerialPort({ ...config, path });
const log = (...msgs) => {
console.log(new Date().toISOString(), ...msgs);
};
port.on('open', () => {
log(`connected at ${path}, pnpId ${config.pnpId}`);
});
port.on('close', (disconnectError) => {
log(`\tPort ${path} closed`, disconnectError);
});
setInterval(() => {
if (port.isOpen) {
log('port.isOpen ===', port.isOpen, 'Manually calling port.read():', port.read());
} else {
log('port.isOpen ===', port.isOpen);
}
}, 1000); my setup
Hope this helps somebody. |
Same issue with Linux and node20 and SerialPort v12. Close never occured when disconnected physically. I need to call a write operation to affect closed. |
Summary of Problem
(Please answer all 3)
What are you trying to do?
Detect when a device is physically disconnected from the usb-port.
What happens?
When a physical device is unplugged there's no close event emitted with [email protected] (tested with all versions between 8.0.1 to 8.0.7)
Doing the same thing with [email protected] it works fine.
Output from the provided code below:
Test with node v13.9.0 and node [email protected]
Same code and a test with node v12.6.0 and node [email protected]
The close event shall be emitted when the physical device is disconnected, without delay and without the need to write to the port. It's no longer visible in the system, verified with ls -l /dev/tty.*
It shall work like it did in node [email protected].
Code to Reproduce the Issue
Versions, Operating System and Hardware
[email protected]
Node.js v13.9.0
Mac OS X 10.15.3
MacBook Pro 13
The text was updated successfully, but these errors were encountered: