#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include "visa.h"
#include "visatype.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
//fnGPIB_usb_hs();
}
MainWindow::~MainWindow()
{
delete ui;
}
int MainWindow::fnGPIB_usb_hs(int control)
{
// 打开GPIB设备
ViSession defaultRM, vi;
ViStatus status;
status = viOpenDefaultRM(&defaultRM);
if (status != VI_SUCCESS) {
qDebug() << "Failed to open the default resource manager.";
return -1;
}
// 打开GPIB设备的地址为1的设备
status = viOpen(defaultRM, "GPIB0::1::INSTR", VI_NULL, VI_NULL, &vi);
if (status != VI_SUCCESS) {
qDebug() << "Failed to open the GPIB device.";
viClose(defaultRM);
return -1;
}
// 发送命令并读取响应
char command[256] = "*IDN?";
char response[256] = "";
ui->textEdit->clear();
status = viWrite(vi, (ViBuf)command, strlen(command), NULL);
if (status == VI_SUCCESS) {
status = viRead(vi, (ViBuf)response, sizeof(response), NULL);
if (status == VI_SUCCESS) {
qDebug() << "Response: " << response;
QString str_response=response;
ui->textEdit->setText(str_response);
}
}
if(control==1)
{
// 发送命令并读取响应
char command1[256] = "OUTPut ON";
char response1[256] = "";
status = viWrite(vi, (ViBuf)command1, strlen(command1), NULL);
if (status == VI_SUCCESS) {
qDebug() << "恭喜你,成功打开电源" << response1;
ui->label->setText("恭喜你,成功打开电源");
// status = viRead(vi, (ViBuf)response1, sizeof(response1), NULL);
// if (status == VI_SUCCESS) {
// qDebug() << "恭喜你,成功打开电源" << response1;
// ui->label->setText("恭喜你,成功打开电源");
// }
}
}else{
// 发送命令并读取响应
char command1[256] = "OUTPut OFF";
char response1[256] = "";
status = viWrite(vi, (ViBuf)command1, strlen(command1), NULL);
if (status == VI_SUCCESS) {
qDebug() << "恭喜你,成功关闭电源" << response1;
ui->label->setText("恭喜你,成功关闭电源");
// status = viRead(vi, (ViBuf)response1, sizeof(response1), NULL);
// if (status == VI_SUCCESS) {
// qDebug() << "恭喜你,成功关闭电源" << response1;
// ui->label->setText("恭喜你,成功关闭电源");
// }
}
}
// 关闭GPIB设备
viClose(vi);
viClose(defaultRM);
}
void MainWindow::on_pushButton_clicked()
{
int open=1;
fnGPIB_usb_hs(open);
}
void MainWindow::on_pushButton_2_clicked()
{
int close=2;
fnGPIB_usb_hs(close);
}
qt-test-GPIB-usb-hs-1.zip qt控制GPIB相关代码
需积分: 1 78 浏览量
2023-10-06
18:21:03
上传
评论
收藏 43KB ZIP 举报
好奇龙猫
- 粉丝: 2w+
- 资源: 122
最新资源
- 基于pygame实现的烟花代码
- mcu-printf关于51单片机使用printf函数进行串口调试的方法
- MySQL和数据表操作
- 微信小程序面试题.pdf
- 基于matlab实现电力系统仿真计算软件包,包括潮流计算,最优潮流计算等.rar
- 基于matlab实现电力系统各种故障波形仿真,单相接地故障,两相间短路,两相接地短路,三相短路等.rar
- 基于matlab实现电动汽车动力性,爬坡性,续驶里程等性能仿真.rar
- Python动态烟花代码.pdf
- 基于matlab实现串口发送接收数据 可配置端口,波特率等 发送可选择ASCII方式或HEX方式
- matlab基于BP神经网络手写字母识别(单一).zip代码9
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈