Guides
Using your own test framework
If your tests talk to the device over a serial line, such as RS-485 or a debug UART, you can keep them. Board.serial opens one of the simulated board's ports on your computer, and pyserial opens it like a real one.
Open a port
import serial
from hardlabs_sdk import Client
with Client().start("company_name/board_name", "build/app.elf") as board:
print(board.serial_ports()) # ['console', 'rs485', 'rs485-b']
bus = board.serial("rs485")
print(bus.url) # socket://127.0.0.1:53817
port = serial.serial_for_url(bus.url, baudrate=115200, timeout=5)
port.write(frame)- Bytes pass through unchanged in both directions, so binary protocols (SLIP frames, CRCs) arrive as sent.
- The address stays the same while the board restarts.
- As on a real serial line, bytes the firmware sends while nothing has the port open are dropped.
Swap a bench rig for the simulation
If your conftest.py finds the device's port in a session fixture, replace that one fixture with the SerialBridge from the hardlabs_serial fixture:
import pytest
@pytest.fixture(name="setup", scope="session", autouse=True)
def setup_fixture(hardlabs_serial):
port = hardlabs_serial("rs485") # the board boots once for the session
set_context(port.url) # your framework's own setuppytest tests/pcb --hardlabs-sim company_name/board_name \
--hardlabs-firmware bootloader.bin@0x00400000 --hardlabs-firmware app.bin@0x00410000Ports for programs not written in Python
python -m hardlabs_sdk up boots the board, prints each port's address and keeps the ports open until you press Ctrl-C:
python -m hardlabs_sdk up company_name/board_name \
--firmware build/app.elf --serial rs485 --serial consoleDevice files
On macOS and Linux, pty=True gives a pseudo-terminal, for tools that need a device path rather than a URL:
bus = board.serial("rs485", pty=True)
print(bus.path) # /dev/ttys012Frameworks that reopen the port for every command
pyserial waits 0.3 s when it closes a socket:// port. The SDK skips that wait for its own ports when they are opened in the same Python process, as the pytest fixtures are. A separate program connected to python -m hardlabs_sdk up still waits 0.3 s on each close.