Table of Contents

Class Ds18b20

Namespace
Pamoja.Sensors
Assembly
Pamoja.Sensors.dll

A Maxim DS18B20 1-Wire thermometer.

public static class Ds18b20
Inheritance
Ds18b20
Inherited Members

Fields

FamilyCode

The 1-Wire family code that identifies a DS18B20 on the bus.

public const byte FamilyCode = 40

Field Value

byte

Methods

BuildScratchpad(float, byte, sbyte, sbyte)

Builds the nine bytes a part in the given state puts on the bus.

public static byte[] BuildScratchpad(float celsius, byte resolutionBits, sbyte alarmHigh, sbyte alarmLow)

Parameters

celsius float

The temperature the part is reading.

resolutionBits byte

The resolution it is configured for, 9 to 12.

alarmHigh sbyte

The high alarm threshold in whole degrees Celsius.

alarmLow sbyte

The low alarm threshold in whole degrees Celsius.

Returns

byte[]

The nine scratchpad bytes in transmission order, CRC last.

Remarks

This is the inverse of ParseScratchpad(ReadOnlySpan<byte>), so a node can be written and tested against what a thermometer sends without one attached.

Exceptions

PamojaException

The resolution is not one the part offers.

Celsius(short)

Converts a raw temperature register to degrees Celsius.

public static float Celsius(short raw)

Parameters

raw short

The 16-bit two's-complement register.

Returns

float

The temperature.

ConfigByte(byte)

Returns the configuration byte that selects a resolution.

public static byte ConfigByte(byte bits)

Parameters

bits byte

The resolution in bits: 9, 10, 11, or 12.

Returns

byte

The byte to write to the configuration register.

Exceptions

PamojaException

The resolution is not one the part offers.

Crc8(ReadOnlySpan<byte>)

Computes the Maxim CRC-8 a 1-Wire device checks its bytes with.

public static byte Crc8(ReadOnlySpan<byte> data)

Parameters

data ReadOnlySpan<byte>

The bytes the checksum covers.

Returns

byte

The checksum.

MaxConversionMicros(byte)

Returns how long a conversion may take at a resolution.

public static uint MaxConversionMicros(byte bits)

Parameters

bits byte

The resolution in bits.

Returns

uint

The datasheet's worst case, in microseconds.

Exceptions

PamojaException

The resolution is not one the part offers.

MicroCelsius(short)

Converts a raw temperature register to micro-degrees Celsius.

public static int MicroCelsius(short raw)

Parameters

raw short

The 16-bit two's-complement register.

Returns

int

The temperature, exact in integer arithmetic.

ParseScratchpad(ReadOnlySpan<byte>)

Parses and CRC-checks a nine-byte scratchpad.

public static Ds18b20Reading ParseScratchpad(ReadOnlySpan<byte> bytes)

Parameters

bytes ReadOnlySpan<byte>

The scratchpad as the device sent it, the ninth its CRC.

Returns

Ds18b20Reading

The decoded reading.

Exceptions

PamojaException

The CRC does not match, which means the read was corrupted on the bus and should be repeated.

ResolutionBits(byte)

Returns the resolution a configuration byte selects.

public static byte ResolutionBits(byte configByte)

Parameters

configByte byte

The byte read from the configuration register.

Returns

byte

The resolution in bits.

StepMicroCelsius(byte)

Returns the temperature step a resolution resolves.

public static uint StepMicroCelsius(byte bits)

Parameters

bits byte

The resolution in bits.

Returns

uint

The step in micro-degrees Celsius.

Exceptions

PamojaException

The resolution is not one the part offers.