Skip to main content

mhs5200

Python driver for MHS-5200A series DDS signal generators.

Control MHS-5200A dual-channel function generators via USB serial connection. Supports frequency, amplitude, waveform, sweep, and arbitrary waveform upload.

Features

  • Dual-channel control (frequency, amplitude, waveform, duty cycle, offset, phase)
  • Sweep function (linear/logarithmic)
  • Arbitrary waveform upload/download (2048 samples, 12-bit resolution)
  • Built-in waveforms (sine, square, triangle, sawtooth)
  • Automatic attenuation handling

Supported Models

MHS-5200A series: MHS-5206A, MHS-5212A, MHS-5220A, MHS-5225A

Installation

pip install mhs5200

Quick Start

from mhs5200 import MHS5200, Waveform

with MHS5200('/dev/ttyUSB0') as gen:  # Windows: 'COM3'
    print(gen.get_device_info())
    
    # CH1: 1kHz sine wave, 5Vpp
    gen.set_frequency(1, 1000)
    gen.set_amplitude(1, 5.0)
    gen.set_waveform(1, Waveform.SINE)
    gen.set_all_outputs(True)

Examples

Dual Channel with Phase Shift

from mhs5200 import MHS5200, Waveform

with MHS5200('/dev/ttyUSB0') as gen:
    # CH1: 1kHz sine
    gen.set_frequency(1, 1000)
    gen.set_amplitude(1, 5.0)
    gen.set_waveform(1, Waveform.SINE)
    
    # CH2: 1kHz sine, 90° phase shift (quadrature)
    gen.set_frequency(2, 1000)
    gen.set_amplitude(2, 5.0)
    gen.set_waveform(2, Waveform.SINE)
    gen.set_phase(90)
    
    gen.set_all_outputs(True)

Square Wave with Duty Cycle

from mhs5200 import MHS5200, Waveform

with MHS5200('/dev/ttyUSB0') as gen:
    gen.set_frequency(1, 10000)
    gen.set_amplitude(1, 3.3)
    gen.set_waveform(1, Waveform.SQUARE)
    gen.set_duty_cycle(1, 25.0)  # 25%
    gen.set_all_outputs(True)

Frequency Sweep

from mhs5200 import MHS5200, SweepMode

with MHS5200('/dev/ttyUSB0') as gen:
    gen.configure_sweep(
        start_hz=100,
        stop_hz=10000,
        time_sec=10,
        mode=SweepMode.LINEAR
    )
    gen.sweep_on()

Arbitrary Waveform

import math
from mhs5200 import MHS5200, Waveform

def generate_waveform(num_samples=2048):
    """Sine wave with 3rd harmonic (30%)."""
    samples = []
    for i in range(num_samples):
        t = i / num_samples * 2 * math.pi
        value = math.sin(t) + 0.3 * math.sin(3 * t)
        sample = int(2048 + value / 1.3 * 2047)
        samples.append(max(0, min(4095, sample)))
    return samples

with MHS5200('/dev/ttyUSB0') as gen:
    waveform = generate_waveform()
    gen.upload_arbitrary_waveform(0, waveform)
    
    gen.set_waveform(1, Waveform.ARB00)
    gen.set_frequency(1, 1000)
    gen.set_amplitude(1, 3.0)
    gen.set_all_outputs(True)

API Reference

Device Information

Method Description
get_device_info() Returns dict with model and serial
get_model() Returns model name
get_serial_number() Returns serial number

Channel Control

Method Description
set_frequency(ch, hz) Set frequency (0.01 Hz resolution)
get_frequency(ch) Get current frequency
set_amplitude(ch, vpp) Set amplitude in Vpp
get_amplitude(ch) Get current amplitude
set_amplitude_auto(ch, vpp) Set amplitude with auto attenuation
set_waveform(ch, waveform) Set waveform type
get_waveform_name(ch) Get waveform name
set_duty_cycle(ch, percent) Set duty cycle (0–99.9%)
set_offset(ch, percent) Set DC offset (−120% to +120%)
set_invert(ch, bool) Invert waveform

Common Control

Method Description
set_phase(degrees) Set phase (−180° to +180°)
set_tracking(bool) Enable/disable channel tracking

Output Control

Method Description
set_all_outputs(bool) Enable/disable all outputs
get_all_outputs() Get output state

Sweep

Method Description
configure_sweep(start, stop, time, mode, ch) Configure and start sweep
sweep_on() Start sweep
sweep_off() Stop sweep
set_sweep_range(start_hz, stop_hz) Set frequency range
set_sweep_time(seconds) Set sweep duration (1–600s)
set_sweep_mode(mode) Set LINEAR or LOG mode

Arbitrary Waveform

Method Description
upload_arbitrary_waveform(slot, samples) Upload 2048 samples to slot 0–15
download_arbitrary_waveform(slot) Download waveform data

Enums

# Waveform types
Waveform.SINE
Waveform.SQUARE
Waveform.TRIANGLE
Waveform.SAWTOOTH_UP
Waveform.SAWTOOTH_DOWN
Waveform.ARB00 – Waveform.ARB15

# Sweep modes
SweepMode.LINEAR
SweepMode.LOG

# Attenuation
Attenuation.ATT_0DB
Attenuation.ATT_20DB

License

MIT License

Metadata

Release files for mhs5200 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mhs5200 0.1.1
File Size Uploaded
mhs5200-0.1.1.tar.gz 10.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mhs5200 0.1.1
File Interpreter ABI Platform
mhs5200-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 20.7 kB

Release files / mhs5200-0.1.1.tar.gz

Download URL mhs5200-0.1.1.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b6891cfb967ceddc07fd104253b32c0fb2a2ef0e730b7e86a9c153173d12c647
BLAKE2b-256 checksum
How to use checksums
e58a64228fe84e147dbfa5fee4f037a481bd92c4b8599107db633c9030eec531
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 10, 2026.

Transparency log

Release files / mhs5200-0.1.1-py3-none-any.whl

Download URL mhs5200-0.1.1-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f997d9fd77c2f3559e7e4484c33cb612ecbe653b01b3632b17428cdb67de4614
BLAKE2b-256 checksum
How to use checksums
aa6d78a044a6ae7b6bac345ad7b38e97ee6a27236db983d4cb48185ac734d0d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 10, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page