OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Use the <code>chrome.serial</code> API to read from and write to a device | 5 // Use the <code>chrome.serial</code> API to read from and write to a device |
6 // connected to a serial port. | 6 // connected to a serial port. |
7 namespace serial { | 7 namespace serial { |
8 | 8 |
9 dictionary DeviceInfo { | 9 dictionary DeviceInfo { |
10 // The device's system path. This should be passed as the <code>path</code> | 10 // The device's system path. This should be passed as the <code>path</code> |
11 // argument to <code>chrome.serial.open</code> in order to open this device. | 11 // argument to <code>chrome.serial.connect</code> in order to connect to |
| 12 // this device. |
12 DOMString path; | 13 DOMString path; |
13 }; | 14 }; |
14 | 15 |
15 callback GetDevicesCallback = void (DeviceInfo[] ports); | 16 callback GetDevicesCallback = void (DeviceInfo[] ports); |
16 | 17 |
17 enum DataBits { seven, eight }; | 18 enum DataBits { seven, eight }; |
18 enum ParityBit { no, odd, even }; | 19 enum ParityBit { no, odd, even }; |
19 enum StopBits { one, two }; | 20 enum StopBits { one, two }; |
20 | 21 |
21 dictionary ConnectionOptions { | 22 dictionary ConnectionOptions { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 // Defaults to 0. | 62 // Defaults to 0. |
62 long? receiveTimeout; | 63 long? receiveTimeout; |
63 | 64 |
64 // The maximum amount of time (in milliseconds) to wait for a | 65 // The maximum amount of time (in milliseconds) to wait for a |
65 // <code>send</code> operation to complete before calling the callback with | 66 // <code>send</code> operation to complete before calling the callback with |
66 // a "timeout" error. If zero, send timeout errors will not be triggered. | 67 // a "timeout" error. If zero, send timeout errors will not be triggered. |
67 // Defaults to 0. | 68 // Defaults to 0. |
68 long? sendTimeout; | 69 long? sendTimeout; |
69 }; | 70 }; |
70 | 71 |
71 // Result of the <code>open</code> method. | |
72 dictionary OpenInfo { | |
73 // The id of the opened connection. | |
74 long connectionId; | |
75 }; | |
76 | |
77 // Callback from the <code>open</code> method; | |
78 callback OpenCallback = void (OpenInfo openInfo); | |
79 | |
80 // Callback from the <code>update</code> method. | |
81 callback UpdateCallback = void (boolean result); | |
82 | |
83 // Returns true if operation was successful. | |
84 callback CloseCallback = void (boolean result); | |
85 | |
86 // Callback from the <code>setPaused</code> method. | |
87 callback SetPausedCallback = void (); | |
88 | |
89 // Result of the <code>getInfo</code> method. | 72 // Result of the <code>getInfo</code> method. |
90 dictionary ConnectionInfo { | 73 dictionary ConnectionInfo { |
91 // The id of the serial port connection. | 74 // The id of the serial port connection. |
92 long connectionId; | 75 long connectionId; |
93 | 76 |
94 // Flag indicating whether the connection is blocked from firing onReceive | 77 // Flag indicating whether the connection is blocked from firing onReceive |
95 // events. | 78 // events. |
96 boolean paused; | 79 boolean paused; |
97 | 80 |
98 // See <code>ConnectionOptions.persistent</code> | 81 // See <code>ConnectionOptions.persistent</code> |
(...skipping 26 matching lines...) Expand all Loading... |
125 | 108 |
126 // See <code>ConnectionOptions.stopBits</code>. This field may be omitted | 109 // See <code>ConnectionOptions.stopBits</code>. This field may be omitted |
127 // if an error occurred while querying the underlying device. | 110 // if an error occurred while querying the underlying device. |
128 StopBits? stopBits; | 111 StopBits? stopBits; |
129 | 112 |
130 // See <code>ConnectionOptions.ctsFlowControl</code>. This field may be | 113 // See <code>ConnectionOptions.ctsFlowControl</code>. This field may be |
131 // omitted if an error occurred while querying the underlying device. | 114 // omitted if an error occurred while querying the underlying device. |
132 boolean? ctsFlowControl; | 115 boolean? ctsFlowControl; |
133 }; | 116 }; |
134 | 117 |
| 118 // Callback from the <code>connect</code> method; |
| 119 callback ConnectCallback = void (ConnectionInfo connectionInfo); |
| 120 |
| 121 // Callback from the <code>update</code> method. |
| 122 callback UpdateCallback = void (boolean result); |
| 123 |
| 124 // Callback from the <code>disconnect</code> method. Returns true if the |
| 125 // operation was successful. |
| 126 callback DisconnectCallback = void (boolean result); |
| 127 |
| 128 // Callback from the <code>setPaused</code> method. |
| 129 callback SetPausedCallback = void (); |
| 130 |
| 131 // Callback from the <code>getInfo</code> method. |
135 callback GetInfoCallback = void (ConnectionInfo connectionInfo); | 132 callback GetInfoCallback = void (ConnectionInfo connectionInfo); |
136 | 133 |
| 134 // Callback from the <code>getConnections</code> method. |
137 callback GetConnectionsCallback = void (ConnectionInfo[] connectionInfos); | 135 callback GetConnectionsCallback = void (ConnectionInfo[] connectionInfos); |
138 | 136 |
139 enum SendError { | 137 enum SendError { |
140 // The connection was closed. | 138 // The connection was disconnected. |
141 closed, | 139 disconnected, |
142 | 140 |
143 // A send was already pending. | 141 // A send was already pending. |
144 pending, | 142 pending, |
145 | 143 |
146 // The send timed out. | 144 // The send timed out. |
147 timeout, | 145 timeout, |
148 | 146 |
149 // A system error occurred and the connection may be unrecoverable. | 147 // A system error occurred and the connection may be unrecoverable. |
150 system_error | 148 system_error |
151 }; | 149 }; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 // Data from an <code>onReceive</code> event. | 192 // Data from an <code>onReceive</code> event. |
195 dictionary ReceiveInfo { | 193 dictionary ReceiveInfo { |
196 // The connection identifier. | 194 // The connection identifier. |
197 long connectionId; | 195 long connectionId; |
198 | 196 |
199 // The data received. | 197 // The data received. |
200 ArrayBuffer data; | 198 ArrayBuffer data; |
201 }; | 199 }; |
202 | 200 |
203 enum ReceiveError { | 201 enum ReceiveError { |
204 // The connection was closed. | 202 // The connection was disconnected. |
205 closed, | 203 disconnected, |
206 | 204 |
207 // No data has been received for <code>receiveTimeout</code> milliseconds. | 205 // No data has been received for <code>receiveTimeout</code> milliseconds. |
208 timeout, | 206 timeout, |
209 | 207 |
210 // The device was most likely disconnected from the host. | 208 // The device was most likely disconnected from the host. |
211 device_lost, | 209 device_lost, |
212 | 210 |
213 // A system error occurred and the connection may be unrecoverable. | 211 // A system error occurred and the connection may be unrecoverable. |
214 system_error | 212 system_error |
215 }; | 213 }; |
216 | 214 |
217 // Data from an <code>onReceiveError</code> event. | 215 // Data from an <code>onReceiveError</code> event. |
218 dictionary ReceiveErrorInfo { | 216 dictionary ReceiveErrorInfo { |
219 // The connection identifier. | 217 // The connection identifier. |
220 long connectionId; | 218 long connectionId; |
221 | 219 |
222 // An error code indicating what went wrong. | 220 // An error code indicating what went wrong. |
223 ReceiveError error; | 221 ReceiveError error; |
224 }; | 222 }; |
225 | 223 |
226 interface Functions { | 224 interface Functions { |
227 // Returns information about available serial devices on the system. | 225 // Returns information about available serial devices on the system. |
228 // The list is regenerated each time this method is called. | 226 // The list is regenerated each time this method is called. |
229 // |callback| : Called with the list of <code>DeviceInfo</code> objects. | 227 // |callback| : Called with the list of <code>DeviceInfo</code> objects. |
230 static void getDevices(GetDevicesCallback callback); | 228 static void getDevices(GetDevicesCallback callback); |
231 | 229 |
232 // Opens a connection to the given serial port. | 230 // Connects to a given serial port. |
233 // |path| : The system path of the serial port to open. | 231 // |path| : The system path of the serial port to open. |
234 // |options| : Port configuration options. | 232 // |options| : Port configuration options. |
235 // |callback| : Called when the connection has been opened. | 233 // |callback| : Called when the connection has been opened. |
236 static void open(DOMString path, | 234 static void connect(DOMString path, |
237 optional ConnectionOptions options, | 235 optional ConnectionOptions options, |
238 OpenCallback callback); | 236 ConnectCallback callback); |
239 | 237 |
240 // Update the option settings on an open serial port. | 238 // Update the option settings on an open serial port connection. |
241 // |connectionId| : The id of the opened connection. | 239 // |connectionId| : The id of the opened connection. |
242 // |options| : Port configuration options. | 240 // |options| : Port configuration options. |
243 // |callback| : Called when the configuation has completed. | 241 // |callback| : Called when the configuation has completed. |
244 static void update(long connectionId, | 242 static void update(long connectionId, |
245 ConnectionOptions options, | 243 ConnectionOptions options, |
246 UpdateCallback callback); | 244 UpdateCallback callback); |
247 | 245 |
248 // Closes an open connection. | 246 // Disconnects from a serial port. |
249 // |connectionId| : The id of the opened connection. | 247 // |connectionId| : The id of the opened connection. |
250 // |callback| : Called when the connection has been closed. | 248 // |callback| : Called when the connection has been closed. |
251 static void close(long connectionId, CloseCallback callback); | 249 static void disconnect(long connectionId, DisconnectCallback callback); |
252 | 250 |
253 // Pauses or unpauses an open connection. | 251 // Pauses or unpauses an open connection. |
254 // |connectionId| : The id of the opened connection. | 252 // |connectionId| : The id of the opened connection. |
255 // |paused| : Flag to indicate whether to pause or unpause. | 253 // |paused| : Flag to indicate whether to pause or unpause. |
256 // |callback| : Called when the connection has been successfully paused or | 254 // |callback| : Called when the connection has been successfully paused or |
257 // unpaused. | 255 // unpaused. |
258 static void setPaused(long connectionId, | 256 static void setPaused(long connectionId, |
259 boolean paused, | 257 boolean paused, |
260 SetPausedCallback callback); | 258 SetPausedCallback callback); |
261 | 259 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 ControlSignals signals, | 291 ControlSignals signals, |
294 SetControlSignalsCallback callback); | 292 SetControlSignalsCallback callback); |
295 }; | 293 }; |
296 | 294 |
297 interface Events { | 295 interface Events { |
298 // Event raised when data has been read from the connection. | 296 // Event raised when data has been read from the connection. |
299 // |info| : Event data. | 297 // |info| : Event data. |
300 static void onReceive(ReceiveInfo info); | 298 static void onReceive(ReceiveInfo info); |
301 | 299 |
302 // Event raised when an error occurred while the runtime was waiting for | 300 // Event raised when an error occurred while the runtime was waiting for |
303 // data on the serial port. Once this event is raised, the connection is set | 301 // data on the serial port. Once this event is raised, the connection may be |
304 // to <code>paused</code>. | 302 // set to <code>paused</code>. A <code>"timeout"</code> error does not pause |
| 303 // the connection. |
305 static void onReceiveError(ReceiveErrorInfo info); | 304 static void onReceiveError(ReceiveErrorInfo info); |
306 }; | 305 }; |
307 }; | 306 }; |
OLD | NEW |