Python API
from eskin import EskinReader, Frame, FrameParser, find_port, list_candidate_portsfrom eskin import ROWS, COLS, TAXELS, FRAME_SIZE, BAUD, SIZE_MM, PITCH_MMEskinReader
Section titled “EskinReader”EskinReader(port=None, baudrate=2_000_000, threshold=60, timeout=1.0, rotate=1)| Argument | Meaning |
|---|---|
port |
The serial port. None calls find_port(), which raises RuntimeError unless exactly one USB serial device is connected. |
baudrate |
Keep the default. Boards with a UART bridge work only at 2 000 000 baud. |
threshold |
Corrected values below this number become 0. |
timeout |
Seconds without data before a read raises TimeoutError. |
rotate |
Clockwise quarter turns for each frame. See Orientation. |
The reader has two modes. Use one of them at a time.
Blocking mode
Section titled “Blocking mode”Your code asks for each frame.
with EskinReader() as reader: reader.calibrate() frame = reader.read_frame() for frame in reader.frames(): ...| Method | Meaning |
|---|---|
open(), close() |
Open and close the port. The with statement calls them. |
read_frame() -> Frame |
Wait for the next frame. Raises TimeoutError after timeout seconds without data. |
read_raw() -> tuple[int, ...] |
Wait for the next frame and return the 2304 raw counts. |
frames() |
An iterator that calls read_frame() without end. |
flush() |
Drop the data in the buffers. The next frame is then new. |
Background mode
Section titled “Background mode”A thread reads all frames. Your code looks at the newest frame or gets a callback.
reader = EskinReader().start()reader.calibrate()reader.on_frame(lambda frame: print(frame.max()))...newest = reader.latestreader.close()| Method or attribute | Meaning |
|---|---|
start() |
Open the port and start the thread. |
stop() |
Stop the thread. close() calls it. |
latest |
The newest Frame, or None before the first frame. |
on_frame(callback) |
Call callback(frame) for each frame. The call runs on the reader thread. Keep it fast. |
error |
The exception that stopped the thread, or None. |
While the thread runs, read_frame(), read_raw() and frames() raise RuntimeError when another thread calls them. Only one thread can read the port.
If the sensor is disconnected, the thread stops, logs the reason to the eskin.reader logger, and stores it in error.
The reader does not connect again. Create a new reader.
Baseline
Section titled “Baseline”| Method or attribute | Meaning |
|---|---|
calibrate(n_frames=20, timeout=None) |
Read n_frames frames and store the maximum of each taxel as the baseline. Returns the baseline. |
clear_baseline() |
Remove the baseline. |
baseline |
The baseline as 2304 counts, or None. |
threshold |
You can change it at any time. |
calibrate() is safe from any thread in both modes. In background mode, the reader thread does the work and the call waits for it.
During a calibration, callbacks and latest do not get new frames. For the 20 mm pad this is about 0.4 seconds.
Diagnostics
Section titled “Diagnostics”| Attribute | Meaning |
|---|---|
is_open |
True when the port is open. |
resyncs |
How many times the parser skipped bytes to find a frame. |
A frozen dataclass.
| Field | Meaning |
|---|---|
timestamp |
time.time() on the computer when the frame was decoded. |
seq |
Frame count since the port was opened. Starts at 1. |
raw |
2304 counts from the sensor, after rotation. |
values |
2304 values after baseline and threshold. |
rows, cols |
48 and 48. |
| Method | Meaning |
|---|---|
frame[row, col] |
The corrected value of one taxel. |
grid() |
The values as a list of 48 rows. |
max(), sum() |
Maximum and sum of values. |
as_array(raw=False) |
A NumPy array with shape (48, 48) and dtype int32. Needs the numpy extra. |
Port discovery
Section titled “Port discovery”| Function | Meaning |
|---|---|
list_candidate_ports() -> list[str] |
All USB serial ports. Other USB serial devices are included. |
find_port() -> str |
The port, when exactly one candidate is present. Otherwise raises RuntimeError. |
FrameParser
Section titled “FrameParser”Use the parser alone when the bytes come from a file or a socket.
from eskin import FrameParser
parser = FrameParser()for chunk in source: # bytes of any length for raw in parser.feed(chunk): # tuples of 2304 ints, wire order ...eskin.protocol also has decode_payload(), encode_frame() and rotation_map(). encode_frame() builds a wire frame from 2304 integers, which is useful in tests.
Visualiser
Section titled “Visualiser”from eskin.viz import serve
serve(reader, host="127.0.0.1", port=8765, open_browser=True, size_mm=20.0)serve() starts the background mode of an open reader and runs the live visualiser until Ctrl-C.