汉泰克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函数查看器(自行搜索下载)实现查找,如下图所示:
在这里插入图片描述
由于官方提供的.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

#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;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/303729.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

升级 Vite 5 出现警告 The CJS build of Vite‘s Node API is deprecated.

&#x1f680; 作者主页&#xff1a; 有来技术 &#x1f525; 开源项目&#xff1a; youlai-mall &#x1f343; vue3-element-admin &#x1f343; youlai-boot &#x1f33a; 仓库主页&#xff1a; Gitee &#x1f4ab; Github &#x1f4ab; GitCode &#x1f496; 欢迎点赞…

DOM高级

1.1 自定义属性操作 1.1.1 获取属性值 element.属性 element.getAttribute(属性) 区别&#xff1a; element.属性&#xff1a;获取元素内置属性 element.getAttribute(属性)&#xff1a;获取自定义的属性 1.1.2 设置属性值 element.属性 值 element.setAttribute(属性&a…

多特征变量序列预测(一)——CNN-LSTM风速预测模型

目录 往期精彩内容&#xff1a; 前言 1 多特征变量数据集制作与预处理 1.1 导入数据 1.2 数据集制作与预处理 2 基于Pytorch的CNN-LSTM 预测模型 2.1 定义CNN-LSTM预测模型 2.2 设置参数&#xff0c;训练模型 3 模型评估与可视化 3.1 结果可视化 3.2 模型评估 代码…

11.文件和异常

文件和异常 实际开发中常常会遇到对数据进行持久化操作的场景&#xff0c;而实现数据持久化最直接简单的方式就是将数据保存到文件中。说到“文件”这个词&#xff0c;可能需要先科普一下关于文件系统的知识&#xff0c;但是这里我们并不浪费笔墨介绍这个概念&#xff0c;请大…

柯桥小语种学习,留学韩语 生活日常口语 语法

① N이다/A/V/았ㄹ/을지도 모르다 说不定 이미 도착했을 지도 모르니까 전화해 봐요 说不定已经到了&#xff0c;打电话试试 주말에 세일이 있을지도 모르니까 주말에 가 보자 周末说不定会搞活动&#xff0c;我们周末去吧 ② ㄴ/은/는/았었는/ㄹ/을지 모르다 不知道 처음이…

第四站:C/C++基础-指针

目录 为什么使用指针 函数的值传递&#xff0c;无法通过调用函数&#xff0c;来修改函数的实参 被调用函数需要提供更多的“返回值”给调用函数 减少值传递时带来的额外开销&#xff0c;提高代码执行效率 使用指针前: 使用指针后: 指针的定义: 指针的含义(进阶): 空指针…

4.6 BOUNDARY CHECKS

我们现在扩展了tile矩阵乘法内核&#xff0c;以处理具有任意宽度的矩阵。扩展必须允许内核正确处理宽度不是tile宽度倍数的矩阵。通过更改图4.14中的示例至33 M、N和P矩阵&#xff0c;图4.18创建了矩阵的宽度为3&#xff0c;不是tile宽度&#xff08;2&#xff09;的倍数。图4.…

怎么将营业执照图片转为excel表格?(批量合并识别技巧)

一、为何要将营业执照转为excel表格&#xff1f; 1、方便管理&#xff1a;将营业执照转为excel格式&#xff0c;可以方便地进行管理和整理&#xff0c;快速查找需要的信息。 2、数据处理&#xff1a;Excel可以提供丰富的计算和数据分析功能&#xff0c;转化为excel后方便数据…

【算法设计与分析】网络流

目录 max-flow 和 min-cut流网络 Flow network最小割 Min-cut最大流 Max-flow Greedy algorithmFord–Fulkerson algorithm剩余网络 Residual networkFord–Fulkerson algorithm算法流程 最大流最小割理论 max-flow min-cut theorem容量扩展算法 capacity-scaling algorithm时间…

Rustdesk本地配置文件存在什么地方?

环境&#xff1a; rustdesk1.1.9 Win10 专业版 问题描述&#xff1a; Rustdesk本地配置文件存在什么地方&#xff1f; 解决方案&#xff1a; RustDesk 是一款功能齐全的远程桌面应用。 支持 Windows、macOS、Linux、iOS、Android、Web 等多个平台。 支持 VP8 / VP9 / AV1 …

UDP 和 TCP 、HTTP、HTTPS、SOCKS5协议的不同之处及应用场景

UDP 和 TCP、HTTP、HTTPS、SOCKS5 协议的不同之处及应用场景&#xff1a; UDP (User Datagram Protocol)&#xff1a; 不同之处&#xff1a;UDP 是无连接的&#xff0c;不保证数据包的顺序到达或完整性&#xff0c;也没有流量控制和拥塞控制机制。它尽可能快地将数据包从源主机…

STL标准库与泛型编程(侯捷)笔记4

STL标准库与泛型编程&#xff08;侯捷&#xff09; 本文是学习笔记&#xff0c;仅供个人学习使用。如有侵权&#xff0c;请联系删除。 参考链接 Youbute: 侯捷-STL标准库与泛型编程 B站: 侯捷 - STL Github:STL源码剖析中源码 https://github.com/SilverMaple/STLSourceCo…

面向应用的离线计算系统:周期任务组合策略

1 场景 业务应用系统想大批量利用数据中心的计算能力跑数,回传结果。比如一个个地区的详情数据。而大数据平台通常是调度平台系统,和业务系统是两个独立的平台系统,如何建立交互方式。 业务有个性化的实验策略,需要组合业务条件达到实验效果。比如捞取不同的数据实验算法…

4.8 SUMMARY 4.9 EXERCISES

总之&#xff0c;在现代处理器中&#xff0c;程序的执行速度可能会受到内存速度的严重限制。为了很好地利用CUDA设备的执行吞吐量&#xff0c;应该在内核代码中获得高计算与全局内存访问率。如果获得的比率很低&#xff0c;则内核受内存约束&#xff1b;即其执行速度受从内存访…

鸿蒙Ability开发-Stage模型下Ability的创建和使用

创建Ability和Page页面 创建两个Ability&#xff1a;EntryAbility&#xff0c;DetailsAbility&#xff0c;其中EntryAbility是由工程默认创建的&#xff0c;这里我们只讲如何创建DetailsAbility。 使用DevEco Studio&#xff0c;选中对应的模块&#xff0c;单击鼠标右键&…

IDEA+Git——项目分支管理

IDEAGit——项目分支管理 1. 前言2. 基础知识点2.1. 分支区分2.2. Git 代码提交规范2.3. 四个工作区域2.4. 文件的四种状态2.5. 常用命令2.6 注重点 3. IDEA分支管理 1. 前言 在Git中&#xff0c;分支是项目的不同版本&#xff0c;当开始开发一个新项目时&#xff0c;主分支通常…

关于外连接、内连接和子查询的使用(2)

目录 一. 前言 二. 使用外连接、内连接和子查询进行解答 三. 思维导图 一. 前言 在前面我们对外连接、内连接和子查询的使用有了一些了解&#xff0c;今天我们将继续更深入的进行学习。&#xff08;这里缺少的八个题目在博主的前面博客有解答&#xff0c;大家可以移步前面一…

Tsmaster使用笔记整理

选择厂商 根据你所选择的CAN分析仪的厂商&#xff0c;确定你的厂商设备设置。 我一般会选择PEAK&#xff0c;和 ZLG多一点&#xff0c;其他的没有用过。除了上图中的&#xff0c;市面上的CAN分析仪还有CANanlyst、广成科技、创芯科技等&#xff0c;但它们都不能在Tsmaster上使…

Android Matrix (二)具体图形变换参数的获取

Android Matrix &#xff08;二&#xff09;具体图形变换参数的获取 Matrix 类在 Android 中用于表示 3x3 的变换矩阵。这个矩阵可以应用于画布&#xff08;Canvas&#xff09;&#xff0c;视图&#xff08;View&#xff09;或者位图&#xff08;Bitmap&#xff09;&#xff0…

嵌入式Linux-Qt环境搭建

本编介绍如何在嵌入式Linux开发板上配置Qt运行环境&#xff0c;并进行Qt程序运行测试。 1 tslib编译 tslib之前在测试触摸屏的时候使用过&#xff0c;这里再来记录一下编译过程。 下载tslib库的源码&#xff1a;https://github.com/libts/tslib/tags 将下载的源码拷贝到ubun…