1.效果图

2. Plot控件用的是QCustomPlot

3. 源码

3.1 窗体头文件artusb3100.h

#ifndef ARTUSB3100_H
#define ARTUSB3100_H
#include <QWidget>
#include <iostream>
#include <QTimer>
#include <QQueue>
const int DATALEN = 1000;
//typedef struct{
//    float data[DATALEN];
//} DATABUFF;
using namespace std;
namespace Ui {
class ArtUSB3100;
}
class ArtUSB3100 : public QWidget
{
    Q_OBJECT
public:
    explicit ArtUSB3100(QWidget *parent = nullptr);
    ~ArtUSB3100();
private slots:
    void on_pushBtnExit_clicked();
    void on_pushButtonStart_clicked();
    void on_pushButtonStop_clicked();
    void timerOutSlot();
    void timerOutShowSlot();
    void on_comboBoxModel_currentIndexChanged(int index);
    void on_comboBoxChannelName_currentIndexChanged(int index);
    void on_comboBoxInputCfg_currentIndexChanged(int index);
private:
    Ui::ArtUSB3100 *ui;
    vector<float>  m_data;
//    QQueue<DATABUFF> m_dataShow;
    QTimer* m_timerGetData;
    QTimer* m_timerShowData;
    QString m_channelName;
    void drawCurve();
    void getData();
    void initCustomPlot();
};
#endif // ARTUSB3100_H

3.2 窗体实现文件 artusb3100.cpp

#include "artusb3100.h"
#include "ui_artusb3100.h"
#include "conio.h"
#include "ArtDaq/Include/Art_DAQ.h"
#include <QDebug>
static int nshowcount = 0;
static int ncollectcount = 0;
#define ArtDAQErrChk(functionCall) if( ArtDAQFailed(error=(functionCall)) ) goto Error;
ArtUSB3100::ArtUSB3100(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ArtUSB3100)
{
    ui->setupUi(this);
    m_channelName = "Dev1/ai0";
    m_timerGetData = new QTimer(this);
    connect(m_timerGetData,SIGNAL(timeout()), this, SLOT(timerOutSlot()));
    m_timerGetData->start(10000);
    m_timerShowData = new QTimer(this);
    connect(m_timerShowData,SIGNAL(timeout()), this, SLOT(timerOutShowSlot()));
    m_timerShowData->start(500);
    int datasize = ui->lineEditSamples->text().toInt();
    m_data.resize(DATALEN * 2);
//    m_dataShow.clear();
    getData();
    initCustomPlot();
}
ArtUSB3100::~ArtUSB3100()
{
    delete ui;
    delete m_timerGetData;
    delete m_timerShowData;
}
void ArtUSB3100::timerOutSlot()
{
    getData();
}
void ArtUSB3100::timerOutShowSlot()
{
    drawCurve();
}
void ArtUSB3100::on_pushBtnExit_clicked()
{
    this->close();
}
void ArtUSB3100::on_pushButtonStart_clicked()
{
    m_timerGetData->start(10000);
    m_timerShowData->start(500);
}
void ArtUSB3100::on_pushButtonStop_clicked()
{
    m_timerGetData->stop();
    m_timerShowData->stop();
}
void ArtUSB3100::initCustomPlot()
{
    const int nsamples = DATALEN / 10;
    // add one graphs to show channel data:
    ui->customPlot->addGraph();
    ui->customPlot->graph(0)->setPen(QPen(Qt::blue)); // line color blue for first graph
//    ui->customPlot->graph(0)->setBrush(QBrush(QColor(0, 0, 255, 20))); // first graph will be filled with translucent blue
    // generate some points of data (y0 for first channel, y1 for second channel,....y7 for last channel):
    QVector<double> x(nsamples), y(nsamples);
    // configure right and top axis to show ticks but no labels:
    // (see QCPAxisRect::setupFullAxesBox for a quicker method to do this)
    ui->customPlot->xAxis2->setVisible(true);
    ui->customPlot->xAxis2->setTickLabels(false);
    ui->customPlot->yAxis2->setVisible(true);
    ui->customPlot->yAxis2->setTickLabels(false);
    // make left and bottom axes always transfer their ranges to right and top axes:
    connect(ui->customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->xAxis2, SLOT(setRange(QCPRange)));
    connect(ui->customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->yAxis2, SLOT(setRange(QCPRange)));
//    // pass data points to graphs:
//    ui->customPlot->graph(0)->setData(x, y);
//    // let the ranges scale themselves so graph 0 fits perfectly in the visible area:
//    ui->customPlot->graph(0)->rescaleAxes();
    // Note: we could have also just called customPlot->rescaleAxes(); instead
    // Allow user to drag axis ranges with mouse, zoom with mouse wheel and select graphs by clicking:
    ui->customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
}
void ArtUSB3100::drawCurve()
{
    const int nsamples = DATALEN /10;
    int offset = DATALEN / 20;
    QVector<double> x(nsamples), y(nsamples);
    for (int i=0; i<nsamples; ++i)
    {
        int index = (i + offset * nshowcount) % (DATALEN * 2);
        x[i] = index;
        y[i] = m_data[index];
    }
    nshowcount ++;
    if (nshowcount == 21) nshowcount = 0;
    ui->customPlot->graph(0)->setData(x, y);
    ui->customPlot->graph(0)->rescaleAxes();
    ui->customPlot->replot();
}
void ArtUSB3100::getData()
{
    int32       error=0;
    TaskHandle  taskHandle=0;
    int32       read;
    float64     data[1000];
//    DATABUFF tempBuff;
    char        errBuff[2048]={'\0'};
    /*********************************************/
    // ArtDAQ Configure Code
    /*********************************************/
    ArtDAQErrChk (ArtDAQ_CreateTask("",&taskHandle));
    ArtDAQErrChk (ArtDAQ_CreateAIVoltageChan(taskHandle,m_channelName.toLatin1().data(),"",ArtDAQ_Val_Cfg_Default,-10.0,10.0,ArtDAQ_Val_Volts,NULL));
    ArtDAQErrChk (ArtDAQ_CfgSampClkTiming(taskHandle,"",10000.0,ArtDAQ_Val_Rising,ArtDAQ_Val_FiniteSamps,1000));
    /*********************************************/
    // ArtDAQ Start Code
    /*********************************************/
    ArtDAQErrChk (ArtDAQ_StartTask(taskHandle));
    /*********************************************/
    // ArtDAQ Read Code
    /*********************************************/
    ArtDAQErrChk (ArtDAQ_ReadAnalogF64(taskHandle,1000,10.0,ArtDAQ_Val_GroupByChannel,data,1000,&read,NULL));
    for (int i=0; i< 1000; ++i) {
//        m_data[i] = data[i];
        m_data[ncollectcount* 1000 +i] = data[i];
//        tempBuff.data[i] = data[i];
    }
    ncollectcount ++;
    if (ncollectcount == 2) ncollectcount = 0;
//    if(m_dataShow.size() == 4)
//    {
//        m_dataShow.dequeue();
//    }
//    m_dataShow.enqueue(tempBuff);
Error:
    if( ArtDAQFailed(error) )
        ArtDAQ_GetExtendedErrorInfo(errBuff,2048);
    if( taskHandle!=0 ) {
        /*********************************************/
        // ArtDAQ Stop Code
        /*********************************************/
        ArtDAQ_StopTask(taskHandle);
        ArtDAQ_ClearTask(taskHandle);
    }
    if( ArtDAQFailed(error) )
        qDebug() << "ArtDAQ_ Error: " << errBuff << endl;
}
void ArtUSB3100::on_comboBoxModel_currentIndexChanged(int index)
{
}
void ArtUSB3100::on_comboBoxChannelName_currentIndexChanged(int index)
{
    m_channelName = ui->comboBoxChannelName->itemText(index);
}
void ArtUSB3100::on_comboBoxInputCfg_currentIndexChanged(int index)
{
}
4. 主程序main.cpp
#include "artusb3100.h"
#include <QApplication>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    ArtUSB3100 w;
    w.show();
    return a.exec();
}
5. 工程文件
#-------------------------------------------------
#
# Project created by QtCreator 2022-10-14T08:56:56
#
#-------------------------------------------------
QT       += core gui
QT       += printsupport
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = ArtUSB3100
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
CONFIG += c++11
SOURCES += \
        main.cpp \
        artusb3100.cpp \
        qcustomplot.cpp
HEADERS += \
        artusb3100.h \
        qcustomplot.h
FORMS += \
        artusb3100.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/ArtDaq/Lib/x64/ -lArt_DAQ
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/ArtDaq/Lib/x64/ -lArt_DAQd
INCLUDEPATH += $$PWD/ArtDaq/Include
DEPENDPATH += $$PWD/ArtDaq/Include

阿尔泰模拟量采集终端相关推荐

  1. PLC模拟量采集在工业自动化控制中的应用

    在复杂的工业现场中,往往需要对温度.电压.电流.压力等等模拟量进行数据采集,可以借助PLC进行控制采集,但目前市场各种PLC模拟量采集模块十分多,不同的厂家不同的PLC都有自己独特的模拟量采集模块,而 ...

  2. STM32使用ADC+DMA进行多通道模拟量采集 (踩坑及傻瓜式解析)

    STM32使用ADC+DMA进行多通道模拟量采集 (踩坑及通俗解析) ​ 利用STM32的片上外设可采集多个模拟量(如传感器数值),并在嵌入式程序中使用.如果只使用了一个通道,用时令ADC转换而后读取 ...

  3. PLC模拟量采集算法数学基础(线性传感器)

    模拟量采集库如何设计,具体算法代码请参看下面这篇博文: PLC模拟量输入 模拟量转换FC:S_ITR_RXXW_BOSS的博客-CSDN博客_s_itr模拟量采集.工业现场应用特别广泛.大部分传感器的 ...

  4. 模拟量采集软件虚拟精度提升方案

    模拟量采集软件虚拟精度提升方案 AI的数据采集精度是AI采集的重要指标,一般来说控制器的AI精度会有一个指标,比如)0.5%,这个精度是标定精度,实际AI通过高一个等级的测量系统如0.1%测量后,经过 ...

  5. Arduino UNO模拟量采集

    Arduino UNO模拟量采集 环境准备 打开arduino开发环境 观察输出结果 环境准备 准备一个滑动变阻器,Arduino uno 板一块,接线图如下: 打开arduino开发环境 编写程序代 ...

  6. Arduino初初教程7——模拟量采集

    2019独角兽企业重金招聘Python工程师标准>>> 模拟量采集需要用到模拟量器件,这里主要指一些随着环境变化输出电压值随之变化的器件,如火焰传感器.部分温度传感器.可调电阻等等 ...

  7. 树莓派拓展模拟量采集(AD)功能

    1.前言 树莓派自身不带有模拟量采集功能(A/D)功能,当需要AD功能时,常通过IIC外接一个A/D模块来实现,如8位A/D芯片PCA9685.本文首先简要介绍PCA9685特性,然后基于树莓派的Bc ...

  8. Arduino最便宜的模拟量采集

    对于大多数人而言,利用Arduino和传感器采集环境数据已经不是问题了,但是,如何控制成本问题呢? 今天我将带大家做一个最最简单的模拟值采集电路,当然这种电路早就有了,我只是引用而已. 大家常见的传感 ...

  9. C#-串口-模拟量采集软件-1

    受公司要求开发一款模拟量采集软件,可连接到串口设备进行实时的数据模拟量采集,及修改串口设备的各项参数,控制单路继电器. 具体界面: 串口设备为八通道数据采集,可根据通道工程量参数设置进行各通道的边缘计 ...

最新文章

  1. Three levels at which any machine carrying out an Information-Processing task must be understood
  2. 石墨文档Websocket百万长连接技术实践
  3. python快速编程答案-100+Python编程题带你快速上手(附答案)
  4. 人脸识别屡遭非议,会成为“潘多拉魔盒”吗?
  5. STM32开发 -- 4G模块开发详解(3)
  6. 不同编程语言的取模运算%
  7. 专利:结构化大数据通信协议
  8. leetcode 82. 删除排序链表中的重复元素 II(map)
  9. Qt工作笔记-发送端发送Json格式的数据包,接收端解析数据包
  10. jQuery 常用效果
  11. 为什么个体户做不大?
  12. java操作ElasticSearch(包含增删改查及基础语法操作)
  13. 发布量子加密手机,浓眉大眼的三星也开始技术碰瓷了?
  14. 基于SSM的境外电商后台管理系统(含word论文文档)
  15. Xcode (xip)官方原版下载 Xcode 所有历史版本
  16. 搜狐云景client工具评測之WordPress的搭建
  17. 关于计算机领域的各种学习交流网站
  18. iBeacon销声匿迹了吗?
  19. 安卓暗黑模式软件_抖音暗黑模式我喜欢你安卓版
  20. 多多情报通:拼多多宝贝排名靠前为什么没流量和访客?

热门文章

  1. 京东API item_search_img - 拍立淘搜索淘宝商品
  2. java 中byte[] 数组的合并
  3. 天道渺渺,正义无敌。
  4. 创龙C6657创建CCS Project
  5. [附源码]Python计算机毕业设计Django共享汽车系统
  6. Vue 常见面试题集锦
  7. 程序员的快乐-用python爬取彼岸网美女图片
  8. 一文透彻了解缺页异常
  9. 测试自动化框架的重要性– iSAFE的优势
  10. SpringBoot整合RabbitMQ(包含生产者和消费者)