Basic Stream¶
This tutorial shows how to start a stream and read data from a Senxor device.
1. connect to the device¶
See the Connect Device tutorial for how to connect to the device.
from senxor import connect, list_senxor
devices = list_senxor("serial")
if not devices:
raise ValueError("No devices found")
dev = connect(devices[0])
2. start the stream¶
dev.start_stream()
3. read the data¶
header, frame = dev.read()
print(f"Frame shape: {frame.shape}, dtype: {frame.dtype}")
print(f"Frame min: {frame.min()} C, max: {frame.max()} C, mean: {frame.mean():.1f} C")
Output:
Frame shape: (120, 160), dtype: float32
Frame min: 20.3 C, max: 34.1 C, mean: 27.2 C
The read() method returns two values: header (a 1-D NumPy array of uint16 containing frame metadata, or None) and frame (a 2-D NumPy array of float32 with shape (height, width)). By default, frame contains temperature values in degrees Celsius.
By default, read() waits until a new frame arrives or a timeout occurs, so when it returns you have a valid frame. If you pass block=False, it returns immediately; when no frame is ready, both header and frame will be None. In that case you must check before using the result:
header, frame = dev.read(block=False)
if frame is not None:
print(f"Frame shape: {frame.shape}")
else:
print("No new frame is available")
Output:
No new frame is available
4. stop the stream¶
dev.stop_stream()
The stop_stream method will stop the stream but keep the connection open.
You can also use the close method, which will stop the stream and close the connection.
Summary¶
start_stream()starts the stream mode.stop_stream()stops the stream mode but keeps the connection open.close()stops the stream and closes the connection.
A full example is available in the Basic Stream example.