Skip to content

Batch Measurements

When you need to take multiple readings — across several instruments or repeated samples from one — mcgpib provides the tools to build automated measurement sequences. Since each bridge serializes commands through its own lock, the key is structuring your requests so the LLM executes them in the right order.

Read from multiple instruments in sequence

Section titled “Read from multiple instruments in sequence”

A typical bench might have a power supply, a multimeter measuring voltage, and another measuring current. To capture a coordinated snapshot:

> On bench-a, read DC voltage from address 1, DC current from address 5,
and the output voltage setting from the power supply at address 22.
Report all three values together.

The LLM calls these in sequence (all on the same bridge, so they serialize automatically):

instrument_query("bench-a", 1, "MEAS:VOLT:DC?") → +1.23456E+01
instrument_query("bench-a", 5, "MEAS:CURR:DC?") → +2.50000E-01
instrument_query("bench-a", 22, "MEAS:VOLT:DC?") → +1.20000E+01

Each call addresses the instrument, sends the command, and reads the response. The bridge handles the GPIB address switching transparently.

Trigger multiple instruments simultaneously

Section titled “Trigger multiple instruments simultaneously”

For measurements that need to start at the same instant, use Group Execute Trigger (GET). This sends a single bus-level trigger that all configured instruments receive at once.

  1. Configure each instrument for bus triggering

    instrument_write("bench-a", 1, "CONF:VOLT:DC 10,0.001")
    instrument_write("bench-a", 1, "TRIG:SOUR BUS")
    instrument_write("bench-a", 1, "INIT")
    instrument_write("bench-a", 5, "CONF:CURR:DC 1,0.0001")
    instrument_write("bench-a", 5, "TRIG:SOUR BUS")
    instrument_write("bench-a", 5, "INIT")

    Each instrument is now armed and waiting for a bus trigger.

  2. Send the trigger to both addresses at once

    bus_trigger("bench-a", addresses=[1, 5])

    The bridge sends ++trg 1 5, which issues GET to both addresses in a single bus transaction.

  3. Fetch the results

    instrument_query("bench-a", 1, "FETCH?") → +1.23456E+01
    instrument_query("bench-a", 5, "FETCH?") → +2.50000E-01

    FETCH? retrieves the measurement taken at the trigger instant without starting a new measurement.

To take a series of readings over time — for example, monitoring a voltage as a circuit warms up:

> Take 10 DC voltage readings from address 1 on bench-a,
waiting 5 seconds between each. Report all values with timestamps.

The LLM calls instrument_query("bench-a", 1, "MEAS:VOLT:DC?") ten times, pausing between calls. Each call produces one reading.

For faster burst measurements, some instruments support multi-sample modes:

instrument_write("bench-a", 1, "SAMP:COUN 10")
instrument_write("bench-a", 1, "TRIG:SOUR IMM")
instrument_write("bench-a", 1, "INIT")
instrument_query("bench-a", 1, "FETCH?")

The FETCH? response may contain comma-separated values for all 10 samples. Not all instruments support multi-sample — check the programming manual for your model.

When instruments are on different GPIB buses (different bridges), operations can run concurrently because each bridge has its own lock. Ask the LLM to read from both:

> Read DC voltage from address 1 on bench-a and
frequency from address 3 on bench-b at the same time

The LLM can issue both instrument_query calls, and they will execute in parallel since they target different bridges. The results come back independently.

Practical example: voltage and current logging

Section titled “Practical example: voltage and current logging”

Here is a complete sequence for monitoring a power supply’s output while logging voltage and current:

> I'm testing a 12V regulator circuit. Set up the power supply at address 22
on bench-a to output 15V on channel 1. Then take 5 measurements of the
regulated output voltage (DMM at address 1) and current draw (DMM at address 5),
with a 2-second interval. Report the results as a table.

The LLM executes a sequence like:

# Configure the power supply
instrument_write("bench-a", 22, "INST:SEL P6V")
instrument_write("bench-a", 22, "VOLT 15")
instrument_write("bench-a", 22, "CURR 0.5")
instrument_write("bench-a", 22, "OUTP ON")
# Loop: take 5 synchronized readings
# (for each iteration)
instrument_query("bench-a", 1, "MEAS:VOLT:DC?")
instrument_query("bench-a", 5, "MEAS:CURR:DC?")
# (pause 2 seconds)
# After logging, disable the supply
instrument_write("bench-a", 22, "OUTP OFF")

The results might look like:

ReadingVoltage (V)Current (mA)
112.001245.23
212.001445.21
312.001345.25
412.001545.22
512.001445.24

The measurement_sequence prompt provides a guided template for setting up and capturing a measurement. It walks the LLM through identifying the instrument, configuring the measurement function, triggering, and validating the result.

> Use the measurement_sequence prompt for dc_voltage on address 1, bench-a

The prompt instructs the LLM to:

  1. Identify the instrument with *IDN? to determine the model
  2. Send the appropriate configuration commands for the measurement type
  3. Trigger and read the measurement
  4. Validate the reading against expected ranges

This is especially helpful for instruments the LLM has not encountered before, since the prompt encodes common SCPI patterns for different measurement types.

Timeout considerations for batch operations

Section titled “Timeout considerations for batch operations”

When running long sequences, keep these in mind:

  • Per-command timeouts apply to each instrument_query individually. A 3-second timeout is fine for a single fast reading but will fail on slow measurements.
  • No global sequence timeout exists in mcgpib. The LLM manages the overall workflow.
  • If one reading times out, the remaining sequence can still continue. The failed read raises an error, but the bridge connection stays active.

Increase the timeout before a batch of slow readings and restore it afterward:

configure_bridge("bench-a", read_timeout_ms=10000)
# ... run slow measurements ...
configure_bridge("bench-a", read_timeout_ms=3000)