Table of Contents

Class Ds18b20

Namespace
Iot.Device.Ds18b20
Assembly
Iot.Device.Ds18b20.dll

DS18B20 - Temperature sensor.

[Interface("DS18B20 - Temperature sensor")]
public class Ds18b20
Inheritance
Ds18b20

Constructors

Ds18b20(OneWireHost, byte[], bool, TemperatureResolution)

Initializes a new instance of the Ds18b20 class.

public Ds18b20(OneWireHost oneWireHost, byte[] deviceAddress = null, bool manyDevicesConnected = false, TemperatureResolution temperatureResolution = TemperatureResolution.VeryHigh)

Parameters

oneWireHost OneWireHost

One wire host (logical bus) to use.

deviceAddress byte[]

The device address (if null, then this device will search for one on the bus and latch on to the first one found).

manyDevicesConnected bool

True for more than one sensor connected to bus.

temperatureResolution TemperatureResolution

Sensor resolution.

Exceptions

ArgumentException

When device address length is not equal to 8 characters.

ArgumentException

When device address is not Ds18b20 sensors family address.

Properties

Address

Gets or sets the 8-byte address of selected device (since there could be more than one such devices on the bus).

public byte[] Address { get; set; }

Property Value

byte[]

AddressNet

Gets an array of addresses of all Ds18B20 devices on network or only devices in alarm if alarm mode is set on.

public byte[][] AddressNet { get; }

Property Value

byte[][]

IsAlarmSearchCommandEnabled

Gets or sets a value indicating whether alarm search mode is enabled.

[Property("IsAlarmSearchCommandEnabled")]
public bool IsAlarmSearchCommandEnabled { get; set; }

Property Value

bool

IsParasitePowered

Gets a value indicating whether it's powered as parasite of the board.

[Property("IsParasitePowered")]
public bool IsParasitePowered { get; }

Property Value

bool

TemperatureHighAlarm

Gets or sets high temperature alarm. Min -55C, Max 125C.

[Property("TemperatureHighAlarm")]
public Temperature TemperatureHighAlarm { get; set; }

Property Value

Temperature

Exceptions

ArgumentOutOfRangeException

When high alarm temperature is not between -55 and 125 degrees.

TemperatureLowAlarm

Gets or sets low temperature alarm. Min -55C, Max 125C.

[Property("TemperatureLowAlarm")]
public Temperature TemperatureLowAlarm { get; set; }

Property Value

Temperature

Exceptions

ArgumentOutOfRangeException

When low alarm temperature is not between -55 and 125 degrees.

TemperatureResolution

Gets or sets temperature resolution.

[Property("TemperatureResolution")]
public TemperatureResolution TemperatureResolution { get; set; }

Property Value

TemperatureResolution

Methods

BeginTrackChanges(TimeSpan)

Starts tracking the changes of temperature.

public void BeginTrackChanges(TimeSpan trackingInterval)

Parameters

trackingInterval TimeSpan

Interval to track the changes to sensor values.

Exceptions

InvalidOperationException

When tracking is already enabled.

ArgumentOutOfRangeException

When tracking interval is shorter than 50 milliseconds.

NotSupportedException

When event handler is not assigned.

ConfigurationRead(bool)

Reads sensor configuration.

public bool ConfigurationRead(bool restoreRegisterFromEEPROM = false)

Parameters

restoreRegisterFromEEPROM bool

Flag indicating if configuration should be restored from EEPROM.

Returns

bool

true on success, else false

ConfigurationWrite(bool)

Writes sensor configuration. The unchanged registers will be overwritten.

public void ConfigurationWrite(bool writeToEEPROM = false)

Parameters

writeToEEPROM bool

Flag indicating if configuration should be written also to EEPROM.

EndTrackChanges()

Stops tracking changes.

public void EndTrackChanges()

Initialize()

Initializes the sensor. This step will perform a reset of the 1-wire bus. It will check for existence of a 1-wire device. If no address was provided, then the 1-wire bus will be searched and the first device that matches the family code will be latched on to. Developer should check for successful initialization by checking the value returned. If ManyDevicesConnected is set it will keep searching until find last device, saving all in AddressNet array.

public bool Initialize()

Returns

bool

true on success, else false

Reset()

Reset the sensor.

public void Reset()

SearchForAlarmCondition()

Search for alarm condition.

public bool SearchForAlarmCondition()

Returns

bool

true on success, else false

TryReadTemperature(out Temperature)

Reads the temperature. A return value indicates whether the reading succeeded.

[Telemetry("Temperature")]
public bool TryReadTemperature(out Temperature temperature)

Parameters

temperature Temperature

Contains the measured temperature if the sensor reacted on request. Contains -999.99 otherwise.

Returns

bool
true
if measurement was not skipped, otherwise
false
.

Events

SensorValueChanged

Event that is called when the sensor value changes.

public event Ds18b20.OnSensorChanged SensorValueChanged

Event Type

Ds18b20.OnSensorChanged