Skip to content

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

device

IDevice

The device to connect to.

required

**kwargs

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
timeout
float | None

Maximum seconds to wait for a frame. None waits until a frame is available. 0 returns immediately when no frame is available.

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 timeout=0 and no frame is available, returns (None, None).

read_reg(reg)

Read a register value from the senxor.

If this operation fails, this function should raise an exception depending on the error.

Parameters:

Name Type Description Default
reg
int

The register to read.

required

Returns:

Type Description
int

The value of the register.

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
regs
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 a value to a register.

If this operation fails, this function should raise an exception depending on the error.

Parameters:

Name Type Description Default
reg
int

The register to write to.

required
value
int

The value to write to the register.

required

write_regs(regs)

(Optional) Write multiple registers to the senxor.

If this operation fails, this function should raise an exception depending on the error.

Parameters:

Name Type Description Default
regs
dict[int, int]

The dictionary of register addresses and their values to write.

required

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.