The UART module supports both read and write capabilities. Writes are done through the 'write' function, and reads are done via a callback function property that can be set. Read and write data should be a JavaScript string.
The module can be used on both QEMU and the Arduino 101. When using QEMU, you can just type directly into the terminal console. For the Arduino 101, UART is read/written from the serial console just as print does.
This IDL provides an overview of the interface; see below for documentation of specific API functions. We have a short document explaining ZJS WebIDL conventions.
Click to show WebIDL
// require returns a UART object // var uart = require('uart'); interface UART { UARTConnection init(UARTOptions options); };dictionary UARTOptions { string port; // long baud = 115200; // long dataBits = 8; // long stopBits = 1; // UARTParity parity = "none"; // boolean flowControl = false; };
[ExternalInterface=(Buffer),ExternalInterface=(EventEmitter)] interface UARTConnection: EventEmitter { // void close(); void write(Buffer data); void setReadRange(long min, long max); };
enum UARTParity { "none", "event", "odd" };
options
UARTOptions TheUARTOptions
object lets you choose the UART device/port you would like to initialize. The Arduino 101, for example, should be "tty0".- Returns: UARTConnection interface, described below.
A UARTConnection is an EventEmitter with the following events:
Buffer
data
Emitted when data is received on the UART RX line. The data
parameter is a
Buffer
with the received data.
data
Buffer The data to be written.
Write data out to the UART TX line.
min
long The minimum number of bytes for triggering theonread
event.max
long The maximum number of bytes for triggering theonread
event.
Whenever at least the min
number of bytes is available, a Buffer
object
containing at most max
number of bytes is sent with the onread
event.