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
3 // found in the LICENSE file.
5 // Use the <code>chrome.serial</code> API to read from and write to a device
6 // connected to a serial port.
9 callback GetPortsCallback = void (DOMString[] ports);
11 enum DataBit { sevenbit, eightbit };
12 enum ParityBit { noparity, oddparity, evenparity };
13 enum StopBit { onestopbit, twostopbit };
15 dictionary OpenOptions {
16 // The requested bitrate of the connection to be opened. For compatibility
17 // with the widest range of hardware, this number should match one of
18 // commonly-available bitrates, such as 110, 300, 1200, 2400, 4800, 9600,
19 // 14400, 19200, 38400, 57600, 115200. There is no guarantee, of course,
20 // that the device connected to the serial port will support the requested
21 // bitrate, even if the port itself supports that bitrate. <code>9600</code>
22 // will be passed by default.
24 // <code>"eightbit"</code> will be passed by default.
26 // <code>"noparity"</code> will be passed by default.
28 // <code>"onestopbit"</code> will be passed by default.
33 // The id of the opened connection.
37 callback OpenCallback = void (OpenInfo openInfo);
39 // Returns true if operation was successful.
40 callback CloseCallback = void (boolean result);
43 // The number of bytes received, or a negative number if an error occurred.
44 // This number will be smaller than the number of bytes requested in the
45 // original read call if the call would need to block to read that number
53 callback ReadCallback = void (ReadInfo readInfo);
55 dictionary WriteInfo {
56 // The number of bytes written.
60 callback WriteCallback = void (WriteInfo writeInfo);
62 // Returns true if operation was successful.
63 callback FlushCallback = void (boolean result);
65 // Boolean true = mark signal (negative serial voltage).
66 // Boolean false = space signal (positive serial voltage).
68 // For SetControlSignals, include the sendable signals that you wish to
69 // change. Signals not included in the dictionary will be left unchanged.
71 // GetControlSignals includes all receivable signals.
72 dictionary ControlSignalOptions {
73 // Serial control signals that your machine can send. Missing fields will
78 // Serial control signals that your machine can receive. If a get operation
79 // fails, success will be false, and these fields will be absent.
81 // DCD (Data Carrier Detect) is equivalent to RLSD (Receive Line Signal
82 // Detect) on some platforms.
87 // Returns a snapshot of current control signals.
88 callback GetControlSignalsCallback = void (ControlSignalOptions options);
90 // Returns true if operation was successful.
91 callback SetControlSignalsCallback = void (boolean result);
94 // Returns names of valid ports on this machine, each of which is likely to
95 // be valid to pass as the port argument to open(). The list is regenerated
96 // each time this method is called, as port validity is dynamic.
98 // |callback| : Called with the list of ports.
99 static void getPorts(GetPortsCallback callback);
101 // Opens a connection to the given serial port.
102 // |port| : The name of the serial port to open.
103 // |options| : Connection options.
104 // |callback| : Called when the connection has been opened.
105 static void open(DOMString port,
106 optional OpenOptions options,
107 OpenCallback callback);
109 // Closes an open connection.
110 // |connectionId| : The id of the opened connection.
111 // |callback| : Called when the connection has been closed.
112 static void close(long connectionId,
113 CloseCallback callback);
115 // Reads a byte from the given connection.
116 // |connectionId| : The id of the connection.
117 // |bytesToRead| : The number of bytes to read.
118 // |callback| : Called when all the requested bytes have been read or
119 // when the read blocks.
120 static void read(long connectionId,
122 ReadCallback callback);
124 // Writes a string to the given connection.
125 // |connectionId| : The id of the connection.
126 // |data| : The string to write.
127 // |callback| : Called when the string has been written.
128 static void write(long connectionId,
130 WriteCallback callback);
132 // Flushes all bytes in the given connection's input and output buffers.
133 // |connectionId| : The id of the connection.
134 // |callback| : Called when the flush is complete.
135 static void flush(long connectionId,
136 FlushCallback callback);
138 static void getControlSignals(long connectionId,
139 GetControlSignalsCallback callback);
141 static void setControlSignals(long connectionId,
142 ControlSignalOptions options,
143 SetControlSignalsCallback callback);