API Reference¶
SensorBridgeShdlcDevice¶
-
class
sensirion_shdlc_sensorbridge.device.
SensorBridgeShdlcDevice
(connection, slave_address)[source]¶ SEK-SensorBridge 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 a SensorBridge 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 SEK-SensorBridge is 0.
-
blink_led
(port)[source]¶ Let the LEDs on the device blink. Useful for example to identify the device on a bus.
Parameters: port (SensorBridgePort) – The port(s) which should blink.
-
measure_voltage
(port)[source]¶ Triggers an analog measurement at the AIN pin. The measured voltage is always positive and in the range of 0-5.5V.
Parameters: port (SensorBridgePort) – The port where the measurement should be executed. Note that ALL
is not supported here.Returns: Measured voltage in Volts. Return type: float
-
set_supply_voltage
(port, voltage)[source]¶ Sets the supply voltage of a port to a certain value.
Parameters: - port (SensorBridgePort) – The port(s) where the voltage should be set.
- voltage (int/float) – The voltage to set in Volts. See
VOLTAGES
for the list of supported values.
-
switch_supply_on
(port)[source]¶ Switches a port supply on. The previously set voltage will be applied.
Parameters: port (SensorBridgePort) – The port(s) to switch on.
-
switch_supply_off
(port)[source]¶ Switches a port supply off.
Parameters: port (SensorBridgePort) – The port(s) to switch off.
-
set_i2c_frequency
(port, frequency)[source]¶ Sets the I2C frequency to the desired value. The default frequency is 400kHz.
Parameters: - port (SensorBridgePort) – The port(s) where the frequency should be set.
- frequency (int/float) – The frequency to set in Hz (e.g. 400’000 for 400kHz). See
I2C_FREQUENCIES
for the list of supported values.
-
scan_i2c
(port, first_address=1, last_address=127)[source]¶ Scans for I2C devices on a specific port within a certain address range.
Parameters: - port (SensorBridgePort) – The port where the scan should be executed. Note that
ALL
is not supported here. - first_address (byte) – First address to scan (1..127), defaults to 1.
- last_address (byte) – Last address to scan (1..127 and >= first address), defaults to 127.
Returns: List of addresses which responded to the scan. Empty list if no device responded.
Return type: list of byte
- port (SensorBridgePort) – The port where the scan should be executed. Note that
-
transceive_i2c
(port, address, tx_data, rx_length, timeout_us)[source]¶ Transceives an I2C frame on a certain port.
Note
If an I2C error (NACK or timeout) occured, this method raises an exception. So the returned RX data is guaranteed to be valid in terms of there was no I2C communication issue.
Parameters: - port (SensorBridgePort) – The port where the transceive should be executed. Note that
ALL
is not supported here. - address (byte) – I2C address of the targeted device.
- tx_data (bytes-like/list) – Raw data (bytes) to send. Pass an empty list or bytes-like object if no write operation is needed.
- rx_length (int) – Number of bytes to receive.
- timeout_us (int/float) – I2C timeout (in Microseconds) when reading bytes. If a frame is NACK’d it will be retried up to the timeout value. Same applies for clock stretching. Note that floats can be passes for convenience, they will be casted to integer internally.
Returns: Received data from the I2C read operation. Empty bytes if no data was read.
Return type: bytes
- port (SensorBridgePort) – The port where the transceive should be executed. Note that
-
start_repeated_i2c_transceive
(port, interval_us, address, tx_data, rx_length, timeout_us, read_delay_us=0)[source]¶ Starts an asynchronous I2C transceive command in a specific interval. Multiple parallel repeated transceives are possible. The returned data is stored in a buffer and can be read out with the
read_buffer()
method.Note
This method returns a handle for each repeated transceive operation. You have to store these handles since they are needed to fetch the received data with
read_buffer()
and to stop the transceive withstop_repeated_i2c_transceive()
.Parameters: - port (SensorBridgePort) – The port(s) where the repeated transceive should be started.
- interval_us (int/float) – The interval in Microseconds. Note that floats can be passes for convenience, they will be casted to integer internally.
- address (byte) – I2C address of the targeted device.
- tx_data (bytes-like/list) – Raw data (bytes) to send. Pass an empty list or bytes-like object if no write operation is needed.
- rx_length (int) – Number of bytes to receive. Set to zero if no read operation is needed.
- timeout_us (int/float) – I2C timeout (in Microseconds) when reading bytes. If a frame is NACK’d it will be retried up to the timeout value. Same applies for clock stretching. Note that floats can be passes for convenience, they will be casted to integer internally.
- read_delay_us (int/float) – This time (in Microseconds) will be inserted between the write and the read frame to allow a device taking a certain amount of time for its measurements. The delay must be smaller than the specified timeout. Defaults to 0, i.e. no delay is inserted. Note that floats can be passes for convenience, they will be casted to integer internally.
Returns: Either one handle or two handles for the started transceive operations, depending on whether the transceive was started on a single channel or on both channels. If
ALL
was passed as port, a tuple of two handles is returned.Return type: RepeatedTransceiveHandle
or a tuple of it
-
stop_repeated_i2c_transceive
(handle=None)[source]¶ Stops a repeated transceive operation.
Parameters: handle (RepeatedTransceiveHandle) – The handle of the repeated transceive which should be stopped (the object which was returned by start_repeated_i2c_transceive()
). Pass None (the default) to stop all active repeated transceives.
-
read_buffer
(handle, max_reads=100)[source]¶ Reads data stored in the buffer of a repeated transceive.
This method sends “read buffer” commands to the device until the whole buffer was read out (since the SHDLC frame length is limited, it’s not possible to read out the whole buffer with a single command). The received values will automatically be removed from the buffer in the device, so you will only get the values received since the last call to this method.
Warning
If you call this method too rarely, the buffer in the device will overrun, i.e. the oldest values are lost. You should check for lost values by reading the property
lost_bytes
of the returned object. This method does not raise an exception if there are values lost since depending on the use-case, this might be expected behavior.Note
If the buffer gets filled faster than you read it out, it’s not possible to read out the whole buffer. In that case, the property
remaining_bytes
of the returned object will hold a value greater than zero. You might want to check this property to be sure the whole buffer was read out. However, often that’s not needed since sooner or later you will also get a buffer overrun in this situation.Note
This method doesn’t raise an exception if there occurred I2C errors (e.g. NACK or timeout) in the transceived I2C frames because this might be expected behavior in some cases. In addition, if only some of the frames contain errors, probably you still want to get all the valid frames. See documentation of
BufferedValue
to see how to get exceptions in case of I2C errors.Parameters: - handle (RepeatedTransceiveHandle) – The handle of the repeated transceive from which the data should be
returned (the object which was returned by
start_repeated_i2c_transceive()
). - max_reads (int) – The maximum count of read commands which should be sent until the read operation will be aborted. This abort condition is needed to avoid an infinite loop if the buffer gets filled faster than it can be read out.
Returns: A buffer object containing some metadata and the buffered data received from the I2C device. See
ReadBufferResponse
for details.Return type: - handle (RepeatedTransceiveHandle) – The handle of the repeated transceive from which the data should be
returned (the object which was returned by
-
set_spi_config
(port, mode, frequency)[source]¶ Sets the SPI mode and frequency.
Parameters: - port (SensorBridgePort) – The port(s) which should be configured.
- mode (byte) – The SPI mode to use. Allowed values are [0, 1, 2, 3].
- frequency (int/float) – The frequency to set in Hz (e.g. 330’000 for 330kHz). See
SPI_FREQUENCIES
for the list of supported values.
-
transceive_spi
(port, tx_data)[source]¶ Transceives an SPI frame on a certain port.
Parameters: - port (SensorBridgePort) – The port where the transceive should be executed. Note that
ALL
is not supported here. - tx_data (bytes-like/list) – Raw data (bytes) to send.
Returns: Received bytes (same number of bytes as tx_data).
Return type: bytes
- port (SensorBridgePort) – The port where the transceive should be executed. Note that
-
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.Warning
If the SEK-SensorBridge is connected through RS485 together with other SHDLC devices on the same bus, make sure that no other device has the slave address 0 and baudrate 115200! These connection settings are used by the bootloader and thus two devices would respond to the bootloader commands. If an update fails because of this, you will have to disconnect the other device with address 0 and do an emergency update to recover this device.
Parameters: - image – The image to flash, either as a
SensorBridgeFirmwareImage
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 (progress in percent) as parameter.
Raises: - ShdlcFirmwareImageIncompatibilityError – If the image is not compatible with the connected device.
- Exception – On other errors.
- image – The image to flash, either as a
-
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.
-
get_article_code
()¶ 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_product_name
()¶ 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_product_type
(as_int=False)¶ 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_serial_number
()¶ Get the serial number of the device.
Returns: The serial number as an ASCII string. Return type: string
-
get_version
()¶ Get the version of the device firmware, hardware and SHDLC protocol.
Returns: The device version as a Version object. Return type: Version
-
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 withFalse
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
-
set_baudrate
(baudrate, update_driver=True)¶ 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 argumentupdate_driver
, the baudrate of the underlayingShdlcPort
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 setupdate_driver
toTrue
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.
-
set_slave_address
(slave_address, update_driver=True)¶ 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 propertyslave_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.
-
slave_address
¶ Get the slave address (not read from the device!).
Returns: The slave address. Return type: byte
-
SensorBridgeFirmwareImage¶
-
class
sensirion_shdlc_sensorbridge.firmware_image.
SensorBridgeFirmwareImage
(hexfile)[source]¶ SEK-SensorBridge firmware image.
This class represents a firmware image for the SEK-SensorBridge. 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
-
RepeatedTransceiveHandle¶
-
class
sensirion_shdlc_sensorbridge.types.
RepeatedTransceiveHandle
(raw_handle, rx_length)[source]¶ Represents a handle to a repeated I2C transceive operation. Use only internally, usually users don’t have to care about this type.
-
__init__
(raw_handle, rx_length)[source]¶ Creates a new handle.
Parameters: - raw_handle (byte) – Handle as returned from the “start repeated transceive” command.
- rx_length – Number of bytes which the corresponding repeated transceive reads from the I2C device.
-
raw_handle
¶ The raw handle (byte) as received from SensorBridge.
-
rx_length
¶ The response length (int) of the corresponding repeated transceive operation.
-
ReadBufferResponse¶
-
class
sensirion_shdlc_sensorbridge.types.
ReadBufferResponse
(rx_length, lost_bytes, remaining_bytes, rx_data)[source]¶ Helper class representing the response to the “read buffer” command, i.e. of the method
read_buffer()
.The class provides some public members which you can access directly.
-
__init__
(rx_length, lost_bytes, remaining_bytes, rx_data)[source]¶ Creates an instance from the raw data received from the device.
Parameters: - rx_length (int) – The read data length of the repeated transceive from which the response is coming from.
- lost_bytes (int) – Number of bytes lost (received from the “read buffer” command).
- remaining_bytes (int) – Number of bytes remaining in the buffer (received from the “read buffer” command).
- rx_data (bytes) – Raw received data bytes containing multiple I2C response status and data received from the I2C device.
-
lost_bytes
¶ Number of lost bytes (int) due to buffer overrun.
-
remaining_bytes
¶ Number of remaining bytes in the buffer after reading it. If the whole buffer was read out, this is zero.
-
values
¶ The received values (list of
BufferedValue
)
-
BufferedValue¶
-
class
sensirion_shdlc_sensorbridge.types.
BufferedValue
(rx_data)[source]¶ Represents a buffered value from a repeated I2C transceive operation. It interprets the raw status and RX data from the buffer and provides a convenient API to access them.
With the
raw_status
andraw_data
you can access the raw data as received from the device. But the propertydata()
provides a more convenient interface since it returns the data if it is valid and raises an exception if it is not valid.Parameters: rx_data (bytes) – The raw buffer data as received from the device. -
__init__
(rx_data)[source]¶ Creates an instance from the received raw data.
Parameters: rx_data (str) – Received raw data from SensorBridge, containing the status byte and the received data from the I2C read operation.
-
raw_status
¶ The raw status (byte) of the I2C transceive operation.
-
raw_data
¶ The raw received I2C data. Attention: This data might be invalid if the transceive operation was not successful!
-
error
¶ An exception of the occurred I2C error or None if the transceive operation was successful.
-
data
¶ Returns the received data if it is valid, or raises an exception if an I2C error occurred.
Raises: SensorBridgeI2cError – If an I2C error occurred, i.e. no valid data is available. Returns: The received bytes. Return type: bytes
-
I²C Errors¶
-
exception
sensirion_shdlc_sensorbridge.i2c_errors.
SensorBridgeI2cError
(code, message='Unknown')[source]¶ I2C transceive error.
-
__init__
(code, message='Unknown')[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
errno
¶ POSIX exception code
-
filename
¶ exception filename
-
filename2
¶ second exception filename
-
strerror
¶ exception strerror
-
with_traceback
()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
exception
sensirion_shdlc_sensorbridge.i2c_errors.
SensorBridgeI2cNackError
[source]¶ I2C transceive NACK error.
-
errno
¶ POSIX exception code
-
filename
¶ exception filename
-
filename2
¶ second exception filename
-
strerror
¶ exception strerror
-
with_traceback
()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
exception
sensirion_shdlc_sensorbridge.i2c_errors.
SensorBridgeI2cTimeoutError
[source]¶ I2C transceive timeout error.
-
errno
¶ POSIX exception code
-
filename
¶ exception filename
-
filename2
¶ second exception filename
-
strerror
¶ exception strerror
-
with_traceback
()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
exception
sensirion_shdlc_sensorbridge.i2c_errors.
SensorBridgeI2cTimingError
[source]¶ I2C repeated transceive timing error.
-
errno
¶ POSIX exception code
-
filename
¶ exception filename
-
filename2
¶ second exception filename
-
strerror
¶ exception strerror
-
with_traceback
()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
sensirion_shdlc_sensorbridge.i2c_errors.
i2c_error_from_code
(code)[source]¶ Return the corresponding exception for a given I2C error code.
Parameters: code (byte) – Error code as received from the device. Returns: The exception for the given error code. If code is zero (no error), None is returned. Return type: None or an instance of SensorBridgeI2cError
Device Errors¶
-
exception
sensirion_shdlc_sensorbridge.device_errors.
SensorBridgeFunctionalityNotImplementedError
[source]¶ SHDLC device error for functionality not implemented.
-
__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.
-
-
exception
sensirion_shdlc_sensorbridge.device_errors.
SensorBridgeNoMorePeriodicMeasurementsPossibleError
[source]¶ SHDLC device error for no more periodic measurements possible.
-
__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.
-
-
exception
sensirion_shdlc_sensorbridge.device_errors.
SensorBridgeFrameChecksumError
[source]¶ SHDLC device error for frame checksum error.
-
__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.
-
-
exception
sensirion_shdlc_sensorbridge.device_errors.
SensorBridgeFrameSizeInfoMismatchError
[source]¶ SHDLC device error for frame size info mismatch.
-
__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.
-
-
exception
sensirion_shdlc_sensorbridge.device_errors.
SensorBridgeI2cNackError
[source]¶ SHDLC device error for I2C NACK.
-
__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.
-
-
exception
sensirion_shdlc_sensorbridge.device_errors.
SensorBridgeI2cTimeoutError
[source]¶ SHDLC device error for I2C timeout.
-
__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.
-
-
exception
sensirion_shdlc_sensorbridge.device_errors.
SensorBridgeFatalError
[source]¶ SHDLC device error for fatal errors.
-
__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.
-
Definitions¶
-
class
sensirion_shdlc_sensorbridge.definitions.
SensorBridgePort
[source]¶ An enum containing all available ports with their corresponding byte values how they are transmitted over SHDLC.
-
ONE
= 0¶ Port 1
-
TWO
= 1¶ Port 2
-
ALL
= 255¶ All ports
-
-
sensirion_shdlc_sensorbridge.definitions.
VOLTAGES
= {1.2: 0, 1.5: 4, 1.8: 1, 2.1: 5, 2.4: 6, 2.7: 7, 3.0: 8, 3.3: 2, 3.6: 9, 4.5: 10, 5.0: 3, 5.5: 11}¶ A dictionary containing all available voltages with their corresponding byte values how they are transmitted over SHDLC.
-
sensirion_shdlc_sensorbridge.definitions.
I2C_FREQUENCIES
= {10000.0: 4, 50000.0: 5, 100000.0: 0, 400000.0: 1, 1000000.0: 2, 2000000.0: 3}¶ A dictionary containing all available I2C frequencies with their corresponding byte values how they are transmitted over SHDLC.
-
sensirion_shdlc_sensorbridge.definitions.
SPI_FREQUENCIES
= {330000.0: 0, 600000.0: 1, 1000000.0: 2, 5000000.0: 3, 10000000.0: 4, 21000000.0: 5}¶ A dictionary containing all available SPI frequencies with their corresponding byte values how they are transmitted over SHDLC.
-
sensirion_shdlc_sensorbridge.definitions.
port_to_byte
(port, accept_all)[source]¶ Convert a port value to the corresponding byte value.
Parameters: - port (SensorBridgePort) – The port to convert.
- accept_all – If True, the value
ALL
is accepted.
Raises: ValueError – If the passed port is not valid.
Returns: The corresponding byte value of the port.
Return type: byte
-
sensirion_shdlc_sensorbridge.definitions.
voltage_to_byte
(voltage)[source]¶ Convert a voltage in Volts to the corresponding byte value.
Parameters: port (int/float) – The voltage to convert. Raises: ValueError – If the passed voltage is not supported. Returns: The corresponding byte value of the voltage. Return type: byte
-
sensirion_shdlc_sensorbridge.definitions.
i2c_frequency_to_byte
(frequency)[source]¶ Convert an I2C frequency in Hz to the corresponding byte value.
Parameters: port (int/float) – The frequency to convert. Raises: ValueError – If the passed frequency is not supported. Returns: The corresponding byte value of the frequency. Return type: byte
-
sensirion_shdlc_sensorbridge.definitions.
spi_frequency_to_byte
(frequency)[source]¶ Convert an SPI frequency in Hz to the corresponding byte value.
Parameters: port (int/float) – The frequency to convert. Raises: ValueError – If the passed frequency is not supported. Returns: The corresponding byte value of the frequency. Return type: byte
Commands¶
-
class
sensirion_shdlc_sensorbridge.commands.device_information.
SensorBridgeCmdDeviceInformationBase
(*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).
-
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_sensorbridge.commands.device_information.
SensorBridgeCmdGetProductType
[source]¶ -
-
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
-
static
-
class
sensirion_shdlc_sensorbridge.commands.device_information.
SensorBridgeCmdGetProductName
[source]¶ -
-
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
-
static
-
class
sensirion_shdlc_sensorbridge.commands.device_information.
SensorBridgeCmdGetArticleCode
[source]¶ -
-
static
interpret_response
(data)[source]¶ Returns: String containing the article code. 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
-
static
-
class
sensirion_shdlc_sensorbridge.commands.device_information.
SensorBridgeCmdGetSerialNumber
[source]¶ -
-
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
-
static
-
class
sensirion_shdlc_sensorbridge.commands.get_version.
SensorBridgeCmdGetVersionBase
(*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).
-
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_sensorbridge.commands.get_version.
SensorBridgeCmdGetVersion
[source]¶ -
__init__
()[source]¶ Get Version Command
Gets the version information for the hardware, firmware and SHDLC protocol.
-
static
interpret_response
(data)[source]¶ Returns: - fw_ver_major (int) - Firmware major version number.
- fw_ver_minor (int) - Firmware minor version number.
- fw_debug (bool) - Firmware debug state. If the debug state is set, the firmware is in development.
- hw_ver_major (int) - Hardware major version number.
- hw_ver_minor (int) - Hardware minor version number.
- protocol_ver_major (int) - Protocol major version number.
- protocol_ver_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
-
-
class
sensirion_shdlc_sensorbridge.commands.slave_address.
SensorBridgeCmdSlaveAddressBase
(*args, **kwargs)[source]¶ SHDLC command 0x90: “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).
-
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_sensorbridge.commands.slave_address.
SensorBridgeCmdSetSlaveAddress
(slave_address)[source]¶ -
__init__
(slave_address)[source]¶ Set Slave Address Command
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. 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 (int) – The new slave address. The address 255 is reserved for broadcasts.
-
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_sensorbridge.commands.baudrate.
SensorBridgeCmdBaudrateBase
(*args, **kwargs)[source]¶ SHDLC command 0x91: “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).
-
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_sensorbridge.commands.baudrate.
SensorBridgeCmdSetBaudrate
(baudrate)[source]¶ -
__init__
(baudrate)[source]¶ Set Baudrate Command
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. Default is 460800 bit/s.
Parameters: baudrate (int) – The new baudrate in bit/s.
-
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_sensorbridge.commands.set_port_voltage.
SensorBridgeCmdSetPortVoltageBase
(*args, **kwargs)[source]¶ SHDLC command 0x00: “Set Port Voltage”.
-
__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).
-
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_sensorbridge.commands.set_port_voltage.
SensorBridgeCmdSetPortVoltage
(port, voltage)[source]¶ -
__init__
(port, voltage)[source]¶ Set Port Voltage Command
Sets the voltage of a port to a certain value.
Parameters: - port (int) –
The port(s) where the voltage should be set:
- 0x00: Port 1
- 0x01: Port 2
- 0xFF: All ports
- voltage (int) –
The voltage to set:
- 0x00: 1.2V
- 0x01: 1.8V
- 0x02: 3.3V
- 0x03: 5.0V
- 0x04: 1.5V
- 0x05: 2.1V
- 0x06: 2.4V
- 0x07: 2.7V
- 0x08: 3.0V
- 0x09: 3.6V
- 0x0A: 4.5V
- 0x0B: 5.5V
- port (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
-
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_sensorbridge.commands.port_voltage_on_off.
SensorBridgeCmdPortVoltageOnOffBase
(*args, **kwargs)[source]¶ SHDLC command 0x01: “Port Voltage On Off”.
-
__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).
-
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_sensorbridge.commands.port_voltage_on_off.
SensorBridgeCmdPortVoltageOnOff
(port, state)[source]¶ -
__init__
(port, state)[source]¶ Port Voltage On Off Command
Switches a port supply on or off. If switched on, the previously set voltage will be applied.
Parameters: - port (int) –
The port(s) to switch on or off:
- 0x00: Port 1
- 0x01: Port 2
- 0xFF: All ports
- state (int) –
The new state to set:
- 0x00: off
- 0x01: on
- port (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
-
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_sensorbridge.commands.set_i2c_frequency.
SensorBridgeCmdSetI2cFrequencyBase
(*args, **kwargs)[source]¶ SHDLC command 0x02: “Set I2c Frequency”.
-
__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).
-
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_sensorbridge.commands.set_i2c_frequency.
SensorBridgeCmdSetI2cFrequency
(port, frequency)[source]¶ -
__init__
(port, frequency)[source]¶ Set I2c Frequency Command
Sets the I2C frequency to the desired value. The default frequency is 400kHz.
Parameters: - port (int) –
The port(s) where the frequency should be set:
- 0x00: Port 1
- 0x01: Port 2
- 0xFF: All ports
- frequency (int) –
The frequency to set:
- 0x00: 100kHz
- 0x01: 400kHz
- 0x02: 1MHz
- 0x03: 2MHz
- 0x04: 10kHz (since FW v5.6)
- 0x05: 50kHz (since FW v5.6)
- port (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
-
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_sensorbridge.commands.i2c_scan.
SensorBridgeCmdI2cScanBase
(*args, **kwargs)[source]¶ SHDLC command 0x10: “I2c Scan”.
-
__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).
-
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_sensorbridge.commands.i2c_scan.
SensorBridgeCmdI2cScan
(port, first_address, last_address)[source]¶ -
__init__
(port, first_address, last_address)[source]¶ I2c Scan Command
Scans for I2C devices on a specific port within a certain address range.
Parameters: - port (int) –
The port where the scan should be executed:
- 0x00: Port 1
- 0x01: Port 2
- first_address (int) – First address to scan (1..127).
- last_address (int) – Last address to scan (1..127 and >= first address).
- port (int) –
-
static
interpret_response
(data)[source]¶ Returns: Array of bytes containing all addresses from devices which responded to the scan. Return type: bytes
-
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_sensorbridge.commands.i2c_transceive.
SensorBridgeCmdI2cTransceiveBase
(*args, **kwargs)[source]¶ SHDLC command 0x11: “I2c Transceive”.
-
__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).
-
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_sensorbridge.commands.i2c_transceive.
SensorBridgeCmdFirstTransceive
(port, i2c_address, tx_length, rx_length, timeout_us, tx_data)[source]¶ -
__init__
(port, i2c_address, tx_length, rx_length, timeout_us, tx_data)[source]¶ First Transceive Command
First frame of a transceive command.
Parameters: - port (int) –
The port where the transceive should be executed:
- 0x00: Port 1
- 0x01: Port 2
- i2c_address (int) – I2C address of the targeted device.
- tx_length (int) – Number of bytes to send. This amount of bytes has to be attached to the command. Set to zero if only read header is needed.
- rx_length (int) – Number of bytes to receive. This amount of bytes are returned as response. Set to zero if no read operation is needed.
- timeout_us (int) – I2C timeout in microseconds when reading bytes. If a frame is NACK’d it will be retried up to the timeout value. Same applies for clock stretching.
- tx_data (bytes) – Bytes to send (if any).
- port (int) –
-
static
interpret_response
(data)[source]¶ Returns: If needed/available, the bytes from the I2C read are returned. Return type: bytes
-
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_sensorbridge.commands.i2c_transceive.
SensorBridgeCmdSubsequentTransceive
(port, tx_data)[source]¶ -
__init__
(port, tx_data)[source]¶ Subsequent Transceive Command
Subsequent frame of a transceive command.
Parameters: - port (int) –
The port where the transceive should be executed:
- 0x00: Port 1
- 0x01: Port 2
- tx_data (bytes) – Bytes to send (if any).
- port (int) –
-
static
interpret_response
(data)[source]¶ Returns: If needed/available, the bytes from the I2C read are returned. Return type: bytes
-
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_sensorbridge.commands.i2c_repeated_transceive.
SensorBridgeCmdI2cRepeatedTransceiveBase
(*args, **kwargs)[source]¶ SHDLC command 0x12: “I2c Repeated Transceive”.
-
__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).
-
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_sensorbridge.commands.i2c_repeated_transceive.
SensorBridgeCmdI2cRepeatedTransceive
(interval_us, port, i2c_address, tx_length, rx_length, timeout_us, read_delay_us, tx_data)[source]¶ -
__init__
(interval_us, port, i2c_address, tx_length, rx_length, timeout_us, read_delay_us, tx_data)[source]¶ I2c Repeated Transceive Command
Starts an asynchronous transceive command in a specific interval. Multiple parallel repeated transceives are possible. The returned data is stored in a buffer and can be read out with the “Read Buffer” command. The amount of data to write or read is limited.
Parameters: - interval_us (int) – The interval in microseconds.
- port (int) –
The port(s) where the repeated transceive should be started:
- 0x00: Port 1
- 0x01: Port 2
- 0xFF: All ports
- i2c_address (int) – I2C address of the targeted device.
- tx_length (int) – Number of bytes to send. This amount of bytes has to be attached to the command. Set to zero if only read header is needed.
- rx_length (int) – Number of bytes to receive. This amount of bytes are returned as response to the read buffer command. Set to zero if no read operation is needed.
- timeout_us (int) – I2C timeout in microseconds when reading bytes. If frame is NACK’d it will be retried up to the timeout value. Same applies for clock stretching.
- read_delay_us (int) – This time will be inserted between the write and the read frame. to allow a device taking a certain amount of time for its measurements. The delay must be smaller than the specified timeout.
- tx_data (bytes) – Bytes to send (if any).
-
static
interpret_response
(data)[source]¶ Returns: One or more unique handles with following information: - Unique number (higher nibble, 0..7)
- Channel number (lower nibble, 0..1)
There are 8 available memory slots for the repeated transceive tasks and they are identified by the unique number.
Return type: bytes
-
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_sensorbridge.commands.read_buffer.
SensorBridgeCmdReadBufferBase
(*args, **kwargs)[source]¶ SHDLC command 0x50: “Read Buffer”.
-
__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).
-
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_sensorbridge.commands.read_buffer.
SensorBridgeCmdReadBuffer
(handle)[source]¶ -
__init__
(handle)[source]¶ Read Buffer Command
Reads data stored in the buffer of a repeated transceive.
Parameters: handle (int) – The handle of the repeated transceive from which the data should be returned.
-
static
interpret_response
(data)[source]¶ Returns: - lost_bytes (int) - Number of bytes lost due to buffer overrun.
- remaining_bytes (int) - Number of bytes remaining in the buffer.
- rx_data (bytes) -
Buffered values. The data is returned in
n*[header][readI2cDataOfOneTransceive]
where header:- 0: valid data
- 1: NACK from Sensor (not available)
- 2: Timeout in Read Operation
- 3: Timing Error. Hardware and/or Sensor can not provide the requested data rate
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_sensorbridge.commands.stop_repeated_transceive.
SensorBridgeCmdStopRepeatedTransceiveBase
(*args, **kwargs)[source]¶ SHDLC command 0x51: “Stop Repeated Transceive”.
-
__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).
-
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_sensorbridge.commands.stop_repeated_transceive.
SensorBridgeCmdStopRepeatedTransceive
(handle)[source]¶ -
__init__
(handle)[source]¶ Stop Repeated Transceive Command
Stops a repeated transceive operation.
Parameters: handle (int) – The handle of the repeated transceive which should be stopped. Pass 0xFF to stop all repeated transceives.
-
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_sensorbridge.commands.spi_config.
SensorBridgeCmdSpiConfigBase
(*args, **kwargs)[source]¶ SHDLC command 0x60: “Spi Config”.
-
__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).
-
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_sensorbridge.commands.spi_config.
SensorBridgeCmdSpiConfig
(port, mode, frequency)[source]¶ -
__init__
(port, mode, frequency)[source]¶ Spi Config Command
Sets the SPI mode and frequency.
Parameters: - port (int) –
The port(s) which should be configured:
- 0x00: Port 1
- 0x01: Port 2
- 0xFF: All ports
- mode (int) –
The SPI mode to use:
- 0x00: Mode 0
- 0x01: Mode 1
- 0x02: Mode 2
- 0x03: Mode 3
- frequency (int) –
The frequency to set:
- 0x00: 330kHz
- 0x01: 600kHz
- 0x02: 1MHz
- 0x03: 5MHz
- 0x04: 10MHz
- 0x05: 21MHz
- port (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
-
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_sensorbridge.commands.spi_transceive.
SensorBridgeCmdSpiTransceiveBase
(*args, **kwargs)[source]¶ SHDLC command 0x61: “Spi Transceive”.
-
__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).
-
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_sensorbridge.commands.spi_transceive.
SensorBridgeCmdSpiTransceive
(port, length, tx_data)[source]¶ -
__init__
(port, length, tx_data)[source]¶ Spi Transceive Command
Transceives an SPI frame on a certain port.
Parameters: - port (int) –
The port where the transceive should be executed:
- 0x00: Port 1
- 0x01: Port 2
- length (int) – Count of bytes to send. This amount of bytes has to be attached to the command.
- tx_data (bytes) – Bytes to send.
- port (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
-
-
class
sensirion_shdlc_sensorbridge.commands.blink.
SensorBridgeCmdBlinkBase
(*args, **kwargs)[source]¶ SHDLC command 0x70: “Blink”.
-
__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).
-
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_sensorbridge.commands.blink.
SensorBridgeCmdBlink
(port)[source]¶ -
__init__
(port)[source]¶ Blink Command
Let the LEDs on the device blink. Useful for example to identify the device on a bus.
Parameters: port (int) – The port(s) which should blink:
- 0x00: Port 1
- 0x01: Port 2
- 0xFF: All ports
-
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_sensorbridge.commands.analog_measurement.
SensorBridgeCmdAnalogMeasurementBase
(*args, **kwargs)[source]¶ SHDLC command 0x80: “Analog Measurement”.
-
__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).
-
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_sensorbridge.commands.analog_measurement.
SensorBridgeCmdAnalogMeasurement
(port)[source]¶ -
__init__
(port)[source]¶ Analog Measurement Command
Triggers an analog measurement at the AIN pin of a specific port. The measured voltage is always positive and in the range of 0-5.5V.
Parameters: port (int) – The port where the measurement should be executed:
- 0x00: Port 1
- 0x01: Port 2
-
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_sensorbridge.commands.firmware_update.
SensorBridgeCmdFirmwareUpdateBase
(*args, **kwargs)[source]¶ SHDLC command 0xF3: “Firmware Update”.
-
__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).
-
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_sensorbridge.commands.firmware_update.
SensorBridgeCmdEnterBootloader
[source]¶ -
__init__
()[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).
-
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_sensorbridge.commands.firmware_update.
SensorBridgeCmdStartUpdate
[source]¶ -
__init__
()[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.
-
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_sensorbridge.commands.firmware_update.
SensorBridgeCmdUpdateData
(data)[source]¶ -
__init__
(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.
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_sensorbridge.commands.firmware_update.
SensorBridgeCmdStopUpdate
(checksum)[source]¶ -
__init__
(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.
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
-