get_events.py¶
Purpose: Collect detector events in a single measurement run
Use case: Basic data acquisition, standalone measurements
Features:
- Same interface as
kazunoko measurewith an added--saveflag for file output - Auto-generated filenames based on device MAC address and timestamp
- Count-based or time-based measurement mode (
--use-event/--use-sec) - Progress bar output
- Verbose logging support
Output filename format: YYYYMMDD/events_{MAC}_{timestamp}_{id}.jsonl
Usage:
# Print to stdout
uv run examples/get_events.py "1:300;2:320;3:310" 100
# Save to file automatically
uv run examples/get_events.py "1:300;2:320;3:310" 100 --save
# Time-based measurement (60 seconds)
uv run examples/get_events.py "1:300;2:320;3:310" 60 --use-sec
# With verbose logging redirected to a log file
uv run examples/get_events.py "1:300;2:320;3:310" 100 --save --verbose 2> measure.log
# Test without hardware
uv run examples/get_events.py "1:300;2:320;3:310" 100 --mock
CLI Options:
| Option | Default | Description |
|---|---|---|
THRESHOLDS |
(required) | Threshold config as ch1:value;ch2:value;ch3:value |
EVENTS_OR_SECS |
(required) | Number of events (--use-event) or duration in seconds (--use-sec) |
--save |
off | Save output to auto-generated file (default: stdout) |
--use-event / --use-sec |
--use-event |
Collect by event count or by duration |
--port / -p |
auto |
Serial port (auto for auto-detection) |
--poll-count / -pc |
10 |
Events to poll per cycle (1–65535) |
--event-timeout / -et |
5.0 |
Timeout in seconds to wait for an event |
--verbose / --quiet |
--quiet |
Show or suppress status messages |
--mock |
off | Use mock device for testing without hardware |
--log-level |
error |
Log level (debug/info/error) |
Implementation pattern:
from kazunoko import Measure, MeasureConfig, parse_thresholds
threshold_dict = parse_thresholds("1:300;2:320;3:310")
config = MeasureConfig(
thresholds=threshold_dict,
poll_count=10,
event_timeout=5.0,
)
measure = Measure(detector, config)
measure.setup()
for event in measure.stream_by_count(100):
print(event.model_dump_json())