.hom Python Scripting
The .hom scripting panel lets you write Python scripts that run closed-loop experiments: reading neural data, making decisions, and sending commands back to the device — all in real time. No firmware upload is needed; scripts run entirely in the HMCLS app.
Two Scripts
| Script | When it runs |
|---|---|
| setup.hom | Once when you press Run |
| loop.hom | Repeatedly at your chosen Hz rate |
HOM Script API
These functions are automatically available in both scripts:
| Function | Description |
|---|---|
send("CMD") | Send a UDP command to the device (e.g. send("FLAG SET 1")) |
log("message") | Print a message to the panel's log output |
end() | Stop the loop cleanly |
Signal(indice, tools, window) | Declare a channel to analyze each tick |
N | Current loop iteration index (integer, starts at 0) |
Signal Declarations
Signal(indice, tools, window) — declare this in setup.hom.
| Parameter | Description |
|---|---|
indice | Channel index (0-based) |
tools | List of metrics to compute each tick: "latest", "mean", "rms", "std", "peak_to_peak", "sample_rate", "fft_max", "fft_power" |
window | Analysis window size in samples |
After declaration, the Signal object is updated each loop tick. Access metrics as signal.rms, signal.mean, etc.
Example
setup.hom:
ch0 = Signal(0, ["rms", "mean"], window=1000)
ch1 = Signal(1, ["rms"], window=1000)
log("Setup complete")
loop.hom:
if ch0.rms > 500:
send("FLAG SET 1")
log(f"Spike burst detected on ch0: RMS={ch0.rms:.1f}")
if N % 100 == 0:
log(f"Tick {N}: ch0_rms={ch0.rms:.1f}, ch1_rms={ch1.rms:.1f}")
Panel Controls
| Control | Description |
|---|---|
| setup.hom card | Click to open the script editor for setup |
| loop.hom card | Click to open the script editor for the loop |
| Python interpreter | Auto-detected or manually selected Python path |
| Loop Hz | Script tick rate: 0.01–100 Hz |
| Run (▶) | Start the scripting loop |
| Stop (■) | Stop the loop |
| Status dot | Green = running, red = stopped/error |
| Tick counter | Shows current iteration N |
| Log output | Last 100 log() lines |
Script Editor Modal
- Syntax highlighting for Python keywords, HOM builtins, strings, comments
- Tab / Shift+Tab for indentation
- Load… / Save… to import/export
.pyor.homfiles - Apply button to save changes to the panel
Persistence
Scripts and the Python interpreter path are saved in the app between sessions.
Python Requirement
A Python 3.x interpreter must be available on your system. The app auto-detects common installations. You can also click Browse… to select a specific interpreter.
Tips
- Start with a slow loop rate (1–2 Hz) when developing. Use
log()to print intermediate values. Once working, increase to your desired rate. - Use
N % 100 == 0to print periodic status without flooding the log. - Call
end()inside the loop to stop gracefully after a condition is met.