| OLD | NEW |
| (Empty) | |
| 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. |
| 4 |
| 5 namespace serial { |
| 6 |
| 7 callback GetPortsCallback = void (DOMString[] ports); |
| 8 |
| 9 dictionary OpenOptions { |
| 10 // The requested bitrate of the connection to be opened. For compatibility |
| 11 // with the widest range of hardware, this number should match one of |
| 12 // commonly-available bitrates, such as 110, 300, 1200, 2400, 4800, 9600, |
| 13 // 14400, 19200, 38400, 57600, 115200. There is no guarantee, of course, |
| 14 // that the device connected to the serial port will support the requested |
| 15 // bitrate, even if the port itself supports that bitrate. |
| 16 long bitrate; |
| 17 }; |
| 18 |
| 19 dictionary OpenInfo { |
| 20 // The id of the opened connection. |
| 21 long connectionId; |
| 22 }; |
| 23 |
| 24 callback OpenCallback = void (OpenInfo openInfo); |
| 25 |
| 26 // Returns true if operation was successful. |
| 27 callback CloseCallback = void (boolean result); |
| 28 |
| 29 dictionary ReadInfo { |
| 30 // The number of bytes received, or a negative number if an error occurred. |
| 31 // This number will be smaller than the number of bytes requested in the |
| 32 // original read call if the call would need to block to read that number |
| 33 // of bytes. |
| 34 long bytesRead; |
| 35 |
| 36 // The data received. |
| 37 ArrayBuffer data; |
| 38 }; |
| 39 |
| 40 callback ReadCallback = void (ReadInfo readInfo); |
| 41 |
| 42 dictionary WriteInfo { |
| 43 // The number of bytes written. |
| 44 long bytesWritten; |
| 45 }; |
| 46 |
| 47 callback WriteCallback = void (WriteInfo writeInfo); |
| 48 |
| 49 // Returns true if operation was successful. |
| 50 callback FlushCallback = void (boolean result); |
| 51 |
| 52 // Boolean true = mark signal (negative serial voltage). |
| 53 // Boolean false = space signal (positive serial voltage). |
| 54 // |
| 55 // For SetControlSignals, include the sendable signals that you wish to |
| 56 // change. Signals not included in the dictionary will be left unchanged. |
| 57 // |
| 58 // GetControlSignals includes all receivable signals. |
| 59 dictionary ControlSignalOptions { |
| 60 // Serial control signals that your machine can send. Missing fields will |
| 61 // be set to false. |
| 62 boolean? dtr; |
| 63 boolean? rts; |
| 64 |
| 65 // Serial control signals that your machine can receive. If a get operation |
| 66 // fails, success will be false, and these fields will be absent. |
| 67 // |
| 68 // DCD (Data Carrier Detect) is equivalent to RLSD (Receive Line Signal |
| 69 // Detect) on some platforms. |
| 70 boolean? dcd; |
| 71 boolean? cts; |
| 72 }; |
| 73 |
| 74 // Returns a snapshot of current control signals. |
| 75 callback GetControlSignalsCallback = void (ControlSignalOptions options); |
| 76 |
| 77 // Returns true if operation was successful. |
| 78 callback SetControlSignalsCallback = void (boolean result); |
| 79 |
| 80 interface Functions { |
| 81 // Returns names of valid ports on this machine, each of which is likely to |
| 82 // be valid to pass as the port argument to open(). The list is regenerated |
| 83 // each time this method is called, as port validity is dynamic. |
| 84 // |
| 85 // |callback| : Called with the list of ports. |
| 86 static void getPorts(GetPortsCallback callback); |
| 87 |
| 88 // Opens a connection to the given serial port. |
| 89 // |port| : The name of the serial port to open. |
| 90 // |options| : Connection options. |
| 91 // |callback| : Called when the connection has been opened. |
| 92 static void open(DOMString port, |
| 93 optional OpenOptions options, |
| 94 OpenCallback callback); |
| 95 |
| 96 // Closes an open connection. |
| 97 // |connectionId| : The id of the opened connection. |
| 98 // |callback| : Called when the connection has been closed. |
| 99 static void close(long connectionId, |
| 100 CloseCallback callback); |
| 101 |
| 102 // Reads a byte from the given connection. |
| 103 // |connectionId| : The id of the connection. |
| 104 // |bytesToRead| : The number of bytes to read. |
| 105 // |callback| : Called when all the requested bytes have been read or |
| 106 // when the read blocks. |
| 107 static void read(long connectionId, |
| 108 long bytesToRead, |
| 109 ReadCallback callback); |
| 110 |
| 111 // Writes a string to the given connection. |
| 112 // |connectionId| : The id of the connection. |
| 113 // |data| : The string to write. |
| 114 // |callback| : Called when the string has been written. |
| 115 static void write(long connectionId, |
| 116 ArrayBuffer data, |
| 117 WriteCallback callback); |
| 118 |
| 119 // Flushes all bytes in the given connection's input and output buffers. |
| 120 // |connectionId| : The id of the connection. |
| 121 // |callback| : Called when the flush is complete. |
| 122 static void flush(long connectionId, |
| 123 FlushCallback callback); |
| 124 |
| 125 static void getControlSignals(long connectionId, |
| 126 GetControlSignalsCallback callback); |
| 127 |
| 128 static void setControlSignals(long connectionId, |
| 129 ControlSignalOptions options, |
| 130 SetControlSignalsCallback callback); |
| 131 }; |
| 132 |
| 133 }; |
| OLD | NEW |