Browse files

Everything must occur after on('open')

I can't be the only one that made the newbie mistake of not registering a 
listener on open and ONLY when that is received start writing/listening for data. 

I can't see any mention of that in the main so here's an update.
  • Loading branch information...
rngadam committed Nov 7, 2012
1 parent ce51f4d commit 94d34bcc54f7946065fc13f5a70c1171f63d79e3
Showing with 21 additions and 0 deletions.
  1. +21 −0
@@ -93,6 +93,27 @@ The options object allows you to pass named options to the serial port during in
**Note, we have added support for either all lowercase OR camelcase of the options (thanks @jagautier), use whichever style you prefer.**
+open event
+You MUST wait for the open event to be emitted before reading/writing to the serial port. The open happens asynchronously so installing 'data' listeners and writing
+before the open event might result in... nothing at all.
+Assuming you are connected to a serial console, you would for example:
+serialPort.on("open", function () {
+ console.log('open');
+ serialPort.on('data', function(data) {
+ console.log('data received: ' + data);
+ });
+ serialPort.write("ls\n", function(err, results) {
+ console.log('err ' + err);
+ console.log('results ' + results);
+ });
List Ports

0 comments on commit 94d34bc

Please sign in to comment.