NAME

Hardware::iButton::Device - object to represent iButtons

SYNOPSIS

use Hardware::iButton::Connection;
$c = new Hardware::iButton::Connection "/dev/ttyS0";
@b = $c->scan();
foreach $b (@b) {
    print "id: ", $b->id(), ", reg0: ",$b->readreg(0),"\n";
}

DESCRIPTION

This module talks to iButtons via the "active" serial interface (anything using the DS2480, including the DS1411k and the DS 9097U). It builds up a list of devices available, lets you read and write their registers, etc.

The connection object is an Hardware::iButton::Connection. The main user-visible purpose of it is to provide a list of Hardware::iButton::Device objects. These can be subclassed once their family codes are known to provide specialized methods unique to the capabilities of that device. Those devices will then be Hardware::iButton::Device::DS1920, etc.

AUTHOR

Brian Warner, warner@lothar.com

SEE ALSO

http://www.ibutton.com, http://sof.mit.edu/ibuttonpunks/

accessors

$family = $b->family();  # "01" for DS1990A/DS2401 "id only" buttons
$serial = $b->serial();  # "000001F1F1F3", as stamped on button
$crc = $b->crc();        # "E5" error check byte
$id = $b->id();   # the previous three joined together: "01000001F1F1F3E5"

select

$b->select();

Activate this button (in Dallas terms, "move it to the Transport Layer"). All other buttons will be idled and will not respond to commands until the bus is reset with $c-reset()>. Returns 1 for success, undef if the button is no longer on the bus.

is_present

$button->is_present();

Checks to see if the given button is still present, using the Search ROM command. Returns 1 if it is, 0 if not.

Button Introspection

or, how not to get lost in your own navel

$model = $b->model();    # "DS1992"
$bytes = $b->memsize(); # 128 bytes
$type = $b->memtype();   # "NVRAM"
$special = $b->specialfuncs();   # "thermometer", "clock", "java", "crypto"

read_memory

$data = $b->read_memory($start, $length);

Reads memory from the iButton. Acts like $data = substr(memory, $start, $length). If you read beyond the end of the device, you will get all ones in the unimplemented addresses.

write_memory

$b->write_memory($start, $data);

Writes memory to the iButton NVRAM. Acts like substr(memory, $start, length($data)) = $data;. Writes in chunks to separate 32-byte pages, each chunk going to the scratchpad first, verified there, then copied into NVRAM. Returns the number of bytes successfully written.

read_temperature

$temp = $b->read_temperature();
$temp = $b->read_temperature_hires();

These methods can be used on DS1820/DS1920 Thermometer iButtons. They return a temperature in degrees C. The range is -55C to +100C, the resolution of the first is 0.5C, the resolution of the second is about 0.01C. The accuracy is about +/- 0.5C.

Useful conversions: $f = $c*9/5 + 32, $c = ($f-32)*5/9 .