Skip to content

senxor

senxor

Top-level package for Senxor devices.

Senxor

__init__(address, interface_type=None, auto_open=True, stop_stream_on_connect=True, get_status_on_connect=True, **kwargs)

Initialize the senxor.

Parameters:

Name Type Description Default
address Any

The address of the senxor.

required
interface_type Literal['serial'] | None

The type of the interface, by default None.

None
auto_open bool

Whether to open the senxor automatically, by default True.

True
stop_stream_on_connect bool

Whether to stop the stream automatically on connect, by default True.

True
get_status_on_connect bool

Whether to get the status of the senxor automatically on connect, by default True.

True
kwargs Any

The extra keyword arguments for the interface.

{}

Raises:

Type Description
ValueError

If the address is not valid for any of the supported types.

close()

Close the senxor. If the senxor is not connected, do nothing.

get_shape()

Get the frame shape(height, width) of the senxor.

Returns:

Type Description
tuple[int, int]

The frame shape(height, width) of the senxor.

open()

Open the senxor. If the senxor is already connected, do nothing.

read(block=True, *, raw=False, celsius=True)

Read the frame data from the senxor, return (header: np.ndarray[uint16], frame: np.ndarray).

The header is a 1D numpy array of uint16, check documentation for more details. The frame depends on the raw and celsius parameters. By default, the frame is a numpy array with shape (height, width), dtype is float32, each element means the temperature in Celsius.

Parameters:

Name Type Description Default
block bool

Whether to block the read operation until a frame is available. If False, if no frame is available, return None immediately.

True
raw bool

Whether to return the raw data or the frame data. Raw data is a flat numpy array of uint16. Frame data is reshaped to a 2D numpy array of uint16. In the most cases, frame data is open to use.

False
celsius bool

Whether to convert the frame data to Celsius. If True, the frame data will be converted to Celsius, float32. If False, the frame data will be returned in 1/10 Kelvin, uint16.

True

Returns:

Type Description
tuple[ndarray, ndarray] | tuple[None, None]

The frame data, as a tuple of two numpy arrays. The first array is the header data, the second array is the frame data.

If block=False and no frame is available, return (None, None).

Raises:

Type Description
SenxorNotConnectedError

If the senxor is not connected.

RuntimeError

If the senxor is not in the stream mode or single capture mode.

SenxorReadTimeoutError

If the read operation timeout due to other reasons.

read_reg(reg)

Read the value from a register.

Notes
  • You need to know the register name or address to use this method.
  • For a more modern and editor-friendly approach, use senxor.regs.REG_NAME to benefit from autocompletion.
  • If you want to read multiple registers at once, read_regs is more efficient as it only communicates with the device once.

Parameters:

Name Type Description Default
reg int | str | Register

The register to read from, specified as a Register instance, a register name, or an integer address.

required

Returns:

Type Description
int

The value read from the register.

Raises:

Type Description
ValueError

If the register is not readable.

Examples:

>>> senxor.read_reg(senxor.regs.EMISSIVITY)
95
>>> senxor.read_reg("EMISSIVITY")
95
>>> senxor.read_reg(0xCA)
95
>>> senxor.read_reg(202)
95

read_regs(regs)

Read the values from multiple registers at once.

Note: This method takes the almost same time as reading one register.

Parameters:

Name Type Description Default
regs list[str | int | Register]

The list of registers to read from, specified as a list of register names, integer addresses, or Register instances.

required

Returns:

Type Description
dict[int, int]

The dictionary of register addresses and their values.

Raises:

Type Description
ValueError

If a register is not readable.

Examples:

>>> senxor.regs_read([0xB1, 0xB2, 0xB3, 0xB4])
{177: 0, 178: 0, 179: 0, 180: 0}

refresh_regmap()

Refresh the regmap cache. This method will read all registers and update all fields.

Then use self.regs.status and self.fields.status to get the status you want.

Examples:

>>> senxor.refresh_regmap()
>>> senxor.regs.status
{177: 0, 0: 0, 1: 0, ...}
>>> senxor.fields.status
{"SW_RESET": 0, "DMA_TIMEOUT_ENABLE": 0, ...}

start_stream()

Start the stream mode.

stop_stream()

Stop the stream mode.

write_reg(reg, value)

Write a value to a register.

Parameters:

Name Type Description Default
reg str | int | Register

The register to write to, specified as a register name, integer address, or Register instance.

required
value int

The value to write to the register (0-0xFF).

required

Returns:

Type Description
Any

The result of the write operation, as returned by the interface.

Raises:

Type Description
ValueError

If the register is not writable or the value is out of range.

Examples:

>>> senxor.write_reg("EMISSIVITY", 0x5F)
>>> senxor.write_reg(0xCA, 0x5F)
>>> senxor.write_reg(senxor.regs.EMISSIVITY, 0x5F)

connect(address=None, type=None, *, auto_open=True, stop_stream=True, **kwargs)

Connect to a Senxor device.

Parameters:

Name Type Description Default
address str | ListPortInfo

The address of the device to connect to.

None
type Literal['serial']

The type of device to connect to. If not provided, will attempt to auto-detect from address.

None
auto_open bool

Whether to automatically open the device.

True
stop_stream bool

Whether to stop the stream when the device is opened.

True
**kwargs

Additional arguments passed to the interface constructor.

{}

Returns:

Type Description
Senxor

The Senxor device.

Examples:

Use a context manager to connect to a device:

>>> from senxor import list_senxor, connect
>>> addrs = list_senxor("serial")
>>> with connect(addrs[0]) as dev:
...     print(f"Connected to device {dev.address}")
Connected to device COM3

Or connect to a device without a context manager:

>>> dev = connect(addrs[0])
>>> print(f"Connected to device {dev.address}")
Connected to device COM3

It's recommended to use a context manager because it will automatically close the device when the context is exited.

list_senxor(type=None, exclude=None)

List all Senxor devices available.

The return value is a list of Senxor devices, use senxor.connect to connect to a device.

Parameters:

Name Type Description Default
type Literal['serial'] | None

The type of device to list. If not provided, all types will be listed.

None
exclude list[str] | str | None

If type is provided, this will be ignored. A list of device names to exclude from the list. If not provided, all devices will be listed.

None

Returns:

Type Description
list

A list of Senxor devices, use senxor.connect to connect to a device.