汉泰克1025G信号发生器二次开发(python和C)

这篇具有很好参考价值的文章主要介绍了汉泰克1025G信号发生器二次开发(python和C)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

信号发生器:汉泰克1025G
SDK开发资料:http://www.hantek.com.cn/products/detail/48

1.python接口

网上已经有大神制作了python的封装接口:https://github.com/AIMAtlanta/Hantek_1025G
这里为了方便查找就再张贴一遍:

# -*- coding: utf-8 -*-
"""
origin source: https://github.com/AIMAtlanta/Hantek_1025G

Python wrapper providing access to C-language API provided by HTDDSDll.h.
Example usage:
ht = HantekDDS()
ht.drive_periodic(amplitude=2.0, frequency=12000., function = 'sine')
"""

import ctypes
import os
import numpy as np
import threading
import time
import matplotlib.pyplot as plt
this_dir = os.path.dirname(os.path.realpath(__file__))
HTDLL = ctypes.windll.LoadLibrary(this_dir + '/HTDDSDll')

FMAX = 200e6  # Maximum DAC sample rate

class HantekDDS():

    """ Interface to Hantek 1025G function generator."""

    def __init__(self, dev=0):
        """ Default constructor."""
        self.idVendor = '0x0483'
        self.idProduct = '0x5726'
        self.revNumber = '0200'
        self.dev_id = None
        self.connect(dev)
        self.param_dict = {'square_duty': 0.5,
                           'triangle_duty': 0.5,
                           'trap_rise': 0.2,
                           'trap_high': 0.3,
                           'trap_fall': 0.2,
                           'exp_mode': 'decay',
                           'exp_time': 0.001,
                           }
        self.halt = False

    def connect(self, dev=0):
        """ Verify existence of device and get device id."""
        for attempt in range(10):
            n_devices = search()
            if n_devices:
                if bool(check(dev)):
                    self.dev_id = dev
                    print('Connected as device {:d}'.format(dev))
                    return
        print('ERROR: Failed to establish connection with HantekDDS.')

    def set_divisor(self, div):
        """ Set the DAC sample rate divisor."""
        setDivNum(self.dev_id, div)

    def set_waveform(self, data):
        """ Set the waveform buffer."""
        data = np.array(data)  # Ensure data is in ndarray
        dlen = len(data)
        if dlen > 4096:
            print('WARNING: Hantek 1025G buffer limited to 4096 samples -- ' +
                  'Truncating data to 4096 elements')
            data = data[:4096]
        if download(self.dev_id, data.tobytes(), dlen):
            pass
        else:
            print('HantekDDS method set_waveform() returned failure code.')

    def drive_periodic(self, amplitude=1.0, frequency=1000.0,
                       offset=0, phase=0, function='sine', **kwargs):
        """ Direct the device to drive a periodic function.

        Args:
          amplitude: Amplitude of signal in Volts (1/2 V_pp)
          frequency: Frequency of signal in Hertz
          offset: Offset of signal in Volts.
          phase: Offset of phase in periods (phase = 0 is equivalent to
            phase=1, phase = 0.5 is 180 degrees out of phase from phase = 0.
          function: Type of periodic function to drive.

            Valid Types
            -----------
              'sine': Sine wave
              'square': Square wave, param 'square_duty' for high duty cycle
                        specified as float in range (0,1)
              'triangle': Triangle wave, param 'duty' for rise duty cycle
                          specified as float in range (0,1)
              'ramp': Synonym for 'triangle'
              'sawtooth': Synonym for 'triangle'
              'trap': Trapezoidal wave, params 'trap_rise', 'trap_high',
                      and 'trap_fall' for duty cycle for rise, high, and fall
                      segments specified as floats > 0 with sum <= 1.
              'exp': Exponential wave, params 'exp_mode' (may be 'rise' or
                     'saturate') and 'exp_time' (time constant in seconds).
        """
        for key,val in kwargs.items():
            if key in self.param_dict:
                self.param_dict[key] = val

        frequency = validate_frequency(frequency)
        phase = phase % 1
        if (amplitude + abs(offset)) > 3.5:
            print('WARNING: amplitude and offset specified will cause ' +
                  'the signal to be clipped.  Consider confining the range ' +
                  'to ±3.5 volts.')

        if function not in periodic_functions.keys():
            print('WARNING: function type for periodic function not found. ' +
                  'Valid values are ' +
                  'Defaulting to sine wave.')
            function = 'sine'

        div, length = get_freq_settings(frequency)
        print(f'freq:{frequency}, div:{div}, length:{length}')
        f = periodic_functions[function]
        signal = f(amplitude, frequency, offset, phase,
                   length, **(self.param_dict))
        digital = np.short(voltage_adc(signal))
        print(digital)
        self.set_waveform(digital)
        self.set_divisor(div)

    def frequency_scan(self, f_start, f_end, nsteps=10, delta=0, dwell=5,
                       ltype='linear', n_repeats=1, amplitude=1.0, offset=0.0):
        """ Scan through a range of frequencies.

        Args:
          f_start: Scan starting frequency in Hertz
          f_end: Scan ending frequency in Hertz
          nsteps: The number of steps to take between f_start and f_end.
          delta: The arithmetic or geometric difference between steps.
                 If non-zero, this setting will override nsteps.
                 Additionally, the frequency sweep may go past f_end.
          n_repeats: The number of times to loop through the entire frequency
                     scan.  Set to -1 to make continuous.
        """
        f_start = validate_frequency(f_start)
        f_end = validate_frequency(f_end)
        if ltype in ['log', 'logarithmic']:
            if delta > 0:
                nsteps = np.ceil(np.log(f_end / f_start) / np.log(delta))
                fspace = np.product(np.append(f_start, delta*np.ones(nsteps)))
            else:
                fspace = np.logspace(np.log10(f_start),
                                     np.log10(f_end), nsteps)
        if ltype in ['lin', 'linear']:
            if delta != 0:
                fspace = np.arange(f_start, f_end + delta, delta)
            else:
                fspace = np.linspace(f_start, f_end, nsteps)
            fspace = np.linspace(f_start, f_end, nsteps)
        self.scanner = threading.Thread(target=self.freq_scan_threaded,
                                        args=(fspace, amplitude,
                                              offset, dwell, n_repeats))
        self.halt = False
        self.scanner.start()
#        self.freq_scan_threaded(fspace, amplitude, offset, dwell, n_repeats)

    def freq_scan_threaded(self, fspace, amp, offset, dwell, n_repeats):
        """ Frequency scan to be started in non-blocking threaded process."""
        queue = int(n_repeats)
        while queue != 0:
            queue -= 1
            for f in fspace:
                if self.halt:
                    return None
                self.drive_periodic(amplitude=amp, frequency=f, offset=offset)
                time.sleep(dwell)

    def stop(self):
        """ Halt the threaded scan process."""
        self.halt = True


def search():
    """ Search for connected Hantek DDS devices.

    Will not return identity of devices, only the number connected.
    """
    fh = HTDLL[7]  # function handle for DDSSearch()
    return fh()


def setFrequency(dev, f, npoints, nperiods):
    """ Set parameters appropriate for a particular frequency.

    Args:
    f: frequency to be set
    """
    fh = HTDLL[11]
    return fh(dev, f, npoints, nperiods)


def getMeasure():
    """ Retrieve the value from the frequency/counter function."""
    raise NotImplementedError


def setSingleWave(dev, state):
    """ Set device to output continuously, or to output only on trigger."""
    fh = HTDLL[13]
    fh(dev, state)


def resetCounter():
    """ Reset the count of the counter function."""
    fh = HTDLL[6]
    return fh(dev)


def setTrigger(dev, internal, falling):
    """ Set trigger parameters."""
    fh = HTDLL[14]
    return fh(dev, internal, falling)


def setDigitalIn():
    """ Read input values (low or high) from digital input ports.

    Lowest four bits of the read array are read from the 4 input pins.
    """
    raise NotImplementedError


def setDIOMode():
    """ Switch between programmable output and generator output."""
    raise NotImplementedError


def setDigitalOut():
    """ Set the output values (low or high) of the digital output ports.

    Lowest twelve bits of the output array are set on the 12 output pins.
    """
    raise NotImplementedError


def download(dev, buf, num):
    """ Transfer a waveform specification to the device waveform buffer.

    Args:
      dev: Device index
      buf: Pointer to short type array (only 12 bits used)
      num: Number of elements in buffer

    Returns:
      bool: 1 on success, 0 on failure
    """
    fh = HTDLL[2]
    return fh(dev, buf, num)


def check(dev):
    """ Check the status of the device.

    Determine whether or not the device can be seen by the operating system

    Args:
      dev: Index of Hantek device.

    Returns:
      bool: status of connection (True = success, False = failure)

    Argument ``dev`` seems to be an internal index, presumably out of the
    number of Hantek devices connected.  If only one Hantek device is
    connected, ``dev`` should probably always be 0.
    """
    fh = HTDLL[1]
    return fh(dev)


def setPowerOnOutput(dev, state):
    """ Set whether waveform should output upon device power-on

    If true, output stored function.  Otherwise, wait for a trigger (?) or
    explicit command to output.
    """
    fh = HTDLL[12]
    return fh(dev, state)


def getDivNum(dev):
    """ Get the DAC frequency divisor

    Args:
      dev: device index

    Returns:
      int: Divisor index number
    """
    fh = HTDLL[4]
    return fh(dev)


def setDivNum(dev, div):
    """ Set the DAC sampling rate divisor.

    Args:
      div: divisor to apply to DAC sampling frequency.

    Values of div from 1:n give sampling rates of fmax / (2 * div).
    When div == 0, sampling rate is ``FMAX`` = 200MS/sec.
    """
    fh = HTDLL[10]
    return fh(dev, div)


def validate_frequency(frequency):
    if frequency > 1e8:
        print('WARNING: frequency {:g} is outside the '.format(frequency) +
              'possible range of frequencies for the Hantek 1025G.  ' +
              'Setting frequency to 10MHz for your "convenience".')
        frequency = 1e7
    if frequency < 1:
        print('WARNING: frequency {:g} is outside the '.format(frequency) +
              'possible range of frequencies for the Hantek 1025G.  ' +
              'Setting frequency to 10Hz for your "convenience".')
        frequency = 10
    return frequency


def get_freq_settings(frequency):
    """ Compute the DAC divisor and sample length for a a target frequency.

    Args:
      frequency: Target frequency in Hertz.

    Returns:
      int: divisor to be passed to setDivNum
      int: length to be passed to signal synthesis routines

    This function returns the same information that setFrequency does, but
    without modifying the DAC divisor.
    """
    frequency = validate_frequency(frequency)
    divisor = int(FMAX/4096/frequency)
    length = int(FMAX / max(1, 2 * divisor) / frequency)
    return divisor, length


def voltage_adc(voltage):
    """ Convert voltage in the range from -3.5V to +3.5V to a 12-bit level."""
    return np.minimum(4095, np.maximum(0, (3.5 - voltage) / 1.70898375e-3))

# Periodic Functions
# ==================


def sine_wave(amplitude, frequency, offset, phase, length, **kwargs):
    """ Construct one period of a sine wave."""
    arg = np.linspace(0, 2*np.pi, length, endpoint=False)
    signal = amplitude * np.sin(arg) + offset
    return np.roll(signal, int(phase * length))


def square_wave(amplitude, frequency, offset, phase, length, **kwargs):
    """ Construct one period of a square wave."""
    duty = kwargs['square_duty']
    cutoff = int(duty * length)
    signal = np.empty(length)
    signal[:cutoff] = amplitude + offset
    signal[cutoff:] = -amplitude + offset
    return np.roll(signal, int(phase * length))


def triangle_wave(amplitude, frequency, offset, phase, length, **kwargs):
    """ Construct one period of a triangle (sawtooth, ramp) wave."""
    duty = kwargs['triangle_duty']
    signal = np.empty(length)
    cutoff = int(duty * length)
    signal[:cutoff] = np.linspace(-amplitude, amplitude,
                                  cutoff, endpoint=False)
    signal[cutoff:] = np.linspace(amplitude, -amplitude,
                                  length - cutoff, endpoint=False)
    signal += offset
    return np.roll(signal, int(phase * length))


def exponential(amplitude, frequency, offset, phase, length, **kwargs):
    """ Construct an exponentially decaying/saturating wave."""
    tau = kwargs['exp_time']
    exp_mode = kwargs['exp_mode']
    time = np.linspace(0, 1/frequency, length, endpoint=False)
    if exp_mode == 'saturate':
        signal = amplitude * (1 - np.exp(-time / tau) + offset)
    if exp_mode == 'decay':
        signal = amplitude * (np.exp(-time / tau) + offset)

    return np.roll(signal, int(phase * length))


def trapezoid(amplitude, frequency, offset, phase, length, **kwargs):
    """ Construct a trapezoidal wave."""
    d_rise = kwargs['trap_rise']
    d_high = kwargs['trap_high']
    d_fall = kwargs['trap_fall']
    if d_high + d_rise + d_fall > 1:
        print('Duty cycle greater than 1 specified for trapezoidal wave. ' +
              'Reseting to reasonable parameters.')
        d_rise = 0.2
        d_high = 0.3
        d_fall = 0.2
    l_r = c_r = int(d_rise * length)
    l_h = int(d_high * length)
    c_h = c_r + l_h
    l_f = int(d_fall * length)
    c_f = c_h + l_f
    signal = np.empty(length)
    signal[:c_r] = np.linspace(-amplitude, amplitude, l_r, endpoint=False)
    signal[c_r:c_h] = amplitude
    signal[c_h:c_f] = np.linspace(amplitude, -amplitude, l_f, endpoint=False)
    signal[c_f:] = -amplitude
    return np.roll(signal, int(phase * length))


def arbitrary(amplitude, frequency, offset, phase, length, **kwargs):
    """ 创建任意波波形."""
    # 数据范围
    num = 10000
    M = 1e6
    n = 1e-9
    t = np.arange(0, 1000*n, (1000/num)*n)  # Only need to modify the parameters on lines 15-22
    # t = np.arange(0, 1000*n, 0.005*n)
    j = 1j
    ts = 50*n  # Duration 50
    f0 = 30*M  # Frequency center 450
    fb = 100*M  # Bandwidth 100
    a = 1/(2*ts**2)
    b = np.sqrt((2*(np.pi**2)*(a**2))/((ts**2)*a)-2*(np.pi**2))
    A = (a/np.pi)**(1/4)  # Amplitude
    t0 = 500*n  # Time center
    w0 = 2*np.pi*f0  # Frequency center
    # Incident wave function
    s = A*np.exp((-0.5*a*((t-t0)**2))+(j*0.5*b*((t-t0)**2))+j*w0*(t-t0))
    s = np.real(s)
    s_max = np.max(s)
    # 注意这里要进行转换
    s = np.floor((2**11-1)*(s/s_max))
    shift = len(s)//length # 原始数据长度5500

    signal = amplitude*(s/2048.0)[::shift]
    print('任意波数据长度:', len(signal))
    signal += offset
    plt.plot(signal)
    plt.show()

    return np.roll(signal, int(phase * length))

# Dictionary of all periodic functions
periodic_functions = {'sine': sine_wave,
                      'square': square_wave,
                      'triangle': triangle_wave,
                      'sawtooth': triangle_wave,
                      'ramp': triangle_wave,
                      'trap': trapezoid,
                      'exp': exponential,
                      'arb': arbitrary
                      }

if __name__ == '__main__':
    # signal = arbitrary(amplitude=1, frequency=1000000, offset=0, phase=1, length=200,)
    ht = HantekDDS()
    # 任意波
    ht.drive_periodic(amplitude=3.5, frequency=2500000., function = 'arb')

上面python接口一个精妙的写法是使用索引的方式获取了函数句柄,例如DDSCheck函数为fh = HTDLL[1],但是问题来了,原作者是如何知道不同函数对应的索引值?经过一番查找,笔者发现可以使用DDL函数查看器(自行搜索下载)实现查找,如下图所示:
汉泰克1025G信号发生器二次开发(python和C),5G,python,c语言
由于官方提供的.dll和.lib文件都是32位的,因此上述程序需要在32位python环境运行

2.C接口

官方提供了VC例程,但是项目太老不容易用新版的VS打开,而且很多时候只需要简单的几个指令即可,下面贴出1025G下载任意波形的代码,注意波形点数和频率有关:

1025G最大采样率为200MS/s(200e6),如果任意波波形频率为100M,即一个周期1us,1us时间在200MS/s采样率下可以采集200个点,因此100M频率任意波形的数据缓冲大小为200,其它以此类推,计算公式如下,其中freq为需要下载波形的频率,FMAX为信号发生器采样频率,这里默认为200MS/s,也可以设置分频系数进行调整
点数 = 1 f r e q 1 F M A X 点数=\frac{\frac{1}{freq}}{\frac{1}{FMAX}} 点数=FMAX1freq1文章来源地址https://www.toymoban.com/news/detail-819657.html

#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <cmath>
#include <cstdint>
#include "HTDDSDll.h"

#pragma comment(lib, "HTDDSDll.lib") // 使用库

#define BUF_SIZE 4096
#define MAX_VOLT 3.5f
typedef unsigned short USHORT;

int main(int argc, char *argv[])
{
    int device_index = 0;
    double frequency = 1e6;

    int wave_point_num = 200; // 1M->200,2M->100,
    int wave_period_num = 1;
    bool downStatus = false; // 波形下载状态
    BOOL device_available;
    // BOOL result_set_frequency;

    // 搜索设备
    printf(">>> Searching DDS devices...\n");
    int result_search = DDSSearch();
    if (result_search > 0)
    {
        printf("Found %d devices!\n", result_search);
    }
    else
    {
        printf("!!! Device not found@\n");
        return -1;
    }

    // 检查设备是否可用
    printf(">>> Checking DDS devices...\n");
    device_available = DDSCheck(device_index);
    if (device_available)
    {
        printf("Device available!\n");
    }
    else
    {
        printf("!!! Device not available!\n");
        return -1;
    }

    // 设置频率
    // result_set_frequency = DDSSetFrequency(device_index, frequency, &wave_point_num, &wave_period_num);
    // if (result_set_frequency) {
    //     printf("Frequency set successfully!\n");
    // } else {
    //     printf("频率设置失败\n");
    //     return -1;
    // }
    // 创建波形
    USHORT buffer1M[BUF_SIZE] = {2048, 2049, 2049, 2048, 2049, 2049, 2048, 2049, 2049, 2048, 2048, 2049, 2048, 2048,
                                 2049, 2049, 2048, 2048, 2049, 2049, 2048, 2048, 2049, 2049, 2048, 2048, 2049, 2049,
                                 2048, 2048, 2048, 2049, 2049, 2048, 2048, 2048, 2049, 2049, 2049, 2048, 2048, 2048,
                                 2049, 2049, 2049, 2049, 2048, 2047, 2046, 2047, 2048, 2051, 2054, 2057, 2056, 2053,
                                 2047, 2039, 2029, 2020, 2011, 2005, 2002, 2002, 2006, 2012, 2020, 2030, 2039, 2046,
                                 2048, 2045, 2030, 2002, 1955, 1884, 1789, 1669, 1533, 1399, 1295, 1263, 1347, 1583,
                                 1981, 2495, 3015, 3370, 3376, 2918, 2048, 1045, 359, 422, 1360, 2784, 3877, 3846,
                                 2553, 823, 1, 874, 2795, 4020, 3302, 1313, 181, 1201, 3160, 3630, 2048, 603,
                                 1283, 2982, 3107, 1602, 1003, 2189, 2957, 2035, 1295, 2059, 2658, 1972, 1579, 2213,
                                 2367, 1818, 1894, 2287, 2048, 1873, 2149, 2111, 1935, 2085, 2100, 1983, 2069, 2075,
                                 2011, 2067, 2055, 2030, 2064, 2044, 2045, 2056, 2042, 2052, 2048, 2047, 2051, 2047,
                                 2050, 2048, 2048, 2049, 2048, 2049, 2048, 2049, 2048, 2049, 2048, 2049, 2048, 2049,
                                 2048, 2049, 2048, 2049, 2048, 2049, 2048, 2049, 2048, 2049, 2048, 2049, 2048, 2049,
                                 2048, 2049, 2048, 2048, 2049, 2048, 2049, 2048, 2048, 2049, 2048, 2049, 2048, 2048,
                                 2049, 2048, 2049, 2049};
    USHORT buffer2M[BUF_SIZE] = {2048, 2048, 2049, 2049, 2048, 2049, 2048, 2048, 2049, 2048, 2049, 2048, 2049, 2048, 2049,
                                 2048, 2048, 2049, 2048, 2049, 2049, 2048, 2049, 2049, 2048, 2046, 2048, 2054, 2056,
                                 2047, 2029, 2011, 2002, 2006, 2020, 2039, 2048, 2030, 1955, 1789, 1533, 1295, 1347,
                                 1981, 3015, 3376, 2048, 359, 1360, 3877, 2553, 1, 2795, 3302, 181, 3160, 2048,
                                 830, 3107, 1003, 2957, 1295, 2658, 1579, 2367, 1894, 2048, 2149, 1935, 2100, 2069,
                                 2011, 2055, 2064, 2045, 2042, 2048, 2051, 2050, 2048, 2048, 2048, 2048, 2048, 2048,
                                 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2049, 2049, 2048, 2048, 2048,
                                 2049, 2049};
    USHORT buffer500k[BUF_SIZE] = {2048, 2048, 2049, 2049, 2049, 2048, 2048, 2048, 2048, 2049, 2049, 2049, 2048, 2048, 2048, 2049, 2049, 2049, 2048, 2048, 2048,
                                   2049, 2049, 2049, 2048, 2048, 2048, 2048, 2049, 2049, 2049, 2048, 2048, 2048, 2049,
                                   2049, 2049, 2049, 2048, 2048, 2048, 2048, 2049, 2049, 2049, 2049, 2048, 2048, 2048,
                                   2048, 2049, 2049, 2049, 2049, 2048, 2048, 2048, 2048, 2049, 2049, 2049, 2049, 2049,
                                   2048, 2048, 2048, 2048, 2048, 2049, 2049, 2049, 2049, 2049, 2048, 2048, 2048, 2048,
                                   2048, 2049, 2049, 2049, 2049, 2049, 2049, 2048, 2048, 2048, 2048, 2048, 2048, 2048,
                                   2049, 2049, 2049, 2049, 2049, 2049, 2049, 2049, 2048, 2047, 2047, 2046, 2046, 2046,
                                   2047, 2047, 2048, 2050, 2051, 2053, 2054, 2056, 2057, 2057, 2056, 2055, 2053, 2051,
                                   2047, 2044, 2039, 2034, 2029, 2024, 2020, 2015, 2011, 2008, 2005, 2003, 2002, 2001,
                                   2002, 2003, 2006, 2008, 2012, 2016, 2020, 2025, 2030, 2034, 2039, 2042, 2046, 2048,
                                   2048, 2048, 2045, 2039, 2030, 2018, 2002, 1981, 1955, 1923, 1884, 1840, 1789, 1731,
                                   1669, 1602, 1533, 1464, 1399, 1341, 1295, 1268, 1263, 1288, 1347, 1445, 1583, 1763,
                                   1981, 2228, 2495, 2764, 3015, 3225, 3370, 3427, 3376, 3207, 2918, 2523, 2048, 1538,
                                   1045, 631, 359, 279, 422, 793, 1360, 2056, 2784, 3430, 3877, 4033, 3846, 3327,
                                   2553, 1659, 823, 222, 1, 229, 874, 1801, 2795, 3606, 4020, 3914, 3302, 2345,
                                   1313, 509, 181, 438, 1201, 2223, 3160, 3691, 3630, 3003, 2048, 1130, 603, 667,
                                   2035, 1487, 1295, 1544, 2059, 2520, 2658, 2415, 1972, 1622, 1579, 1843, 2213, 2432,
                                   2367, 2091, 1818, 1741, 1894, 2141, 2287, 2236, 2048, 1886, 1873, 2001, 2149, 2194,
                                   2111, 1988, 1935, 1987, 2085, 2135, 2100, 2023, 1983, 2010, 2069, 2098, 2075, 2030,
                                   2011, 2033, 2067, 2076, 2055, 2031, 2030, 2049, 2064, 2059, 2044, 2037, 2045, 2055,
                                   2056, 2048, 2042, 2045, 2052, 2053, 2048, 2045, 2047, 2050, 2051, 2048, 2047, 2048,
                                   2050, 2049, 2048, 2048, 2048, 2049, 2049, 2048, 2048, 2049, 2049, 2048, 2048, 2048,
                                   2049, 2049, 2048, 2048, 2049, 2049, 2048, 2048, 2049, 2049, 2048, 2048, 2049, 2049,
                                   2048, 2048, 2049, 2049, 2048, 2048, 2049, 2049, 2048, 2048, 2049, 2049, 2048, 2048,
                                   2049, 2049, 2048, 2048, 2049, 2049, 2048, 2048, 2049, 2049, 2048, 2049, 2049, 2048,
                                   2048, 2049, 2049, 2048, 2048, 2049, 2048, 2048, 2049, 2049, 2048, 2049, 2049, 2048,
                                   2048, 2049, 2048, 2048, 2049, 2049, 2048, 2049, 2049, 2048, 2048, 2049, 2048, 2048,
                                   2049, 2048, 2048, 2049, 2049, 2048, 2049, 2049, 2048, 2048, 2049, 2049, 2049, 2048, 2048,};
    // 下载波形
    // 根据传入的参数选择数组
    std::string param;

    if (argc > 1) // 输入参数,控制下载波形
    {
        param = argv[1];

        // 显示帮助信息
        if (param == "-h")
        {
            std::cout << "Help information:\n";
            std::cout << "Usage: \n";
            std::cout << "  main.exe [frequency]\n";
            std::cout << "Where [frequency] can be:\n";
            std::cout << "  1M   - Generate 1MHz waveform\n";
            std::cout << "  2M   - Generate 2MHz waveform\n";
            std::cout << "  500k - Generate 500kHz waveform\n";
            std::cout << "If no argument provided, just check device status.\n";
        }

        else
        {
            if (param == "1M")
            {
                wave_point_num = 200;
                downStatus = DDSDownload(device_index, buffer1M, wave_point_num);
                printf(">>> Writing 1M-freq wave...\n");
            }
            else if (param == "2M")
            {
                wave_point_num = 100;
                downStatus = DDSDownload(device_index, buffer2M, wave_point_num);
                printf(">>> Writing 2M-freq wave...\n");
            }
            else if (param == "500k")
            {
                wave_point_num = 400;
                downStatus = DDSDownload(device_index, buffer500k, wave_point_num);
                printf(">>> Writing 500k-freq wave...\n");
            }
            else
            { // 默认情况为检查设备状态
                printf("!!! Wrong arguments, please check !\n");
            }
            if (downStatus)
            {
                printf("Writing wave successfully!\n");
            }
            else
            {
                printf("Failed to write wave!\n");
                return -1;
            }
        }
    }
    return 0;
}

到了这里,关于汉泰克1025G信号发生器二次开发(python和C)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 「Verilog学习笔记」信号发生器

    专栏前言 本专栏的内容主要是记录本人学习Verilog过程中的一些知识点,刷题网站用的是牛客网         方波的实现,较为简单,只需要设置一个计数器,使输出保持10个时钟为0,跳变为20,再保持10个时钟。依次循环。可以按照如下的过程实现:cnt每个时钟加一,当cnt=

    2024年02月05日
    浏览(39)
  • 电子制作——ICL8038信号发生器

    电子制作——一个电调的诞生之路 电子制作——ICL8038信号发生器 寒假放假在家,手头刚好缺了一个信号发生器用。在网上查了资料,发现ICL8083这个芯片很不错,虽然有点老,但是用起来方便,制作电路板发厂又很简单,所以做了一个DEMO以供实验用。 ICL8038是一个可以产生多

    2023年04月17日
    浏览(34)
  • 基于FPGA的信号发生器(四)

         基于FPGA的信号发生器的硬件电路通常需要以下组件: FPGA芯片:FPGA芯片是这个电路的核心部件,用于实现信号生成算法和控制逻辑。选择合适规模的FPGA芯片以满足你的信号发生器的性能和功能需求。 时钟源:信号发生器需要一个稳定的时钟源,以确定信号的频率和采

    2024年04月14日
    浏览(48)
  • 基于AD9833的信号发生器

    本文利用FPGA控制AD9833,实现信号发生器的功能。本文将对AD9833的手册进行详细的解读,并对其配置方法进行解析,最后在Verilog中进行编码,将代码烧录置FPGA中,FPGA通过外部引脚控制AD9833输出所需要的正弦波、方波和三角波。三种波形能够输出的频率范围为0~12.5Mhz。 AD9833是

    2024年02月03日
    浏览(44)
  • FPGA实验五:信号发生器设计

    目录 一、实验目的 二、设计要求 三、实验代码 1.代码原理分析 2.代码设计思路

    2024年02月12日
    浏览(40)
  • 基于FPGA的DDS信号发生器

        两个礼拜前就像写这个文档了,但是一直鸽到现在,主要是人摆了。还有个技术上的原因是,我想用串口屏显示波形,在串口调试助手上返回的数据是对的,但是发到串口屏上啥反应没有,人就很麻,如果这个弄不出来,前面 HMI 串口屏的工程、人机交互界面就白做了。

    2024年02月06日
    浏览(46)
  • VHDL语言序列信号发生器的实现

    题目:实现图示电路(产生1101001序列码) 详细描述:用VHDL设计194,再用VHDL层次结构设计方法设计程序实现图示电路并仿真,底层器件是194,要求层次化设计,分模块调试   二、底层器件  194 代码: Flow Summary         2.仿真波形及解释   此波形图是验证194的异步清零和并

    2024年02月11日
    浏览(28)
  • QuartusDDS信号发生器Verilog代码仿真

    名称:QuartusDDS信号发生器Verilog代码仿真(文末获取) 软件:Quartus 语言:Verilog 代码功能: DDS信号发生器 可以输出正弦波、方波、三角波 可以改变波形的频率 1. 工程文件 2. 程序文件 3. 程序编译 4. RTL图 5. Testbench 6. 仿真图 整体仿真图 方波ROM模块 三角波ROM模块 Sin波ROM模块

    2024年02月02日
    浏览(36)
  • MATLAB GUI笔记(九):信号发生器

    选择Blank GUI,然后更改保存路径 然后拖动出来 更改字体大小和显示内容 可以更改字体大小和显示内容 更改字体大小和显示内容以及标签Tag 更改字体大小和显示内容以及Tag 更改字体大小和显示内容 更改字体大小和显示内容以及Tag 选择查看回调,点击Callback 拖动1个按钮,

    2024年02月07日
    浏览(35)
  • fpga课设-多功能信号发生器

    1绪论 1.1 背景 信号发生器作为一种历史悠久的测量仪器,早在20年代电子设备刚出现时就产生了。随着通信和雷达技术的发展,40年代出现了主要用于测试各种接收机的标准信号发生器,使得信号发生器从定性分析的测试仪器发展成定量分析的测量仪器。同时还出现了可用来

    2024年02月05日
    浏览(45)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包