Table of Contents

Class Scd4x

Namespace
Pamoja.Sensors
Assembly
Pamoja.Sensors.dll

A Sensirion SCD40 or SCD41 carbon dioxide sensor. Every call goes straight to the pamoja C ABI, which decodes exactly what the manufacturer's datasheet specifies.

public static class Scd4x
Inheritance
Scd4x
Inherited Members

Methods

AllowedDuringMeasurement(ushort)

Reports whether an SCD4x accepts a command while it is measuring.

public static bool AllowedDuringMeasurement(ushort command)

Parameters

command ushort

The command.

Returns

bool

The value the C ABI computes.

AmbientPressurePascals(ushort)

Reads an SCD4x ambient-pressure word back as a pressure.

public static uint AmbientPressurePascals(ushort word)

Parameters

word ushort

The word.

Returns

uint

The value the C ABI computes.

AmbientPressureWord(uint)

Builds the SCD4x ambient-pressure word for a pressure.

public static ushort AmbientPressureWord(uint pascals)

Parameters

pascals uint

The pascals.

Returns

ushort

The value the C ABI computes.

AutomaticSelfCalibrationEnabled(ushort)

Reports whether an SCD4x word says automatic self-calibration is on.

public static bool AutomaticSelfCalibrationEnabled(ushort word)

Parameters

word ushort

The word.

Returns

bool

The value the C ABI computes.

AutomaticSelfCalibrationWord(bool)

Builds the SCD4x word that turns automatic self-calibration on or off.

public static ushort AutomaticSelfCalibrationWord(bool enabled)

Parameters

enabled bool

The enabled.

Returns

ushort

The value the C ABI computes.

Celsius(ushort)

Converts a raw SCD4x temperature word to degrees Celsius.

public static float Celsius(ushort raw)

Parameters

raw ushort

The raw.

Returns

float

The value the C ABI computes.

CommandFrame(ushort)

Builds the two bytes that address an SCD4x command, most significant first.

public static byte[] CommandFrame(ushort command)

Parameters

command ushort

The command.

Returns

byte[]

The decoded value.

Exceptions

PamojaException

The device data is not valid.

Crc(ReadOnlySpan<byte>)

Computes the CRC-8 an SCD4x appends to every data word.

public static byte Crc(ReadOnlySpan<byte> data)

Parameters

data ReadOnlySpan<byte>

The data.

Returns

byte

The value the C ABI computes.

DataReady(ushort)

Reports whether an SCD4x data-ready word says a fresh result is waiting.

public static bool DataReady(ushort word)

Parameters

word ushort

The word.

Returns

bool

The value the C ABI computes.

ForcedRecalibrationCorrectionPpm(ushort)

Reads the correction a forced recalibration applied.

public static int? ForcedRecalibrationCorrectionPpm(ushort word)

Parameters

word ushort

The word.

Returns

int?

The value, or null where the part defines none.

ForcedRecalibrationWord(bool, int)

Builds the word an SCD4x returns for a forced-recalibration outcome.

public static ushort ForcedRecalibrationWord(bool succeeded, int correctionPpm)

Parameters

succeeded bool

The succeeded.

correctionPpm int

The correction ppm.

Returns

ushort

The value the C ABI computes.

HumidityMilliPercent(ushort)

Converts a raw SCD4x humidity word to milli-percent.

public static uint HumidityMilliPercent(ushort raw)

Parameters

raw ushort

The raw.

Returns

uint

The value the C ABI computes.

HumidityRaw(uint)

Builds the SCD4x humidity word that decodes to a relative humidity.

public static ushort HumidityRaw(uint milliPercent)

Parameters

milliPercent uint

The milli percent.

Returns

ushort

The value the C ABI computes.

MaxDurationMs(ushort)

Returns how long an SCD4x command may take before its result can be read.

public static ushort? MaxDurationMs(ushort command)

Parameters

command ushort

The command.

Returns

ushort?

The value, or null where the part defines none.

MeasurementBytes(ushort, ushort, ushort)

Builds the nine bytes an SCD4x sends for a set of raw words, each CRC included.

public static byte[] MeasurementBytes(ushort co2Ppm, ushort temperatureRaw, ushort humidityRaw)

Parameters

co2Ppm ushort

The co2 ppm.

temperatureRaw ushort

The temperature raw.

humidityRaw ushort

The humidity raw.

Returns

byte[]

The decoded value.

Exceptions

PamojaException

The device data is not valid.

MeasurementFromPhysical(ushort, int, uint)

Builds the SCD4x measurement a sensor reporting these physical values would send.

public static PamojaScd4xMeasurement MeasurementFromPhysical(ushort co2Ppm, int milliCelsius, uint humidityMilliPercent)

Parameters

co2Ppm ushort

The co2 ppm.

milliCelsius int

The milli celsius.

humidityMilliPercent uint

The humidity milli percent.

Returns

PamojaScd4xMeasurement

The decoded value.

Exceptions

PamojaException

The device data is not valid.

MilliCelsius(ushort)

Converts a raw SCD4x temperature word to milli-degrees Celsius.

public static int MilliCelsius(ushort raw)

Parameters

raw ushort

The raw.

Returns

int

The value the C ABI computes.

ParseMeasurement(ReadOnlySpan<byte>)

Parses and CRC-checks a nine-byte SCD4x measurement frame.

public static PamojaScd4xMeasurement ParseMeasurement(ReadOnlySpan<byte> frame)

Parameters

frame ReadOnlySpan<byte>

The frame.

Returns

PamojaScd4xMeasurement

The decoded value.

Exceptions

PamojaException

The device data is not valid.

RelativeHumidityPercent(ushort)

Converts a raw SCD4x humidity word to a relative humidity percentage.

public static float RelativeHumidityPercent(ushort raw)

Parameters

raw ushort

The raw.

Returns

float

The value the C ABI computes.

SelfTestPassed(ushort)

Reports whether an SCD4x self-test word says the part is healthy.

public static bool SelfTestPassed(ushort word)

Parameters

word ushort

The word.

Returns

bool

The value the C ABI computes.

SerialNumber(ReadOnlySpan<byte>)

Reads the 48-bit serial number out of a nine-byte SCD4x frame.

public static ulong SerialNumber(ReadOnlySpan<byte> frame)

Parameters

frame ReadOnlySpan<byte>

The frame.

Returns

ulong

The decoded value.

Exceptions

PamojaException

The device data is not valid.

SerialNumberFrame(ulong)

Builds the nine bytes an SCD4x sends for a serial number, each CRC included.

public static byte[] SerialNumberFrame(ulong serial)

Parameters

serial ulong

The serial.

Returns

byte[]

The decoded value.

Exceptions

PamojaException

The device data is not valid.

TemperatureOffsetMilliCelsius(ushort)

Reads an SCD4x temperature-offset word back as an offset.

public static uint TemperatureOffsetMilliCelsius(ushort word)

Parameters

word ushort

The word.

Returns

uint

The value the C ABI computes.

TemperatureOffsetWord(uint)

Builds the SCD4x temperature-offset word for an offset.

public static ushort TemperatureOffsetWord(uint milliCelsius)

Parameters

milliCelsius uint

The milli celsius.

Returns

ushort

The value the C ABI computes.

TemperatureRaw(int)

Builds the SCD4x temperature word that decodes to a temperature.

public static ushort TemperatureRaw(int milliCelsius)

Parameters

milliCelsius int

The milli celsius.

Returns

ushort

The value the C ABI computes.

Word(ReadOnlySpan<byte>)

Reads a CRC-checked three-byte SCD4x word frame.

public static ushort Word(ReadOnlySpan<byte> frame)

Parameters

frame ReadOnlySpan<byte>

The frame.

Returns

ushort

The decoded value.

Exceptions

PamojaException

The device data is not valid.

WordFrame(ushort)

Builds the three bytes an SCD4x sends for a word: the word then its CRC.

public static byte[] WordFrame(ushort value)

Parameters

value ushort

The value.

Returns

byte[]

The decoded value.

Exceptions

PamojaException

The device data is not valid.

WriteFrame(ushort, ushort)

Builds the five bytes that write a word to an SCD4x: command, word, CRC.

public static byte[] WriteFrame(ushort command, ushort value)

Parameters

command ushort

The command.

value ushort

The value.

Returns

byte[]

The decoded value.

Exceptions

PamojaException

The device data is not valid.