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

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

相关推荐
ANnianStriver2 小时前
PetLumina 07 — 宠物管理升级与 JavaScript 大数精度修复
开发语言·javascript·ai编程·宠物
辣椒思密达2 小时前
Python公开数据采集实战:如何解决请求高频拦截与Session会话中断问题
开发语言·python
Albart5753 小时前
Python 实战教程:用 30 分钟学会解决真实问题
开发语言·python
2301_773643623 小时前
ceph池
开发语言·ceph·python
两年半的个人练习生^_^3 小时前
JMM 进阶:彻底理解 CAS 实现原理
java·开发语言
半个烧饼不加肉3 小时前
JS 底层探究-- 事件循环
开发语言·前端·javascript
asdfg12589633 小时前
C 语言中产生伪随机数的标准做法
c语言·开发语言
KobeSacre4 小时前
JUC 概述
java·开发语言
Jun6264 小时前
QT(2)-通过管道关联CMD
开发语言·qt·命令模式