Skip to main content

Python Examples

These examples use the Board helper defined in the UDP Interface Overview. Save it as hmcls_udp.py next to your scripts. They assume a board reachable at 192.168.1.11 (the address the board falls back to on a direct cable connection; use the address shown on the device screen otherwise).

Run without the HMCLS app on the same PC

The HMCLS app holds port 55153 (replies and events) and, while it is connected, port 55151 (data stream). Close it before running these scripts on the same computer.

Connect, configure and start​

session.py
from hmcls_udp import Board

board = Board("192.168.1.11")
MY_IP = "192.168.1.50" # the IP of this PC

info = board.request("INFO")
print("state:", info["state"], "| owner:", info["dest"])

if info["dest"] not in ("none", MY_IP):
print("The board is used by", info["dest"], "- taking it over")
board.request(f"DEST {MY_IP}") # stream and events now come to this PC

if info["state"] == "needs_setup":
board.request("SETUP", timeout=5.0)

board.request("START")

Read the data stream​

See Data Stream for the datagram format and a complete decoding script.

Flag lifecycle​

flag_example.py
from hmcls_udp import Board

board = Board("192.168.1.11")

board.request("FLAG SET 3")
print(board.query("FLAG TAKE 3")) # ['FLAG 3 1'] (was set, now cleared)
print(board.query("FLAG TAKE 3")) # ['FLAG 3 0'] (already cleared)

NET relay​

net_relay_example.py
from hmcls_udp import Board

# From the PC: ask board A to raise flag 1 on board B.
board_a = Board("192.168.1.11")
board_a.request("NET 192.168.1.21 FLAG SET 1")

Spike monitoring​

Spike detection raises flag 33 + channel for every spike. Poll it with FLAG TAKE:

spike_monitor.py
import time
from hmcls_udp import Board

board = Board("192.168.1.11")
board.request("SPIKE ON 4.5 NEG 1.5 CH 0")

while True:
line = board.query("FLAG TAKE 33", timeout=0.05)[0] # channel 0 -> flag 33
if line.endswith(" 1"):
print(f"Spike on channel 0 at {time.time():.3f}")
time.sleep(0.001)

Elapsed time​

GET_TIME timestamps events relative to the current acquisition:

get_time_example.py
from hmcls_udp import Board

board = Board("192.168.1.11")
ms = int(board.query("GET_TIME")[0].split()[1])
print(f"Elapsed: {ms} ms")

Acquisition mode​

chip_mode_example.py
from hmcls_udp import Board

board = Board("192.168.1.11")
board.request("STOP")
board.request("SET_CHIP_MODE SIM") # synthetic data, no headstage needed
board.request("SETUP", timeout=5.0)
print(board.query("GET_CHIP_MODE")) # ['CHIP_MODE SIM']

I2C​

Addresses and values are hexadecimal.

i2c_example.py
from hmcls_udp import Board

board = Board("192.168.1.11")
board.request("I2C WRITE 0x48 0x01 0xC3 0x83") # write two bytes to register 0x01
line = board.query("I2C READ 0x48 0x01 2")[0] # 'I2C 0xC3 0x83'
print([int(v, 16) for v in line.split()[1:]])

Impedance sweep​

See DEEP_ZCHECK and ZCHECK_SCAN for complete scripts.