Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including ds2482 with all npm packages installed. Try it out:

var ds2482 = require("ds2482")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

ds2482 v0.3.0

Provides an interface for the Dallas DS2482 onewire bridge

DS2482 Onewire Bridge

![Gitter](https://badges.gitter.im/Join Chat.svg)

Provides an interface for the Dallas DS2482 onewire bridge

Install

$ npm install ds2482

Usage

const DS2482 = require('ds2482');

const wire = new DS2482();

wire.init()
.then(() => wire.search())

.then(found => {
  console.log(found); // Returns a list of ROM addresses as hex encoded strings
})

.catch(err => {
  console.error(err);
});

API

new DS2482([options])

Creates an interface for a Dallas DS2482 i2c to onewire bridge chip

Options:

  • i2c an instance of i2c
  • address the i2c address of the bridge chip, default: 0x18
  • device the location of the i2c interface, default: /dev/i2c-1

wire.init() alias: wire.reset()

Resets the bridge chip and any onewire devices connected to it

Returns: Promise <Uint8> resolves with status register


wire.configureBridge([options])

Configures the onewire interface for subsequent communication

Options:

  • activePullup controls whether to use active or passive pullup
  • strongPullup enables strong pullup only after next command then resets
  • overdrive enable overdrive speed for the bridge chip

Returns: Promise <Uint8> resolves with configuration register


wire.selectChannel([channel])

Select the onewire channel to use for subsequent commands

Note: Only for use with DS2482-800

Arguments:

  • channel channel to select, defaults to 0

Returns: Promise <Uint8> resolves with channel selection register


wire.sendCommand(command [, rom])

Sends a command to a onewire device if specified or all onewire devices if omitted

Arguments:

  • command command to send as an unsigned integer
  • rom optional ROM address of the device to send the command to as a 16 character hex encoded string

Returns: Promise <Uint8> resolves with status register


wire.search()

Searches the bus for all onewire devices and returns a list of ROM addresses as hex encoded strings

Returns: Promise <String[]> resolves with list of roms

[
  "2826274402000012",
  "2889075f0200003e",
  "3ae9f412000000a6"
]

wire.searchByFamily(family)

Searches the bus for all onewire devices of a particular family and returns a list of ROM addresses as hex encoded strings

Arguments:

  • family the family to search as either an unsigned integer or 2 character hex encoded string

Returns: Promise <String[]> resolves with list of roms

[
  "2826274402000012",
  "2889075f0200003e"
]

wire.searchROM()

Searches the bus for the next onewire device and returns the ROM address as a hex encoded string

Returns: Promise <String> resolves with rom

"2826274402000012"

wire.readROM()

Reads the ROM address of the single onewire device and returns it as a hex encoded string

NOTE: Will return a CRC mismatch error if multiple devices are on the bus

Returns: Promise <String> resolves with rom


wire.matchROM(rom)

Selects a single onewire device to send a command to

Arguments:

  • rom the ROM address of the device to select as a 16 character hex encoded string

Returns: Promise <Uint8> resolves with status register


wire.skipROM()

Selects all onewire devices to send a command to

NOTE: Can only be used for commands that don't return a response

Returns: Promise <Uint8> resolves with status register


wire.writeData(data)

Writes one or more bytes to the onewire bus

Arguments:

  • data a single byte, array of bytes or data buffer to be written out

Returns: Promise <Uint8> resolves with status register


wire.readData(size)

Reads one or more bytes from the onewire bus and returns a data buffer

Arguments:

  • size number of bytes to be read in

Returns: Promise <Buffer> resolves with data buffer


DS2482.checkCRC(buffer)

Checks that the crc in the last byte matches the rest of the buffer

Arguments:

  • buffer the data buffer to be checked

Returns: Boolean

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free