API Reference

Svm40ShdlcDevice

class sensirion_shdlc_svm40.device.Svm40ShdlcDevice(connection, slave_address)[source]

SVM40 device.

This is a low-level driver which just provides all SHDLC commands as Python methods. Typically, calling a method sends one SHDLC request to the device and interprets its response. There is no higher level functionality available, please look for other drivers if you need a higher level interface.

There is no (or very few) caching functionality in this driver. For example if you call get_serial_number() 100 times, it will send the command 100 times over the SHDLC interface to the device. This makes the driver (nearly) stateless.

__init__(connection, slave_address)[source]

Create an SVM40 device instance on an SHDLC connection.

Note

This constructor does not communicate with the device, so it’s possible to instantiate an object even if the device is not connected or powered yet.

Parameters:
  • connection (ShdlcConnection) – The connection used for the communication.
  • slave_address (byte) – The address of the device. The default address of the SVM40 is 0.
get_product_type(as_int=False)[source]

Get the product type. The product type (sometimes also called “device type”) can be used to detect what kind of SHDLC product is connected.

Parameters:as_int (bool) – If True, the product type is returned as an integer, otherwise as a string of hexadecimal digits (default).
Returns:The product type as an integer or string of hexadecimal digits.
Return type:string/int
get_product_name()[source]

Get the product name of the device.

Returns:The product name as an ASCII string.
Return type:string
get_serial_number()[source]

Get the serial number of the device.

Returns:The serial number as an ASCII string.
Return type:string
get_version()[source]

Get the version of the device firmware, hardware and SHDLC protocol.

Returns:The device version as a Version object.
Return type:Version
get_system_up_time()[source]

Get the system up time of the device.

Returns:The time since the last power-on or device reset [s].
Return type:int
device_reset()[source]

Execute a device reset (reboot firmware, similar to power cycle).

get_compensation_temperature_offset()[source]

Gets the temperature offset for RHT measurements.

Returns:Temperature offset in degrees celsius.
Return type:float
set_compensation_temperature_offset(t_offset, send_as_integer=False)[source]

Sets the temperature offset for RHT measurements.

Note

Execute the command store_nv_data() command after writing the parameter to store it in the non-volatile memory of the device otherwise the parameter will be reset upton a device reset.

Parameters:
  • t_offset (float) – Temperature offset in degrees celsius.
  • send_as_integer (bool) – Set to True to use the integer format. This option was added for firmware version >= 2.0 which will accepted either a float value (4 bytes) or an int16 value (2 bytes). Firmware versions prior to 2.0 will only accept the float format. Float temperature values are in degrees celsius with no scaling. Integer temperature values are in degrees celsius with a scaling of 200.
get_voc_tuning_parameters()[source]

Gets the currently set parameters for customizing the VOC algorithm.

Returns:
  • voc_index_offset (int) - VOC index representing typical (average) conditions. The default value is 100.
  • learning_time_hours (int) - Time constant of long-term estimator in hours. Past events will be forgotten after about twice the learning time. The default value is 12 hours.
  • gating_max_duration_minutes (int) - Maximum duration of gating in minutes (freeze of estimator during high VOC index signal). Zero disables the gating. The default value is 180 minutes.
  • std_initial (int) - Initial estimate for standard deviation. Lower value boosts events during initial learning period, but may result in larger device-to-device variations. The default value is 50.
Return type:tuple
set_voc_tuning_parameters(voc_index_offset, learning_time_hours, gating_max_duration_minutes, std_initial)[source]

Sets parameters to customize the VOC algorithm. This command is only available in idle mode.

Note

Execute the store command after writing the parameter to store it in the non-volatile memory of the device otherwise the parameter will be reset upton a device reset.

Parameters:
  • voc_index_offset (int) – VOC index representing typical (average) conditions. The default value is 100.
  • learning_time_hours (int) – Time constant of long-term estimator in hours. Past events will be forgotten after about twice the learning time. The default value is 12 hours.
  • gating_max_duration_minutes (int) – Maximum duration of gating in minutes (freeze of estimator during high VOC index signal). Set to zero to disable the gating. The default value is 180 minutes.
  • std_initial (int) – Initial estimate for standard deviation. Lower value boosts events during initial learning period, but may result in larger device-to-device variations. The default value is 50.
store_nv_data()[source]

Stores all customer engine parameters to the non-volatile memory.

get_voc_state()[source]

Gets the current VOC algorithm state. Retrieved values can be used to set the VOC algorithm state to resume operation after a short interruption, skipping initial learning phase. This command is only available during measurement mode.

Note

This feature can only be used after at least 3 hours of continuous operation.

Returns:Current VOC algorithm state.
Return type:list(int)
set_voc_state(state)[source]

Set previously retrieved VOC algorithm state to resume operation after a short interruption, skipping initial learning phase. This command is only available in idle mode.

Note

This feature should not be used after interruptions of more than 10 minutes.

Parameters:state (list(int)) – Current VOC algorithm state.
start_measurement()[source]

Starts continuous measurement in polling mode.

Note

This command is only available in idle mode.

stop_measurement()[source]

Leaves the measurement mode and returns to the idle mode.

Note

This command is only available in measurement mode.

read_measured_values()[source]

Returns the new measurement results.

Note

This command is only available in measurement mode. The firmware updates the measurement values every second. Polling data with a faster sampling rate will return the same values. The first measurement is available 1 second after the start measurement command is issued. Any readout prior to this will return zero initialized values.

Returns:The measured air quality, humidity and temperature.
  • air_quality (AirQuality) - Air quality response object.
  • humidity (Humidity) - Humidity response object.
  • temperature (Temperature) - Temperature response object.
Return type:tuple
read_measured_values_raw()[source]

Returns the new measurement results with raw values added.

Note

This command is only available in measurement mode. The firmware updates the measurement values every second. Polling data with a faster sampling rate will return the same values. The first measurement is available 1 second after the start measurement command is issued. Any readout prior to this will return zero initialized values.

Returns:The measured air quality, humidity and temperature including the raw values without engine compensation.
  • air_quality (AirQuality) - Air quality response object.
  • humidity (Humidity) - Humidity response object.
  • temperature (Temperature) - Temperature response object.
  • raw_voc_ticks (int) - Raw VOC output ticks as read from the SGP sensor.
  • raw_humidity (Humidity) - Humidity response object.
  • raw_temperature (Temperature) - Temperature response object.
Return type:tuple
update_firmware(image, emergency=False, status_callback=None, progress_callback=None)[source]

Update the firmware on the device.

This method allows you to download a new firmware (provided as a *.hex file) to the device. A device reset is performed after the firmware update.

Note

This can take several minutes, don’t abort it! If aborted, the device stays in the bootloader and you need to restart the update with emergency=True to recover.

Parameters:
  • image – The image to flash, either as a :py:Svm40FirmwareImage object, a file-like object, or the filename (str) to the *.hex file.
  • emergency (bool) – Must be set to True if the device is already in bootloader mode, False otherwise.
  • status_callback (callable) – Optional callback for status report, taking a string as parameter.
  • progress_callback (callable) – Optional callback for progress report, taking a float as parameter (progress in percent).
Raises:
connection

Get the used SHDLC connection.

Returns:The used SHDLC connection.
Return type:ShdlcConnection
execute(command)

Execute an SHDLC command.

Parameters:command (ShdlcCommand) – The command to execute.
Returns:The interpreted response of the executed command.
last_error_flag

Get the error flag which was received with the last response of the device. So this flag gets updated with every command sent to the device. If the flag is True, typically the derived classes provide a method to read the exact error reason from the device (the corresponding SHDLC command is called “Get Device Status”).

Note

When creating an instance of ShdlcDeviceBase, this property is initialized with False and will not be updated until you send the first command to the device.

Returns:True if the device indicated an error, False otherwise.
Return type:bool
slave_address

Get the slave address (not read from the device!).

Returns:The slave address.
Return type:byte

Response Data Types

Air Quality

class sensirion_shdlc_svm40.response_types.AirQuality(ticks)[source]

Represents a measurement response for the air quality.

With the ticks you can access the raw data as received from the device. For the converted value the voc_index attribute is available.

__init__(ticks)[source]

Creates an instance from the received raw data.

Parameters:ticks (int) – The read ticks as received from the device.
ticks

The ticks (int) as received from the device.

voc_index

The converted VOC index.

Humidity

class sensirion_shdlc_svm40.response_types.Humidity(ticks)[source]

Represents a measurement response for the humidity.

With the ticks you can access the raw data as received from the device. For the converted value the percent_rh attribute is available.

__init__(ticks)[source]

Creates an instance from the received raw data.

Parameters:ticks (int) – The read ticks as received from the device.
ticks

The ticks (int) as received from the device.

percent_rh

The converted humidity in %RH.

Temperature

class sensirion_shdlc_svm40.response_types.Temperature(ticks)[source]

Represents a measurement response for the temperature.

With the ticks you can access the raw data as received from the device. For the converted values you can choose between degrees_celsius and degrees_fahrenheit.

__init__(ticks)[source]

Creates an instance from the received raw data.

Parameters:ticks (int) – The read ticks as received from the device.
ticks

The ticks (int) as received from the device.

degrees_celsius

The converted temperature in °C.

degrees_fahrenheit

The converted temperature in °F.

Svm40FirmwareImage

class sensirion_shdlc_svm40.firmware_image.Svm40FirmwareImage(hexfile)[source]

SVM40 firmware image.

This class represents a firmware image for the SVM40 device. It is used to load and verify Intel-Hex files for performing firmware updates over SHDLC.

__init__(hexfile)[source]

Constructor which loads and parses the firmware from a hex file.

Parameters:hexfile (str/file) – The filename or file-like object containing the firmware in Intel-Hex format (*.hex).
Raises:ShdlcFirmwareImageSignatureError – If the signature of the image is invalid.
application_version

Get the application firmware version which is contained in the loaded image.

Returns:Application firmware version (note: debug flag is not supported, it’s always False).
Return type:FirmwareVersion
available_bytes

Get the count of available bytes left.

Returns:Count of available bytes.
Return type:int
bootloader_version

Get the bootloader version which is contained in the loaded image.

Returns:Bootloader version (note: debug flag is not supported, it’s always False).
Return type:FirmwareVersion
checksum

Get the checksum over the application firmware part of the loaded image. This is the checksum which needs to be sent to the product bootloader.

Returns:Checksum as a byte.
Return type:byte
product_type

Get the product type for which the loaded firmware is made.

Returns:Product type as an integer.
Return type:int
read(size=-1)

Read the next bytes of the application firmware.

Parameters:size (int) – Maximum count of bytes to read (-1 reads all available)
Returns:Firmware data block.
Return type:bytes
size

Get the size of the application firmware.

Returns:Size in bytes.
Return type:int

Device Errors

Command Not Allowed In Current State

class sensirion_shdlc_svm40.device_errors.Svm40CommandNotAllowedInCurrentState[source]

Command is not allowed in the current state.

__init__()[source]

Constructor.

Parameters:
  • code (byte) – The error code received from the device.
  • message (string) – The error description for the given error code.
error_code

Get the error code received from the device.

Returns:Received error code.
Return type:byte
error_message

Get the description of the received error code.

Returns:Error message.
Return type:string
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

Fatal Error

class sensirion_shdlc_svm40.device_errors.Svm40FatalError[source]

An error without specific error code occurred.

__init__()[source]

Constructor.

Parameters:
  • code (byte) – The error code received from the device.
  • message (string) – The error description for the given error code.
error_code

Get the error code received from the device.

Returns:Received error code.
Return type:byte
error_message

Get the description of the received error code.

Returns:Error message.
Return type:string
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

Commands

Start Measurement

class sensirion_shdlc_svm40.commands.start_measurement.Svm40CmdStartMeasurementBase(*args, **kwargs)[source]

SHDLC command 0x00: “Start Measurement”.

__init__(*args, **kwargs)[source]

Constructor.

check_response_length(data)

Check if the response length is correct.

Parameters:data (bytes) – Raw data (payload) received from the device.
Raises:ShdlcResponseError – If length is wrong.
data

Get the command data (payload).

Returns:Command data (length 0..255).
Return type:bytes
id

Get the command ID.

Returns:Command ID (0..255).
Return type:byte
interpret_response(data)

Interpret the response to this command received from the device. This converts the raw byte array to the actual data type(s) depending on the sent command.

Parameters:data (bytes) – Raw data (payload) received from the device.
Returns:Interpreted response. Data type and meaning depends on the sent command. None for commands without response data. See the actual command implementation for details.
max_response_time

Get the maximum response time for this command.

Returns:Maximum response time in seconds.
Return type:float
post_processing_time

Get the post processing time for this command. The post processing time defines how long a device needs to execute a command after responding to the SHDLC command. Most devices don’t need post processing (command is executed before the response is sent). Only special commands (e.g. a device reset) are executed after the response is sent.

Returns:Maximum response time in seconds.
Return type:float
class sensirion_shdlc_svm40.commands.start_measurement.Svm40CmdStartContinuousMeasurement[source]

Start Continuous Measurement Command

Starts continuous measurement in polling mode.

Note

This command is only available in idle mode.

__init__()[source]

Constructor.

check_response_length(data)

Check if the response length is correct.

Parameters:data (bytes) – Raw data (payload) received from the device.
Raises:ShdlcResponseError – If length is wrong.
data

Get the command data (payload).

Returns:Command data (length 0..255).
Return type:bytes
id

Get the command ID.

Returns:Command ID (0..255).
Return type:byte
interpret_response(data)

Interpret the response to this command received from the device. This converts the raw byte array to the actual data type(s) depending on the sent command.

Parameters:data (bytes) – Raw data (payload) received from the device.
Returns:Interpreted response. Data type and meaning depends on the sent command. None for commands without response data. See the actual command implementation for details.
max_response_time

Get the maximum response time for this command.

Returns:Maximum response time in seconds.
Return type:float
post_processing_time

Get the post processing time for this command. The post processing time defines how long a device needs to execute a command after responding to the SHDLC command. Most devices don’t need post processing (command is executed before the response is sent). Only special commands (e.g. a device reset) are executed after the response is sent.

Returns:Maximum response time in seconds.
Return type:float

Stop Measurement

class sensirion_shdlc_svm40.commands.stop_measurement.Svm40CmdStopMeasurementBase(*args, **kwargs)[source]

SHDLC command 0x01: “Stop Measurement”.

__init__(*args, **kwargs)[source]

Constructor.

check_response_length(data)

Check if the response length is correct.

Parameters:data (bytes) – Raw data (payload) received from the device.
Raises:ShdlcResponseError – If length is wrong.
data

Get the command data (payload).

Returns:Command data (length 0..255).
Return type:bytes
id

Get the command ID.

Returns:Command ID (0..255).
Return type:byte
interpret_response(data)

Interpret the response to this command received from the device. This converts the raw byte array to the actual data type(s) depending on the sent command.

Parameters:data (bytes) – Raw data (payload) received from the device.
Returns:Interpreted response. Data type and meaning depends on the sent command. None for commands without response data. See the actual command implementation for details.
max_response_time

Get the maximum response time for this command.

Returns:Maximum response time in seconds.
Return type:float
post_processing_time

Get the post processing time for this command. The post processing time defines how long a device needs to execute a command after responding to the SHDLC command. Most devices don’t need post processing (command is executed before the response is sent). Only special commands (e.g. a device reset) are executed after the response is sent.

Returns:Maximum response time in seconds.
Return type:float
class sensirion_shdlc_svm40.commands.stop_measurement.Svm40CmdStopMeasurement[source]

Stop Measurement Command

Leaves the measurement mode and returns to the idle mode.

Note

This command is only available in measurement mode.

__init__()[source]

Constructor.

check_response_length(data)

Check if the response length is correct.

Parameters:data (bytes) – Raw data (payload) received from the device.
Raises:ShdlcResponseError – If length is wrong.
data

Get the command data (payload).

Returns:Command data (length 0..255).
Return type:bytes
id

Get the command ID.

Returns:Command ID (0..255).
Return type:byte
interpret_response(data)

Interpret the response to this command received from the device. This converts the raw byte array to the actual data type(s) depending on the sent command.

Parameters:data (bytes) – Raw data (payload) received from the device.
Returns:Interpreted response. Data type and meaning depends on the sent command. None for commands without response data. See the actual command implementation for details.
max_response_time

Get the maximum response time for this command.

Returns:Maximum response time in seconds.
Return type:float
post_processing_time

Get the post processing time for this command. The post processing time defines how long a device needs to execute a command after responding to the SHDLC command. Most devices don’t need post processing (command is executed before the response is sent). Only special commands (e.g. a device reset) are executed after the response is sent.

Returns:Maximum response time in seconds.
Return type:float

Read Measured Values

class sensirion_shdlc_svm40.commands.read_measured_values.Svm40CmdReadMeasuredValuesBase(*args, **kwargs)[source]

SHDLC command 0x03: “Read Measured Values”.

__init__(*args, **kwargs)[source]

Constructor.

check_response_length(data)

Check if the response length is correct.

Parameters:data (bytes) – Raw data (payload) received from the device.
Raises:ShdlcResponseError – If length is wrong.
data

Get the command data (payload).

Returns:Command data (length 0..255).
Return type:bytes
id

Get the command ID.

Returns:Command ID (0..255).
Return type:byte
interpret_response(data)

Interpret the response to this command received from the device. This converts the raw byte array to the actual data type(s) depending on the sent command.

Parameters:data (bytes) – Raw data (payload) received from the device.
Returns:Interpreted response. Data type and meaning depends on the sent command. None for commands without response data. See the actual command implementation for details.
max_response_time

Get the maximum response time for this command.

Returns:Maximum response time in seconds.
Return type:float
post_processing_time

Get the post processing time for this command. The post processing time defines how long a device needs to execute a command after responding to the SHDLC command. Most devices don’t need post processing (command is executed before the response is sent). Only special commands (e.g. a device reset) are executed after the response is sent.

Returns:Maximum response time in seconds.
Return type:float
class sensirion_shdlc_svm40.commands.read_measured_values.Svm40CmdReadMeasuredValuesAsIntegers[source]

Read Measured Values As Integers Command

Returns the new measurement results as integers.

Note

This command is only available in measurement mode. The firmware updates the measurement values every second. Polling data with a faster sampling rate will return the same values. The first measurement is available 1 second after the start measurement command is issued. Any readout prior to this will return zero initialized values.

__init__()[source]

Constructor.

static interpret_response(data)[source]
Returns:
  • voc_index (int) - VOC algorithm output with a scaling value of 10.
  • humidity (int) - Compensated ambient humidity in % RH with a scaling factor of 100.
  • temperature (int) - Compensated ambient temperature in degrees celsius with a scaling of 200.
Return type:tuple
check_response_length(data)

Check if the response length is correct.

Parameters:data (bytes) – Raw data (payload) received from the device.
Raises:ShdlcResponseError – If length is wrong.
data

Get the command data (payload).

Returns:Command data (length 0..255).
Return type:bytes
id

Get the command ID.

Returns:Command ID (0..255).
Return type:byte
max_response_time

Get the maximum response time for this command.

Returns:Maximum response time in seconds.
Return type:float
post_processing_time

Get the post processing time for this command. The post processing time defines how long a device needs to execute a command after responding to the SHDLC command. Most devices don’t need post processing (command is executed before the response is sent). Only special commands (e.g. a device reset) are executed after the response is sent.

Returns:Maximum response time in seconds.
Return type:float
class sensirion_shdlc_svm40.commands.read_measured_values.Svm40CmdReadMeasuredValuesAsIntegersWithRawParameters[source]

Read Measured Values As Integers With Raw Parameters Command

Returns the new measurement results as integers with raw values added.

Note

This command is only available in measurement mode. The firmware updates the measurement values every second. Polling data with a faster sampling rate will return the same values. The first measurement is available 1 second after the start measurement command is issued. Any readout prior to this will return zero initialized values.

__init__()[source]

Constructor.

static interpret_response(data)[source]
Returns:
  • voc_index (int) - VOC algorithm output with a scaling value of 10.
  • humidity (int) - Compensated ambient humidity in % RH with a scaling factor of 100.
  • temperature (int) - Compensated ambient temperature in degrees celsius with a scaling of 200.
  • raw_voc_ticks (int) - Raw VOC output ticks as read from the SGP sensor.
  • raw_humidity (int) - Uncompensated raw humidity in % RH as read from the SHT40 with a scaling factor of 100.
  • raw_temperature (int) - Uncompensated raw temperature in degrees celsius as read from the SHT40 with a scaling of 200.
Return type:tuple
check_response_length(data)

Check if the response length is correct.

Parameters:data (bytes) – Raw data (payload) received from the device.
Raises:ShdlcResponseError – If length is wrong.
data

Get the command data (payload).

Returns:Command data (length 0..255).
Return type:bytes
id

Get the command ID.

Returns:Command ID (0..255).
Return type:byte
max_response_time

Get the maximum response time for this command.

Returns:Maximum response time in seconds.
Return type:float
post_processing_time

Get the post processing time for this command. The post processing time defines how long a device needs to execute a command after responding to the SHDLC command. Most devices don’t need post processing (command is executed before the response is sent). Only special commands (e.g. a device reset) are executed after the response is sent.

Returns:Maximum response time in seconds.
Return type:float

Customer Engine Parameters

Device Information

class sensirion_shdlc_svm40.commands.device_information.Svm40CmdDeviceInformationBase(*args, **kwargs)[source]

SHDLC command 0xD0: “Device Information”.

__init__(*args, **kwargs)[source]

Constructor.

check_response_length(data)

Check if the response length is correct.

Parameters:data (bytes) – Raw data (payload) received from the device.
Raises:ShdlcResponseError – If length is wrong.
data

Get the command data (payload).

Returns:Command data (length 0..255).
Return type:bytes
id

Get the command ID.

Returns:Command ID (0..255).
Return type:byte
interpret_response(data)

Interpret the response to this command received from the device. This converts the raw byte array to the actual data type(s) depending on the sent command.

Parameters:data (bytes) – Raw data (payload) received from the device.
Returns:Interpreted response. Data type and meaning depends on the sent command. None for commands without response data. See the actual command implementation for details.
max_response_time

Get the maximum response time for this command.

Returns:Maximum response time in seconds.
Return type:float
post_processing_time

Get the post processing time for this command. The post processing time defines how long a device needs to execute a command after responding to the SHDLC command. Most devices don’t need post processing (command is executed before the response is sent). Only special commands (e.g. a device reset) are executed after the response is sent.

Returns:Maximum response time in seconds.
Return type:float
class sensirion_shdlc_svm40.commands.device_information.Svm40CmdGetProductType[source]

Get Product Type Command

Gets the product type from the device.

__init__()[source]

Constructor.

static interpret_response(data)[source]
Returns:String containing the product type.
Return type:str
check_response_length(data)

Check if the response length is correct.

Parameters:data (bytes) – Raw data (payload) received from the device.
Raises:ShdlcResponseError – If length is wrong.
data

Get the command data (payload).

Returns:Command data (length 0..255).
Return type:bytes
id

Get the command ID.

Returns:Command ID (0..255).
Return type:byte
max_response_time

Get the maximum response time for this command.

Returns:Maximum response time in seconds.
Return type:float
post_processing_time

Get the post processing time for this command. The post processing time defines how long a device needs to execute a command after responding to the SHDLC command. Most devices don’t need post processing (command is executed before the response is sent). Only special commands (e.g. a device reset) are executed after the response is sent.

Returns:Maximum response time in seconds.
Return type:float
class sensirion_shdlc_svm40.commands.device_information.Svm40CmdGetProductName[source]

Get Product Name Command

Gets the product name from the device.

__init__()[source]

Constructor.

static interpret_response(data)[source]
Returns:String containing the product name.
Return type:str
check_response_length(data)

Check if the response length is correct.

Parameters:data (bytes) – Raw data (payload) received from the device.
Raises:ShdlcResponseError – If length is wrong.
data

Get the command data (payload).

Returns:Command data (length 0..255).
Return type:bytes
id

Get the command ID.

Returns:Command ID (0..255).
Return type:byte
max_response_time

Get the maximum response time for this command.

Returns:Maximum response time in seconds.
Return type:float
post_processing_time

Get the post processing time for this command. The post processing time defines how long a device needs to execute a command after responding to the SHDLC command. Most devices don’t need post processing (command is executed before the response is sent). Only special commands (e.g. a device reset) are executed after the response is sent.

Returns:Maximum response time in seconds.
Return type:float
class sensirion_shdlc_svm40.commands.device_information.Svm40CmdGetSerialNumber[source]

Get Serial Number Command

Gets the serial number from the device.

__init__()[source]

Constructor.

static interpret_response(data)[source]
Returns:String containing the serial number.
Return type:str
check_response_length(data)

Check if the response length is correct.

Parameters:data (bytes) – Raw data (payload) received from the device.
Raises:ShdlcResponseError – If length is wrong.
data

Get the command data (payload).

Returns:Command data (length 0..255).
Return type:bytes
id

Get the command ID.

Returns:Command ID (0..255).
Return type:byte
max_response_time

Get the maximum response time for this command.

Returns:Maximum response time in seconds.
Return type:float
post_processing_time

Get the post processing time for this command. The post processing time defines how long a device needs to execute a command after responding to the SHDLC command. Most devices don’t need post processing (command is executed before the response is sent). Only special commands (e.g. a device reset) are executed after the response is sent.

Returns:Maximum response time in seconds.
Return type:float

Get Version

class sensirion_shdlc_svm40.commands.get_version.Svm40CmdGetVersionBase(*args, **kwargs)[source]

SHDLC command 0xD1: “Get Version”.

__init__(*args, **kwargs)[source]

Constructor.

check_response_length(data)

Check if the response length is correct.

Parameters:data (bytes) – Raw data (payload) received from the device.
Raises:ShdlcResponseError – If length is wrong.
data

Get the command data (payload).

Returns:Command data (length 0..255).
Return type:bytes
id

Get the command ID.

Returns:Command ID (0..255).
Return type:byte
interpret_response(data)

Interpret the response to this command received from the device. This converts the raw byte array to the actual data type(s) depending on the sent command.

Parameters:data (bytes) – Raw data (payload) received from the device.
Returns:Interpreted response. Data type and meaning depends on the sent command. None for commands without response data. See the actual command implementation for details.
max_response_time

Get the maximum response time for this command.

Returns:Maximum response time in seconds.
Return type:float
post_processing_time

Get the post processing time for this command. The post processing time defines how long a device needs to execute a command after responding to the SHDLC command. Most devices don’t need post processing (command is executed before the response is sent). Only special commands (e.g. a device reset) are executed after the response is sent.

Returns:Maximum response time in seconds.
Return type:float
class sensirion_shdlc_svm40.commands.get_version.Svm40CmdGetVersion[source]

Get Version Command

Gets the version information for the hardware, firmware and SHDLC protocol.

__init__()[source]

Constructor.

static interpret_response(data)[source]
Returns:
  • firmware_major (int) - Firmware major version number.
  • firmware_minor (int) - Firmware minor version number.
  • firmware_debug (bool) - Firmware debug state. If the debug state is set, the firmware is in development.
  • hardware_major (int) - Hardware major version number.
  • hardware_minor (int) - Hardware minor version number.
  • protocol_major (int) - Protocol major version number.
  • protocol_minor (int) - Protocol minor version number.
Return type:tuple
check_response_length(data)

Check if the response length is correct.

Parameters:data (bytes) – Raw data (payload) received from the device.
Raises:ShdlcResponseError – If length is wrong.
data

Get the command data (payload).

Returns:Command data (length 0..255).
Return type:bytes
id

Get the command ID.

Returns:Command ID (0..255).
Return type:byte
max_response_time

Get the maximum response time for this command.

Returns:Maximum response time in seconds.
Return type:float
post_processing_time

Get the post processing time for this command. The post processing time defines how long a device needs to execute a command after responding to the SHDLC command. Most devices don’t need post processing (command is executed before the response is sent). Only special commands (e.g. a device reset) are executed after the response is sent.

Returns:Maximum response time in seconds.
Return type:float

Device Reset

class sensirion_shdlc_svm40.commands.device_reset.Svm40CmdDeviceResetBase(*args, **kwargs)[source]

SHDLC command 0xD3: “Device Reset”.

__init__(*args, **kwargs)[source]

Constructor.

check_response_length(data)

Check if the response length is correct.

Parameters:data (bytes) – Raw data (payload) received from the device.
Raises:ShdlcResponseError – If length is wrong.
data

Get the command data (payload).

Returns:Command data (length 0..255).
Return type:bytes
id

Get the command ID.

Returns:Command ID (0..255).
Return type:byte
interpret_response(data)

Interpret the response to this command received from the device. This converts the raw byte array to the actual data type(s) depending on the sent command.

Parameters:data (bytes) – Raw data (payload) received from the device.
Returns:Interpreted response. Data type and meaning depends on the sent command. None for commands without response data. See the actual command implementation for details.
max_response_time

Get the maximum response time for this command.

Returns:Maximum response time in seconds.
Return type:float
post_processing_time

Get the post processing time for this command. The post processing time defines how long a device needs to execute a command after responding to the SHDLC command. Most devices don’t need post processing (command is executed before the response is sent). Only special commands (e.g. a device reset) are executed after the response is sent.

Returns:Maximum response time in seconds.
Return type:float
class sensirion_shdlc_svm40.commands.device_reset.Svm40CmdDeviceReset[source]

Device Reset Command

Executs a reset on the device.

Note

The device will reply before executing the reset. If the command is send with broadcast, the reset is done directly after the reception of the command.

__init__()[source]

Constructor.

check_response_length(data)

Check if the response length is correct.

Parameters:data (bytes) – Raw data (payload) received from the device.
Raises:ShdlcResponseError – If length is wrong.
data

Get the command data (payload).

Returns:Command data (length 0..255).
Return type:bytes
id

Get the command ID.

Returns:Command ID (0..255).
Return type:byte
interpret_response(data)

Interpret the response to this command received from the device. This converts the raw byte array to the actual data type(s) depending on the sent command.

Parameters:data (bytes) – Raw data (payload) received from the device.
Returns:Interpreted response. Data type and meaning depends on the sent command. None for commands without response data. See the actual command implementation for details.
max_response_time

Get the maximum response time for this command.

Returns:Maximum response time in seconds.
Return type:float
post_processing_time

Get the post processing time for this command. The post processing time defines how long a device needs to execute a command after responding to the SHDLC command. Most devices don’t need post processing (command is executed before the response is sent). Only special commands (e.g. a device reset) are executed after the response is sent.

Returns:Maximum response time in seconds.
Return type:float

Get System Up Time

class sensirion_shdlc_svm40.commands.get_system_up_time.Svm40CmdGetSystemUpTimeBase(*args, **kwargs)[source]

SHDLC command 0x93: “Get System Up Time”.

__init__(*args, **kwargs)[source]

Constructor.

check_response_length(data)

Check if the response length is correct.

Parameters:data (bytes) – Raw data (payload) received from the device.
Raises:ShdlcResponseError – If length is wrong.
data

Get the command data (payload).

Returns:Command data (length 0..255).
Return type:bytes
id

Get the command ID.

Returns:Command ID (0..255).
Return type:byte
interpret_response(data)

Interpret the response to this command received from the device. This converts the raw byte array to the actual data type(s) depending on the sent command.

Parameters:data (bytes) – Raw data (payload) received from the device.
Returns:Interpreted response. Data type and meaning depends on the sent command. None for commands without response data. See the actual command implementation for details.
max_response_time

Get the maximum response time for this command.

Returns:Maximum response time in seconds.
Return type:float
post_processing_time

Get the post processing time for this command. The post processing time defines how long a device needs to execute a command after responding to the SHDLC command. Most devices don’t need post processing (command is executed before the response is sent). Only special commands (e.g. a device reset) are executed after the response is sent.

Returns:Maximum response time in seconds.
Return type:float
class sensirion_shdlc_svm40.commands.get_system_up_time.Svm40CmdGetSystemUpTime[source]

Get System Up Time Command

Get the system up time of the device.

__init__()[source]

Constructor.

static interpret_response(data)[source]
Returns:The time since the last power-on or device reset in seconds.
Return type:int
check_response_length(data)

Check if the response length is correct.

Parameters:data (bytes) – Raw data (payload) received from the device.
Raises:ShdlcResponseError – If length is wrong.
data

Get the command data (payload).

Returns:Command data (length 0..255).
Return type:bytes
id

Get the command ID.

Returns:Command ID (0..255).
Return type:byte
max_response_time

Get the maximum response time for this command.

Returns:Maximum response time in seconds.
Return type:float
post_processing_time

Get the post processing time for this command. The post processing time defines how long a device needs to execute a command after responding to the SHDLC command. Most devices don’t need post processing (command is executed before the response is sent). Only special commands (e.g. a device reset) are executed after the response is sent.

Returns:Maximum response time in seconds.
Return type:float

Firmware Update

class sensirion_shdlc_svm40.commands.firmware_update.Svm40CmdFirmwareUpdateBase(*args, **kwargs)[source]

SHDLC command 0xF3: “Firmware Update”.

__init__(*args, **kwargs)[source]

Constructor.

check_response_length(data)

Check if the response length is correct.

Parameters:data (bytes) – Raw data (payload) received from the device.
Raises:ShdlcResponseError – If length is wrong.
data

Get the command data (payload).

Returns:Command data (length 0..255).
Return type:bytes
id

Get the command ID.

Returns:Command ID (0..255).
Return type:byte
interpret_response(data)

Interpret the response to this command received from the device. This converts the raw byte array to the actual data type(s) depending on the sent command.

Parameters:data (bytes) – Raw data (payload) received from the device.
Returns:Interpreted response. Data type and meaning depends on the sent command. None for commands without response data. See the actual command implementation for details.
max_response_time

Get the maximum response time for this command.

Returns:Maximum response time in seconds.
Return type:float
post_processing_time

Get the post processing time for this command. The post processing time defines how long a device needs to execute a command after responding to the SHDLC command. Most devices don’t need post processing (command is executed before the response is sent). Only special commands (e.g. a device reset) are executed after the response is sent.

Returns:Maximum response time in seconds.
Return type:float
class sensirion_shdlc_svm40.commands.firmware_update.Svm40CmdEnterBootloader[source]

Enter Bootloader Command

Command to enter into the bootloader mode. The device will reboot into bootloader mode and wait until the new Firmware is received (start update command expected). Even after a power reset, the device returns into bootloader mode. The response frame is sent before the reset.

Note

After the response frame is received, the device will not accept new commands until fully booted (wait at least 1 s).

__init__()[source]

Constructor.

check_response_length(data)

Check if the response length is correct.

Parameters:data (bytes) – Raw data (payload) received from the device.
Raises:ShdlcResponseError – If length is wrong.
data

Get the command data (payload).

Returns:Command data (length 0..255).
Return type:bytes
id

Get the command ID.

Returns:Command ID (0..255).
Return type:byte
interpret_response(data)

Interpret the response to this command received from the device. This converts the raw byte array to the actual data type(s) depending on the sent command.

Parameters:data (bytes) – Raw data (payload) received from the device.
Returns:Interpreted response. Data type and meaning depends on the sent command. None for commands without response data. See the actual command implementation for details.
max_response_time

Get the maximum response time for this command.

Returns:Maximum response time in seconds.
Return type:float
post_processing_time

Get the post processing time for this command. The post processing time defines how long a device needs to execute a command after responding to the SHDLC command. Most devices don’t need post processing (command is executed before the response is sent). Only special commands (e.g. a device reset) are executed after the response is sent.

Returns:Maximum response time in seconds.
Return type:float
class sensirion_shdlc_svm40.commands.firmware_update.Svm40CmdStartUpdate[source]

Start Update Command

Command to start the firmware update. The devices flash will be erased (except bootloader) and the internal pointers resetted. The device is then ready to receive the new firmware with the update data command.

Note

Only supported when in bootloader mode.

__init__()[source]

Constructor.

check_response_length(data)

Check if the response length is correct.

Parameters:data (bytes) – Raw data (payload) received from the device.
Raises:ShdlcResponseError – If length is wrong.
data

Get the command data (payload).

Returns:Command data (length 0..255).
Return type:bytes
id

Get the command ID.

Returns:Command ID (0..255).
Return type:byte
interpret_response(data)

Interpret the response to this command received from the device. This converts the raw byte array to the actual data type(s) depending on the sent command.

Parameters:data (bytes) – Raw data (payload) received from the device.
Returns:Interpreted response. Data type and meaning depends on the sent command. None for commands without response data. See the actual command implementation for details.
max_response_time

Get the maximum response time for this command.

Returns:Maximum response time in seconds.
Return type:float
post_processing_time

Get the post processing time for this command. The post processing time defines how long a device needs to execute a command after responding to the SHDLC command. Most devices don’t need post processing (command is executed before the response is sent). Only special commands (e.g. a device reset) are executed after the response is sent.

Returns:Maximum response time in seconds.
Return type:float
class sensirion_shdlc_svm40.commands.firmware_update.Svm40CmdUpdateData(data)[source]

Update Data Command

Command to send the new firmware data as hex code in binary format.

Note

Only supported when in bootloader mode after receiving the start update command. Send even number of bytes except for the last frame.

__init__(data)[source]

Constructor.

Parameters:data (bytes) – Firmware hex data in binary format.
check_response_length(data)

Check if the response length is correct.

Parameters:data (bytes) – Raw data (payload) received from the device.
Raises:ShdlcResponseError – If length is wrong.
data

Get the command data (payload).

Returns:Command data (length 0..255).
Return type:bytes
id

Get the command ID.

Returns:Command ID (0..255).
Return type:byte
interpret_response(data)

Interpret the response to this command received from the device. This converts the raw byte array to the actual data type(s) depending on the sent command.

Parameters:data (bytes) – Raw data (payload) received from the device.
Returns:Interpreted response. Data type and meaning depends on the sent command. None for commands without response data. See the actual command implementation for details.
max_response_time

Get the maximum response time for this command.

Returns:Maximum response time in seconds.
Return type:float
post_processing_time

Get the post processing time for this command. The post processing time defines how long a device needs to execute a command after responding to the SHDLC command. Most devices don’t need post processing (command is executed before the response is sent). Only special commands (e.g. a device reset) are executed after the response is sent.

Returns:Maximum response time in seconds.
Return type:float
class sensirion_shdlc_svm40.commands.firmware_update.Svm40CmdStopUpdate(checksum)[source]

Stop Update Command

After all update data frames are sent, the stop update marks the end of the update sequence. The checksum is sent to the device and verification is done. The device state represents the success of the update sequence. If successfully, the device writes the signature and reboots into the application.

Note

The checksum is calculated the same way as the SHDLC checksum. First sum all firmware update data bytes and then take the LSB of the result and invert it. This will be the checksum.

__init__(checksum)[source]

Constructor.

Parameters:checksum (int) – Checksum of the firmware data.
check_response_length(data)

Check if the response length is correct.

Parameters:data (bytes) – Raw data (payload) received from the device.
Raises:ShdlcResponseError – If length is wrong.
data

Get the command data (payload).

Returns:Command data (length 0..255).
Return type:bytes
id

Get the command ID.

Returns:Command ID (0..255).
Return type:byte
interpret_response(data)

Interpret the response to this command received from the device. This converts the raw byte array to the actual data type(s) depending on the sent command.

Parameters:data (bytes) – Raw data (payload) received from the device.
Returns:Interpreted response. Data type and meaning depends on the sent command. None for commands without response data. See the actual command implementation for details.
max_response_time

Get the maximum response time for this command.

Returns:Maximum response time in seconds.
Return type:float
post_processing_time

Get the post processing time for this command. The post processing time defines how long a device needs to execute a command after responding to the SHDLC command. Most devices don’t need post processing (command is executed before the response is sent). Only special commands (e.g. a device reset) are executed after the response is sent.

Returns:Maximum response time in seconds.
Return type:float