Install the PyTestLab skills, tell Claude Code what you want to measure, and let it build a reusable experiment around your instruments.
Controlling an oscilloscope with AI should start with your bench, not a blank Python file. Which instrument is connected? Does it already have a profile? How should the agent connect, read a channel and save the result?
PyTestLab gives the agent a Python interface for that work. The PyTestLab agent skills teach it the setup: install the library, discover available instrument resources, match or build a profile, then write a small experiment using the Bench and factory APIs.
This guide follows that path with Claude Code. By the end, the useful output is not just an AI answer. It is a bench configuration, a measurement script and waveform data you can inspect, plot and analyse again.
1. Install the skills and give your agent a concrete task#
Get the agent skills: github.com/labiium/pytestlab-skills. Use pytestlab-onboarding for setup, pytestlab-experiments for Bench-based procedures, and ptl-profile-skill when a model needs a profile.
No Python installed? Give the setup to your agent:
If Python is missing, install uv from its official source and use it to set up Python 3.14. Create or reuse this project’s `.venv`, install PyTestLab there, and use that environment for every command and script. Do not change my system Python or operate instruments during setup.
Use the computer connected to the instrument, or one that can reach its LAN interface. Keep a compatible environment that already works.
From your experiment project, install the three skills for Claude Code:
npx skills add labiium/pytestlab-skills --skill pytestlab-onboarding pytestlab-experiments ptl-profile-skill -a claude-code -y
This uses the open-source skills installer and requires Node.js/npm. The repository README also provides a plain Git installation. Installing the skills adds instructions for the agent; it does not connect to equipment or run a measurement.
Before continuing, ask Claude to read all three installed skills and confirm their names. If it cannot find them, fix the installation in this project first.
Start Claude Code in that project and give it this task:
Use pytestlab-onboarding to set up PyTestLab in this project and discover the instruments available to this computer. Help me select my oscilloscope and create bench.yaml. Reuse a matching profile; if none exists, use ptl-profile-skill with the manufacturer's programming manual to build one. Then use pytestlab-experiments to capture channel 1, save the waveform and plot its FFT. Keep the Python simple and use Bench. Show me the selected resource and planned instrument changes before running them.
You can add the scope model, connection details and signal you already know. The agent should not make you type information it can find locally, but it should not guess which physical device you mean either.
Claude Code can read project files, write code and execute terminal commands. That is enough to run this workflow. The same skills can guide other coding agents; Claude Code is the example here, not a PyTestLab requirement.
2. Let the agent install PyTestLab and find the instrument#
The agent uses the environment it just prepared. If you prefer manual setup with an existing Python installation:
python -m venv .venv
source .venv/bin/activate
python -m pip install pytestlab
Use Python 3.11 or newer. On Windows, activate with .venv\Scripts\Activate.ps1. PyVISA and PyUSB are already dependencies of PyTestLab. You do not need to install the PyVISA Python package separately.
Use PyTestLab’s built-in discovery CLI:
ptl visa list
This lists VISA resources visible to the configured backend, including supported USB instruments. It is different from ptl profile list, which lists software profiles rather than attached equipment. Leave --idn off for simple discovery: that option opens the listed instruments and sends identification queries.
This guide targets PyTestLab 0.3.0 and its built-in VISA discovery CLI.
Only fix a missing backend if there is one#
PyVISA is the Python interface; a VISA backend provides the actual communication. If your bench already has a working NI-VISA, Keysight VISA or other supported backend, keep it. If resource-manager initialization reports that no implementation is available, the agent can diagnose it with pyvisa-info and install an appropriate missing backend, for example:
python -m pip install pyvisa-py
That is a conditional fix, not an extra installation every user needs. With the pure-Python backend, USB may also need a system USB library or platform driver; installing the Python pyusb package alone does not provide those. Follow the PyTestLab installation guide and PyVISA-py installation requirements for the connection you actually use.
Discovery does not find every network instrument. If the scope is missing, use its known VISA address rather than concluding it is unsupported. Match the selected resource to the intended model instead of opening the first result automatically. The computer executing the script must be able to reach the scope.
3. Match a profile, or build one from the programming manual#
A PyTestLab profile describes how to operate a particular instrument model: its supported commands, parameters, limits and response handling. The bench file supplies the lab-specific connection.
For an existing supported model, the agent can inspect the profile:
ptl profile list
ptl profile show keysight/DSOX1204G
No matching profile is not the end of the workflow. Give the agent the manufacturer's programming manual and datasheet, or ask it to locate the official documents. The ptl-profile-skill guides it to:
- Extract the relevant commands, response formats and specifications from those documents.
- Build a reusable YAML profile for the installed PyTestLab version.
- Run the available schema and command checks.
- Verify the required operations on the selected instrument before calling them hardware-tested.
Build the model integration once, then reuse it across experiments. Do not import a profile module or rewrite raw SCPI strings inside every measurement script.
A new device can require a driver or parser change when its behavior is not expressible by the existing driver. The skill should identify that specific gap, not invent a profile that merely passes a YAML check. Offline validation and physical verification are separate steps.
4. Put the connection in bench.yaml, not your experiment#
For this example, the agent creates:
bench_name: Oscilloscope measurement
instruments:
scope:
profile: keysight/DSOX1204G
address: TCPIP0::192.168.1.100::inst0::INSTR
Replace the example address with your actual resource and use your instrument's matching profile. A custom profile can be referenced by its local YAML path in the profile field.
Now every experiment can use bench.scope. The Bench factory loads the configuration and manages the connection. The bench descriptor guide explains the structure.
5. Read a channel in a few lines#
With the scope configured for the signal, save this as capture.py alongside bench.yaml:
from pytestlab import Bench
with Bench.open("bench.yaml") as bench:
trace = bench.scope.read_channels(1)
trace.to_dataframe().write_csv("waveform.csv")
Run .venv/bin/python capture.py from that project folder, or .venv\Scripts\python.exe capture.py on Windows. The result is waveform.csv in the same working folder. Ask the agent to show the saved path and check that it contains samples.
That captures channel 1 and saves its samples. The dataframe includes Time (s) and Channel 1 (V). It is not a photograph of the screen: you have the data needed for plotting and analysis.
If the task needs explicit setup, add the settings before the acquisition:
from pytestlab import Bench
with Bench.open("bench.yaml") as bench:
scope = bench.scope
scope.set_channel_axis(channel=1, scale=0.5, offset=0)
scope.set_time_axis(scale=0.001, position=0)
scope.configure_trigger(channel=1, level=0)
trace = scope.read_channels(1)
trace.to_dataframe().write_csv("waveform.csv")
Here the vertical scale is 0.5 V/div and the timebase is 1 ms/div. Choose values that fit your actual signal, check the probe attenuation, and ensure the signal is not clipped. Start with a known low-voltage signal and verify the physical connection and input limits.
Reset the scope when you want a fresh starting state#
The reset operation is simply:
scope.reset()
Put it after obtaining scope and before applying your measurement settings. Reset changes instrument state and can discard an existing setup, so it should be requested explicitly rather than silently added to every script.
The agent can write and explain the procedure before you approve execution. Claude Code's permissions help control tool execution; they do not replace correct wiring and electrical limits.
6. Plot the waveform and calculate an FFT#
Once the CSV is saved, the agent can analyse it without reconnecting to the scope. Save this as analyse.py next to the CSV and run it with the same project Python:
import polars as pl
import matplotlib.pyplot as plt
frame = pl.read_csv("waveform.csv")
t = frame["Time (s)"].to_numpy()
v = frame["Channel 1 (V)"].to_numpy()
plt.plot(t, v)
plt.xlabel("Time (s)")
plt.ylabel("Voltage (V)")
plt.show()
For a first frequency-domain view, append this to the same analyse.py file, using the t and v arrays above. Close the first plot window to continue to the FFT plot:
import numpy as np
v = v - v.mean()
frequency = np.fft.rfftfreq(len(v), d=t[1] - t[0])
spectrum = np.abs(np.fft.rfft(v))
plt.figure()
plt.plot(frequency, spectrum)
plt.xlabel("Frequency (Hz)")
plt.ylabel("FFT magnitude (unnormalised)")
plt.show()
This removes the DC component and plots an unnormalised magnitude spectrum, not calibrated spectral amplitude or power. The calculation assumes evenly spaced samples. For accurate amplitude estimates or signals that do not fit whole cycles into the capture, ask the agent to apply an appropriate window and normalization.
This is where code extends the instrument's usefulness: custom frequency analysis, event detection, comparisons between captures and report generation can operate on the same saved data. It does not extend analog bandwidth, recover clipped peaks or undo aliasing. Inspect the acquisition before trusting the analysis.
7. Repeat with a loop, not another conversation#
For ten captures, replace capture.py with this complete procedure:
from pytestlab import Bench
with Bench.open("bench.yaml") as bench:
for capture in range(10):
trace = bench.scope.read_channels(1)
trace.to_dataframe().write_csv(f"waveform-{capture:02d}.csv")
The model does not need to reason through ten separate acquisition tool calls. Python handles the repetition and filenames; the agent can work on comparing the resulting waveforms or adjusting the next experiment.
These are sequential captures, not a guarantee of fixed-interval, gapless or synchronized acquisition. If timing matters, choose the instrument's appropriate acquisition mode rather than assuming a fast loop solves it.
For the broader rationale, read why code is the right medium for AI laboratory agents.
Do I need an oscilloscope MCP server?#
Not to get started with Claude Code and PyTestLab. The agent can run the reviewed Python procedure directly on the computer connected to your bench.
MCP is useful when an agent needs to discover and call a defined set of remote tools. It can also expose a saved PyTestLab procedure. Those are complementary choices: MCP determines how the agent reaches a tool; the Python procedure contains the experiment logic.
Start with your own scope#
Install the PyTestLab skills, give your agent the measurement goal and let it prepare the bench. Reuse an existing profile or build the missing one from its programming manual. Then capture a channel, inspect the data and make the next experiment a few lines of code rather than another integration project.
Validation note: channel capture, export and repetition were exercised with a software simulator fixture; the CSV and FFT examples were also tested. No live instrument was operated. Verify physical acquisition and reset on your own bench before relying on the results.