API Reference¶
ShdlcSerialFrameBuilder¶
-
class
sensirion_shdlc_driver.serial_frame_builder.
ShdlcSerialFrameBuilder
[source]¶ Base class for
ShdlcSerialMosiFrameBuilder
andShdlcSerialMisoFrameBuilder
.
-
class
sensirion_shdlc_driver.serial_frame_builder.
ShdlcSerialMosiFrameBuilder
(slave_address, command_id, data)[source]¶ Serial MOSI (master out, slave in) frame builder.
This class allows to convert structured data (slave address, command ID etc.) into the raw bytes which are then sent to the serial port.
-
class
sensirion_shdlc_driver.serial_frame_builder.
ShdlcSerialMisoFrameBuilder
[source]¶ Serial MISO (master in, slave sout) frame builder.
This class allows to convert raw bytes received from the serial port into structured data (slave address, command ID etc.).
-
data
¶ Get the received data.
Returns: The received data. Return type: bytearray
-
start_received
¶ Check if the start byte was already received.
Returns: Whether the start byte was already received or not. Return type: bool
-
ShdlcPort¶
-
class
sensirion_shdlc_driver.port.
ShdlcPort
[source]¶ Common interface for all communication ports for transceiving SHDLC frames.
Concrete implementations may use the serial port or another interface for transceiving SHDLC frames. All methods must be implemented thread-safe, i.e. allowing them to be called from multiple threads at the same time.
-
description
¶ Get a description of the port.
Returns: Description string. Return type: string
-
bitrate
¶ The current bitrate in bit/s.
Type: int
-
lock
¶ Get the lock object of the port to allow locking it, i.e. to get exclusive access across multiple method calls.
Returns: The lock object. Return type: threading.RLock
-
is_open
¶ Indicates whether the port is open.
Returns: If True
the port is open, ifFalse
the port is closed.Return type: bool
-
open
()[source]¶ Open the port. Only needs to be called if the port is not already opened. Does nothing if the port is already opened.
-
close
()[source]¶ Close the port to release the underlying resources. Does nothing if the port is already closed.
-
transceive
(slave_address, command_id, data, response_timeout)[source]¶ Send SHDLC frame to port and return received response frame.
Note
The specified response timeout defines the maximum time the device needs until it starts to send the response after receiving the last byte from the master request. The time needed for the transmission itself and other possible overhead or delays depends on hardware, drivers, bitrate etc. and must be taken into account in the implementation of this method.
Parameters: - slave_address (byte) – Slave address.
- command_id (byte) – SHDLC command ID.
- data (bytes-like) – Payload.
- response_timeout (float) – Response timeout in seconds (maximum time until the first byte is received).
Returns: Received address, command_id, state, and payload.
Return type: byte, byte, byte, bytes
Raises: - ShdlcTimeoutError – If no response received within timeout.
- ShdlcResponseError – If the received response is invalid.
-
-
class
sensirion_shdlc_driver.port.
ShdlcSerialPort
(port, baudrate, additional_response_time=0.1, do_open=True)[source]¶ SHDLC transceiver for the serial port (e.g. UART/RS232/RS485).
This class implements the ShdlcPort interface for the serial port.
Note
This class can be used in a “with”-statement, and it’s recommended to do so as it automatically closes the port after using it.
-
__init__
(port, baudrate, additional_response_time=0.1, do_open=True)[source]¶ Create and optionally open a serial port. Throws an exception if the port cannot be opened.
Parameters: - port (string) – The serial port (e.g. “COM2” or “/dev/ttyUSB0”)
- baudrate (int) – The baudrate in bit/s.
- additional_response_time (float) – Additional response time (in
Seconds) used when receiving frames. See property
additional_response_time
for details. Defaults to 0.1 (i.e. 100ms) which should be enough in most cases. - do_open (bool) – Whether the serial port should be opened immediately or not.
If
False
, you will have to callopen()
manually before using this object. Defaults toTrue
.
-
description
¶ Get a description of the port.
Returns: Description string. Return type: string
-
bitrate
¶ The current bitrate in bit/s.
Type: int
-
additional_response_time
¶ The additional response time (in Seconds) used when receiving frames.
Since the timeout measurement of serial communication is typically very inaccurate (e.g. USB-UART converter drivers often buffer I/O data for 16ms), this class adds some extra time to the specified response timeout to avoid timeout errors even if the device responded within the given timeout. If needed, this extra time can be changed either with this property, or with the parameter
additional_response_time
of__init__()
.Type: float
-
lock
¶ Get the lock object of the port to allow locking it, i.e. to get exclusive access across multiple method calls.
Returns: The lock object. Return type: threading.RLock
-
is_open
¶ Indicates whether the port is open.
Returns: If True
the port is open, ifFalse
the port is closed.Return type: bool
-
open
()[source]¶ Open the serial port (only needs to be called if
do_open
in__init__()
was set toFalse
). Does nothing if the port is already opened.
-
transceive
(slave_address, command_id, data, response_timeout)[source]¶ Send SHDLC frame to port and return received response frame.
Parameters: - slave_address (byte) – Slave address.
- command_id (byte) – SHDLC command ID.
- data (bytes-like) – Payload.
- response_timeout (float) – Response timeout in seconds (maximum time until the first byte is received).
Returns: Received address, command_id, state, and payload.
Return type: byte, byte, byte, bytes
Raises: - ShdlcTimeoutError – If no response received within timeout.
- ShdlcResponseError – If the received response is invalid.
-
ShdlcConnection¶
-
class
sensirion_shdlc_driver.connection.
ShdlcConnection
(port)[source]¶ This class represents the connection to an SHDLC bus. So you need to instantiate one object per bus, no matter how many devices are connected to that bus system.
The basic functionality of the class is to send SHDLC frames to devices and receive their response. Handling of communication errors (e.g. timeout or checksum errors) and device errors is done in this class.
-
__init__
(port)[source]¶ Open an SHDLC connection on a specific port.
Note
This constructor does not send or receive any data to resp. from the specified port.
Parameters: port (ShdlcPort) – The port used for communication (must implement the ShdlcPort
interface)
-
execute
(slave_address, command, wait_post_process=True)[source]¶ Execute an ShdlcCommand and return the interpreted response. Executing a command means:
- Send request (MOSI) frame
- Receive response (MISO) frame
- Validate and interpret response data
- Wait until post processing is done (optional, and only if needed)
Parameters: - slave_address (byte) – Slave address.
- command (ShdlcCommand) – SHDLC command to execute.
- wait_post_process (bool) – If true and the command needs some time for post processing, this thread blocks until post processing is done.
Returns: Received response (interpreted) and error state flag.
Return type: object, bool
-
transceive
(slave_address, command_id, data, response_timeout)[source]¶ Send a raw SHDLC command and return the received raw response.
Parameters: - slave_address (byte) – Slave address.
- command_id (byte) – SHDLC command ID.
- data (bytes-like) – Payload (may be empty).
- response_timeout (float) – Response timeout in seconds (maximum time until the first byte is received).
Returns: Received response payload and error state flag.
Return type: bytes, bool
-
ShdlcDevice¶
-
class
sensirion_shdlc_driver.device.
ShdlcDevice
(connection, slave_address)[source]¶ Generic SHDLC device, providing only common SHDLC commands. This class is intended only to communicate with devices which do not provide a corresponding device driver (yet). With this class you can for example read the serial number of a device even if no device specific driver exists. But if there exists a device specific driver, you should always use it instead of this driver.
This is a low-level driver which just provides all SHDLC commands as Python methods. Typically, calling a method sends one SHDLC request to the device and interprets its response. There is no higher level functionality available, please look for other drivers if you need a higher level interface.
There is no (or very few) caching functionality in this driver. For example if you call
get_serial_number()
100 times, it will send the command 100 times over the SHDLC interface to the device. This makes the driver (nearly) stateless.-
__init__
(connection, slave_address)[source]¶ Create an SHDLC device instance on an SHDLC connection.
Note
This constructor does not communicate with the device, so it’s possible to instantiate an object even if the device is not connected or powered yet.
Parameters: - connection (ShdlcConnection) – The connection used for the communication.
- slave_address (byte) – The address of the device.
-
get_product_type
(as_int=False)[source]¶ Get the product type. The product type (sometimes also called “device type”) can be used to detect what kind of SHDLC product is connected.
Parameters: as_int (bool) – If True
, the product type is returned as an integer, otherwise as a string of hexadecimal digits (default).Returns: The product type as an integer or string of hexadecimal digits. Return type: string/int
-
get_product_subtype
()[source]¶ Get the product subtype. Some product types exist in multiple slightly different variants, this command allows to determine the exact variant of the connected device. Sometimes this is called “device subtype”.
Note
This command is not supported by every product type.
Returns: The product subtype as a byte (the interpretation depends on the connected product type). Return type: byte
-
get_product_name
()[source]¶ Get the product name of the device.
Note
This command is not supported by every product type.
Returns: The product name as an ASCII string. Return type: string
-
get_article_code
()[source]¶ Get the article code of the device.
Note
This command is not supported by every product type.
Returns: The article code as an ASCII string. Return type: string
-
get_serial_number
()[source]¶ Get the serial number of the device.
Returns: The serial number as an ASCII string. Return type: string
-
get_version
()[source]¶ Get the version of the device firmware, hardware and SHDLC protocol.
Returns: The device version as a Version object. Return type: Version
-
get_error_state
(clear=True, as_exception=False)[source]¶ Get and optionally clear the device error state and the last error. The state and error code interpretation depends on the connected device type.
Parameters: - clear (bool) – If
True
, the error state on the device gets cleared. - as_exception (bool) – If
True
, the error state is returned as anShdlcDeviceError
object instead of a byte.
Returns: The device state as a 32-bit unsigned integer containing all error flags, and the last error which occurred on the device. If
as_exception
isTrue
, it’s returned as anShdlcDeviceError
object orNone
, otherwise as a byte.Return type: int, byte/ShdlcDeviceError/None
- clear (bool) – If
-
get_slave_address
()[source]¶ Get the SHDLC slave address of the device.
Note
See also the property
slave_address
which returns the device’s slave address without sending a command. This method really sends a command to the device, even though the slave address is actually already known by this object.Returns: The slave address of the device. Return type: byte
-
set_slave_address
(slave_address, update_driver=True)[source]¶ Set the SHDLC slave address of the device.
Note
The slave address is stored in non-volatile memory of the device and thus persists after a device reset. So the next time connecting to the device, you have to use the new address.
Warning
When changing the address of a slave, make sure there isn’t already a slave with that address on the same bus! In that case you would get communication issues which can only be fixed by disconnecting one of the slaves.
Parameters: - slave_address (byte) – The new slave address [0..254]. The address 255 is reserved for broadcasts.
- update_driver (bool) – If
True
, the 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.
-
get_baudrate
()[source]¶ Get the SHDLC baudrate of the device.
Note
This method really sends a command to the device, even though the baudrate is already known by the used
ShdlcPort
object.Returns: The baudrate of the device [bit/s]. Return type: int
-
set_baudrate
(baudrate, update_driver=True)[source]¶ Set the SHDLC baudrate of the device.
Note
The baudrate is stored in non-volatile memory of the device and thus persists after a device reset. So the next time connecting to the device, you have to use the new baudrate.
Warning
If you pass
True
to the 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.
-
get_reply_delay
()[source]¶ Get the SHDLC reply delay of the device.
See
set_reply_delay()
for details.Returns: The reply delay of the device [μs]. Return type: byte
-
set_reply_delay
(reply_delay)[source]¶ Set the SHDLC reply delay of the device.
The reply delay allows to increase the minimum response time of the slave to a given value in Microseconds. This is needed for RS485 masters which require some time to switch from sending to receiving. If the slave starts sending the response while the master is still driving the bus lines, a conflict on the bus occurs and communication fails. If you use such a slow RS485 master, you can increase the reply delay of all slaves to avoid this issue.
Parameters: reply_delay (byte) – The new reply delay [μs].
-
get_system_up_time
()[source]¶ Get the system up time of the device.
Returns: The time since the last power-on or device reset [s]. Return type: int
-
factory_reset
()[source]¶ Perform a factory reset (restore the off-the-shelf factory configuration).
Warning
This resets any configuration done after leaving the factory! Keep in mind that this command might also change communication parameters (i.e. baudrate and slave address) and thus you might have to adjust the driver’s parameters to allow further communication with the device.
-
ShdlcCommand¶
-
class
sensirion_shdlc_driver.command.
ShdlcCommand
(id, data, max_response_time, min_response_length=0, max_response_length=255, post_processing_time=0.0)[source]¶ Base class for all SHDLC commands.
-
__init__
(id, data, max_response_time, min_response_length=0, max_response_length=255, post_processing_time=0.0)[source]¶ Constructor.
Parameters: - id (byte) – Command ID (0..255).
- data (bytes-like/list) – MOSI data (0..255 bytes).
- max_response_time (float) – Maximum time the device needs to response (used as timeout).
- min_response_length (byte) – Minimum expected response length.
- max_response_length (byte) – Maximum expected response length.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
-
id
¶ Get the command ID.
Returns: Command ID (0..255). Return type: byte
-
data
¶ Get the command data (payload).
Returns: Command data (length 0..255). Return type: bytes
-
max_response_time
¶ Get the maximum response time for this command.
Returns: Maximum response time in seconds. Return type: float
-
post_processing_time
¶ Get the post processing time for this command. The post processing time defines how long a device needs to execute a command after responding to the SHDLC command. Most devices don’t need post processing (command is executed before the response is sent). Only special commands (e.g. a device reset) are executed after the response is sent.
Returns: Maximum response time in seconds. Return type: float
-
check_response_length
(data)[source]¶ Check if the response length is correct.
Parameters: data (bytes) – Raw data (payload) received from the device. Raises: ShdlcResponseError – If length is wrong.
-
interpret_response
(data)[source]¶ Interpret the response to this command received from the device. This converts the raw byte array to the actual data type(s) depending on the sent command.
Parameters: data (bytes) – Raw data (payload) received from the device. Returns: Interpreted response. Data type and meaning depends on the sent command. None for commands without response data. See the actual command implementation for details.
-
-
class
sensirion_shdlc_driver.commands.baudrate.
ShdlcCmdBaudrateBase
(*args, **kwargs)[source]¶ SHDLC command 0x91: “Get/Set Baudrate”.
-
__init__
(*args, **kwargs)[source]¶ Constructor.
Parameters: - id (byte) – Command ID (0..255).
- data (bytes-like/list) – MOSI data (0..255 bytes).
- max_response_time (float) – Maximum time the device needs to response (used as timeout).
- min_response_length (byte) – Minimum expected response length.
- max_response_length (byte) – Maximum expected response length.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
-
-
class
sensirion_shdlc_driver.commands.baudrate.
ShdlcCmdSetBaudrate
(baudrate)[source]¶ -
__init__
(baudrate)[source]¶ Constructor.
Parameters: - id (byte) – Command ID (0..255).
- data (bytes-like/list) – MOSI data (0..255 bytes).
- max_response_time (float) – Maximum time the device needs to response (used as timeout).
- min_response_length (byte) – Minimum expected response length.
- max_response_length (byte) – Maximum expected response length.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
-
-
class
sensirion_shdlc_driver.commands.baudrate.
ShdlcCmdGetBaudrate
[source]¶ -
__init__
()[source]¶ Constructor.
Parameters: - id (byte) – Command ID (0..255).
- data (bytes-like/list) – MOSI data (0..255 bytes).
- max_response_time (float) – Maximum time the device needs to response (used as timeout).
- min_response_length (byte) – Minimum expected response length.
- max_response_length (byte) – Maximum expected response length.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
-
-
class
sensirion_shdlc_driver.commands.device_info.
ShdlcCmdDeviceInfoBase
(*args, **kwargs)[source]¶ SHDLC command 0xD0: “Device Information”.
-
__init__
(*args, **kwargs)[source]¶ Constructor.
Parameters: - id (byte) – Command ID (0..255).
- data (bytes-like/list) – MOSI data (0..255 bytes).
- max_response_time (float) – Maximum time the device needs to response (used as timeout).
- min_response_length (byte) – Minimum expected response length.
- max_response_length (byte) – Maximum expected response length.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
-
-
class
sensirion_shdlc_driver.commands.device_info.
ShdlcCmdGetProductType
[source]¶ -
__init__
()[source]¶ Constructor.
Parameters: - id (byte) – Command ID (0..255).
- data (bytes-like/list) – MOSI data (0..255 bytes).
- max_response_time (float) – Maximum time the device needs to response (used as timeout).
- min_response_length (byte) – Minimum expected response length.
- max_response_length (byte) – Maximum expected response length.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
-
interpret_response
(data)[source]¶ Interpret the response to this command received from the device. This converts the raw byte array to the actual data type(s) depending on the sent command.
Parameters: data (bytes) – Raw data (payload) received from the device. Returns: Interpreted response. Data type and meaning depends on the sent command. None for commands without response data. See the actual command implementation for details.
-
-
class
sensirion_shdlc_driver.commands.device_info.
ShdlcCmdGetProductName
[source]¶ -
__init__
()[source]¶ Constructor.
Parameters: - id (byte) – Command ID (0..255).
- data (bytes-like/list) – MOSI data (0..255 bytes).
- max_response_time (float) – Maximum time the device needs to response (used as timeout).
- min_response_length (byte) – Minimum expected response length.
- max_response_length (byte) – Maximum expected response length.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
-
interpret_response
(data)[source]¶ Interpret the response to this command received from the device. This converts the raw byte array to the actual data type(s) depending on the sent command.
Parameters: data (bytes) – Raw data (payload) received from the device. Returns: Interpreted response. Data type and meaning depends on the sent command. None for commands without response data. See the actual command implementation for details.
-
-
class
sensirion_shdlc_driver.commands.device_info.
ShdlcCmdGetArticleCode
[source]¶ -
__init__
()[source]¶ Constructor.
Parameters: - id (byte) – Command ID (0..255).
- data (bytes-like/list) – MOSI data (0..255 bytes).
- max_response_time (float) – Maximum time the device needs to response (used as timeout).
- min_response_length (byte) – Minimum expected response length.
- max_response_length (byte) – Maximum expected response length.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
-
interpret_response
(data)[source]¶ Interpret the response to this command received from the device. This converts the raw byte array to the actual data type(s) depending on the sent command.
Parameters: data (bytes) – Raw data (payload) received from the device. Returns: Interpreted response. Data type and meaning depends on the sent command. None for commands without response data. See the actual command implementation for details.
-
-
class
sensirion_shdlc_driver.commands.device_info.
ShdlcCmdGetSerialNumber
[source]¶ -
__init__
()[source]¶ Constructor.
Parameters: - id (byte) – Command ID (0..255).
- data (bytes-like/list) – MOSI data (0..255 bytes).
- max_response_time (float) – Maximum time the device needs to response (used as timeout).
- min_response_length (byte) – Minimum expected response length.
- max_response_length (byte) – Maximum expected response length.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
-
interpret_response
(data)[source]¶ Interpret the response to this command received from the device. This converts the raw byte array to the actual data type(s) depending on the sent command.
Parameters: data (bytes) – Raw data (payload) received from the device. Returns: Interpreted response. Data type and meaning depends on the sent command. None for commands without response data. See the actual command implementation for details.
-
-
class
sensirion_shdlc_driver.commands.device_info.
ShdlcCmdGetProductSubType
[source]¶ -
__init__
()[source]¶ Constructor.
Parameters: - id (byte) – Command ID (0..255).
- data (bytes-like/list) – MOSI data (0..255 bytes).
- max_response_time (float) – Maximum time the device needs to response (used as timeout).
- min_response_length (byte) – Minimum expected response length.
- max_response_length (byte) – Maximum expected response length.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
-
interpret_response
(data)[source]¶ Interpret the response to this command received from the device. This converts the raw byte array to the actual data type(s) depending on the sent command.
Parameters: data (bytes) – Raw data (payload) received from the device. Returns: Interpreted response. Data type and meaning depends on the sent command. None for commands without response data. See the actual command implementation for details.
-
-
class
sensirion_shdlc_driver.commands.device_reset.
ShdlcCmdDeviceResetBase
(*args, **kwargs)[source]¶ SHDLC command 0xD3: “Device Reset”.
-
__init__
(*args, **kwargs)[source]¶ Constructor.
Parameters: - id (byte) – Command ID (0..255).
- data (bytes-like/list) – MOSI data (0..255 bytes).
- max_response_time (float) – Maximum time the device needs to response (used as timeout).
- min_response_length (byte) – Minimum expected response length.
- max_response_length (byte) – Maximum expected response length.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
-
-
class
sensirion_shdlc_driver.commands.device_reset.
ShdlcCmdDeviceReset
[source]¶ -
__init__
()[source]¶ Constructor.
Parameters: - id (byte) – Command ID (0..255).
- data (bytes-like/list) – MOSI data (0..255 bytes).
- max_response_time (float) – Maximum time the device needs to response (used as timeout).
- min_response_length (byte) – Minimum expected response length.
- max_response_length (byte) – Maximum expected response length.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
-
-
class
sensirion_shdlc_driver.commands.device_version.
ShdlcCmdDeviceVersionBase
(*args, **kwargs)[source]¶ SHDLC command 0xD1: “Get Version”.
-
__init__
(*args, **kwargs)[source]¶ Constructor.
Parameters: - id (byte) – Command ID (0..255).
- data (bytes-like/list) – MOSI data (0..255 bytes).
- max_response_time (float) – Maximum time the device needs to response (used as timeout).
- min_response_length (byte) – Minimum expected response length.
- max_response_length (byte) – Maximum expected response length.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
-
-
class
sensirion_shdlc_driver.commands.device_version.
ShdlcCmdGetVersion
[source]¶ -
__init__
()[source]¶ Constructor.
Parameters: - id (byte) – Command ID (0..255).
- data (bytes-like/list) – MOSI data (0..255 bytes).
- max_response_time (float) – Maximum time the device needs to response (used as timeout).
- min_response_length (byte) – Minimum expected response length.
- max_response_length (byte) – Maximum expected response length.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
-
interpret_response
(data)[source]¶ Interpret the response to this command received from the device. This converts the raw byte array to the actual data type(s) depending on the sent command.
Parameters: data (bytes) – Raw data (payload) received from the device. Returns: Interpreted response. Data type and meaning depends on the sent command. None for commands without response data. See the actual command implementation for details.
-
-
class
sensirion_shdlc_driver.commands.error_state.
ShdlcCmdErrorStateBase
(*args, **kwargs)[source]¶ SHDLC command 0xD2: “Device Error State”.
-
__init__
(*args, **kwargs)[source]¶ Constructor.
Parameters: - id (byte) – Command ID (0..255).
- data (bytes-like/list) – MOSI data (0..255 bytes).
- max_response_time (float) – Maximum time the device needs to response (used as timeout).
- min_response_length (byte) – Minimum expected response length.
- max_response_length (byte) – Maximum expected response length.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
-
-
class
sensirion_shdlc_driver.commands.error_state.
ShdlcCmdGetErrorState
(clear)[source]¶ -
__init__
(clear)[source]¶ Constructor.
Parameters: - id (byte) – Command ID (0..255).
- data (bytes-like/list) – MOSI data (0..255 bytes).
- max_response_time (float) – Maximum time the device needs to response (used as timeout).
- min_response_length (byte) – Minimum expected response length.
- max_response_length (byte) – Maximum expected response length.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
-
-
class
sensirion_shdlc_driver.commands.factory_reset.
ShdlcCmdFactoryResetBase
(*args, **kwargs)[source]¶ SHDLC command 0x92: “Factory Reset”.
-
__init__
(*args, **kwargs)[source]¶ Constructor.
Parameters: - id (byte) – Command ID (0..255).
- data (bytes-like/list) – MOSI data (0..255 bytes).
- max_response_time (float) – Maximum time the device needs to response (used as timeout).
- min_response_length (byte) – Minimum expected response length.
- max_response_length (byte) – Maximum expected response length.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
-
-
class
sensirion_shdlc_driver.commands.factory_reset.
ShdlcCmdFactoryReset
[source]¶ -
__init__
()[source]¶ Constructor.
Parameters: - id (byte) – Command ID (0..255).
- data (bytes-like/list) – MOSI data (0..255 bytes).
- max_response_time (float) – Maximum time the device needs to response (used as timeout).
- min_response_length (byte) – Minimum expected response length.
- max_response_length (byte) – Maximum expected response length.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
-
-
class
sensirion_shdlc_driver.commands.reply_delay.
ShdlcCmdReplyDelayBase
(*args, **kwargs)[source]¶ SHDLC command 0x95: “Get/Set Reply Delay”.
-
__init__
(*args, **kwargs)[source]¶ Constructor.
Parameters: - id (byte) – Command ID (0..255).
- data (bytes-like/list) – MOSI data (0..255 bytes).
- max_response_time (float) – Maximum time the device needs to response (used as timeout).
- min_response_length (byte) – Minimum expected response length.
- max_response_length (byte) – Maximum expected response length.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
-
-
class
sensirion_shdlc_driver.commands.reply_delay.
ShdlcCmdSetReplyDelay
(reply_delay)[source]¶ -
__init__
(reply_delay)[source]¶ Constructor.
Parameters: - id (byte) – Command ID (0..255).
- data (bytes-like/list) – MOSI data (0..255 bytes).
- max_response_time (float) – Maximum time the device needs to response (used as timeout).
- min_response_length (byte) – Minimum expected response length.
- max_response_length (byte) – Maximum expected response length.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
-
-
class
sensirion_shdlc_driver.commands.reply_delay.
ShdlcCmdGetReplyDelay
[source]¶ -
__init__
()[source]¶ Constructor.
Parameters: - id (byte) – Command ID (0..255).
- data (bytes-like/list) – MOSI data (0..255 bytes).
- max_response_time (float) – Maximum time the device needs to response (used as timeout).
- min_response_length (byte) – Minimum expected response length.
- max_response_length (byte) – Maximum expected response length.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
-
-
class
sensirion_shdlc_driver.commands.slave_address.
ShdlcCmdSlaveAddressBase
(*args, **kwargs)[source]¶ SHDLC command 0x90: “Get/Set Slave Address”.
-
__init__
(*args, **kwargs)[source]¶ Constructor.
Parameters: - id (byte) – Command ID (0..255).
- data (bytes-like/list) – MOSI data (0..255 bytes).
- max_response_time (float) – Maximum time the device needs to response (used as timeout).
- min_response_length (byte) – Minimum expected response length.
- max_response_length (byte) – Maximum expected response length.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
-
-
class
sensirion_shdlc_driver.commands.slave_address.
ShdlcCmdSetSlaveAddress
(slave_address)[source]¶ -
__init__
(slave_address)[source]¶ Constructor.
Parameters: - id (byte) – Command ID (0..255).
- data (bytes-like/list) – MOSI data (0..255 bytes).
- max_response_time (float) – Maximum time the device needs to response (used as timeout).
- min_response_length (byte) – Minimum expected response length.
- max_response_length (byte) – Maximum expected response length.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
-
-
class
sensirion_shdlc_driver.commands.slave_address.
ShdlcCmdGetSlaveAddress
[source]¶ -
__init__
()[source]¶ Constructor.
Parameters: - id (byte) – Command ID (0..255).
- data (bytes-like/list) – MOSI data (0..255 bytes).
- max_response_time (float) – Maximum time the device needs to response (used as timeout).
- min_response_length (byte) – Minimum expected response length.
- max_response_length (byte) – Maximum expected response length.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
-
-
class
sensirion_shdlc_driver.commands.system_up_time.
ShdlcCmdSystemUpTimeBase
(*args, **kwargs)[source]¶ SHDLC command 0x93: “System Up Time”.
-
__init__
(*args, **kwargs)[source]¶ Constructor.
Parameters: - id (byte) – Command ID (0..255).
- data (bytes-like/list) – MOSI data (0..255 bytes).
- max_response_time (float) – Maximum time the device needs to response (used as timeout).
- min_response_length (byte) – Minimum expected response length.
- max_response_length (byte) – Maximum expected response length.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
-
-
class
sensirion_shdlc_driver.commands.system_up_time.
ShdlcCmdGetSystemUpTime
[source]¶ -
__init__
()[source]¶ Constructor.
Parameters: - id (byte) – Command ID (0..255).
- data (bytes-like/list) – MOSI data (0..255 bytes).
- max_response_time (float) – Maximum time the device needs to response (used as timeout).
- min_response_length (byte) – Minimum expected response length.
- max_response_length (byte) – Maximum expected response length.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing (typically 0.0s).
-
Types¶
-
class
sensirion_shdlc_driver.types.
FirmwareVersion
(major, minor, debug)[source]¶ Class representing the firmware version of an SHDLC device.
-
class
sensirion_shdlc_driver.types.
HardwareVersion
(major, minor)[source]¶ Class representing the hardware version of an SHDLC device.
-
class
sensirion_shdlc_driver.types.
ProtocolVersion
(major, minor)[source]¶ Class representing the SHDLC protocol version of an SHDLC device.
-
class
sensirion_shdlc_driver.types.
Version
(firmware, hardware, protocol)[source]¶ Class representing all version numbers of an SHDLC device. This is used for the “Get Version” command.
-
__init__
(firmware, hardware, protocol)[source]¶ Constructor.
Parameters: - firmware (FirmwareVersion) – Firmware version.
- hardware (HardwareVersion) – Hardware version.
- protocol (ProtocolVersion) – SHDLC protocol version.
-
Exceptions¶
-
exception
sensirion_shdlc_driver.errors.
ShdlcError
[source]¶ Base class for all SHDLC related exceptions.
-
exception
sensirion_shdlc_driver.errors.
ShdlcFirmwareImageSignatureError
(signature)[source]¶ SHDLC firmware image signature error.
-
exception
sensirion_shdlc_driver.errors.
ShdlcFirmwareImageIncompatibilityError
(image_type, device_type)[source]¶ SHDLC firmware image incompatibility error.
-
exception
sensirion_shdlc_driver.errors.
ShdlcTimeoutError
[source]¶ SHDLC timeout exception (device did not respond to command).
-
exception
sensirion_shdlc_driver.errors.
ShdlcResponseError
(message, received_data=None)[source]¶ SHDLC response error (slave response contains invalid data)
-
__init__
(message, received_data=None)[source]¶ Constructor.
Parameters: - message (string) – Error message.
- received_data – The received (invalid) raw data.
-
received_data
¶ Get the (invalid) raw data which was received from the device.
Returns: The raw data received from the device. Return type: bytes
-
-
exception
sensirion_shdlc_driver.errors.
ShdlcDeviceError
(code, message='Unknown error.')[source]¶ SHDLC device error (communication was successful, but slave failed to execute a command). For each error code a subclass exists to provide the corresponding error messages.
-
__init__
(code, message='Unknown error.')[source]¶ Constructor.
Parameters: - code (byte) – The error code received from the device.
- message (string) – The error description for the given error code.
-
error_code
¶ Get the error code received from the device.
Returns: Received error code. Return type: byte
-
error_message
¶ Get the description of the received error code.
Returns: Error message. Return type: string
-
-
exception
sensirion_shdlc_driver.errors.
ShdlcCommandDataSizeError
[source]¶ SHDLC device error for wrong data size.
-
exception
sensirion_shdlc_driver.errors.
ShdlcUnknownCommandError
[source]¶ SHDLC device error for unknown command.
-
exception
sensirion_shdlc_driver.errors.
ShdlcAccessRightError
[source]¶ SHDLC device error for wrong access right.
-
exception
sensirion_shdlc_driver.errors.
ShdlcCommandParameterError
[source]¶ SHDLC device error for illegal command parameter.