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

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

相关推荐
用户8055336980314 小时前
不止三件套:QObject 属性系统全关键字与运行时反射!
c++·qt
xcyxiner15 小时前
DicomViewer (vcpkg Windows和ubuntu编译)7
qt
Quz6 天前
QML Hello World 入门示例
qt
xcyxiner9 天前
DicomViewer (dcmtk读取dcm文件)5
qt
xcyxiner9 天前
DicomViewer (后台线程处理文件)4
qt
xcyxiner10 天前
DicomViewer (添加模型类)3
qt
xcyxiner10 天前
DicomViewer (目录调整) 2
qt
xcyxiner10 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
LDR00612 天前
Type-C 快充全面升级!LDR6601 赋能个人护理便携电机,重塑剃须刀 / 理发器新体验
c语言·开发语言
雪碧聊技术12 天前
Tree.js是什么?一文讲透
开发语言·javascript·ecmascript