-
-
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
Close and Disconnect events doesn't work properly #458
Comments
The unplug shows up with:
It will say: "Type error: undefined is not a function". How to use this to try to reconnect I'm not sure. I've been struggling with how to gracefully disconnect and reconnect ports without having to restart the whole node program and I'm not doing well. |
I've never been able to get
to fire no matter what happens. If this would fire when a port is disconnected then it would help to know what to do next. |
Thanks for your reply. Nothing, also with I have to develop an application where the users don't know nothing about the serial port and they have to connect and disconnect the device at random time and the App have to stay ON and always ready to listen a new device....but if I can not intercepet event I can't do that application. The unique solution could will be that user manage close connection manually on front end application...do u know what I mean? (sorry about my english) |
I need to do the same thing and I don't know how to do it either. |
windows 8.1 64bit I've got same issue with nw.js then i've found usb-detection, but it failed complie on windows. How to reconnect serial port without reload whole app? |
Are these all windows only? On Friday, February 13, 2015, crapthings notifications@github.com wrote:
Chris Williams @voodootikigod http://twitter.com/voodootikigod | GitHub Maker of Improbable Things: JSConf http://jsconf.com/ | RobotsConf |
The problem is on Windows 7 and Windows 8.1 for me. I've never tryed on linux |
My issue is with Windows 7. I'm going down the road of spawning a separate process for each serial port and when |
Having a similar issue with Ubuntu 14.04 A serial port (Prolific) connected over a USB port is taking data fine. Then when the USB cable is disconnected there is no error generated, data stops, and yet the other parts of the process keep working just fine. In this case the
that is thrown in the Windows 7 case is not thrown in Linux. So in the Linux case we could look for no data received in x seconds to indicate that the port is disconnected and raise a stink about it with the user. It would be nice if the registered p.on('error') function would be called as soon as the USB cable is pulled. Just plugging the cable back in does not restart the connection. Port Listing:
is able to see the port come and go so I guess we could just keep running the logging every second or two and when the port gets plugged back in then call for the reconnect. |
+1 for reconnect. |
+1 for a way to do this |
👍
|
I track to data event from the serial port and update variable if (Date.now() - lastDataTime > 1000) {
throw "Disconnect";
} It worked for me. |
I'm having the same issue too. On Windows, supplying options.disconnectedCallback to new SerialPort(...) is not called when the connection is interrupted. Also, on('close', ...) and on('disconnect', ...) are not called either. |
Can confirm as well. Wanted to around with Node.js and some basic serial port communication. I'm using the basic readdata example with a callback (setTimeout). If I set the timeout to 1000, I get about 2-3 responses before the port silently closes. If I set the timeout to 300, I might get more. Something is timing out, but there is no reporting, no errors, nothing that i can find to log out. Also -- I created a serialPort.on('close'...) to reopen the port, but this never gets fired. Here's the code: var com = require("serialport");
var serialPort = new com.SerialPort("COM23", {
baudrate: 9600,
parser: com.parsers.readline('>')
});
serialPort.on('open',function() {
console.log('Port open');
setTimeout(serialPort.write("C\r\n"), 300);
});
serialPort.on('data', function(data) {
console.log("Temp C: " , data);
setTimeout(serialPort.write("C\r\n"), 300);
});
// This 'close' never fires. just dies silently.
serialPort.on('close', function() {
console.log("it got closed...going to reopen");
serialPort = new com.SerialPort("COM23", {
baudrate: 9600,
parser: com.parsers.readline('>')
});
}) Here's the output:
I've tried different ways to set the timeouts, from external to the callback as well, but I get the same problem -- the port just closes. |
Disconnected happens in a few different places. We also don't emit the event if we provide a handler, nor do consistently call the disconnect logic. On top of that we remove all events if we're disconnected. Adding this to the backlog to clearly define in #702 |
Disconnect logic is still in a poor state but we've fixed a few crashes and places where errors were not being handled correctly. When it comes to disconnects windows will work a lot easier now in our latest beta and you should be getting your events. #733 Please try it out |
We're tracking the disconnect issues here #702 I think we've solved your other issues so I'm going to close this for now. Feel free to reopen. |
@humblewizard Having a similar issue with electron,are you fixed? |
When I gets unplugged a device, I cannot find a way to detect this. There is no automatic event...nothing! I know that it's an old bug (#393) but I've tryed with Windows 8.1 and Windows 7 and I've always had the same response namely no event. For example this code:
I try with node v0.10.26 and v0.12.0.
Anybody still have this problem on Windows?
thanks
The text was updated successfully, but these errors were encountered: