Skip to content
This repository

Everything must occur after on('open') #107

Merged
merged 1 commit into from over 1 year ago

3 participants

Ricky Ng-Adam Josh Chaney Chris Williams
Ricky Ng-Adam

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 README.md so here's an update.

Ricky Ng-Adam 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 README.md so here's an update.
94d34bc
Josh Chaney

+1 -- I thought I was going crazy, this fixed my problem. Thanks!

Chris Williams voodootikigod merged commit 7a79a94 into from December 23, 2012
Chris Williams voodootikigod closed this December 23, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Nov 08, 2012
Ricky Ng-Adam 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 README.md so here's an update.
94d34bc
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 21 additions and 0 deletions. Show diff stats Hide diff stats

  1. 21  README.md
21  README.md
Source Rendered
@@ -93,6 +93,27 @@ The options object allows you to pass named options to the serial port during in
93 93
 
94 94
 **Note, we have added support for either all lowercase OR camelcase of the options (thanks @jagautier), use whichever style you prefer.**
95 95
 
  96
+open event
  97
+----------
  98
+
  99
+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 
  100
+before the open event might result in... nothing at all.
  101
+
  102
+Assuming you are connected to a serial console, you would for example:
  103
+
  104
+<pre>
  105
+serialPort.on("open", function () {
  106
+  console.log('open');
  107
+  serialPort.on('data', function(data) {
  108
+    console.log('data received: ' + data);
  109
+  });  
  110
+  serialPort.write("ls\n", function(err, results) {
  111
+    console.log('err ' + err);
  112
+    console.log('results ' + results);
  113
+  });  
  114
+});
  115
+</pre>
  116
+
96 117
 List Ports
97 118
 ----------
98 119
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.