Skip to main content

.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​

ScriptWhen it runs
setup.homOnce when you press Run
loop.homRepeatedly at your chosen Hz rate

HOM Script API​

These functions are automatically available in both scripts:

FunctionDescription
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
NCurrent loop iteration index (integer, starts at 0)

Signal Declarations​

Signal(indice, tools, window) — declare this in setup.hom.

ParameterDescription
indiceChannel index (0-based)
toolsList of metrics to compute each tick: "latest", "mean", "rms", "std", "peak_to_peak", "sample_rate", "fft_max", "fft_power"
windowAnalysis 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​

ControlDescription
setup.hom cardClick to open the script editor for setup
loop.hom cardClick to open the script editor for the loop
Python interpreterAuto-detected or manually selected Python path
Loop HzScript tick rate: 0.01–100 Hz
Run (▶)Start the scripting loop
Stop (■)Stop the loop
Status dotGreen = running, red = stopped/error
Tick counterShows current iteration N
Log outputLast 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 .py or .hom files
  • 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 == 0 to print periodic status without flooding the log.
  • Call end() inside the loop to stop gracefully after a condition is met.