QT(19)-VISA控制仪器

1.安装VISA库

下载NI-VISA - NI

或者去KEYSIGHT官网找文件(KEYSIGHT文件优先,仪器都是这个公司的)

安装完之后,确认是否正常有库文件

2.应用程序

test.pro,在最后添加库文件

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++17

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    main.cpp \
    mainwindow.cpp

HEADERS += \
    mainwindow.h

FORMS += \
    mainwindow.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

INCLUDEPATH += "C:/Program Files (x86)/IVI Foundation/VISA/WinNT/Include"
LIBS += "C:\Program Files (x86)\IVI Foundation\VISA\WinNT\Lib_x64\msc\visa64.lib"

mainwindow.cpp实现频率控制

#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <visa.h>

#define MAX_SCPI_LEN 1024
#define DEFAULT_TMO 2000
#define N9010A_INSTR "TCPIP0::192.168.1.200::hislip0::INSTR"
#define TEST_CMD ":FREQ:CENT 50 MHz"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // 初始化 VISA 会话
    ViSession defaultRM, instr;
    ViStatus status = viOpenDefaultRM(&defaultRM);
    if (status != VI_SUCCESS) {
        //qDebug() << "Failed to open default resource manager.";
    }

    // 打开仪器
    status = viOpen(defaultRM, N9010A_INSTR, VI_NULL, VI_NULL, &instr);
    if (status != VI_SUCCESS) {
        //qDebug() << "Failed to open instrument.";
        viClose(defaultRM);
    }

    // 设置中心频率为 80 MHz
    char freqCmd[] = ":FREQ:CENT 100 MHz";
    status = viWrite(instr, (ViByte*)freqCmd, strlen(freqCmd), VI_NULL);
    if (status == VI_SUCCESS) {
        //qDebug() << "Center frequency set to 80 MHz.";
    } else {
        //qDebug() << "Failed to set center frequency.";
    }

    // 读取仪器响应
    char buffer[100];
    status = viRead(instr, (ViByte*)buffer, sizeof(buffer) - 1, VI_NULL);
    if (status == VI_SUCCESS) {
        buffer[status] = '\0';
        //qDebug() << "Instrument response:" << buffer;
    } else {
        //qDebug() << "Failed to read instrument response.";
    }

    // 关闭 VISA 会话
    viClose(instr);
    viClose(defaultRM);
}

MainWindow::~MainWindow()
{
    delete ui;
}

如果设备在同一个局域网,将会设置频谱仪的中心频率

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值