senxor.interface.protocol
DeviceState(is_streaming, frame_shape, fps_divider, no_header)
dataclass
is_streaming
instance-attribute
frame_shape
instance-attribute
fps_divider
instance-attribute
no_header
instance-attribute
IDevice
Bases: Protocol
Protocol class for the device.
This class is used to provide a uniform interface for the communication with
the device, e.g. serial port, socket, etc. It must have a name attribute for identification.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the device. |
interface_type |
ClassVar[str]
|
The type of the interface. |
INTERFACE_TYPE
class-attribute
name
property
The name of the device.
ISenxorInterface(device)
Bases: Protocol
Protocol class for the Senxor devices.
This class is used to provide a uniform interface for the communication with the device, e.g. USB, TCP/IP, etc.
Attributes:
| Name | Type | Description |
|---|---|---|
device |
IDevice
|
The device to communicate with. |
is_connected |
bool
|
Whether the device is connected. |
data_ready |
bool
|
Whether the data is ready to be read. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
IDevice
|
The device to connect to. |
required |
|
Any
|
Additional keyword arguments to pass to the interface. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
device
property
The device to communicate with.
is_connected
property
Whether the device is connected.
data_ready
property
(Optional) Whether the data is ready to be read.
list_devices()
classmethod
List all the devices of this interface.
open()
Open the connection to the device.
If the device is already open, this method should not raise an exception.
close()
Close the connection to the device.
If the device is already closed, this method should not raise an exception.
bind_state(state)
Receive the latest device state snapshot from Senxor.
read(timeout=None)
Read a frame from the senxor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
float | None
|
Maximum seconds to wait for a frame. |
None
|
Raises:
| Type | Description |
|---|---|
SenxorResponseTimeoutError
|
If no frame is available before the timeout expires. |
Returns:
| Type | Description |
|---|---|
tuple[bytes | None, bytes | None]
|
Frame header and payload bytes. When |
read_reg(reg)
read_regs(regs)
(Optional) Read multiple registers from the senxor.
If this operation fails, this function should raise an exception depending on the error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[int]
|
The list of registers to read. |
required |
Returns:
| Type | Description |
|---|---|
dict[int, int]
|
The dictionary of register addresses and their values. |
write_reg(reg, value)
write_regs(regs)
hard_reset()
(Optional) Hard reset the device.
This operation is optional and may not be supported by all devices.
This method should not automatically re-open the connection to the device.
Returns:
| Type | Description |
|---|---|
None
|
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the device does not support hard reset. |