### Platform Support The following shows uart module APIs available for each platform. | | Linux
(Ubuntu) | Raspbian
(Raspberry Pi) | Nuttx
(STM32F4-Discovery) | | :---: | :---: | :---: | :---: | | uart.open | O | O | O | | uartport.write | O | O | O | | uartport.writeSync | O | O | O | | uartport.close | O | O | O | | uartport.closeSync | O | O | O | ## Contents * [UART](#uart) * [Constructor](#uart-constructor) * [`new UART()`](#new-uart) * [Prototype Methods](#uart-prototype-methods) * [`uart.open(configurable[, callback])`](#uart-open) * [UARTPort](#uartport) * [Prototype Methods](#uartport-prototype-methods) * [`uartport.write(data[, callback])`](#uartport-write) * [`uartport.writeSync(data)`](#uartport-write-sync) * [`uartport.close([callback])`](#uartport-close) * [`uartport.closeSync()`](#uartport-close-sync) * [Event](#uartport-event) ## Class: UART ## Constructor ### `new UART()` Returns a new UART object which can open UART port. ## Prototype methods ### `uart.open(configuration[, callback])` * `configuration ` * `device `, mandatory configuration * `baudRate (Default value is 9600)` * `dataBits (Default value is 8)` * `callback ` * Returns: `` 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. * [STM32F4-discovery](../../targets/nuttx-stm32f4/Stm32f4dis.md#uart) Opens UART port with the specified configuration. Following methods can be called with UARTPort object. **Example** ```javascript var Uart = require('uart'); var uart = new Uart(); var configuration = { device: '/dev/ttyUSB0' baudRate: 115200, dataBits: 8, } var serial = uart.open(configuration, function(err) { // Do something. }); ``` ## Class: UARTPort ## Prototype methods ### `uartport.write(data[, callback])` * `data ` * `callback ` Writes data to UART device asynchronously. **Example** ```javascript serial.write("Hello?", function(err) { if (err) { // Do something. } serial.close(); }); ``` ### `uartport.writeSync(data)` * `data ` Writes data to UART device synchronously. **Example** ```javascript serial.writeSync("Hello?"); serial.close(); ``` ### `uartport.close([callback])` * `callback ` Closes UART device asynchronously. ### `uartport.closeSync()` Closes UART device synchronously. ## Events ### `'data'` * `callback ` `data` is a string from sender For example, ```javascript ... serial.on('data', function(data) { console.log('read result: ' + data.toString()); }); ```