API Reference

ShdlcSerialFrameBuilder

class sensirion_shdlc_driver.serial_frame_builder.ShdlcSerialFrameBuilder[source]

Base class for ShdlcSerialMosiFrameBuilder and ShdlcSerialMisoFrameBuilder.

__init__()[source]

Constructor.

class sensirion_shdlc_driver.serial_frame_builder.ShdlcSerialMosiFrameBuilder(slave_address, command_id, data)[source]

Serial MOSI (master out, slave in) frame builder.

This class allows to convert structured data (slave address, command ID etc.) into the raw bytes which are then sent to the serial port.

__init__(slave_address, command_id, data)[source]

Constructor.

Parameters:
  • slave_address (byte) – Slave address.
  • command_id (byte) – Command ID.
  • data (bytes-like) – Payload (can be empty).
to_bytes()[source]

Convert the structured data from the constructor to raw bytes.

Returns:The raw data which can be sent to the serial port.
Return type:bytes
class sensirion_shdlc_driver.serial_frame_builder.ShdlcSerialMisoFrameBuilder[source]

Serial MISO (master in, slave sout) frame builder.

This class allows to convert raw bytes received from the serial port into structured data (slave address, command ID etc.).

__init__()[source]

Constructor.

data

Get the received data.

Returns:The received data.
Return type:bytearray
start_received

Check if the start byte was already received.

Returns:Whether the start byte was already received or not.
Return type:bool
add_data(data)[source]

Add more data (received from the serial port) and check if a complete frame is received.

Parameters:data (bytes-like) – The bytes received from the serial port.
Returns:Whether the received data contains a complete frame or not.
Return type:bool
interpret_data()[source]

Interpret and validate received raw data and return it.

Returns:Received address, command_id, state, and payload.
Return type:byte, byte, byte, bytes

ShdlcPort

class sensirion_shdlc_driver.port.ShdlcPort[source]

Common interface for all communication ports for transceiving SHDLC frames.

Concrete implementations may use the serial port or another interface for transceiving SHDLC frames. All methods must be implemented thread-safe, i.e. allowing them to be called from multiple threads at the same time.

description

Get a description of the port.

Returns:Description string.
Return type:string
bitrate

The current bitrate in bit/s.

Type:int
lock

Get the lock object of the port to allow locking it, i.e. to get exclusive access across multiple method calls.

Returns:The lock object.
Return type:threading.RLock
is_open

Indicates whether the port is open.

Returns:If True the port is open, if False the port is closed.
Return type:bool
open()[source]

Open the port. Only needs to be called if the port is not already opened. Does nothing if the port is already opened.

close()[source]

Close the port to release the underlying resources. Does nothing if the port is already closed.

transceive(slave_address, command_id, data, response_timeout)[source]

Send SHDLC frame to port and return received response frame.

Note

The specified response timeout defines the maximum time the device needs until it starts to send the response after receiving the last byte from the master request. The time needed for the transmission itself and other possible overhead or delays depends on hardware, drivers, bitrate etc. and must be taken into account in the implementation of this method.

Parameters:
  • slave_address (byte) – Slave address.
  • command_id (byte) – SHDLC command ID.
  • data (bytes-like) – Payload.
  • response_timeout (float) – Response timeout in seconds (maximum time until the first byte is received).
Returns:

Received address, command_id, state, and payload.

Return type:

byte, byte, byte, bytes

Raises:
class sensirion_shdlc_driver.port.ShdlcSerialPort(port, baudrate, additional_response_time=0.1, do_open=True)[source]

SHDLC transceiver for the serial port (e.g. UART/RS232/RS485).

This class implements the ShdlcPort interface for the serial port.

Note

This class can be used in a “with”-statement, and it’s recommended to do so as it automatically closes the port after using it.

__init__(port, baudrate, additional_response_time=0.1, do_open=True)[source]

Create and optionally open a serial port. Throws an exception if the port cannot be opened.

Parameters:
  • port (string) – The serial port (e.g. “COM2” or “/dev/ttyUSB0”)
  • baudrate (int) – The baudrate in bit/s.
  • additional_response_time (float) – Additional response time (in Seconds) used when receiving frames. See property additional_response_time for details. Defaults to 0.1 (i.e. 100ms) which should be enough in most cases.
  • do_open (bool) – Whether the serial port should be opened immediately or not. If False, you will have to call open() manually before using this object. Defaults to True.
description

Get a description of the port.

Returns:Description string.
Return type:string
bitrate

The current bitrate in bit/s.

Type:int
additional_response_time

The additional response time (in Seconds) used when receiving frames.

Since the timeout measurement of serial communication is typically very inaccurate (e.g. USB-UART converter drivers often buffer I/O data for 16ms), this class adds some extra time to the specified response timeout to avoid timeout errors even if the device responded within the given timeout. If needed, this extra time can be changed either with this property, or with the parameter additional_response_time of __init__().

Type:float
lock

Get the lock object of the port to allow locking it, i.e. to get exclusive access across multiple method calls.

Returns:The lock object.
Return type:threading.RLock
is_open

Indicates whether the port is open.

Returns:If True the port is open, if False the port is closed.
Return type:bool
open()[source]

Open the serial port (only needs to be called if do_open in __init__() was set to False). Does nothing if the port is already opened.

close()[source]

Close (release) the serial port. Does nothing if the port is already closed.

transceive(slave_address, command_id, data, response_timeout)[source]

Send SHDLC frame to port and return received response frame.

Parameters:
  • slave_address (byte) – Slave address.
  • command_id (byte) – SHDLC command ID.
  • data (bytes-like) – Payload.
  • response_timeout (float) – Response timeout in seconds (maximum time until the first byte is received).
Returns:

Received address, command_id, state, and payload.

Return type:

byte, byte, byte, bytes

Raises:
class sensirion_shdlc_driver.port.ShdlcTcpPort(ip, port, socket_timeout=5.0, do_open=True)[source]

SHDLC transceiver for a TCP/IP port in client connection mode.

This class implements the ShdlcPort interface for a client connection on a TCP/IP port.

Note

This class can be used in a “with”-statement, and it’s recommended to do so as it automatically closes the port after using it.

__init__(ip, port, socket_timeout=5.0, do_open=True)[source]

Create and optionally open a TCP socket. Throws an exception if the socket cannot be opened.

Parameters:
  • ip (string) – The IP address (e.g. “192.168.100.200”).
  • port (int) – The TCP port.
  • socket_timeout (float) – General TCP socket base timeout. Upon data transmission, the socket timeout is adjusted for each command, i.e. the timeout is increased with the parameter response_timeout of transceive().
  • do_open (bool) – Whether the port should be opened immediately or not. If False, you will have to call open() manually before using this object. Defaults to True.
description

Get the description of the TCP socket (address and port).

Returns:Description string.
Return type:string
socket_timeout

The base timeout of the TCP socket (in seconds) during transmission.

The actual socket timeout is adjusted for each command. There are commands (e.g. flash erase) which require several seconds to be successfully executed. Therefore, the actual socket timeout value is calculated by the sum of the base timeout, plus the parameter response_timeout of transceive().

Type:float
lock

Get the lock object of the port to allow locking it, i.e. to get exclusive access across multiple method calls.

Returns:The lock object.
Return type:threading.RLock
is_open

Indicates whether the port is open.

Returns:If True the port is open, if False the port is closed.
Return type:bool
open()[source]

Open the TCP socket (only needs to be called if do_open in __init__() was set to False). Does nothing if the socket is already opened.

close()[source]

Close the TCP socket. Does nothing if the socket is already closed.

transceive(slave_address, command_id, data, response_timeout)[source]

Send SHDLC frame to the TCP socket and return received response frame.

Parameters:
  • slave_address (byte) – Slave address.
  • command_id (byte) – SHDLC command ID.
  • data (bytes-like) – Payload.
  • response_timeout (float) – Response timeout in seconds. The actual command response timeout is defined by the sum of this parameter and the socket base timeout.
Returns:

Received address, command_id, state, and payload.

Return type:

byte, byte, byte, bytes

Raises:

ShdlcConnection

class sensirion_shdlc_driver.connection.ShdlcConnection(port)[source]

This class represents the connection to an SHDLC bus. So you need to instantiate one object per bus, no matter how many devices are connected to that bus system.

The basic functionality of the class is to send SHDLC frames to devices and receive their response. Handling of communication errors (e.g. timeout or checksum errors) and device errors is done in this class.

__init__(port)[source]

Open an SHDLC connection on a specific port.

Note

This constructor does not send or receive any data to resp. from the specified port.

Parameters:port (ShdlcPort) – The port used for communication (must implement the ShdlcPort interface)
port

Get the underlying port.

Returns:An ShdlcPort object.
Return type:ShdlcPort
execute(slave_address, command, wait_post_process=True)[source]

Execute an ShdlcCommand and return the interpreted response. Executing a command means:

  • Send request (MOSI) frame
  • Receive response (MISO) frame
  • Validate and interpret response data
  • Wait until post processing is done (optional, and only if needed)
Parameters:
  • slave_address (byte) – Slave address.
  • command (ShdlcCommand) – SHDLC command to execute.
  • wait_post_process (bool) – If true and the command needs some time for post processing, this thread blocks until post processing is done.
Returns:

Received response (interpreted) and error state flag.

Return type:

object, bool

transceive(slave_address, command_id, data, response_timeout)[source]

Send a raw SHDLC command and return the received raw response.

Parameters:
  • slave_address (byte) – Slave address.
  • command_id (byte) – SHDLC command ID.
  • data (bytes-like) – Payload (may be empty).
  • response_timeout (float) – Response timeout in seconds (maximum time until the first byte is received).
Returns:

Received response payload and error state flag.

Return type:

bytes, bool

ShdlcDevice

class sensirion_shdlc_driver.device_base.ShdlcDeviceBase(connection, slave_address)[source]

Base class for all SHDLC devices, providing only the basic functionality without implementing any SHDLC commands. The main purpose of this class is to allow derived classes to register their device-specific errors and to allow executing SHDLC commands.

__init__(connection, slave_address)[source]

Create an SHDLC 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.
connection

Get the used SHDLC connection.

Returns:The used SHDLC connection.
Return type:ShdlcConnection
slave_address

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

Returns:The slave address.
Return type:byte
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
execute(command)[source]

Execute an SHDLC command.

Parameters:command (ShdlcCommand) – The command to execute.
Returns:The interpreted response of the executed command.
class sensirion_shdlc_driver.device.ShdlcDevice(connection, slave_address)[source]

Generic SHDLC device, providing only common SHDLC commands. This class is intended only to communicate with devices which do not provide a corresponding device driver (yet). With this class you can for example read the serial number of a device even if no device specific driver exists. But if there exists a device specific driver, you should always use it instead of this driver.

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 SHDLC 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.
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_subtype()[source]

Get the product subtype. Some product types exist in multiple slightly different variants, this command allows to determine the exact variant of the connected device. Sometimes this is called “device subtype”.

Note

This command is not supported by every product type.

Returns:The product subtype as a byte (the interpretation depends on the connected product type).
Return type:byte
get_product_name()[source]

Get the product name of the device.

Note

This command is not supported by every product type.

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

Get the article code of the device.

Note

This command is not supported by every product type.

Returns:The article code 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_error_state(clear=True, as_exception=False)[source]

Get and optionally clear the device error state and the last error. The state and error code interpretation depends on the connected device type.

Parameters:
  • clear (bool) – If True, the error state on the device gets cleared.
  • as_exception (bool) – If True, the error state is returned as an ShdlcDeviceError object instead of a byte.
Returns:

The device state as a 32-bit unsigned integer containing all error flags, and the last error which occurred on the device. If as_exception is True, it’s returned as an ShdlcDeviceError object or None, otherwise as a byte.

Return type:

int, byte/ShdlcDeviceError/None

get_slave_address()[source]

Get the SHDLC slave address of the device.

Note

See also the property slave_address which returns the device’s slave address without sending a command. This method really sends a command to the device, even though the slave address is actually already known by this object.

Returns:The slave address of the device.
Return type:byte
set_slave_address(slave_address, update_driver=True)[source]

Set the SHDLC slave address of the device.

Note

The slave address is stored in non-volatile memory of the device and thus persists after a device reset. So the next time connecting to the device, you have to use the new address.

Warning

When changing the address of a slave, make sure there isn’t already a slave with that address on the same bus! In that case you would get communication issues which can only be fixed by disconnecting one of the slaves.

Parameters:
  • slave_address (byte) – The new slave address [0..254]. The address 255 is reserved for broadcasts.
  • update_driver (bool) – If True, the property slave_address of this object is also updated with the new address. This is needed to allow further communication with the device, as its address has changed.
get_baudrate()[source]

Get the SHDLC baudrate of the device.

Note

This method really sends a command to the device, even though the baudrate is already known by the used ShdlcPort object.

Returns:The baudrate of the device [bit/s].
Return type:int
set_baudrate(baudrate, update_driver=True)[source]

Set the SHDLC baudrate of the device.

Note

The baudrate is stored in non-volatile memory of the device and thus persists after a device reset. So the next time connecting to the device, you have to use the new baudrate.

Warning

If you pass True to the argument update_driver, the baudrate of the underlaying ShdlcPort object is changed. As the baudrate applies to the whole bus (with all its slaves), you might no longer be able to communicate with other slaves. Generally you should change the baudrate of all slaves consecutively, and only set update_driver to True the last time.

Parameters:
  • baudrate (int) – The new baudrate. See device documentation for a list of supported baudrates. Many devices support the baudrates 9600, 19200 and 115200.
  • update_driver (bool) – If true, the baudrate of the ShdlcPort object is also updated with the baudrate. This is needed to allow further communication with the device, as its baudrate has changed.
get_reply_delay()[source]

Get the SHDLC reply delay of the device.

See set_reply_delay() for details.

Returns:The reply delay of the device [μs].
Return type:byte
set_reply_delay(reply_delay)[source]

Set the SHDLC reply delay of the device.

The reply delay allows to increase the minimum response time of the slave to a given value in Microseconds. This is needed for RS485 masters which require some time to switch from sending to receiving. If the slave starts sending the response while the master is still driving the bus lines, a conflict on the bus occurs and communication fails. If you use such a slow RS485 master, you can increase the reply delay of all slaves to avoid this issue.

Parameters:reply_delay (byte) – The new reply delay [μs].
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).

factory_reset()[source]

Perform a factory reset (restore the off-the-shelf factory configuration).

Warning

This resets any configuration done after leaving the factory! Keep in mind that this command might also change communication parameters (i.e. baudrate and slave address) and thus you might have to adjust the driver’s parameters to allow further communication with the device.

ShdlcFirmwareImage

class sensirion_shdlc_driver.firmware_image.ShdlcFirmwareImage(hexfile, bl_start_addr, app_start_addr, signature=b'JGOK', bl_version_offset=4100)[source]

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

Since the different SHDLC devices use different memory layouts, this class needs to know the bootloader base address and application base address (see constructor parameters). Drivers for specific SHDLC devices should create a subclass to provide a new type which already contains the correct addresses, so users don’t have to care about these details.

Note

This class is intended only for devices which contain the SHDLC bootloader. Devices which support firmware updates with another system aren’t supported by this class.

Note

The package intelhex must be installed to use this class. See Firmware Updater Dependencies for details.

__init__(hexfile, bl_start_addr, app_start_addr, signature=b'JGOK', bl_version_offset=4100)[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).
  • bl_start_addr (int) – The base address of the bootloader inside the firmware image.
  • app_start_addr (int) – The base address of the application inside the firmware image.
  • signature (bytes) – Signature bytes used for the application.
  • bl_version_offset (int) – Bootloader version address offset.
Raises:

ShdlcFirmwareImageSignatureError – If the signature of the image is invalid.

product_type

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

Returns:Product type as an integer.
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
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
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
size

Get the size of the application firmware.

Returns:Size in bytes.
Return type:int
available_bytes

Get the count of available bytes left.

Returns:Count of available bytes.
Return type:int
read(size=-1)[source]

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

ShdlcFirmwareUpdate

class sensirion_shdlc_driver.firmware_update.ShdlcFirmwareUpdate(device, image, status_callback=None, progress_callback=None)[source]

Helper class to perform firmware updates over SHDLC.

Note

Device-specific drivers should provide a simple wrapper method to easily perform firmware updates. So usually you don’t have to use this class directly.

__init__(device, image, status_callback=None, progress_callback=None)[source]

Constructor.

Parameters:
  • device (ShdlcDevice) – The device to update.
  • image (ShdlcFirmwareImage) – The image to flash.
  • status_callback (callable) – Optional callback for status report, taking a string as parameter.
  • progress_callback (callable) – Optional callback for progress report, taking a float (progress in percent) as parameter.
execute(emergency=False)[source]

Perform 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:

emergency (bool) – Must be set to True if the device is already in bootloader mode, False otherwise.

Raises:

ShdlcCommand

class sensirion_shdlc_driver.command.ShdlcCommand(id, data, max_response_time, min_response_length=0, max_response_length=255, post_processing_time=0.0)[source]

Base class for all SHDLC commands.

__init__(id, data, max_response_time, min_response_length=0, max_response_length=255, post_processing_time=0.0)[source]

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
id

Get the command ID.

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

Get the command data (payload).

Returns:Command data (length 0..255).
Return type:bytes
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
check_response_length(data)[source]

Check if the response length is correct.

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

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.
class sensirion_shdlc_driver.commands.baudrate.ShdlcCmdBaudrateBase(*args, **kwargs)[source]

SHDLC command 0x91: “Get/Set Baudrate”.

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

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
class sensirion_shdlc_driver.commands.baudrate.ShdlcCmdSetBaudrate(baudrate)[source]
__init__(baudrate)[source]

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
class sensirion_shdlc_driver.commands.baudrate.ShdlcCmdGetBaudrate[source]
__init__()[source]

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
interpret_response(data)[source]
Return int:Baudrate [bit/s].
class sensirion_shdlc_driver.commands.bootloader.ShdlcCmdBootloaderBase(*args, **kwargs)[source]

SHDLC command 0xF3: “Bootloader”.

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

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
class sensirion_shdlc_driver.commands.bootloader.ShdlcCmdEnterBootloader[source]
__init__()[source]

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
class sensirion_shdlc_driver.commands.bootloader.ShdlcCmdFirmwareUpdateStart[source]
__init__()[source]

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
class sensirion_shdlc_driver.commands.bootloader.ShdlcCmdFirmwareUpdateData(data)[source]
__init__(data)[source]

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
class sensirion_shdlc_driver.commands.bootloader.ShdlcCmdFirmwareUpdateStop(checksum)[source]
__init__(checksum)[source]

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
class sensirion_shdlc_driver.commands.device_info.ShdlcCmdDeviceInfoBase(*args, **kwargs)[source]

SHDLC command 0xD0: “Device Information”.

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

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
class sensirion_shdlc_driver.commands.device_info.ShdlcCmdGetProductType[source]
__init__()[source]

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
interpret_response(data)[source]

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.
class sensirion_shdlc_driver.commands.device_info.ShdlcCmdGetProductName[source]
__init__()[source]

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
interpret_response(data)[source]

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.
class sensirion_shdlc_driver.commands.device_info.ShdlcCmdGetArticleCode[source]
__init__()[source]

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
interpret_response(data)[source]

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.
class sensirion_shdlc_driver.commands.device_info.ShdlcCmdGetSerialNumber[source]
__init__()[source]

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
interpret_response(data)[source]

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.
class sensirion_shdlc_driver.commands.device_info.ShdlcCmdGetProductSubType[source]
__init__()[source]

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
interpret_response(data)[source]

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.
class sensirion_shdlc_driver.commands.device_reset.ShdlcCmdDeviceResetBase(*args, **kwargs)[source]

SHDLC command 0xD3: “Device Reset”.

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

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
class sensirion_shdlc_driver.commands.device_reset.ShdlcCmdDeviceReset[source]
__init__()[source]

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
class sensirion_shdlc_driver.commands.device_version.ShdlcCmdDeviceVersionBase(*args, **kwargs)[source]

SHDLC command 0xD1: “Get Version”.

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

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
class sensirion_shdlc_driver.commands.device_version.ShdlcCmdGetVersion[source]
__init__()[source]

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
interpret_response(data)[source]

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.
class sensirion_shdlc_driver.commands.error_state.ShdlcCmdErrorStateBase(*args, **kwargs)[source]

SHDLC command 0xD2: “Device Error State”.

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

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
class sensirion_shdlc_driver.commands.error_state.ShdlcCmdGetErrorState(clear)[source]
__init__(clear)[source]

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
interpret_response(data)[source]
Return int, byte:
 Device state (32 flags as integer) and the last error (byte) which occurred on the device.
class sensirion_shdlc_driver.commands.factory_reset.ShdlcCmdFactoryResetBase(*args, **kwargs)[source]

SHDLC command 0x92: “Factory Reset”.

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

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
class sensirion_shdlc_driver.commands.factory_reset.ShdlcCmdFactoryReset[source]
__init__()[source]

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
class sensirion_shdlc_driver.commands.reply_delay.ShdlcCmdReplyDelayBase(*args, **kwargs)[source]

SHDLC command 0x95: “Get/Set Reply Delay”.

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

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
class sensirion_shdlc_driver.commands.reply_delay.ShdlcCmdSetReplyDelay(reply_delay)[source]
__init__(reply_delay)[source]

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
class sensirion_shdlc_driver.commands.reply_delay.ShdlcCmdGetReplyDelay[source]
__init__()[source]

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
interpret_response(data)[source]
Return byte:Reply delay [μs].
class sensirion_shdlc_driver.commands.slave_address.ShdlcCmdSlaveAddressBase(*args, **kwargs)[source]

SHDLC command 0x90: “Get/Set Slave Address”.

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

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
class sensirion_shdlc_driver.commands.slave_address.ShdlcCmdSetSlaveAddress(slave_address)[source]
__init__(slave_address)[source]

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
class sensirion_shdlc_driver.commands.slave_address.ShdlcCmdGetSlaveAddress[source]
__init__()[source]

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
interpret_response(data)[source]
Return byte:Slave address.
class sensirion_shdlc_driver.commands.system_up_time.ShdlcCmdSystemUpTimeBase(*args, **kwargs)[source]

SHDLC command 0x93: “System Up Time”.

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

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
class sensirion_shdlc_driver.commands.system_up_time.ShdlcCmdGetSystemUpTime[source]
__init__()[source]

Constructor.

Parameters:
  • id (byte) – Command ID (0..255).
  • data (bytes-like/list) – MOSI data (0..255 bytes).
  • max_response_time (float) – Maximum time the device needs to response (used as timeout).
  • min_response_length (byte) – Minimum expected response length.
  • max_response_length (byte) – Maximum expected response length.
  • post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
interpret_response(data)[source]
Return int:System up time [s].

Types

class sensirion_shdlc_driver.types.FirmwareVersion(major, minor, debug)[source]

Class representing the firmware version of an SHDLC device.

__init__(major, minor, debug)[source]

Constructor.

Parameters:
  • major (byte) – Major version (0..255).
  • minor (byte) – Minor version (0..99).
  • debug (bool) – Debug flag (False for official releases).
__str__()[source]

Return str(self).

class sensirion_shdlc_driver.types.HardwareVersion(major, minor)[source]

Class representing the hardware version of an SHDLC device.

__init__(major, minor)[source]

Constructor.

Parameters:
  • major (byte) – Major version (0..255).
  • minor (byte) – Minor version (0..99).
__str__()[source]

Return str(self).

class sensirion_shdlc_driver.types.ProtocolVersion(major, minor)[source]

Class representing the SHDLC protocol version of an SHDLC device.

__init__(major, minor)[source]

Constructor.

Parameters:
  • major (byte) – Major version (0..255).
  • minor (byte) – Minor version (0..99).
__str__()[source]

Return str(self).

class sensirion_shdlc_driver.types.Version(firmware, hardware, protocol)[source]

Class representing all version numbers of an SHDLC device. This is used for the “Get Version” command.

__init__(firmware, hardware, protocol)[source]

Constructor.

Parameters:
__str__()[source]

Return str(self).

Exceptions

Inheritance diagram of sensirion_shdlc_driver.errors
exception sensirion_shdlc_driver.errors.ShdlcError[source]

Base class for all SHDLC related exceptions.

exception sensirion_shdlc_driver.errors.ShdlcFirmwareImageSignatureError(signature)[source]

SHDLC firmware image signature error.

__init__(signature)[source]

Constructor.

Parameters:signature (bytes) – Firmware image signature.
exception sensirion_shdlc_driver.errors.ShdlcFirmwareImageIncompatibilityError(image_type, device_type)[source]

SHDLC firmware image incompatibility error.

__init__(image_type, device_type)[source]

Constructor.

Parameters:
  • image_type (int) – Device type of the firmware image.
  • device_type (int) – Device type of the connected device.
exception sensirion_shdlc_driver.errors.ShdlcTimeoutError[source]

SHDLC timeout exception (device did not respond to command).

__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

exception sensirion_shdlc_driver.errors.ShdlcResponseError(message, received_data=None)[source]

SHDLC response error (slave response contains invalid data)

__init__(message, received_data=None)[source]

Constructor.

Parameters:
  • message (string) – Error message.
  • received_data – The received (invalid) raw data.
received_data

Get the (invalid) raw data which was received from the device.

Returns:The raw data received from the device.
Return type:bytes
exception sensirion_shdlc_driver.errors.ShdlcDeviceError(code, message='Unknown error.')[source]

SHDLC device error (communication was successful, but slave failed to execute a command). For each error code a subclass exists to provide the corresponding error messages.

__init__(code, message='Unknown error.')[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
exception sensirion_shdlc_driver.errors.ShdlcCommandDataSizeError[source]

SHDLC device error for wrong data size.

__init__()[source]

Constructor.

Parameters:
  • code (byte) – The error code received from the device.
  • message (string) – The error description for the given error code.
exception sensirion_shdlc_driver.errors.ShdlcUnknownCommandError[source]

SHDLC device error for unknown command.

__init__()[source]

Constructor.

Parameters:
  • code (byte) – The error code received from the device.
  • message (string) – The error description for the given error code.
exception sensirion_shdlc_driver.errors.ShdlcAccessRightError[source]

SHDLC device error for wrong access right.

__init__()[source]

Constructor.

Parameters:
  • code (byte) – The error code received from the device.
  • message (string) – The error description for the given error code.
exception sensirion_shdlc_driver.errors.ShdlcCommandParameterError[source]

SHDLC device error for illegal command parameter.

__init__()[source]

Constructor.

Parameters:
  • code (byte) – The error code received from the device.
  • message (string) – The error description for the given error code.
exception sensirion_shdlc_driver.errors.ShdlcChecksumError[source]

SHDLC device error for wrong checksum.

__init__()[source]

Constructor.

Parameters:
  • code (byte) – The error code received from the device.
  • message (string) – The error description for the given error code.
exception sensirion_shdlc_driver.errors.ShdlcFirmwareUpdateError[source]

SHDLC device error for firmware update failure.

__init__()[source]

Constructor.

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