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

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

相关推荐
w_zero_one24 分钟前
递归算法(一)
java·开发语言·算法
Julien20041 小时前
管理机密(一)
运维·服务器·开发语言·学习方法
Chen_harmony1 小时前
七、STL与string类
开发语言·c++
沐晓时光2 小时前
C语言入门,字符串和字符串函数知识讲解
c语言·开发语言
xxxiugou1232 小时前
C++命名空间与引用全解析
开发语言·c++
BroNekoX3 小时前
我将基于 QtQuick 框架开发的音乐播放器性能做到顶级
qt
yangmu32033 小时前
编程语言发展简史:从机器指令到智能协作
开发语言
Pniubi6 小时前
Java为什么要分堆和栈
java·开发语言
小小晓.6 小时前
Qt 对话框、QLineEdit 与布局管理实战详解
开发语言·qt
炸薯条!7 小时前
博客系统测试报告
开发语言·lua