Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(443)

Side by Side Diff: chrome/common/extensions/docs/templates/articles/app_serial.html

Issue 177113013: Bluetooth: add Device events, and cleanup JS API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@arman-patch
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <h1>Serial Devices</h1> 1 <h1>Serial Devices</h1>
2 2
3 <p> 3 <p>
4 </p> 4 </p>
5 5
6 <p> 6 <p>
7 This document describes how to use the <a href="serial.html">serial API</a> to r ead 7 This document describes how to use the <a href="serial.html">serial API</a> to r ead
8 and write from serial devices. Chrome Apps can also connect to 8 and write from serial devices. Chrome Apps can also connect to
9 <a href="app_usb.html">USB</a> and <a href="bluetooth.html">Bluetooth</a> device s. 9 <a href="app_usb.html">USB</a> and <a href="app_bluetooth.html">Bluetooth</a> de vices.
10 </p> 10 </p>
11 11
12 <p class="note"> 12 <p class="note">
13 <b>Samples:</b> For examples that illustrate how Chrome Apps can connect to hard ware devices through a serial port, see the 13 <b>Samples:</b> For examples that illustrate how Chrome Apps can connect to hard ware devices through a serial port, see the
14 <a href="https://github.com/GoogleChrome/chrome-app-samples/tree/master/serial/a dkjs#readme">adkjs</a>, 14 <a href="https://github.com/GoogleChrome/chrome-app-samples/tree/master/serial/a dkjs#readme">adkjs</a>,
15 <a href="https://github.com/GoogleChrome/chrome-app-samples/tree/master/serial/l edtoggle#readme">ledtoggle</a> and the 15 <a href="https://github.com/GoogleChrome/chrome-app-samples/tree/master/serial/l edtoggle#readme">ledtoggle</a> and the
16 <a href="https://github.com/GoogleChrome/chrome-app-samples/tree/master/servo#re adme">servo</a> samples. 16 <a href="https://github.com/GoogleChrome/chrome-app-samples/tree/master/servo#re adme">servo</a> samples.
17 </p> 17 </p>
18 18
19 <h2 id="requirement">Manifest requirement</h2> 19 <h2 id="requirement">Manifest requirement</h2>
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 _this.connectionId = connectionInfo.connectionId; 81 _this.connectionId = connectionInfo.connectionId;
82 // Do whatever you need to do with the opened port. 82 // Do whatever you need to do with the opened port.
83 } 83 }
84 // Connect to the serial port /dev/ttyS01 84 // Connect to the serial port /dev/ttyS01
85 chrome.serial.connect("/dev/ttyS01", {bitrate: 115200}, onConnect); 85 chrome.serial.connect("/dev/ttyS01", {bitrate: 115200}, onConnect);
86 </pre> 86 </pre>
87 87
88 <h2 id="disconnect">Disconnect from a serial port</h2> 88 <h2 id="disconnect">Disconnect from a serial port</h2>
89 89
90 <p> 90 <p>
91 When an app terminates, connections to serial ports that are not persistent 91 When an app terminates, connections to serial ports that are not persistent
92 are automatically closed by the platform. However, if you want to disconnect 92 are automatically closed by the platform. However, if you want to disconnect
93 while your app is still running, you can use the $ref:serial.disconnect method: 93 while your app is still running, you can use the $ref:serial.disconnect method:
94 </p> 94 </p>
95 95
96 <pre> 96 <pre>
97 var onDisconnect = function(result) { 97 var onDisconnect = function(result) {
98 if (result) { 98 if (result) {
99 console.log("Disconnected from the serial port"); 99 console.log("Disconnected from the serial port");
100 } else { 100 } else {
101 console.log("Disconnect failed"); 101 console.log("Disconnect failed");
102 } 102 }
103 } 103 }
104 chrome.serial.disconnect(connectionId, onDisconnect); 104 chrome.serial.disconnect(connectionId, onDisconnect);
105 </pre> 105 </pre>
106 106
107 <h2 id="reading">Reading from a serial port</h2> 107 <h2 id="reading">Reading from a serial port</h2>
108 108
109 <p> 109 <p>
110 The serial API reads from the serial port and delivers the read bytes as an Arra yBuffer to event listeners. 110 The serial API reads from the serial port and delivers the read bytes as an Arra yBuffer to event listeners.
111 111
112 Every port that your application is connected to will generate read events to al l listeners added through 112 Every port that your application is connected to will generate read events to al l listeners added through
113 <code>chrome.serial.onReceive.addListener(onReceiveCallback)</code>. If you are connected to more than one port at the 113 <code>chrome.serial.onReceive.addListener(onReceiveCallback)</code>. If you are connected to more than one port at the
114 same time, you may find the corresponding <code>connectionId</code> of an incomi ng read event in the callback parameter 114 same time, you may find the corresponding <code>connectionId</code> of an incomi ng read event in the callback parameter
115 of $ref:serial.onReceive. 115 of $ref:serial.onReceive.
116 </p> 116 </p>
117 <p> 117 <p>
118 The following example can accumulate read bytes until a new line is read, conver ting the received ArrayBuffer to String and 118 The following example can accumulate read bytes until a new line is read, conver ting the received ArrayBuffer to String and
119 calling a method when a newline is found as the last character received: 119 calling a method when a newline is found as the last character received:
120 </p> 120 </p>
121 121
122 <pre> 122 <pre>
123 var stringReceived = ''; 123 var stringReceived = '';
124 124
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 chrome.serial.flush(connectionId, onFlush); 175 chrome.serial.flush(connectionId, onFlush);
176 </pre> 176 </pre>
177 177
178 <h2 id="More">More</h2> 178 <h2 id="More">More</h2>
179 179
180 <p> 180 <p>
181 The Serial API has several other features. You can, for example, set a connectio n to persistent, so it can receive data 181 The Serial API has several other features. You can, for example, set a connectio n to persistent, so it can receive data
182 even when your app is not running, or you can update connection parameters on th e fly, like bitrate, timeouts, control signals, and many others 182 even when your app is not running, or you can update connection parameters on th e fly, like bitrate, timeouts, control signals, and many others
183 with the $ref:serial.update method. See the full reference of the $ref:serial A PI for more information. 183 with the $ref:serial.update method. See the full reference of the $ref:serial A PI for more information.
184 </p> 184 </p>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698