Skip to content

Configure Bridges

mcgpib supports two transport types for connecting to AR488 bridges: serial (USB) and TCP (WiFi). Each bridge gets its own [[bridge]] section in the TOML configuration file with transport-specific options and tuning parameters.

mcgpib searches for its config file in this order:

  1. The path in the $MCGPIB_CONFIG environment variable
  2. ./mcgpib.toml in the current working directory
  3. ~/.config/mcgpib/config.toml

If no file is found, mcgpib starts with no bridges configured.

Serial is the simplest and most reliable transport. Connect the ESP32 to your machine with a USB cable.

mcgpib.toml
[[bridge]]
name = "bench-a"
transport = "serial"
port = "/dev/ttyUSB0"
baudrate = 115200

Required fields:

FieldDescription
nameUnique identifier for this bridge. Alphanumeric with hyphens and underscores.
transportSet to "serial".
portSerial port path.
baudrateBaud rate matching the AR488 firmware (default 115200).

Finding your serial port:

  • Linux: ls /dev/ttyUSB* or ls /dev/ttyACM*
  • macOS: ls /dev/cu.usbserial-* or ls /dev/cu.usbmodem*
  • Windows: Check Device Manager for COM ports (e.g., COM3)

These fields are optional and apply to both serial and TCP bridges.

mcgpib.toml
[[bridge]]
name = "bench-a"
transport = "serial"
port = "/dev/ttyUSB0"
baudrate = 115200
auto_scan = true
auto_identify = true
read_timeout_ms = 3000
inter_command_delay_ms = 10
FieldDefaultDescription
auto_scantrueScan the bus for listeners immediately after connecting.
auto_identifytrueSend *IDN? to each discovered listener during scan.
read_timeout_ms3000How long to wait for an instrument response (1—32000 ms).
inter_command_delay_ms10Pause between consecutive bus commands (0—1000 ms).

The right timeout depends on your instruments and transport:

Scenarioread_timeout_msinter_command_delay_ms
Serial, fast instruments (34401A, 2000)300010
Serial, slow instruments (electrometer, source measure)1000010
TCP, typical bench500020
TCP, high-latency network1000030

Set auto_scan = false when:

  • You want faster connection times and will scan manually later
  • The bus has instruments that behave unpredictably when polled (some older instruments respond to findlstn inconsistently)
  • You are connecting to an empty bridge for diagnostic purposes

Set auto_identify = false (while keeping auto_scan = true) when:

  • You want to discover listener addresses quickly without the overhead of *IDN? queries
  • Your instruments do not support IEEE 488.2 identification

Add multiple [[bridge]] sections to manage separate GPIB buses from a single mcgpib instance:

mcgpib.toml
[server]
log_level = "INFO"
read_timeout_ms = 3000
[[bridge]]
name = "bench-a"
transport = "serial"
port = "/dev/ttyUSB0"
baudrate = 115200
auto_scan = true
auto_identify = true
[[bridge]]
name = "bench-b"
transport = "tcp"
host = "192.168.1.50"
tcp_port = 23
read_timeout_ms = 5000
inter_command_delay_ms = 20

Each bridge operates independently with its own connection, lock, and bus state. Operations on different bridges run concurrently. The name field must be unique across all bridges.

The [server] section sets defaults that apply when a bridge does not specify its own value:

mcgpib.toml
[server]
log_level = "INFO"
read_timeout_ms = 3000
FieldDefaultDescription
log_level"INFO"Logging verbosity: DEBUG, INFO, WARNING, ERROR.
read_timeout_ms3000Default read timeout, overridden by per-bridge read_timeout_ms.

Some bridge settings can be changed after connecting without editing the config file:

> Set the read timeout on bench-a to 10 seconds

The LLM calls configure_bridge("bench-a", read_timeout_ms=10000). Runtime-configurable parameters:

ParameterDescription
read_timeout_msRead timeout in milliseconds
auto_modeAuto-read mode (0=off, 1=prologix, 2=on-query, 3=continuous)
eosEnd-of-send character (0=CRLF, 1=CR, 2=LF, 3=None)
eoiWhether to assert EOI on the last byte sent

If you move a bridge from USB to WiFi (or vice versa), update the transport and its associated fields in the config:

Before: serial
[[bridge]]
name = "bench-a"
transport = "serial"
port = "/dev/ttyUSB0"
baudrate = 115200
After: TCP
[[bridge]]
name = "bench-a"
transport = "tcp"
host = "192.168.1.50"
tcp_port = 23
read_timeout_ms = 5000
inter_command_delay_ms = 20

Keep the name the same so that any scripts or saved conversations referencing "bench-a" continue to work. Restart mcgpib after changing the config file.