You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -493,7 +492,7 @@ The write operation is non-blocking. When it returns, data might still not have
493
492
494
493
Some devices, like the Arduino, reset when you open a connection to them. In such cases, immediately writing to the device will cause lost data as they wont be ready to receive the data. This is often worked around by having the Arduino send a "ready" byte that your Node program waits for before writing. You can also often get away with waiting around 400ms.
495
494
496
-
If a port is disconnected during a write, the write will error in addition to the disconnect event.
495
+
If a port is disconnected during a write, the write will error in addition to the `close` event.
497
496
498
497
Even though serialport is a stream, when writing it can accept arrays of bytes in addition to strings and buffers. This extra functionality is pretty sweet.
499
498
@@ -668,19 +667,10 @@ The `data` event puts the port in flowing mode. Data is emitted as soon as it's
The `disconnect` event's callback is called with an error object. This will always happen before a `close` event if a disconnection is detected. If a disconnect happens and there is no event handler for the disconnect event an error event will be emitted instead. The error will have the `disconnected` property set to `true`.
675
-
676
-
**Kind**: event emitted by [<code>SerialPort</code>](#exp_module_serialport--SerialPort)
The `close` event's callback is called with no arguments when the port is closed. In the event of an error, an error event is triggered.
673
+
The `close` event's callback is called with no arguments when the port is closed. In the case of a disconnect it will be called with a Disconnect Error object (`err.disconnected == true`). In the event of a close error (unlikely), an error event is triggered.
684
674
685
675
**Kind**: event emitted by [<code>SerialPort</code>](#exp_module_serialport--SerialPort)
Copy file name to clipboardExpand all lines: UPGRADE_GUIDE.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,8 @@ Upgrading from 4.x to 5.x
2
2
-------------
3
3
5.x is a major rewrite to make node serialport a NodeJS stream. While the api surface is similar there have been a number of changes to ensure more consistent error handling and operation of a serial port.
4
4
5
+
- Removed the `disconnect` event. The `close` event now fires with a disconnect error object in the event of a disconnection.
Copy file name to clipboardExpand all lines: lib/serialport.js
+8-19Lines changed: 8 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -95,7 +95,6 @@ function allocNewReadPool(poolSize) {
95
95
* @emits module:serialport#data
96
96
* @emits module:serialport#close
97
97
* @emits module:serialport#error
98
-
* @emits module:serialport#disconnect
99
98
* @alias module:serialport
100
99
*/
101
100
functionSerialPort(path,options,callback){
@@ -278,7 +277,7 @@ The write operation is non-blocking. When it returns, data might still not have
278
277
279
278
Some devices, like the Arduino, reset when you open a connection to them. In such cases, immediately writing to the device will cause lost data as they wont be ready to receive the data. This is often worked around by having the Arduino send a "ready" byte that your Node program waits for before writing. You can also often get away with waiting around 400ms.
280
279
281
-
If a port is disconnected during a write, the write will error in addition to the disconnect event.
280
+
If a port is disconnected during a write, the write will error in addition to the `close` event.
282
281
283
282
Even though serialport is a stream, when writing it can accept arrays of bytes in addition to strings and buffers. This extra functionality is pretty sweet.
* The `disconnect` event's callback is called with an error object. This will always happen before a `close` event if a disconnection is detected. If a disconnect happens and there is no event handler for the disconnect event an error event will be emitted instead. The error will have the `disconnected` property set to `true`.
384
-
* @event module:serialport#disconnect
385
-
*/
386
-
387
381
SerialPort.prototype._disconnected=function(err){
388
382
if(!this.isOpen){
389
383
debug('disconnected aborted because already closed',err);
390
384
return;
391
385
}
392
386
debug('disconnected',err);
393
387
err.disconnected=true;
394
-
395
-
if(this.listeners('disconnect').length>0){
396
-
this.emit('disconnect',err);
397
-
}else{
398
-
this.emit('error',err);
399
-
}
400
-
401
-
this.close();
388
+
this.close(null,err);
402
389
};
403
390
404
391
/**
405
-
* The `close` event's callback is called with no arguments when the port is closed. In the event of an error, an error event is triggered.
392
+
* The `close` event's callback is called with no arguments when the port is closed. In the case of a disconnect it will be called with a Disconnect Error object (`err.disconnected == true`). In the event of a close error (unlikely), an error event is triggered.
0 commit comments