3 The following shows uart module APIs available for each platform.
5 | | Linux<br/>(Ubuntu) | Raspbian<br/>(Raspberry Pi) | Nuttx<br/>(STM32F4-Discovery) |
6 | :---: | :---: | :---: | :---: |
7 | uart.open | O | O | O |
8 | uartport.write | O | O | O |
9 | uartport.writeSync | O | O | O |
10 | uartport.close | O | O | O |
11 | uartport.closeSync | O | O | O |
16 * [Constructor](#uart-constructor)
17 * [`new UART()`](#new-uart)
18 * [Prototype Methods](#uart-prototype-methods)
19 * [`uart.open(configurable[, callback])`](#uart-open)
20 * [UARTPort](#uartport)
21 * [Prototype Methods](#uartport-prototype-methods)
22 * [`uartport.write(data[, callback])`](#uartport-write)
23 * [`uartport.writeSync(data)`](#uartport-write-sync)
24 * [`uartport.close([callback])`](#uartport-close)
25 * [`uartport.closeSync()`](#uartport-close-sync)
26 * [Event](#uartport-event)
29 ## Class: UART <a name="uart"></a>
32 ## Constructor <a name="uart-constructor"></a>
35 ### `new UART()` <a name="uart-new"></a>
37 Returns a new UART object which can open UART port.
40 ## Prototype methods <a name="uart-prototype-methods"></a>
43 ### `uart.open(configuration[, callback])` <a name="uart-open"></a>
44 * `configuration <Object>`
45 * `device <String>`, mandatory configuration
46 * `baudRate <Number> (Default value is 9600)`
47 * `dataBits <Number> (Default value is 8)`
48 * `callback <Function(err: Error | null)>`
49 * Returns: `<UARTPort>`
51 On Nuttx, you can set the properties of `configuration` only on Nuttx config. `Device Drivers -> Serial Driver Support -> U[S]ART(N) Configuration` will help. And if you want to get information about `device`, please see below list.
52 * [STM32F4-discovery](../../targets/nuttx-stm32f4/Stm32f4dis.md#uart)
54 Opens UART port with the specified configuration. Following methods can be called with UARTPort object.
59 var Uart = require('uart');
61 var uart = new Uart();
63 device: '/dev/ttyUSB0'
68 var serial = uart.open(configuration, function(err) {
74 ## Class: UARTPort <a name="uartport"></a>
77 ## Prototype methods <a name="uartport-prototype-methods"></a>
80 ### `uartport.write(data[, callback])` <a name="uartport-write"></a>
82 * `callback <Function(err: Error | null)>`
84 Writes data to UART device asynchronously.
88 serial.write("Hello?", function(err) {
96 ### `uartport.writeSync(data)` <a name="uartport-write-sync"></a>
99 Writes data to UART device synchronously.
103 serial.writeSync("Hello?");
108 ### `uartport.close([callback])` <a name="uartport-close"></a>
109 * `callback <Function(err: Error | null)>`
111 Closes UART device asynchronously.
114 ### `uartport.closeSync()` <a name="uartport-close-sync"></a>
116 Closes UART device synchronously.
119 ## Events <a name="uartport-event"></a>
123 * `callback <Function(data)>`
125 `data` is a string from sender
130 serial.on('data', function(data) {
131 console.log('read result: ' + data.toString());