Class: Lens.Device

Device Represents a connection to a serial device.

Lens.Device(driver) ARCore/device.js, line 228

Creates a new device connection. Does not open the connection.

Argument Type Description
driver String

Name of the driver to use.

Static Methods

Lens.Device.registerDriver(name, factory) ARCore/device.js, line 483

Registers a new driver that can be used to communicate with a serial device. Drivers are created by specifying a factory that returns an instance of the driver.

An instance of the driver must have the properties open and close. If may have one or more of the properties getState, setState, write, read, and onReceive, depending on the most logical way for clients to interact with the device.

Each of these driver methods receive three arguments: first, a callback that should be called with the result of the operation; second, an array of arguments passed to the driver by the client; and third, a proxy for the chrome object that gives access to the chrome.serial API.

The factory should be lightweight. Any heavy-lifting should be done in the open method; drivers are sometimes instantiated and never used

See Devices for more information how to create device drivers.

Argument Type Description
name String

Name of this driver

factory function

Factory that returns an instance of this driver.

Lens.Device.registerUSBSerialDriver(name, opts) ARCore/device.js, line 514

A helper for registering drivers that connect to a USB-serial device with an identifiable property. open and close methods are automatically written for you, and your factory will receive the connection id from the chrome.serial API as well as the chrome proxy object. The factory should then return an object containing one or more of the properties getState, setState, write, read, and onReceive, depending on the most logical way for clients to interact with the device.

It may also have a close property. This close function will be called before the built-in close handler that actually closes the connection to the device. This function must still call the callback with either true or false. False indicates that the close operation should be aborted.

Argument Type Description
name String

Name of the driver

opts Object

Configuration options

Properties
Argument Type Description
id Object

Identifying properties of the USB-serial device.

bitrate Number

Bitrate of the device

Instance Methods

close(args, callback) ARCore/device.js, line 293

Closes the connection to the device.

Argument Type Description
args Array

Arguments to pass to the driver

callback function

Callback invoked when the connection is closed.

getDriverState() → {String} ARCore/device.js, line 351

Returns the state of the driver.

Returns:

one of "open", "opening", "closed", or "closing".

getState(args, callback) ARCore/device.js, line 386

Gets the state of this device, as determined by the driver.

Argument Type Attributes Description
args Array <optional>

Array of arguments.

callback function <optional>

Function that will receive the state as an argument.

onReceive(args, callback) ARCore/device.js, line 432

Registers a callback to be called when new data is received from a device.

Argument Type Attributes Description
args Array <optional>

Array of arguments.

callback function <optional>

Function that will be called when data arrives.

open(args, callback) ARCore/device.js, line 251

Opens a connection to the device.

Argument Type Description
args Array

Arguments to pass to the driver

callback function

Callback invoked when the connection is open.

read(args, callback) ARCore/device.js, line 420

Reads from this device. The format of the data is determined by the driver.

Argument Type Attributes Description
args Array <optional>

Array of arguments.

callback function <optional>

Function that will be called with the result of the read operation.

setState(args, callback) ARCore/device.js, line 397

Sets the state of this device, as determined by the driver.

Argument Type Attributes Description
args Array <optional>

Array of arguments.

callback function <optional>

Function that will be called when the operation is complete.

supports(method) → {Boolean} ARCore/device.js, line 334

Return true if this device supports the given method.

Argument Type Description
method String

Name of the method

write(args, callback) ARCore/device.js, line 408

Writes to this device. The format of the data is determined by the driver.

Argument Type Attributes Description
args Array <optional>

Array of arguments.

callback function <optional>

Function that will be called when the operation is complete.