console

The console object provides access to the systems’s debugging console.

console.log(message)

Outputs a debug message to the console

console.info(message)

Outputs an informational message to the console

console.warn(message)

Outputs a warning message to the console

console.error(message)

Outputs an error message to the console

 

Worker

Worker(path)

Creates a new worker instance that runs in the background independently of other scripts.

worker.postMessage(message)

Send a message to the worker instance.

message:

The object to deliver to the worker; this will be in the data field in the event delivered to the worker’s global onmessage handler. This may be any value or JavaScript object handled by the structured clone algorithm.

worker.terminate()

Terminate a web worker, and free its resources.

worker.onmessage = function(event) {}

The onmessage handler is called on a Worker object when the worker’s parent receives a message from its worker (i.e. when the worker sends a message using global.postMessage()).

Serial

Serial()

Creates a new serial instance

Serial.open(device, options)

Opens the specified device.

device:

Device driver path such as “/dev/ttyAMA0” or “/dev/ttyUSB0” etc.

options:

  • baudrate (number) – Baud rate such as 9600 or 115200 etc.
  • databits (number) – Number of data bits. Possible values: 5, 6, 7, 8
  • parity (string) – Enable parity checking. Possible values: “odd”, “even”, “none”
  • stopbits (number) – Number of stop bits. Possible values: 0, 1, 2
  • xonxoff (boolean) – Enable software flow control.
  • rtscts (boolean) – Enable hardware (RTS/CTS) flow control.

Serial.close()

Close device immediately.

Serial.send(data)

Enqueues data to be transmitted.

data:

Data to be transmitted..

Serial.flush()

Flushes both data received but not handled (by onmessage handler), and data sent (by send method) but not transmitted.

Serial.onmessage = function(event) {}

onmessage handler is called whenever any data are available.

event.data:

Data received.

Serial.onerror = function(event) {}

onerror handler is called whenever there is any error.

event:

The error object representing the cause of error.

Possible error types:

  • RangeError when parameter are out of range, e.g. baud rate, data bits.
  • Error when the error is generated by the underlying operating system

Serial.onsuccess = function(event) {}

onsuccess handler is called whenever the requested operation finishes successfully. (such as: open, flush, close)