This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Go package for communicating with Prologix GPIB-USB and GPIB-ETHERNET controllers, which bridge a computer to GPIB (IEEE 488) test instruments. Part of the gotmc ecosystem and designed to work with the ivi package for standardized instrument control. Requires Go 1.25+.
# Format and vet (runs automatically before tests)
just check
# Run unit tests with coverage and race detection
just unit
# Lint with golangci-lint
just lint
# Run a single test
go test -run TestIsPrimaryAddressValid ./...
# HTML coverage report
just cover
# Run example (requires hardware): just key3631 /dev/ttyUSB0 5just (Justfile) is the task runner; there is no Makefile.
The package uses a layered design separating transport from GPIB protocol logic:
- Transport layer (
driver/): Providesio.ReadWriterimplementations for different connection types. Currently onlydriver/vcp/(Virtual COM Port via serial) is implemented. Thedriver/usb/anddriver/net/directories are placeholders for future D2XX and Ethernet support. - Controller (
controller.go): Core type wrapping anyio.ReadWriter. Constructed viaNewController()with functional options (WithSecondaryAddress,WithDebug,WithAR488). Handles GPIB address setup, controller initialization commands, and the++command prefix for Prologix-specific commands. - Commands (
commands.go): Methods onControllerfor Prologix++commands (e.g.,ClearDevice,SetReadTimeout,Version,InstrumentAddress). - Examples (
examples/vcp/): Working examples for real instruments (E3631A, DS345, Fluke 45, 33220A). All follow the same pattern: open VCP → create Controller → query version → run device commands → restore front panel → close.
Key design points:
Controllersatisfies theivi.Transportinterface viaCommand,Query,ReadBinary,WriteBinary, andClose. It distinguishes between instrument communication (Command,Query,Write) and Prologix controller commands (CommandController,QueryController) which prepend++.- Context-aware I/O:
Controllerchecks if the underlyingio.ReadWriterimplements optionalContextReader/ContextWriterinterfaces. If so, it delegates directly; otherwise it falls back to goroutine-based context handling. - The
WithAR488()option skipsverboseandsavecfgcommands for Arduino AR488 compatibility. Queryautomatically sends++read eoiwhen auto read-after-write is disabled.- Binary data methods (
Write/Read) vs string methods (WriteString,Command,Query) handle GPIB character escaping differently. Prologix strips unescaped LF, CR, ESC, and+characters, soWriteescapes them automatically. - VCP serial config is hardcoded to Prologix defaults: 115200 baud, 7 data bits, even parity, 1 stop bit.
github.com/gotmc/query— SCPI query helpersgo.bug.st/serial— cross-platform serial port accessgo.uber.org/multierr— error combining