Skip to content

hydrasdr/hydrasdr-tmio

Repository files navigation

HydraSDR T&M I/O Library

Cross-platform Test & Measurement instrument communication library supporting GPIB, Ethernet/LXI, USB TMC, and Serial interfaces.

Current status: Only GPIB USB is implemented (Agilent/Keysight 82357A/B adapter).

Supported Hardware

GPIB Adapter: Agilent/Keysight 82357A/B (native USB protocol)

Instruments with high-level APIs:

Instrument Header Documentation
HP 8753D VNA tmio_hp8753d.h README_HP8753D.md
HP 53150A Counter tmio_hp53150a.h README_HP53150A.md
Agilent E4432B Signal Gen tmio_agilent_e4432b.h README_AGILENT_E4432B.md

Warning: Agilent/Keysight 82357A/B Limitations

The adapter becomes stuck if you send commands to a non-existent GPIB address or invalid commands.

Recovery requires physical USB unplug/replug - software reset does not work. Always verify GPIB addresses before use.

Building

Prerequisites: CMake 3.16+, libusb-1.0, C11 compiler

# Linux / macOS
mkdir build && cd build && cmake .. && make

# Windows (MSVC) - libusb auto-downloaded
mkdir build && cd build
cmake .. -G "Visual Studio 17 2022" -A x64
cmake --build . --config Release

# Windows (MinGW64) - requires: pacman -S mingw-w64-x86_64-libusb
mkdir build && cd build && cmake .. -G Ninja && ninja

Linux USB Permissions

On Linux, install udev rules for non-root access:

cmake .. -DINSTALL_UDEV_RULES=ON
sudo ninja install   # or: sudo make install
sudo udevadm control --reload-rules

Then replug the adapter.

Quick Start

#include "tmio.h"

int main(void)
{
    tmio_device_t *dev;
    char response[256];

    tmio_open(&dev, TMIO_ADAPTER_GPIB_82357B);
    tmio_set_addr(dev, 19);
    tmio_query(dev, "*IDN?", response, sizeof(response), 5000);
    printf("Device: %s\n", response);
    tmio_close(dev);
    return 0;
}

API Reference

Function Description
tmio_open(&dev, type) Open adapter
tmio_close(dev) Close adapter
tmio_set_addr(dev, addr) Set GPIB address (0-30)
tmio_write_str(dev, cmd) Write command string
tmio_read(dev, buf, len, &actual, timeout) Read response
tmio_query(dev, cmd, resp, len, timeout) Write then read
tmio_clear(dev) Send device clear (SDC)
tmio_trigger(dev) Send trigger (GET)
tmio_set_debug_level(level) Set verbosity (0-3, use -v/-vv/-vvv)

Error Codes

Code Name Description
0 TMIO_SUCCESS Success
-1 TMIO_ERROR_NOT_FOUND Device not found
-2 TMIO_ERROR_ACCESS Access denied
-3 TMIO_ERROR_IO I/O error
-4 TMIO_ERROR_TIMEOUT Timeout
-5 TMIO_ERROR_INVALID_PARAM Invalid parameter
-6 TMIO_ERROR_NO_MEMORY Out of memory
-7 TMIO_ERROR_NOT_SUPPORTED Not supported
-8 TMIO_ERROR_NO_SIGNAL No input signal

Testing

Unit Tests (no hardware)

ninja tmio_test_unit      # or: make tmio_test_unit

Command-Line Tools

Each supported instrument has a dedicated tool for testing and interaction:

Tool Instrument Default GPIB
tmio_hp8753d_tool HP 8753D Vector Network Analyzer 16
tmio_hp53150a_tool HP 53150A Frequency Counter 24
tmio_agilent_e4432b_tool Agilent E4432B Signal Generator 19
tmio_gpib_tool Generic GPIB query tool -

Usage: ./tmio_<tool> -a <gpib_addr> <command>

Common commands:

Command Description
all Run all tests (identification, capabilities, state, controls)
idn Query instrument identification
caps Query capabilities (frequency/power ranges)
state Query current instrument settings
freq Test frequency get/set
errors Check error queue

Examples:

./tmio_hp8753d_tool -a 16 all        # Run all VNA tests
./tmio_hp53150a_tool -a 24 idn       # Get counter identification
./tmio_agilent_e4432b_tool -a 19 state  # Get signal generator state
./tmio_gpib_tool -a 19 -q "*IDN?"    # Send raw SCPI query

Use -h for full command list. Use -v for verbose output.

CMake Targets

ninja run_instruments     # Run all instrument tools
ninja run_hp8753d         # Run HP 8753D tool only
ninja run_hp53150a        # Run HP 53150A tool only
ninja run_agilent_e4432b  # Run E4432B tool only

For Developers

Tool Description
tmio_unit_test Unit tests for API validation (no hardware)
tmio_api_test Full API test suite for all instruments
./tmio_unit_test                     # Run all unit tests
./tmio_api_test all                  # Test all connected instruments
./tmio_api_test -a 16 hp8753d        # Test HP 8753D at address 16
./tmio_api_test -o report.txt all    # Save results to file

License

MIT License - Copyright (c) 2025-2026, Benjamin Vernoux

About

HydraSDR T&M I/O Library Cross-platform Test & Measurement instrument communication library supporting GPIB (planned Ethernet/LXI, USB TMC, Serial ....)

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors