Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Latest commit

 

History

History
85 lines (70 loc) · 2.7 KB

uart.md

File metadata and controls

85 lines (70 loc) · 2.7 KB

Zephyr.js API for UART

Introduction

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.

Web IDL

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" };

UART API

uart.init(options)

  • options UARTOptions The UARTOptions 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.

UARTConnection API

A UARTConnection is an EventEmitter with the following events:

Event: 'read'

  • Buffer data

Emitted when data is received on the UART RX line. The data parameter is a Buffer with the received data.

uartConnection.write(data)

  • data Buffer The data to be written.

Write data out to the UART TX line.

uartConnection.setReadRange(min, max);`

  • min long The minimum number of bytes for triggering the onread event.
  • max long The maximum number of bytes for triggering the onread 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.

Sample Apps