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
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:
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:
4. stop the 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.