├── .gitignore ├── green.png ├── qword.cpp ├── qword.h ├── red.png ├── favicon.ico ├── D2K-Dask.dll ├── D2K-Dask.lib ├── 20190725230700.jpg ├── main.cpp ├── README.md ├── qdaqcard.h ├── 4nmflywheel.pro ├── csqldatabase.h ├── motordriver.h ├── qmotorreport.h ├── mainwindow.h ├── motor.cpp ├── qdaqcard.cpp ├── motordriver.cpp ├── csqldatabase.cpp ├── motor.h ├── 4nmflywheel.pro.user ├── 4nmflywheel.pro.user.870df22 ├── mainwindow.cpp ├── qmotorreport.cpp └── D2kDask.h /.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamermontane/4nmflywheel/HEAD/green.png -------------------------------------------------------------------------------- /qword.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamermontane/4nmflywheel/HEAD/qword.cpp -------------------------------------------------------------------------------- /qword.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamermontane/4nmflywheel/HEAD/qword.h -------------------------------------------------------------------------------- /red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamermontane/4nmflywheel/HEAD/red.png -------------------------------------------------------------------------------- /favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamermontane/4nmflywheel/HEAD/favicon.ico -------------------------------------------------------------------------------- /D2K-Dask.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamermontane/4nmflywheel/HEAD/D2K-Dask.dll -------------------------------------------------------------------------------- /D2K-Dask.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamermontane/4nmflywheel/HEAD/D2K-Dask.lib -------------------------------------------------------------------------------- /20190725230700.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamermontane/4nmflywheel/HEAD/20190725230700.jpg -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | this is a flywheel control software. 2 | 基于 QT 框架的一款电机监控软件,采用rs422串口通信,sqlite数据库,qcustomplot画图 3 | 特点: 4 | 1. 基于qt的多线程的串口通讯&数据库操作 5 | 2. 使用多态以实现复用(开发中) 6 | 7 | ![Image text](https://github.com/softrobotYCLi/4nmflywheel/raw/master/20190725230700.jpg) 8 | -------------------------------------------------------------------------------- /qdaqcard.h: -------------------------------------------------------------------------------- 1 | #ifndef QDAQCARD_H 2 | #define QDAQCARD_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "D2kDask.h" 9 | 10 | //该数据采集卡型号为adlink DAQ2213 11 | 12 | using namespace DAQCARD; 13 | class QDaqcard : public QObject 14 | { 15 | Q_OBJECT 16 | public: 17 | explicit QDaqcard(QObject *parent = 0); 18 | ~QDaqcard(); 19 | void init(); 20 | 21 | signals: 22 | void logMsg(QString); 23 | void sendAllData(const QVector&); 24 | void sendSurgeCurrnt(const QVector&); 25 | public slots: 26 | void readAllChannel(); 27 | void getSurgeCurrent(U16 channel, QVector &v, int point_num); 28 | void setDOPort(uint port,bool status); 29 | private: 30 | bool is_init_ = false; 31 | DAQCARD::I16 card_; 32 | uchar m_DO_port_status_ = 0xff; 33 | }; 34 | 35 | #endif // QDAQCARD_H 36 | -------------------------------------------------------------------------------- /4nmflywheel.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2019-07-05T22:07:09 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui printsupport axcontainer 8 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 9 | 10 | CONFIG += C++ 11 11 | 12 | TARGET = 4nmflywheel 13 | TEMPLATE = app 14 | 15 | 16 | SOURCES += main.cpp\ 17 | mainwindow.cpp \ 18 | csqldatabase.cpp \ 19 | motor.cpp \ 20 | qcustomplot.cpp \ 21 | motordriver.cpp \ 22 | qmotorreport.cpp \ 23 | qword.cpp \ 24 | qdaqcard.cpp 25 | 26 | HEADERS += mainwindow.h \ 27 | csqldatabase.h \ 28 | motor.h \ 29 | qcustomplot.h \ 30 | motordriver.h \ 31 | qmotorreport.h \ 32 | qword.h \ 33 | D2kDask.h \ 34 | qdaqcard.h 35 | 36 | FORMS += mainwindow.ui 37 | 38 | QT += sql 39 | 40 | LIBS += -LC:/4nmflywheel/4nmflywheel -lD2K-Dask 41 | #LIBS += -LC:/mycode/motionStudio -ltmlcomm 42 | 43 | QT += serialport 44 | RC_ICONS = favicon.ico 45 | -------------------------------------------------------------------------------- /csqldatabase.h: -------------------------------------------------------------------------------- 1 | #ifndef CSQLDATABASE_H 2 | #define CSQLDATABASE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "motor.h" 18 | //if appear this warning:"MySQL server has gone away QMYSQL: Unable to execute query, 19 | //you can follow https://stackoverflow.com/questions/10474922/error-2006-hy000-mysql-server-has-gone-away 20 | //set global max_allowed_packet=64*1024*1024; 21 | class SqlDataBase : public QObject 22 | { 23 | Q_OBJECT 24 | public: 25 | explicit SqlDataBase(QObject *parent = 0); 26 | bool sqlInit(); 27 | void initMySQL(); 28 | ~SqlDataBase(){ 29 | delete p_sql_query_; 30 | m_data_base_.close(); 31 | } 32 | 33 | void doSqlQuery(QString query_str, int dst = 0); 34 | QString makeSaveString(QString exp_name, QString usr_name, QString exp_no, QVector); 35 | QString getLastExpId(QString motor_id); 36 | void getExpDataFromSqlDB(QString motor_id,QString exp_id,QString motor_mode,QString,QString); 37 | signals: 38 | void emitExpData(const QVector > &); 39 | void emitLastExpData(const QVector > &); 40 | void sendQueryRes(QSqlQuery,int); 41 | void sendErrorText(QString); 42 | public slots: 43 | void insertIntoDB(QString exp_name, QString usr_name, QString exp_no,const QVector &motor); 44 | void analysisSqlForDocRes(QSqlQuery, int dst); 45 | void getLastExpData(QString motor_id,QString motor_mode); 46 | private: 47 | QSqlDatabase m_data_base_; 48 | QSqlQuery* p_sql_query_; 49 | }; 50 | 51 | #endif // CSQLDATABASE_H 52 | -------------------------------------------------------------------------------- /motordriver.h: -------------------------------------------------------------------------------- 1 | #ifndef MOTORDRIVER_H 2 | #define MOTORDRIVER_H 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | class MotorDriver : public QObject 13 | { 14 | Q_OBJECT 15 | public: 16 | explicit MotorDriver(QObject *parent = 0); 17 | 18 | ~MotorDriver(){ 19 | disconnect(this->serial_port_,SIGNAL(readyRead()),this,SLOT(resolveDataFromSerialport())); 20 | if (serial_port_ != nullptr && serial_port_->isOpen()){ 21 | serial_port_->close(); 22 | delete serial_port_; 23 | qDebug()<isOpen()){ 26 | delete serial_port_; 27 | } 28 | else{ 29 | serial_port_ = nullptr; 30 | } 31 | 32 | } 33 | 34 | 35 | QByteArray calSpdData(QString spd); 36 | QByteArray calSpdData2(QString spd,QString acc); 37 | QByteArray calTorData(QString tor); 38 | 39 | void setPortName(QString str){ 40 | port_name = str; 41 | } 42 | 43 | void setBaudRate(QString baud){ 44 | baud_rate = baud; 45 | } 46 | 47 | signals: 48 | void sendErrText(QString); 49 | 50 | void sendMotorSpd(double); 51 | void sendMotorCur(double); 52 | void sendMotorTmp(double); 53 | void sendMotorStatus(uchar); 54 | 55 | 56 | public slots: 57 | void ctlMotorSpd2(double spd = 0,double acc = 0); 58 | void ctlMotorSpd(double spd = 0); 59 | void ctlMotorTor(double tor = 0); 60 | void getMotorData(); 61 | void resolveDataFromSerialport(); 62 | bool init(); 63 | private: 64 | 65 | QSerialPort* serial_port_; 66 | bool isInit; 67 | QString port_name; 68 | QString baud_rate; 69 | QByteArray recv_data_buf; 70 | /* 71 | * //----------flywheel 4Nm----------- 72 | union spd_array{ 73 | uchar array[2]; 74 | qint16 spd; 75 | }spd_array_; 76 | 77 | union tor_array{ 78 | uchar array[2]; 79 | qint16 torque; 80 | }tor_array_; 81 | 82 | union recv_spd{ 83 | qint16 spd; 84 | uchar array[2]; 85 | }recv_spd_; 86 | 87 | union recv_cur{ 88 | quint16 cur; 89 | uchar array[2]; 90 | }recv_cur_; 91 | //----------flywheel 4Nm end----------- 92 | */ 93 | //----------flywheel 50Nm start-------- 94 | union{ 95 | uchar array[4]; 96 | int32_t spd; 97 | }spd_array_; 98 | union{ 99 | uchar array[4]; 100 | int32_t acc; 101 | }acc_array_; 102 | 103 | union recv_spd{ 104 | qint32 spd; 105 | uchar array[4]; 106 | }recv_spd_; 107 | 108 | union recv_cur{ 109 | quint32 cur; 110 | uchar array[4]; 111 | }recv_cur_; 112 | //----------flywheel 50Nm end---------- 113 | }; 114 | 115 | #endif // MOTORDRIVER_H 116 | -------------------------------------------------------------------------------- /qmotorreport.h: -------------------------------------------------------------------------------- 1 | #ifndef QMOTORREPORT_H 2 | #define QMOTORREPORT_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | class QMotorReport : public QObject 17 | { 18 | Q_OBJECT 19 | public: 20 | explicit QMotorReport(QObject *parent = 0); 21 | void setExpInfomation(const QVector&); 22 | 23 | //创建word报告 24 | void createWordReport(); 25 | 26 | //计算设置速度-实际速度 27 | void calExpDataSetSpd(); 28 | //计算最大反作用力矩 29 | 30 | //计算稳速功耗 31 | 32 | //计算最大功耗 33 | 34 | //计算最大角动量 35 | 36 | //计算力矩控制特性 37 | 38 | //转速模式电机电流 39 | 40 | //启动摩擦力矩 41 | 42 | //最大损失力矩 43 | 44 | //力矩响应时间 45 | 46 | //整机滑行时间 47 | 48 | //浪涌电流测试 49 | 50 | 51 | signals: 52 | void logMsg(QString); 53 | void reportCreated(); 54 | public slots: 55 | void getDataFromSql(const QVector > &res); 56 | 57 | //从原始数据中提取和初始化被测数据 58 | void initExpData(); 59 | private: 60 | //实验相关参数 61 | QString exp_id_; 62 | QString exp_name_; 63 | QString usr_name_; 64 | QString exp_no_; 65 | QString exp_time_; 66 | QString exp_address_; 67 | QString exp_vacuum_; 68 | QString flywheel_no_; 69 | 70 | 71 | //实验原始数据 72 | QVector flywheel_act_cur_; 73 | QVector flywheel_vol_; 74 | QVector flywheel_cur_; 75 | QVector flywheel_setSpd_; 76 | QVector flywheel_spd_; 77 | QVector flywheel_setTor_; 78 | QVector flywheel_tor_; 79 | QVector flywheel_wate_; 80 | QVector flywheel_JDL_; 81 | QVector flywheel_JDL_const_; 82 | QVector flywheel_JDL_dynamic_; 83 | QVector flywheel_mode_; 84 | 85 | /*-----------------师弟看这里----------------*/ 86 | //需要计算的值 11 12等为该测试项目的编号 87 | QList m_test_unit_setspd_; //11.速度测试、17.转速模式电机电流 88 | QList m_test_unit_max_tor_; //12.最大反作用力矩 89 | QList m_test_unit_avg_wate_; //13.稳速功耗 90 | QList m_test_unit_max_wate_; //14.最大功耗 91 | QList m_test_unit_max_jdl_; //15.最大角动量 92 | QList m_test_unit_tor_; //16.力矩模式 93 | QList m_test_unit_start_tor_; //18.启动模式摩擦力矩 94 | QList m_test_unit_loss_tor_; //19.最大损失力矩 95 | QList m_test_unit_tor_time_; //110.力矩响应时间 96 | QList m_test_unit_hx_time_; //111.整机滑行时间 97 | QList m_test_unit_start_cur_; //112.浪涌电流测试 98 | 99 | 100 | //测试结果存放地点 101 | //如有多条记录,以1.2.3.的形式列出 102 | QVector > m_result_spd_; //速度测试 1.平均速度 2.角动量常值偏差 3.角动量动态偏差 103 | double m_result_max_tor_; //最大力矩 104 | QVector m_result_wate_; //稳速功耗 105 | double m_result_max_wate_; //最大功耗 106 | double m_result_max_jdl_; //最大角动量 107 | QVector > m_result_tor_; //力矩控制特性 1.实测电机电流 2.实测输出力矩 108 | QVector > m_result_cur_; //转速模式电机电流 1.测试口总电流 2.实测电机电流 109 | double m_result_start_tor_; //启动摩擦力矩 110 | double m_result_loss_tor_; //最大损失力矩 111 | double m_result_tor_time_; //力矩响应时间 112 | double m_result_hx_time_; //整机滑行时间 113 | double m_result_start_cur_; //浪涌电流测试 114 | 115 | }; 116 | 117 | #endif // QMOTORREPORT_H 118 | -------------------------------------------------------------------------------- /mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "motor.h" 14 | #include "motordriver.h" 15 | #include "csqldatabase.h" 16 | #include "qmotorreport.h" 17 | #include "qdaqcard.h" 18 | 19 | namespace Ui { 20 | class MainWindow; 21 | } 22 | 23 | class MainWindow : public QMainWindow 24 | { 25 | Q_OBJECT 26 | 27 | public: 28 | explicit MainWindow(QWidget *parent = 0); 29 | ~MainWindow(); 30 | bool initDriver1(); 31 | void initCombox(); 32 | void updateMotor1Display(); 33 | void initQCustomPlot1(); 34 | void initSql(); //数据库初始化 35 | void initReport(); //报表初始化 36 | void initDaqCard(); //数据采集卡初始化 37 | QVector makeSqlVector(Motor &); 38 | signals: 39 | void sendToSqlDB(QString,QString,QString,QVector); 40 | //请求从数据库中请求实验数据 41 | void getLastExpData(QString,QString); 42 | 43 | //非真空getdata信号 44 | void sendCurrentSpdForAutoTest(double); 45 | 46 | //真空一键测试--发送需要测试的模式 47 | void startAutoTestModeNoAir(QVector); 48 | //速度模式刷新信号 49 | void refreshAutoTestSpd(); 50 | //滑行模式刷新信号 51 | void refreshAutoTestHX(); 52 | public slots: 53 | void logMsg(QString); 54 | 55 | 56 | private slots: 57 | void on_pushButton_system_power_1_clicked(); 58 | 59 | void on_pushButton_single_test_mode_1_clicked(); 60 | 61 | void updateMotor(); 62 | 63 | void on_doubleSpinBox_motor_test_spd_1_editingFinished(); 64 | 65 | void on_comboBox_motor_test_mode_1_currentIndexChanged(int index); 66 | 67 | void refreshCustomPlotData1(); 68 | 69 | void on_doubleSpinBox_moto_test_time_valueChanged(double arg1); 70 | 71 | void on_pushButton_auto_test_with_air_power_1_clicked(); 72 | 73 | 74 | void on_pushButton_sql_query_clicked(); 75 | 76 | void updataSqlTableView(const QVector > &); 77 | 78 | void on_pushButton_make_report_clicked(); 79 | 80 | void setMotorDataFromDAQCard(const QVector &res); 81 | 82 | void on_pushButton_ele_test_ly_mode_power_1_clicked(); 83 | 84 | void on_tab1_horizontalSlider_valueChanged(int value); 85 | 86 | void on_pushButton_auto_test_noair_power_1_clicked(); 87 | 88 | void on_doubleSpinBox_motor_test_acc_valueChanged(double arg1); 89 | private: 90 | Ui::MainWindow *ui; 91 | 92 | Motor* p_motor1_; 93 | // Motor m_motor2_; 94 | // Motor m_motor3_; 95 | // Motor m_motor4_; 96 | // Motor m_motor5_; 97 | // Motor m_motor6_; 98 | 99 | MotorDriver* p_driver1_; 100 | // MotorDriver* p_driver2_; 101 | // MotorDriver* p_driver3_; 102 | // MotorDriver* p_driver4_; 103 | // MotorDriver* p_driver5_; 104 | // MotorDriver* p_driver6_; 105 | 106 | QThread* p_driver_thread1_; 107 | QThread* p_motor_thread1_; 108 | //...etc 109 | 110 | 111 | bool m_sys_status_1_; 112 | //获取数据定时器 113 | QTimer m_timer_get_data_; 114 | //发送控制指令定时器 115 | QTimer m_timer_update_; 116 | //界面刷新buffer 117 | QVector keyContainer; 118 | QVector tmpContainer; 119 | QVector curContainer; 120 | QVector spdContainer; 121 | QVector setSpdContainer; 122 | 123 | //数据库部分 124 | SqlDataBase* p_sql_; 125 | QThread* p_sql_thread_; 126 | uint tab_num_ = 0; 127 | 128 | //报表部分 129 | QMotorReport* p_repoter_; 130 | QThread* p_repoter_thread_; 131 | 132 | //数据采集卡部分 133 | QDaqcard* p_daqcard_; 134 | QThread* p_daqcard_thread_; 135 | 136 | }; 137 | 138 | #endif // MAINWINDOW_H 139 | -------------------------------------------------------------------------------- /motor.cpp: -------------------------------------------------------------------------------- 1 | #include "motor.h" 2 | 3 | 4 | QList Motor::getNoAirTestUnit() const 5 | { 6 | return air_test_containor_raw_data_; 7 | } 8 | //真空测试模式 9 | void Motor::initTestModeNOAir(QVector mode_lst) 10 | { 11 | exp_id_ = QDateTime::currentDateTime().toString("yyMMddhhmmss"); 12 | for (QString &lst:mode_lst){ 13 | all_test_mode_.push_back(lst.toInt()); 14 | } 15 | //发射开始循环信号 16 | emit autoTestStart(); 17 | } 18 | 19 | //将会被autoTestStart触发 20 | void Motor::selectTestMode() 21 | { 22 | if (all_test_mode_.isEmpty()){ 23 | emit autoTestEnd(); 24 | 25 | } 26 | else{ 27 | int cur_mode = all_test_mode_.front(); 28 | all_test_mode_.pop_front(); 29 | switch (cur_mode) { 30 | case FLYWHEEL_MODE_SPD: 31 | initAutoTestSpdMode(); 32 | break; 33 | case FLYWHEEL_MODE_HX: 34 | initHXMode(); 35 | break; 36 | default: 37 | break; 38 | } 39 | } 40 | } 41 | 42 | void Motor::initAutoTestSpdMode() 43 | { 44 | if (getIsRunning()){ 45 | setFlywheelMode(FLYWHEEL_MODE_SPD); 46 | auto_test_spd_mode_containor_.clear(); 47 | auto_test_spd_mode_containor_ = auto_test_spd_mode__containor_raw_data_; 48 | 49 | if(p_timer_auto_test_ == nullptr){ 50 | p_timer_auto_test_ = new QTimer; 51 | } 52 | 53 | connect(p_timer_auto_test_,SIGNAL(timeout()),this,SLOT(nxtNoAirModeTestSpd())); 54 | p_timer_auto_test_->setInterval(5000); 55 | is_timer_started = false; 56 | auto_test_spd_mode_ = true; 57 | setSetSpeed(0); 58 | } 59 | else{ 60 | auto_test_spd_mode_ = false; 61 | p_timer_auto_test_->stop(); 62 | disconnect(p_timer_auto_test_,SIGNAL(timeout()),this,SLOT(nxtNoAirModeTestSpd())); 63 | } 64 | } 65 | 66 | void Motor::nxtNoAirModeTestSpd() 67 | { 68 | if(!getIsRunning()){ 69 | auto_test_spd_mode_ = false; 70 | p_timer_auto_test_->stop(); 71 | disconnect(p_timer_auto_test_,SIGNAL(timeout()),this,SLOT(nxtNoAirModeTestSpd())); 72 | return; 73 | } 74 | is_timer_started = false; 75 | p_timer_auto_test_->stop(); 76 | auto_test_spd_mode_containor_.pop_front(); 77 | if (auto_test_spd_mode_containor_.empty()){ 78 | auto_test_spd_mode_ = false; 79 | disconnect(p_timer_auto_test_,SIGNAL(timeout()),this,SLOT(nxtNoAirModeTestSpd())); 80 | 81 | //发射开始循环信号,以开启下一个模式 82 | emit autoTestStart(); 83 | } 84 | } 85 | //控制一键测试的目标速度 86 | void Motor::setSpdOfAutoTestSpdMode() 87 | { 88 | if(!getIsRunning()){ 89 | auto_test_spd_mode_ = false; 90 | p_timer_auto_test_->stop(); 91 | disconnect(p_timer_auto_test_,SIGNAL(timeout()),this,SLOT(nxtNoAirModeTestSpd())); 92 | return; 93 | } 94 | if (!auto_test_spd_mode_containor_.empty()){ 95 | this->setSetSpeed(auto_test_spd_mode_containor_.front()); 96 | if (abs(this->getSpeed() - auto_test_spd_mode_containor_.front()) < 10){ 97 | if (!is_timer_started){ 98 | p_timer_auto_test_->start(); 99 | is_timer_started = true; 100 | } 101 | } 102 | } 103 | } 104 | 105 | void Motor::initHXMode() 106 | { 107 | setFlywheelMode(FLYWHEEL_MODE_HX); 108 | is_hx_mode_init = true; 109 | reach_target_ = false; 110 | hx_mode_target_spd_ = 4000; 111 | } 112 | 113 | void Motor::setSpdOfAutoTestHXMode() 114 | { 115 | if(!getIsRunning()){ 116 | is_hx_mode_init = false; 117 | } 118 | else{ 119 | //此处应该有控制滑行模式的指令,但是50的飞轮没有 120 | if (!reach_target_){ 121 | setSetSpeed(hx_mode_target_spd_); 122 | } 123 | else{ 124 | //此处应该是开启滑行指令 125 | setSetSpeed(hx_mode_target_spd_); 126 | } 127 | if (abs(this->getSpeed() - hx_mode_target_spd_) < 1){ 128 | if (!reach_target_){ 129 | reach_target_ = true; 130 | hx_mode_target_spd_ = 0; 131 | } 132 | else{ 133 | reach_target_ = false; 134 | is_hx_mode_init = false; 135 | //发射开始循环信号,以开启下一个模式 136 | emit autoTestStart(); 137 | } 138 | } 139 | } 140 | } 141 | 142 | -------------------------------------------------------------------------------- /qdaqcard.cpp: -------------------------------------------------------------------------------- 1 | #include "qdaqcard.h" 2 | 3 | QDaqcard::QDaqcard(QObject *parent) : QObject(parent) 4 | { 5 | qRegisterMetaType>("QVector"); 6 | m_DO_port_status_ = 0xff; 7 | } 8 | //析构时自动将继电器关闭 9 | QDaqcard::~QDaqcard() 10 | { 11 | D2K_DO_WritePort(card_, Channel_P1A, 255); 12 | D2K_Release_Card(card_); 13 | } 14 | 15 | //DAQ card初始化函数,此时初始化的CARD为2213,AI采集口为0-6,输入为差分输入模式 16 | void QDaqcard::init() 17 | { 18 | I16 err, card_num = 0, card_type=DAQ_2213; 19 | if ((card_=D2K_Register_Card (card_type, card_num)) <0 ) { 20 | logMsg(tr("Register_Card error=%1").arg(QString::number(card_))); 21 | return; 22 | } 23 | //需要使用的采集卡channel 24 | for (int i = 0;i < 7;++i){ 25 | err = D2K_AI_CH_Config (card_, i, AD_B_10_V | AI_DIFF); 26 | if (err!=0) { 27 | logMsg(tr("D2K_AI_CH_Config error=%1").arg(QString::number(err))); 28 | return; 29 | } 30 | } 31 | is_init_ = true; 32 | 33 | //tmp do 34 | //port configured 35 | D2K_DIO_PortConfig(card_ ,Channel_P1A, 36 | OUTPUT_PORT); 37 | D2K_DIO_PortConfig(card_, Channel_P1B, 38 | OUTPUT_PORT); 39 | D2K_DIO_PortConfig(card_, Channel_P1CL, 40 | OUTPUT_PORT); 41 | D2K_DIO_PortConfig(card_, Channel_P1CH, 42 | OUTPUT_PORT); 43 | D2K_DO_WritePort(card_, Channel_P1A, 255); 44 | } 45 | //读取AI 0-6采集口的值,并发送信号。 46 | void QDaqcard::readAllChannel() 47 | { 48 | if (!is_init_) return; 49 | QVector res; 50 | F64 chan_voltage; 51 | //使用循环去读取 52 | for (int i = 0; i <7;++i){ 53 | I16 err = D2K_AI_VReadChannel (card_, i, &chan_voltage); 54 | if (err!=0) { 55 | logMsg(tr("D2K_AI_ReadChannel error=%1").arg(QString::number(err))); 56 | return; 57 | } 58 | res.push_back(chan_voltage); 59 | } 60 | emit sendAllData(res); 61 | } 62 | //采集浪涌电流,channel从0-6,pointnum为采集数量 63 | void QDaqcard::getSurgeCurrent(U16 channel,QVector &v,int point_num) 64 | { 65 | F64 chan_voltage; 66 | v.resize(point_num); 67 | 68 | for (int i = 0;iserial_port_,SIGNAL(readyRead()),this,SLOT(resolveDataFromSerialport())); 43 | 44 | if (!serial_port_->isOpen()){ 45 | 46 | serial_port_->setPortName(port_name); 47 | serial_port_->setBaudRate(baud_rate.toInt()); 48 | serial_port_->setParity(QSerialPort::OddParity); 49 | 50 | 51 | if(!serial_port_->open(QIODevice::ReadWrite)){ 52 | 53 | emit sendErrText(serial_port_->errorString()); 54 | return false; 55 | 56 | } 57 | 58 | } 59 | qDebug()<write(spd_str) != spd_str.size()){ 126 | emit sendErrText(QString("driver control error")); 127 | } 128 | } 129 | } 130 | 131 | void MotorDriver::ctlMotorSpd(double spd) 132 | { 133 | if (!isInit){ 134 | emit sendErrText(QString("driver not init")); 135 | } 136 | else{ 137 | QByteArray spd_str = calSpdData(QString::number(spd)); 138 | if(serial_port_->write(spd_str) != spd_str.size()){ 139 | emit sendErrText(QString("driver control error")); 140 | } 141 | } 142 | } 143 | 144 | void MotorDriver::ctlMotorTor(double tor) 145 | { 146 | if (!isInit){ 147 | emit sendErrText(QString("driver not init")); 148 | } 149 | else{ 150 | QByteArray tor_str = calTorData(QString::number(tor)); 151 | if(serial_port_->write(tor_str) != tor_str.size()){ 152 | emit sendErrText(QString("driver control error")); 153 | } 154 | } 155 | } 156 | 157 | void MotorDriver::getMotorData() 158 | { 159 | /* flywheel 4nm 160 | QByteArray get_str; 161 | get_str.resize(1); 162 | get_str[0] = 0xa5; 163 | serial_port_->write(get_str); 164 | */ 165 | 166 | } 167 | 168 | void MotorDriver::resolveDataFromSerialport() 169 | { 170 | QByteArray tmp_data = serial_port_->readAll(); 171 | for (int i = 0;i < tmp_data.size();++i){ 172 | 173 | /*flywheel 4nm 174 | //a full frame detected 175 | if (recv_data_buf.size() >= 7){ 176 | //check frame 177 | uchar t = 0x00; 178 | for (uint i = 0; i < 6;++i){ 179 | t += recv_data_buf[i]; 180 | } 181 | if (t != recv_data_buf[6]){ 182 | recv_data_buf = recv_data_buf.mid(1); 183 | emit sendErrText("recv message error! chack communication!"); 184 | return; 185 | } 186 | 187 | 188 | 189 | recv_spd_.array[1] = recv_data_buf[0]; 190 | recv_spd_.array[0] = recv_data_buf[1]; 191 | 192 | emit sendMotorSpd(recv_spd_.spd * 0.05); 193 | 194 | recv_cur_.array[1] = recv_data_buf[2]; 195 | recv_cur_.array[0] = recv_data_buf[3]; 196 | emit sendMotorCur(recv_cur_.cur * 0.0017); 197 | 198 | uchar tmp = recv_data_buf[4]; 199 | emit sendMotorTmp(tmp); 200 | 201 | uchar status = recv_data_buf[5]; 202 | emit sendMotorStatus(status); 203 | 204 | if (recv_data_buf.size() == 7){ 205 | recv_data_buf.clear(); 206 | } 207 | else{ 208 | recv_data_buf = recv_data_buf.mid(7); 209 | } 210 | } 211 | */ 212 | 213 | 214 | if (recv_data_buf.size() == 0){ 215 | if (tmp_data.at(i) == char(0xff)){ 216 | recv_data_buf.push_back(tmp_data.at(i)); 217 | } 218 | } 219 | else if (recv_data_buf.size() < 11) 220 | recv_data_buf.push_back(tmp_data.at(i)); 221 | else if (recv_data_buf.size() == 11 &&( recv_data_buf[9] != char(0x11) 222 | || recv_data_buf[0] != char(0xff))){ 223 | recv_data_buf = recv_data_buf.mid(1); 224 | recv_data_buf.push_back(tmp_data.at(i)); 225 | emit sendErrText("串口数据错位!"); 226 | } 227 | if (recv_data_buf.size() == 11 && recv_data_buf[9] == char(0x11) 228 | && recv_data_buf[0] == char(0xff)){ 229 | //check frame 230 | uint8_t t = 0x00; 231 | for (uint i = 0; i < 10;++i){ 232 | t += recv_data_buf[i]; 233 | } 234 | 235 | if (t != uint8_t(recv_data_buf[10])){ 236 | recv_data_buf = recv_data_buf.mid(1); 237 | emit sendErrText("校验和错误!"); 238 | return; 239 | } 240 | recv_spd_.array[3] = recv_data_buf[1]; 241 | recv_spd_.array[2] = recv_data_buf[2]; 242 | recv_spd_.array[1] = recv_data_buf[3]; 243 | recv_spd_.array[0] = recv_data_buf[4]; 244 | 245 | emit sendMotorSpd(recv_spd_.spd * 0.001); 246 | 247 | recv_cur_.array[3] = recv_data_buf[5]; 248 | recv_cur_.array[2] = recv_data_buf[6]; 249 | recv_cur_.array[1] = recv_data_buf[7]; 250 | recv_cur_.array[0] = recv_data_buf[8]; 251 | emit sendMotorCur(recv_cur_.cur * 0.001); 252 | recv_data_buf.clear(); 253 | } 254 | } 255 | } 256 | 257 | -------------------------------------------------------------------------------- /csqldatabase.cpp: -------------------------------------------------------------------------------- 1 | #include "csqldatabase.h" 2 | 3 | SqlDataBase::SqlDataBase(QObject *parent) : QObject(parent) 4 | { 5 | // sqlInit(); 6 | qRegisterMetaType("QSqlQuery"); 7 | qRegisterMetaType>("QVector"); 8 | qRegisterMetaType >>("QVector >"); 9 | 10 | 11 | connect(this,&SqlDataBase::sendQueryRes,this,&SqlDataBase::analysisSqlForDocRes); 12 | } 13 | 14 | bool SqlDataBase::sqlInit() 15 | { 16 | //qDebug() << QSqlDatabase::drivers();//查看当前支持的SQL驱动 17 | if (QSqlDatabase::contains("qt_sql_default_connection")) //判断是否存在这个连接 18 | { 19 | m_data_base_ = QSqlDatabase::database("qt_sql_default_connection"); 20 | } 21 | else 22 | { 23 | m_data_base_ = QSqlDatabase::addDatabase("QSQLITE"); //是SQLite对应的驱动名,不能改 第二个参数被省略了, 24 | m_data_base_.setUserName("HDU"); //第二个参数的默认参数就是上面提到的Qt默认连接名称qt_sql_default_connection。 25 | m_data_base_.setDatabaseName("motionDataBase.db");//如果需要使用自定义的连接名称 26 | //(如果程序需要处理多个数据库文件的话就会这样),则应该加入第二个参数 27 | 28 | m_data_base_.setPassword("123456"); 29 | } 30 | if (!m_data_base_.open()){ 31 | qDebug()<<" sql init error!"; 32 | emit sendErrorText(" sql init error!"); 33 | return false; 34 | } 35 | p_sql_query_ = new QSqlQuery(m_data_base_); 36 | return true; 37 | } 38 | 39 | void SqlDataBase::initMySQL() 40 | { 41 | if (QSqlDatabase::contains("qt_sql_default_connection")) //判断是否存在这个连接 42 | { 43 | m_data_base_ = QSqlDatabase::database("qt_sql_default_connection"); 44 | } 45 | else 46 | { 47 | m_data_base_ = QSqlDatabase::addDatabase("QMYSQL"); 48 | m_data_base_.setUserName("root"); 49 | m_data_base_.setDatabaseName("flywheel"); 50 | m_data_base_.setPassword("123456"); 51 | } 52 | if (!m_data_base_.open()){ 53 | qDebug()<<" mysql init error!"; 54 | emit sendErrorText("mysql init error!"); 55 | } 56 | p_sql_query_ = new QSqlQuery(m_data_base_); 57 | } 58 | 59 | void SqlDataBase::doSqlQuery(QString query_str, int dst) 60 | { 61 | if (!p_sql_query_->exec(query_str)) 62 | { 63 | qDebug() << p_sql_query_->lastError().text(); 64 | emit sendErrorText(p_sql_query_->lastError().text()); 65 | } 66 | else{ 67 | if (dst == 1){ 68 | emit sendQueryRes(*p_sql_query_,1); 69 | } 70 | else if (dst == 2){ 71 | emit sendQueryRes(*p_sql_query_,2); 72 | } 73 | else{ 74 | return; 75 | } 76 | } 77 | } 78 | 79 | QString SqlDataBase::makeSaveString(QString exp_name, QString usr_name, QString exp_no, 80 | QVector motor) 81 | { 82 | // qDebug()<<"SQL:"<= \""); 181 | query_str.append(start_time); 182 | query_str.append("\" AND "); 183 | query_str.append(" TIME <= \""); 184 | query_str.append(end_time); 185 | query_str.append("\""); 186 | } 187 | else{ 188 | query_str.append(" AND "); 189 | query_str.append(" TIME >= \""); 190 | query_str.append(start_time); 191 | query_str.append("\" AND "); 192 | query_str.append(" TIME <= \""); 193 | query_str.append(end_time); 194 | query_str.append("\""); 195 | } 196 | query_str.append(" LIMIT 1000"); 197 | doSqlQuery(query_str,1); 198 | } 199 | 200 | void SqlDataBase::insertIntoDB(QString exp_name, QString usr_name, QString exp_no,const QVector &motor) 201 | { 202 | // qDebug()<<"SQL:"< > res; 212 | while(query_res.next()){ 213 | QVector t; 214 | for (int i =0;i<20;++i){ 215 | t.append(query_res.value(i).toString()); 216 | } 217 | res.push_back(std::move(t)); 218 | } 219 | if (dst == 1) 220 | emit emitExpData(res); 221 | else if (dst == 2){ 222 | emit emitLastExpData(res); 223 | } 224 | } 225 | 226 | //得到最后一次实验数据 227 | void SqlDataBase::getLastExpData(QString motor_id,QString motor_mode) 228 | { 229 | QString query_str = "SELECT * FROM "; 230 | query_str.append(motor_id); 231 | query_str.append(" WHERE EXPID = "); 232 | query_str.append(getLastExpId(motor_id)); 233 | if (motor_mode.size() != 0){ 234 | query_str.append(" AND "); 235 | query_str.append(" WHERE "); 236 | query_str.append(" FLYWHEELMODE = "); 237 | query_str.append(motor_mode); 238 | } 239 | doSqlQuery(query_str,2); 240 | } 241 | 242 | 243 | -------------------------------------------------------------------------------- /motor.h: -------------------------------------------------------------------------------- 1 | #ifndef MOTOR_H 2 | #define MOTOR_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | //计算常数定义 14 | static const double J_ = 0.0064; 15 | static const double PI_ = 3.1415926; 16 | 17 | //模式编号定义-在后面添加 18 | enum FLYWHEEL_MODE{ 19 | FLYWHEEL_MODE_SPD, //速度 20 | FLYWHEEL_MODE_XP, //斜坡 21 | FLYWHEEL_MODE_TOR, //力矩 22 | FLYWHEEL_MODE_AUTOTESTNOAIR,//自动测试1 23 | FLYWHEEL_MODE_AUTOTEST2, //自动测试2 24 | FLYWHEEL_MODE_AUTOTEST3, //自动测试3 25 | FLYWHEEL_MODE_HX //滑行模式 26 | }; 27 | /* 28 | * 电机类 29 | * 如果后期发现时间效率达不到要求,部分计算算法可以优化 30 | * 31 | * @author LYC 32 | * @time 2019/07/15 33 | */ 34 | class MotorBasic : public QObject{ 35 | 36 | Q_OBJECT 37 | 38 | public: 39 | MotorBasic(): id_(0),vol_(12),cur_(0), 40 | spd_(0),acc_(0.1),setSpd_(0),torque_(0), 41 | setTorque_(0),isRunning_(false),channel_("") 42 | { 43 | 44 | } 45 | 46 | 47 | ~MotorBasic(){ 48 | 49 | } 50 | signals: 51 | void sendMoTorSpd(double); 52 | void sendMoTorSpd(double,double); 53 | void sendMoTorTor(double); 54 | void spdChanged(double); 55 | void sendErrorText(QString); 56 | public slots: 57 | void setSetSpeed(const double spd){ 58 | this->setSpd_ = spd; 59 | emit sendMoTorSpd(setSpd_,acc_); 60 | } 61 | void setSpeed(const double spd){ 62 | this->spd_ = spd; 63 | emit spdChanged(spd); 64 | } 65 | void setCurrent(const double cur){ 66 | this->cur_ = cur; 67 | } 68 | void setVoltage(const double vol){ 69 | this->vol_ = vol; 70 | } 71 | void setAccelerate(const double acc){ 72 | this->acc_ = acc; 73 | emit sendMoTorSpd(setSpd_,acc_); 74 | } 75 | void setId(const uint id){ 76 | this->id_ = id; 77 | } 78 | void setIsRunning(const bool isRunning){ 79 | this->isRunning_ = isRunning; 80 | } 81 | 82 | void setTorque(const double tor){ 83 | 84 | this->torque_ = tor; 85 | 86 | } 87 | void setSetTorque(const double setTor){ 88 | mode_ = FLYWHEEL_MODE_TOR; 89 | this->setTorque_ = setTor; 90 | emit sendMoTorTor(setTor); 91 | } 92 | 93 | public: 94 | //设置速度 95 | double getSetSpeed() const{ 96 | return this->setSpd_; 97 | } 98 | 99 | //实时速度 100 | double getSpeed() const{ 101 | return this->spd_; 102 | } 103 | 104 | //电流 105 | double getCurrent() const{ 106 | return this->cur_; 107 | } 108 | 109 | //电压 110 | double getVoltage() const{ 111 | return this->vol_; 112 | } 113 | 114 | //ID 115 | 116 | uint getID() const{ 117 | return this->id_; 118 | } 119 | //ACC 120 | double getAccelerate() const{ 121 | return this->acc_; 122 | } 123 | 124 | //isrunning 125 | bool getIsRunning(){ 126 | return isRunning_; 127 | } 128 | 129 | 130 | 131 | //torque 132 | double getSetTorque() const{ 133 | return this->setTorque_; 134 | } 135 | 136 | double getTorque() const{ 137 | return this->torque_; 138 | } 139 | //设置通道号,保存数据库时用 140 | QString getChannel()const{ 141 | return this->channel_; 142 | } 143 | 144 | void setChannel(QString str){ 145 | this->channel_ = str; 146 | } 147 | 148 | FLYWHEEL_MODE getFlywheelMode() const{ 149 | return mode_; 150 | } 151 | 152 | void setFlywheelMode(FLYWHEEL_MODE mode){ 153 | mode_ = mode; 154 | } 155 | 156 | private: 157 | uint id_; 158 | double vol_; 159 | double cur_; 160 | double spd_; 161 | double acc_; 162 | double setSpd_; 163 | 164 | double torque_; 165 | double setTorque_; 166 | 167 | bool isRunning_; 168 | QString channel_; 169 | 170 | //模式代码 171 | FLYWHEEL_MODE mode_ = FLYWHEEL_MODE_SPD; 172 | }; 173 | 174 | class Motor : public MotorBasic{ 175 | 176 | Q_OBJECT 177 | 178 | public: 179 | Motor():last_ten_cur_(0), 180 | last_ten_vol_(12), 181 | last_ten_spd_(0) 182 | { 183 | initXpMode(0,0); 184 | connect(this,SIGNAL(spdChanged(double)),this,SLOT(setLastTen(double))); 185 | 186 | //非真空测试数据初始化 187 | air_test_containor_raw_data_.append(0); 188 | air_test_containor_raw_data_.append(100); 189 | air_test_containor_raw_data_.append(500); 190 | air_test_containor_raw_data_.append(1000); 191 | air_test_containor_raw_data_.append(1500); 192 | air_test_containor_raw_data_.append(2000); 193 | air_test_containor_raw_data_.append(2500); 194 | air_test_containor_raw_data_.append(3000); 195 | air_test_containor_raw_data_.append(-3000); 196 | air_test_containor_raw_data_.append(-2500); 197 | air_test_containor_raw_data_.append(-2000); 198 | air_test_containor_raw_data_.append(-1500); 199 | air_test_containor_raw_data_.append(-1000); 200 | air_test_containor_raw_data_.append(-500); 201 | //一键测试,速度模式初始化 202 | auto_test_spd_mode__containor_raw_data_.append(0); 203 | auto_test_spd_mode__containor_raw_data_.append(100); 204 | auto_test_spd_mode__containor_raw_data_.append(500); 205 | auto_test_spd_mode__containor_raw_data_.append(1000); 206 | auto_test_spd_mode__containor_raw_data_.append(1500); 207 | auto_test_spd_mode__containor_raw_data_.append(2000); 208 | auto_test_spd_mode__containor_raw_data_.append(2500); 209 | auto_test_spd_mode__containor_raw_data_.append(3000); 210 | auto_test_spd_mode__containor_raw_data_.append(-3000); 211 | auto_test_spd_mode__containor_raw_data_.append(-2500); 212 | auto_test_spd_mode__containor_raw_data_.append(-2000); 213 | auto_test_spd_mode__containor_raw_data_.append(-1500); 214 | auto_test_spd_mode__containor_raw_data_.append(-1000); 215 | auto_test_spd_mode__containor_raw_data_.append(-500); 216 | 217 | connect(this,SIGNAL(autoTestStart()),this,SLOT(selectTestMode())); 218 | } 219 | ~Motor(){ 220 | 221 | } 222 | 223 | 224 | //得到温度 225 | double getTemperature() const{ 226 | return this->temperature_; 227 | } 228 | //得到功率 229 | double getWate() const{ 230 | return this->wate_; 231 | } 232 | 233 | //得到角动量 234 | double getAngularMomentum() const{ 235 | return this->angular_momentum_; 236 | } 237 | //得到角动量常值偏差 238 | double getAngularMomentumConst() const{ 239 | return this->angular_momentum_const_d; 240 | } 241 | //得到角动量动态偏差 242 | double getAngularMomentumDynamic() const{ 243 | return this->angular_momentum_dynamic_d; 244 | } 245 | //得到反作用力矩 246 | double getReactionMoment_() const{ 247 | return this->reaction_moment_; 248 | } 249 | //斜坡模式 250 | void initXpMode(double espd,double interval){ 251 | this->xp_end_spd_ = espd; 252 | this->xp_spd_interval_ = interval; 253 | this->setAccelerate(interval); 254 | this->xp_status_ = false; 255 | } 256 | void setXpStatus(bool status){ 257 | this->xp_status_ = status; 258 | } 259 | bool getXpStatus() const{ 260 | return this->xp_status_; 261 | } 262 | bool getAirMode() const{ 263 | return this->is_air_init_; 264 | } 265 | void setAirMode(bool mode){ 266 | this->is_air_init_ = mode; 267 | } 268 | 269 | QString getExpId() const{ 270 | return this->exp_id_; 271 | } 272 | //从外部得到当前非真空测试项目 273 | QList getNoAirTestUnit() const; 274 | //读取采集到的电流 275 | double getActCur()const{ 276 | return this->act_cur_; 277 | } 278 | public slots: 279 | //设置采集到的电流 280 | void setActCur(double cur){ 281 | this->act_cur_ = cur; 282 | } 283 | 284 | //get last ten 285 | void setLastTen(double spd){ 286 | // qDebug()<<"motor thread:"<getVoltage()); 289 | } 290 | else{ 291 | last_ten_vol_queue_.pop_front(); 292 | last_ten_vol_queue_.push_back(this->getVoltage()); 293 | } 294 | 295 | if (last_ten_cur_queue_.size() <10){ 296 | last_ten_cur_queue_.push_back(this->getCurrent()); 297 | } 298 | else{ 299 | last_ten_cur_queue_.pop_front(); 300 | last_ten_cur_queue_.push_back(this->getCurrent()); 301 | } 302 | 303 | if (last_ten_spd_queue_.size() <10){ 304 | last_ten_spd_queue_.push_back(spd); 305 | } 306 | else{ 307 | last_ten_spd_queue_.pop_front(); 308 | last_ten_spd_queue_.push_back(spd); 309 | } 310 | last_ten_cur_ = 0; 311 | for(double &t:last_ten_cur_queue_){ 312 | last_ten_cur_ += t; 313 | } 314 | last_ten_cur_ /= last_ten_cur_queue_.size(); 315 | 316 | last_ten_spd_ = 0; 317 | for(double &t:last_ten_spd_queue_){ 318 | last_ten_spd_ += t; 319 | } 320 | last_ten_spd_ /= last_ten_spd_queue_.size(); 321 | 322 | last_ten_vol_ = 0; 323 | for(double &t:last_ten_vol_queue_){ 324 | last_ten_vol_ += t; 325 | } 326 | last_ten_vol_ /= last_ten_vol_queue_.size(); 327 | //cal 328 | setAngularMomentum(); 329 | setAngularMomentumConst(); 330 | setAngularMomentumDynamic(); 331 | setReactionMoment(); 332 | } 333 | 334 | //设置温度 335 | void setTemperature(const double tmp){ 336 | temperature_ = 4050/(qLn(((7500*tmp)/(256-tmp))) + 4.98) - 273; 337 | } 338 | //设置功率 339 | void setWate(){ 340 | wate_ = last_ten_cur_ * last_ten_vol_; 341 | } 342 | 343 | //设置角动量 344 | void setAngularMomentum(){ 345 | this->angular_momentum_ = 9.55*J_ * this->last_ten_spd_; 346 | } 347 | //设置角动量常值偏差 348 | void setAngularMomentumConst(){ 349 | 350 | this->angular_momentum_const_d = 0.00428 * qAbs(this->getSpeed() - this->last_ten_spd_); 351 | } 352 | //设置角动量动态偏差 353 | void setAngularMomentumDynamic(){ 354 | double tmp_max = *(std::max_element(last_ten_spd_queue_.begin(),last_ten_spd_queue_.end())); 355 | 356 | this->angular_momentum_dynamic_d = 0.00428 * qAbs(tmp_max - last_ten_spd_); 357 | } 358 | //设置反作用力矩 359 | void setReactionMoment(){ 360 | if (last_ten_spd_queue_.size() <= 2) return; 361 | double last_spd = *last_ten_spd_queue_.rbegin(); 362 | double last_last__spd = *(++last_ten_spd_queue_.rbegin()); 363 | double current_reaction = (last_spd - last_last__spd)* J_ * 2 * PI_ / (60 * current_interval) ; 364 | //求平均10个 365 | if (last_ten_reaction_queue_.size() <10){ 366 | last_ten_reaction_queue_.push_back(current_reaction); 367 | } 368 | else{ 369 | last_ten_reaction_queue_.pop_front(); 370 | last_ten_reaction_queue_.push_back(current_reaction); 371 | } 372 | 373 | for(double &t:last_ten_reaction_queue_){ 374 | last_ten_reaction_ += t; 375 | } 376 | this->reaction_moment_ = last_ten_reaction_ / last_ten_reaction_queue_.size(); 377 | } 378 | //设置当前间隔 379 | void setCurrentInterval(const double interval){ 380 | this->current_interval = interval; 381 | } 382 | 383 | //斜坡模式 384 | void calXpMode(){ 385 | 386 | setFlywheelMode(FLYWHEEL_MODE_XP); 387 | 388 | if (qAbs(qAbs(getSpeed()) - qAbs(xp_end_spd_)) > qAbs(xp_spd_interval_)){ 389 | double ctl_spd = getSpeed()+xp_spd_interval_; 390 | if (ctl_spd < -6050){ 391 | 392 | setSetSpeed(-6050); 393 | } 394 | else if (ctl_spd > 6050){ 395 | setSetSpeed(6050); 396 | } 397 | else 398 | setSetSpeed(ctl_spd); 399 | } 400 | else{ 401 | setSetSpeed(xp_end_spd_); 402 | } 403 | } 404 | //非真空一键测试函数1 405 | void initTestModeWithAir(){ 406 | if (getIsRunning()){ 407 | setFlywheelMode(FLYWHEEL_MODE_AUTOTESTNOAIR); 408 | 409 | exp_id_ = QDateTime::currentDateTime().toString("yyMMddhhmmss"); 410 | if (is_air_init_){ 411 | return; 412 | } 413 | air_test_containor_.clear(); 414 | air_test_containor_ = air_test_containor_raw_data_; 415 | 416 | is_air_init_ = true; 417 | if(p_timer_auto_test_ == nullptr){ 418 | p_timer_auto_test_ = new QTimer; 419 | } 420 | 421 | connect(p_timer_auto_test_,SIGNAL(timeout()),this,SLOT(nxtWithAirModeTestSpd())); 422 | p_timer_auto_test_->setInterval(5000); 423 | is_timer_started = false; 424 | setSetSpeed(0); 425 | } 426 | else{ 427 | resetTestModeWithAir(); 428 | } 429 | } 430 | //非真空一键测试函数1 431 | void resetTestModeWithAir(){ 432 | if(!getIsRunning() && is_air_init_){ 433 | exp_id_.clear(); 434 | is_air_init_ = false; 435 | p_timer_auto_test_->stop(); 436 | disconnect(p_timer_auto_test_,SIGNAL(timeout()),this,SLOT(nxtWithAirModeTestSpd())); 437 | return; 438 | } 439 | } 440 | //为了减少定时器的使用,因此这个槽函数通过mainwindow的定时器调用。 441 | void runWithAirMode(double spd){ 442 | if(!getIsRunning()){ 443 | exp_id_.clear(); 444 | is_air_init_ = false; 445 | p_timer_auto_test_->stop(); 446 | disconnect(p_timer_auto_test_,SIGNAL(timeout()),this,SLOT(nxtWithAirModeTestSpd())); 447 | return; 448 | } 449 | if (!air_test_containor_.empty()){ 450 | this->setSetSpeed(air_test_containor_.front()); 451 | if (abs(spd - air_test_containor_.front()) < 10){ 452 | if (!is_timer_started){ 453 | p_timer_auto_test_->start(); 454 | is_timer_started = true; 455 | } 456 | } 457 | } 458 | } 459 | //非真空一键测试函数1 460 | void nxtWithAirModeTestSpd(){ 461 | if(!getIsRunning()){ 462 | exp_id_.clear(); 463 | is_air_init_ = false; 464 | p_timer_auto_test_->stop(); 465 | disconnect(p_timer_auto_test_,SIGNAL(timeout()),this,SLOT(nxtWithAirModeTestSpd())); 466 | return; 467 | } 468 | is_timer_started = false; 469 | p_timer_auto_test_->stop(); 470 | air_test_containor_.pop_front(); 471 | if (air_test_containor_.empty()){ 472 | is_air_init_ = false; 473 | disconnect(p_timer_auto_test_,SIGNAL(timeout()),this,SLOT(nxtWithAirModeTestSpd())); 474 | emit airTestEnd(); 475 | } 476 | } 477 | 478 | //真空一键测试函数-初始化 479 | void initTestModeNOAir(QVector mode_lst); 480 | 481 | //测试模式初始化 482 | void selectTestMode(); 483 | 484 | //初始化一键测试的速度模式 485 | void initAutoTestSpdMode(); 486 | 487 | //负责保持一段时间 488 | void nxtNoAirModeTestSpd(); 489 | 490 | //负责控制速度 491 | void setSpdOfAutoTestSpdMode(); 492 | 493 | bool getAutoTestSpdMode() const 494 | { 495 | return auto_test_spd_mode_; 496 | } 497 | 498 | //滑行模式init 499 | void initHXMode(); 500 | 501 | bool getHXMode() const 502 | { 503 | return is_hx_mode_init; 504 | } 505 | 506 | //负责控制滑行模式速度 507 | void setSpdOfAutoTestHXMode(); 508 | signals: 509 | void airTestEnd(); 510 | void autoTestStart(); 511 | void autoTestEnd(); 512 | private: 513 | double temperature_; 514 | double wate_; 515 | 516 | //存放最近10个电流 517 | QQueue last_ten_cur_queue_; 518 | double last_ten_cur_; 519 | //存放最近10个电压 520 | QQueue last_ten_vol_queue_; 521 | double last_ten_vol_; 522 | //存放最近10个转速 523 | QQueue last_ten_spd_queue_; 524 | double last_ten_spd_; 525 | //反作用力矩 526 | QQueue last_ten_reaction_queue_; 527 | double last_ten_reaction_; 528 | 529 | //角动量 530 | double angular_momentum_; 531 | //角动量常值偏差 532 | double angular_momentum_const_d; 533 | //角动量动态偏差 534 | double angular_momentum_dynamic_d; 535 | //反作用力矩 536 | double reaction_moment_; 537 | //当前运行间隔 538 | double current_interval = 0.5; 539 | //实际电流(从数据采集卡采到的) 540 | double act_cur_ = 0; 541 | //斜坡模式 542 | bool xp_status_; 543 | double xp_end_spd_; 544 | double xp_spd_interval_; 545 | 546 | //非真空测试 547 | QList air_test_containor_; 548 | QList air_test_containor_raw_data_; 549 | bool is_air_init_ = false; 550 | bool is_timer_started = false; 551 | QTimer* p_timer_auto_test_ = nullptr; 552 | 553 | //真空测试 554 | QList all_test_mode_; //存放所有需要测试的项目 555 | 556 | QList auto_test_spd_mode_containor_; 557 | QList auto_test_spd_mode__containor_raw_data_; 558 | bool auto_test_spd_mode_ = false; 559 | 560 | QString exp_id_; //用来记录一键测试的编号(用以区分不同实验) 561 | //滑行模式 562 | bool is_hx_mode_init = false; 563 | double hx_mode_target_spd_; 564 | bool reach_target_ = false; 565 | }; 566 | 567 | #endif // MOTOR_H 568 | -------------------------------------------------------------------------------- /4nmflywheel.pro.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {96c94a3f-402a-4c58-94cf-d8edb1dda2a7} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | true 41 | false 42 | 0 43 | true 44 | 0 45 | 8 46 | true 47 | 1 48 | true 49 | true 50 | true 51 | false 52 | 53 | 54 | 55 | ProjectExplorer.Project.PluginSettings 56 | 57 | 58 | 59 | ProjectExplorer.Project.Target.0 60 | 61 | Desktop Qt 5.6.0 MinGW 32bit 62 | Desktop Qt 5.6.0 MinGW 32bit 63 | qt.56.win32_mingw49_kit 64 | 0 65 | 0 66 | 0 67 | 68 | C:/4nmflywheel 69 | 70 | 71 | true 72 | qmake 73 | 74 | QtProjectManager.QMakeBuildStep 75 | true 76 | 77 | false 78 | false 79 | false 80 | 81 | 82 | true 83 | Make 84 | 85 | Qt4ProjectManager.MakeStep 86 | 87 | false 88 | 89 | 90 | 91 | 2 92 | 构建 93 | 94 | ProjectExplorer.BuildSteps.Build 95 | 96 | 97 | 98 | true 99 | Make 100 | 101 | Qt4ProjectManager.MakeStep 102 | 103 | true 104 | clean 105 | 106 | 107 | 1 108 | 清理 109 | 110 | ProjectExplorer.BuildSteps.Clean 111 | 112 | 2 113 | false 114 | 115 | Debug 116 | 117 | Qt4ProjectManager.Qt4BuildConfiguration 118 | 2 119 | true 120 | 121 | 122 | C:/4nmflywheel/build-4nmflywheel-Desktop_Qt_5_6_0_MinGW_32bit-Release 123 | 124 | 125 | true 126 | qmake 127 | 128 | QtProjectManager.QMakeBuildStep 129 | false 130 | 131 | false 132 | false 133 | false 134 | 135 | 136 | true 137 | Make 138 | 139 | Qt4ProjectManager.MakeStep 140 | 141 | false 142 | 143 | 144 | 145 | 2 146 | 构建 147 | 148 | ProjectExplorer.BuildSteps.Build 149 | 150 | 151 | 152 | true 153 | Make 154 | 155 | Qt4ProjectManager.MakeStep 156 | 157 | true 158 | clean 159 | 160 | 161 | 1 162 | 清理 163 | 164 | ProjectExplorer.BuildSteps.Clean 165 | 166 | 2 167 | false 168 | 169 | Release 170 | 171 | Qt4ProjectManager.Qt4BuildConfiguration 172 | 0 173 | true 174 | 175 | 176 | C:/4nmflywheel/build-4nmflywheel-Desktop_Qt_5_6_0_MinGW_32bit-Profile 177 | 178 | 179 | true 180 | qmake 181 | 182 | QtProjectManager.QMakeBuildStep 183 | true 184 | 185 | false 186 | true 187 | false 188 | 189 | 190 | true 191 | Make 192 | 193 | Qt4ProjectManager.MakeStep 194 | 195 | false 196 | 197 | 198 | 199 | 2 200 | 构建 201 | 202 | ProjectExplorer.BuildSteps.Build 203 | 204 | 205 | 206 | true 207 | Make 208 | 209 | Qt4ProjectManager.MakeStep 210 | 211 | true 212 | clean 213 | 214 | 215 | 1 216 | 清理 217 | 218 | ProjectExplorer.BuildSteps.Clean 219 | 220 | 2 221 | false 222 | 223 | Profile 224 | 225 | Qt4ProjectManager.Qt4BuildConfiguration 226 | 0 227 | true 228 | 229 | 3 230 | 231 | 232 | 0 233 | 部署 234 | 235 | ProjectExplorer.BuildSteps.Deploy 236 | 237 | 1 238 | 在本地部署 239 | 240 | ProjectExplorer.DefaultDeployConfiguration 241 | 242 | 1 243 | 244 | 245 | false 246 | 1000 247 | 248 | true 249 | 250 | false 251 | false 252 | false 253 | false 254 | true 255 | 0.01 256 | 10 257 | true 258 | 1 259 | 25 260 | 261 | 1 262 | true 263 | false 264 | true 265 | valgrind 266 | 267 | 0 268 | 1 269 | 2 270 | 3 271 | 4 272 | 5 273 | 6 274 | 7 275 | 8 276 | 9 277 | 10 278 | 11 279 | 12 280 | 13 281 | 14 282 | 283 | 2 284 | 285 | 4nmflywheel 286 | 287 | Qt4ProjectManager.Qt4RunConfiguration:C:/4nmflywheel/4nmflywheel/4nmflywheel.pro 288 | true 289 | 290 | 4nmflywheel.pro 291 | false 292 | false 293 | 294 | 3768 295 | false 296 | true 297 | false 298 | false 299 | true 300 | 301 | 1 302 | 303 | 304 | 305 | ProjectExplorer.Project.TargetCount 306 | 1 307 | 308 | 309 | ProjectExplorer.Project.Updater.FileVersion 310 | 18 311 | 312 | 313 | Version 314 | 18 315 | 316 | 317 | -------------------------------------------------------------------------------- /4nmflywheel.pro.user.870df22: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {870df227-1c11-4896-a1a9-6d3952f4f6eb} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | true 41 | false 42 | 0 43 | true 44 | 0 45 | 8 46 | true 47 | 1 48 | true 49 | true 50 | true 51 | false 52 | 53 | 54 | 55 | ProjectExplorer.Project.PluginSettings 56 | 57 | 58 | 59 | ProjectExplorer.Project.Target.0 60 | 61 | Desktop Qt 5.6.0 MinGW 32bit 62 | Desktop Qt 5.6.0 MinGW 32bit 63 | qt.56.win32_mingw49_kit 64 | 0 65 | 0 66 | 0 67 | 68 | C:/4nmflywheel 69 | 70 | 71 | true 72 | qmake 73 | 74 | QtProjectManager.QMakeBuildStep 75 | true 76 | 77 | false 78 | false 79 | false 80 | 81 | 82 | true 83 | Make 84 | 85 | Qt4ProjectManager.MakeStep 86 | 87 | false 88 | 89 | 90 | 91 | 2 92 | 构建 93 | 94 | ProjectExplorer.BuildSteps.Build 95 | 96 | 97 | 98 | true 99 | Make 100 | 101 | Qt4ProjectManager.MakeStep 102 | 103 | true 104 | clean 105 | 106 | 107 | 1 108 | 清理 109 | 110 | ProjectExplorer.BuildSteps.Clean 111 | 112 | 2 113 | false 114 | 115 | Debug 116 | 117 | Qt4ProjectManager.Qt4BuildConfiguration 118 | 2 119 | true 120 | 121 | 122 | C:/4nmflywheel/build-4nmflywheel-Desktop_Qt_5_6_0_MinGW_32bit-Release 123 | 124 | 125 | true 126 | qmake 127 | 128 | QtProjectManager.QMakeBuildStep 129 | false 130 | 131 | false 132 | false 133 | false 134 | 135 | 136 | true 137 | Make 138 | 139 | Qt4ProjectManager.MakeStep 140 | 141 | false 142 | 143 | 144 | 145 | 2 146 | 构建 147 | 148 | ProjectExplorer.BuildSteps.Build 149 | 150 | 151 | 152 | true 153 | Make 154 | 155 | Qt4ProjectManager.MakeStep 156 | 157 | true 158 | clean 159 | 160 | 161 | 1 162 | 清理 163 | 164 | ProjectExplorer.BuildSteps.Clean 165 | 166 | 2 167 | false 168 | 169 | Release 170 | 171 | Qt4ProjectManager.Qt4BuildConfiguration 172 | 0 173 | true 174 | 175 | 176 | C:/4nmflywheel/build-4nmflywheel-Desktop_Qt_5_6_0_MinGW_32bit-Profile 177 | 178 | 179 | true 180 | qmake 181 | 182 | QtProjectManager.QMakeBuildStep 183 | true 184 | 185 | false 186 | true 187 | false 188 | 189 | 190 | true 191 | Make 192 | 193 | Qt4ProjectManager.MakeStep 194 | 195 | false 196 | 197 | 198 | 199 | 2 200 | 构建 201 | 202 | ProjectExplorer.BuildSteps.Build 203 | 204 | 205 | 206 | true 207 | Make 208 | 209 | Qt4ProjectManager.MakeStep 210 | 211 | true 212 | clean 213 | 214 | 215 | 1 216 | 清理 217 | 218 | ProjectExplorer.BuildSteps.Clean 219 | 220 | 2 221 | false 222 | 223 | Profile 224 | 225 | Qt4ProjectManager.Qt4BuildConfiguration 226 | 0 227 | true 228 | 229 | 3 230 | 231 | 232 | 0 233 | 部署 234 | 235 | ProjectExplorer.BuildSteps.Deploy 236 | 237 | 1 238 | 在本地部署 239 | 240 | ProjectExplorer.DefaultDeployConfiguration 241 | 242 | 1 243 | 244 | 245 | false 246 | 1000 247 | 248 | true 249 | 250 | false 251 | false 252 | false 253 | false 254 | true 255 | 0.01 256 | 10 257 | true 258 | 1 259 | 25 260 | 261 | 1 262 | true 263 | false 264 | true 265 | valgrind 266 | 267 | 0 268 | 1 269 | 2 270 | 3 271 | 4 272 | 5 273 | 6 274 | 7 275 | 8 276 | 9 277 | 10 278 | 11 279 | 12 280 | 13 281 | 14 282 | 283 | 2 284 | 285 | 4nmflywheel 286 | 287 | Qt4ProjectManager.Qt4RunConfiguration:C:/4nmflywheel/4nmflywheel/4nmflywheel.pro 288 | true 289 | 290 | 4nmflywheel.pro 291 | false 292 | false 293 | 294 | 3768 295 | false 296 | true 297 | false 298 | false 299 | true 300 | 301 | 1 302 | 303 | 304 | 305 | ProjectExplorer.Project.TargetCount 306 | 1 307 | 308 | 309 | ProjectExplorer.Project.Updater.FileVersion 310 | 18 311 | 312 | 313 | Version 314 | 18 315 | 316 | 317 | -------------------------------------------------------------------------------- /mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | 4 | MainWindow::MainWindow(QWidget *parent) : 5 | QMainWindow(parent), 6 | ui(new Ui::MainWindow), 7 | m_sys_status_1_(false) 8 | { 9 | ui->setupUi(this); 10 | m_timer_get_data_.setInterval(100); //get data timer 0.1s 11 | qRegisterMetaType >>("QVector >"); 12 | qRegisterMetaType>("QVector"); 13 | qRegisterMetaType>("QVector"); 14 | qDebug()<<"MAIN THREAD:"<doubleSpinBox_motor_test_acc->setEnabled(false); 29 | qApp->setStyle(QStyleFactory::create("fusion")); 30 | } 31 | 32 | MainWindow::~MainWindow() 33 | { 34 | delete ui; 35 | p_driver_thread1_->quit(); 36 | p_driver_thread1_->wait(); 37 | } 38 | 39 | bool MainWindow::initDriver1() 40 | { 41 | p_motor_thread1_ = new QThread; 42 | p_motor1_ = new Motor; 43 | p_motor1_->setChannel("MOTOR1"); 44 | p_motor1_->setAccelerate(50); 45 | p_motor1_->moveToThread(p_motor_thread1_); 46 | connect(ui->pushButton_auto_test_with_air_power_1,SIGNAL(clicked(bool)),p_motor1_,SLOT(initTestModeWithAir())); 47 | 48 | p_motor_thread1_->start(); 49 | 50 | //driver thread 1 51 | p_driver1_ = new MotorDriver; 52 | p_driver_thread1_ = new QThread; 53 | p_driver1_->moveToThread(p_driver_thread1_); 54 | 55 | connect(p_driver_thread1_,&QThread::finished,p_driver1_,&MotorDriver::deleteLater); 56 | connect(p_driver_thread1_,&QThread::finished,p_driver_thread1_,&QThread::deleteLater); 57 | connect(p_driver1_,&MotorDriver::sendErrText,this,&MainWindow::logMsg); 58 | connect(p_driver_thread1_,&QThread::started,p_driver1_,&MotorDriver::init); 59 | //seems that should connect driver obj later 60 | p_driver1_->setPortName("COM1"); 61 | p_driver1_->setBaudRate("115200"); 62 | p_driver_thread1_->start(); 63 | 64 | //get data timer init 65 | 66 | connect(&m_timer_get_data_,&QTimer::timeout,p_driver1_,&MotorDriver::getMotorData); 67 | 68 | //control init 69 | // connect(&p_motor1_,&Motor::sendMoTorSpd,p_driver1_,&MotorDriver::ctlMotorSpd()); 70 | connect(p_motor1_,SIGNAL(sendMoTorSpd(double,double)),p_driver1_,SLOT(ctlMotorSpd2(double,double))); 71 | connect(p_motor1_,&Motor::sendMoTorTor,p_driver1_,&MotorDriver::ctlMotorTor); 72 | connect(p_driver1_,&MotorDriver::sendMotorSpd,p_motor1_,&Motor::setSpeed); 73 | connect(p_driver1_,&MotorDriver::sendMotorCur,p_motor1_,&Motor::setCurrent); 74 | connect(p_driver1_,&MotorDriver::sendMotorTmp,p_motor1_,&Motor::setTemperature); 75 | connect(this,&MainWindow::startAutoTestModeNoAir,p_motor1_,&Motor::initTestModeNOAir); 76 | connect(this,&MainWindow::sendCurrentSpdForAutoTest,p_motor1_,&Motor::runWithAirMode); 77 | connect(this,&MainWindow::refreshAutoTestSpd,p_motor1_,&Motor::setSpdOfAutoTestSpdMode); 78 | connect(this,&MainWindow::refreshAutoTestHX,p_motor1_,&Motor::setSpdOfAutoTestHXMode); 79 | //采样间隔改了的话,记得改这个 80 | p_motor1_->setCurrentInterval(double(m_timer_get_data_.interval()) / 1000); 81 | return true; 82 | } 83 | 84 | //初始化数据库 85 | void MainWindow::initSql() 86 | { 87 | p_sql_ = new SqlDataBase; 88 | p_sql_thread_ = new QThread; 89 | p_sql_->moveToThread(p_sql_thread_); 90 | // p_sql_->sqlInit(); 91 | p_sql_->initMySQL(); 92 | 93 | connect(p_sql_thread_,&QThread::finished,p_sql_,&SqlDataBase::deleteLater); 94 | connect(p_sql_thread_,&QThread::finished,p_sql_thread_,&QThread::deleteLater); 95 | 96 | connect(this,&MainWindow::sendToSqlDB,p_sql_,&SqlDataBase::insertIntoDB); 97 | 98 | connect(p_sql_,&SqlDataBase::sendErrorText,this,&MainWindow::logMsg); 99 | connect(p_sql_,&SqlDataBase::emitExpData,this,&MainWindow::updataSqlTableView); 100 | p_sql_thread_->start(); 101 | 102 | 103 | 104 | } 105 | 106 | void MainWindow::initReport() 107 | { 108 | p_repoter_ = new QMotorReport; 109 | p_repoter_thread_ = new QThread; 110 | p_repoter_->moveToThread(p_repoter_thread_); 111 | 112 | connect(p_sql_thread_,&QThread::finished,p_repoter_,&QMotorReport::deleteLater); 113 | connect(p_sql_thread_,&QThread::finished,p_repoter_thread_,&QThread::deleteLater); 114 | 115 | //将接受数据与处理函数连接 116 | // connect(p_sql_,&SqlDataBase::emitExpData,p_repoter_,&QMotorReport::getDataFromSql); 117 | connect(this,&MainWindow::getLastExpData,p_sql_,&SqlDataBase::getLastExpData); 118 | connect(p_sql_,&SqlDataBase::emitLastExpData,p_repoter_,&QMotorReport::getDataFromSql); 119 | connect(p_repoter_,&QMotorReport::logMsg,this,&MainWindow::logMsg); 120 | 121 | p_repoter_thread_->start(); 122 | 123 | ui->dateTimeEdit_start_time->setDateTime(QDateTime::currentDateTime()); 124 | ui->dateTimeEdit_end_time->setDateTime(QDateTime::currentDateTime()); 125 | } 126 | 127 | void MainWindow::initDaqCard() 128 | { 129 | p_daqcard_ = new QDaqcard; 130 | p_daqcard_thread_ = new QThread; 131 | p_daqcard_->moveToThread(p_daqcard_thread_); 132 | 133 | connect(p_daqcard_thread_,&QThread::finished,p_daqcard_,&QMotorReport::deleteLater); 134 | connect(p_daqcard_thread_,&QThread::finished,p_daqcard_thread_,&QThread::deleteLater); 135 | connect(p_daqcard_,&QDaqcard::logMsg,this,&MainWindow::logMsg); 136 | connect(p_daqcard_thread_,&QThread::started,p_daqcard_,&QDaqcard::init); 137 | connect(&m_timer_get_data_,&QTimer::timeout,p_daqcard_,&QDaqcard::readAllChannel); 138 | connect(p_daqcard_,&QDaqcard::sendAllData,this,&MainWindow::setMotorDataFromDAQCard); 139 | p_daqcard_thread_->start(); 140 | } 141 | 142 | void MainWindow::initCombox() 143 | { 144 | ui->comboBox_motor_test_mode_1->addItem("速度模式"); 145 | ui->comboBox_motor_test_mode_1->addItem("力矩模式"); 146 | ui->comboBox_motor_test_mode_1->addItem("斜坡模式"); 147 | } 148 | 149 | //更新电机1---波形显示 150 | void MainWindow::initQCustomPlot1() 151 | { 152 | 153 | ui->qcp_motor_cur_1->addGraph(); 154 | ui->qcp_motor_cur_1->graph(0)->setPen(QPen(Qt::blue)); 155 | ui->qcp_motor_cur_1->graph(0)->setName("motorCurrent"); 156 | 157 | QSharedPointer timeTicker(new QCPAxisTickerTime); 158 | timeTicker->setTimeFormat("%m:%s"); // %h代表小时 159 | ui->qcp_motor_cur_1->xAxis->setTicker(timeTicker); 160 | ui->qcp_motor_cur_1->axisRect()->setupFullAxesBox(); 161 | ui->qcp_motor_cur_1->yAxis->setLabel("电流(A)"); 162 | 163 | // make left and bottom axes transfer their ranges to right and top axes: 164 | connect( ui->qcp_motor_cur_1->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->qcp_motor_cur_1->xAxis2, SLOT(setRange(QCPRange))); 165 | connect( ui->qcp_motor_cur_1->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->qcp_motor_cur_1->yAxis2, SLOT(setRange(QCPRange))); 166 | 167 | // setup a timer that repeatedly calls MainWindow::realtimeDataSlot: 168 | 169 | //dataTimer.start(0); // Interval 0 means to refresh as fast as possibl 170 | 171 | ui->qcp_motor_spd_1->addGraph(); 172 | ui->qcp_motor_spd_1->graph(0)->setPen(QPen(Qt::red)); 173 | ui->qcp_motor_spd_1->addGraph(); 174 | ui->qcp_motor_spd_1->graph(1)->setPen(QPen(Qt::green)); 175 | 176 | ui->qcp_motor_spd_1->yAxis->setLabel("转速(rpm)"); 177 | 178 | ui->qcp_motor_spd_1->xAxis->setTicker(timeTicker); 179 | ui->qcp_motor_spd_1->axisRect()->setupFullAxesBox(); 180 | ui->qcp_motor_spd_1->yAxis->setRange(0,1); 181 | 182 | connect( ui->qcp_motor_spd_1->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->qcp_motor_spd_1->xAxis2, SLOT(setRange(QCPRange))); 183 | connect( ui->qcp_motor_spd_1->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->qcp_motor_spd_1->yAxis2, SLOT(setRange(QCPRange))); 184 | 185 | ui->qcp_motor_tmp_1->addGraph(); 186 | ui->qcp_motor_tmp_1->graph(0)->setPen(QPen(Qt::red)); 187 | 188 | ui->qcp_motor_tmp_1->yAxis->setLabel("温度(℃)"); 189 | 190 | ui->qcp_motor_tmp_1->xAxis->setTicker(timeTicker); 191 | ui->qcp_motor_tmp_1->axisRect()->setupFullAxesBox(); 192 | //ui->widget->yAxis->setRange(-30,30); 193 | 194 | 195 | ui->qcp_motor_tmp_1->xAxis->setTicker(timeTicker); 196 | 197 | connect( ui->qcp_motor_tmp_1->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->qcp_motor_tmp_1->xAxis2, SLOT(setRange(QCPRange))); 198 | connect( ui->qcp_motor_tmp_1->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->qcp_motor_tmp_1->yAxis2, SLOT(setRange(QCPRange))); 199 | 200 | ui->qcp_motor_tmp_1->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); 201 | ui->qcp_motor_spd_1->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); 202 | ui->qcp_motor_cur_1->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); 203 | } 204 | 205 | void MainWindow::logMsg(QString text) 206 | { 207 | qDebug() << text; 208 | ui->statusBar->showMessage(text,5000); 209 | } 210 | 211 | void MainWindow::on_pushButton_system_power_1_clicked() 212 | { 213 | if (!m_sys_status_1_){ 214 | //power not open 215 | 216 | m_sys_status_1_ = true; 217 | ui->pushButton_system_power_1->setText("关闭"); 218 | p_daqcard_->setDOPort(1,true); 219 | 220 | } 221 | else{ 222 | //power had open 223 | 224 | p_daqcard_->setDOPort(1,false); 225 | m_sys_status_1_ = false; 226 | ui->pushButton_system_power_1->setText("启动"); 227 | 228 | if (p_motor1_->getIsRunning()){ 229 | QMessageBox::warning(this,"警告","依然有任务运行中,但电源已关闭。"); 230 | } 231 | } 232 | } 233 | 234 | void MainWindow::on_pushButton_single_test_mode_1_clicked() 235 | { 236 | static bool this_mode_running = false; 237 | static bool xp_mode_running = false; 238 | if (!m_sys_status_1_){ 239 | QMessageBox::warning(this,"电源未打开","电源未打开,请开启总电源!"); 240 | } 241 | else{ 242 | if(!p_motor1_->getIsRunning() && !this_mode_running){ 243 | switch(ui->comboBox_motor_test_mode_1->currentIndex()){ 244 | case 0: 245 | p_motor1_->setSetSpeed(ui->doubleSpinBox_motor_test_spd_1->text().toDouble()); 246 | p_motor1_->setAccelerate(ui->doubleSpinBox_motor_test_acc->text().toDouble()); 247 | break; 248 | case 1: p_motor1_->setSetTorque(ui->doubleSpinBox_motor_test_spd_1->text().toDouble());break; 249 | case 2: 250 | p_motor1_->setSetSpeed(0); 251 | p_motor1_->initXpMode(ui->doubleSpinBox_motor_test_spd_1->text().toDouble() 252 | ,ui->doubleSpinBox_motor_test_acc->text().toDouble()); 253 | connect(&m_timer_get_data_,SIGNAL(timeout()),p_motor1_,SLOT(calXpMode())); 254 | xp_mode_running = true; 255 | p_motor1_->setXpStatus(true); 256 | break; 257 | default: 258 | break; 259 | } 260 | // m_timer_get_data_.setInterval(); 261 | 262 | keyContainer.resize(0); 263 | tmpContainer.resize(0); 264 | curContainer.resize(0); 265 | spdContainer.resize(0); 266 | setSpdContainer.resize(0); 267 | 268 | p_motor1_->setIsRunning(true); 269 | m_timer_get_data_.start(); 270 | this_mode_running = true; 271 | ui->pushButton_single_test_mode_1->setText("停止"); 272 | ui->comboBox_motor_test_mode_1->setEnabled(false); 273 | } 274 | else{ 275 | if (this_mode_running){ 276 | if (xp_mode_running){ 277 | disconnect(&m_timer_get_data_,SIGNAL(timeout()),p_motor1_,SLOT(calXpMode())); 278 | xp_mode_running = false; 279 | p_motor1_->setXpStatus(false); 280 | } 281 | p_motor1_->setIsRunning(false); 282 | p_motor1_->setSetSpeed(0); 283 | m_timer_get_data_.stop(); 284 | this_mode_running = false; 285 | ui->pushButton_single_test_mode_1->setText("启动"); 286 | ui->comboBox_motor_test_mode_1->setEnabled(true); 287 | } 288 | else{ 289 | QMessageBox::warning(this,"警告","其它模式运行中。"); 290 | } 291 | } 292 | } 293 | } 294 | 295 | //为sql查询生成一个vector,为了方便信号槽数据的传递。 296 | QVector MainWindow::makeSqlVector(Motor &motor) 297 | { 298 | static QVector res; 299 | res.clear(); 300 | res.append(motor.getChannel()); 301 | res.append(motor.getExpId()); 302 | res.append(QString::number(motor.getID())); 303 | res.append(QString::number(motor.getVoltage())); 304 | res.append(QString::number(motor.getCurrent())); 305 | res.append(QString::number(motor.getSetSpeed())); 306 | res.append(QString::number(motor.getSpeed())); 307 | res.append(QString::number(motor.getSetTorque())); 308 | res.append(QString::number(motor.getTorque())); 309 | res.append(QString::number(motor.getWate())); 310 | res.append(QString::number(motor.getAngularMomentum())); 311 | res.append(QString::number(motor.getAngularMomentumConst())); 312 | res.append(QString::number(motor.getAngularMomentumDynamic())); 313 | res.append(QString::number(motor.getFlywheelMode())); 314 | res.append(ui->lineEdit_vacuum->text()); 315 | res.append(ui->lineEdit_exp_address->text()); 316 | res.append(QString::number(motor.getActCur())); 317 | return res; 318 | } 319 | //更新电机1 总控制函数 320 | void MainWindow::updateMotor() 321 | { 322 | if (p_motor1_->getIsRunning()){ 323 | //斜坡模式不用发 324 | 325 | if (!p_motor1_->getXpStatus() && !p_motor1_->getAirMode() && 326 | !p_motor1_->getAutoTestSpdMode() && !p_motor1_->getHXMode()) 327 | { 328 | p_motor1_->setSetSpeed(ui->doubleSpinBox_motor_test_spd_1->text().toDouble()); 329 | } 330 | //更新显示界面 331 | updateMotor1Display(); 332 | refreshCustomPlotData1(); 333 | 334 | //非真空速度测试 335 | if (p_motor1_->getAirMode()){ 336 | emit sendCurrentSpdForAutoTest(p_motor1_->getSpeed()); 337 | } 338 | //一键测试,速度模式 339 | else if (p_motor1_->getAutoTestSpdMode()){ 340 | emit refreshAutoTestSpd(); 341 | } 342 | //一键测试,滑行模式 343 | else if (p_motor1_->getHXMode()){ 344 | emit refreshAutoTestHX(); 345 | } 346 | 347 | 348 | //更新数据库,为了防止插入太快,每隔0.1S插入一次 349 | static QTime time(QTime::currentTime()); 350 | // calculate two new data points: 351 | double key = time.elapsed()/1000.0; // time elapsed since start of demo, in seconds elaspsed上次开始后得持续时间 352 | static double lastPointKey = 0; 353 | if (key - lastPointKey > 0.1){ 354 | emit sendToSqlDB(ui->lineEdit_exp_name_1->text(),ui->lineEdit_exp_usr_name_1->text(), 355 | ui->lineEdit_exp_fw_id_1->text(),makeSqlVector(*p_motor1_)); 356 | lastPointKey = key; 357 | if (key > 43200){ 358 | //12h重置一次! 359 | time.restart(); 360 | lastPointKey = 0; 361 | } 362 | } 363 | } 364 | //...etc motor 365 | } 366 | //更新电机1---数据显示 367 | void MainWindow::updateMotor1Display() 368 | { 369 | //update lineedit 370 | ui->lineEdit_sys_vol_1->setText(QString::number(p_motor1_->getVoltage())); 371 | ui->lineEdit_sys_cur_1->setText(QString::number(p_motor1_->getActCur())); 372 | ui->lineEdit_motor_set_spd_1->setText(QString::number(p_motor1_->getSetSpeed())); 373 | ui->lineEdit_motor_act_spd_1->setText(QString::number(p_motor1_->getSpeed())); 374 | ui->lineEdit_motor_cur_1->setText(QString::number(p_motor1_->getCurrent())); 375 | ui->lineEdit_motor_act_tor_1->setText(QString::number(p_motor1_->getReactionMoment_())); 376 | ui->lineEdit_motor_jdl_1->setText(QString::number(p_motor1_->getAngularMomentum())); 377 | ui->lineEdit_motor_jdl_czpc_1->setText(QString::number(p_motor1_->getAngularMomentumConst())); 378 | ui->lineEdit_motor_jdl_dtpc_1->setText(QString::number(p_motor1_->getAngularMomentumDynamic())); 379 | ui->lineEdit_motor_wate_1->setText(QString::number(p_motor1_->getWate())); 380 | ui->lineEdit_motor_wate_overview_1->setText(QString::number(p_motor1_->getWate())); 381 | } 382 | //转速改变响应函数 383 | void MainWindow::on_doubleSpinBox_motor_test_spd_1_editingFinished() 384 | { 385 | if(p_motor1_->getIsRunning()){ 386 | switch(ui->comboBox_motor_test_mode_1->currentIndex()){ 387 | case 0: p_motor1_->setSetSpeed(ui->doubleSpinBox_motor_test_spd_1->text().toDouble()); break; 388 | case 1: p_motor1_->setSetTorque(ui->doubleSpinBox_motor_test_spd_1->text().toDouble());break; 389 | default: 390 | break; 391 | } 392 | } 393 | } 394 | //测试模式下拉框改变响应函数 395 | void MainWindow::on_comboBox_motor_test_mode_1_currentIndexChanged(int index) 396 | { 397 | switch (index) { 398 | case 0: 399 | ui->label_setval_1->setText("设置速度"); 400 | ui->label_setval_right_1->setText("设置速度"); 401 | // ui->doubleSpinBox_motor_test_acc->setEnabled(false); 402 | break; 403 | case 1: 404 | ui->label_setval_1->setText("设置力矩"); 405 | ui->label_setval_right_1->setText("设置力矩"); 406 | // ui->doubleSpinBox_motor_test_acc->setEnabled(false); 407 | break; 408 | case 2: 409 | ui->label_setval_1->setText("设置速度"); 410 | ui->label_setval_right_1->setText("设置速度"); 411 | // ui->doubleSpinBox_motor_test_acc->setEnabled(true); 412 | break; 413 | default: 414 | break; 415 | } 416 | } 417 | //刷新界面速度、电流等图部分 418 | void MainWindow::refreshCustomPlotData1() 419 | { 420 | static QTime time(QTime::currentTime()); 421 | // calculate two new data points: 422 | double key = time.elapsed()/1000.0; // time elapsed since start of demo, in seconds elaspsed上次开始后得持续时间 423 | static double lastPointKey = 0; 424 | if (key-lastPointKey > 0.01) // at most add point every 0.5 s 425 | { 426 | 427 | // add data to lines: 428 | keyContainer.push_back(key); 429 | tmpContainer.push_back(p_motor1_->getTemperature()); 430 | curContainer.push_back(p_motor1_->getCurrent()); 431 | spdContainer.push_back(p_motor1_->getSpeed()); 432 | setSpdContainer.push_back(p_motor1_->getSetSpeed()); 433 | 434 | ui->qcp_motor_tmp_1->graph(0)->setData(keyContainer,tmpContainer,true); 435 | ui->qcp_motor_cur_1->graph(0)->setData(keyContainer,curContainer,true); 436 | ui->qcp_motor_spd_1->graph(0)->setData(keyContainer,spdContainer,true); 437 | ui->qcp_motor_spd_1->graph(1)->setData(keyContainer,setSpdContainer,true); 438 | lastPointKey = key; 439 | int disp_num = ui->label_tab1_disp_num->text().toInt(); 440 | if (keyContainer.size() >= disp_num){ 441 | keyContainer.pop_front(); 442 | tmpContainer.pop_front(); 443 | curContainer.pop_front(); 444 | spdContainer.pop_front(); 445 | setSpdContainer.pop_front(); 446 | } 447 | ui->qcp_motor_tmp_1->graph(0)->rescaleValueAxis(true); 448 | ui->qcp_motor_cur_1->graph(0)->rescaleValueAxis(true); 449 | ui->qcp_motor_spd_1->graph(0)->rescaleValueAxis(true); 450 | ui->qcp_motor_spd_1->graph(1)->rescaleValueAxis(true); 451 | 452 | ui->qcp_motor_cur_1->yAxis->setRange(*std::min_element(curContainer.begin(),curContainer.end()), 453 | *std::max_element(curContainer.begin(),curContainer.end())); 454 | ui->qcp_motor_spd_1->yAxis->setRange(*std::min_element(spdContainer.begin(),spdContainer.end()), 455 | *std::max_element(spdContainer.begin(),spdContainer.end())); 456 | ui->qcp_motor_tmp_1->yAxis->setRange(*std::min_element(tmpContainer.begin(),tmpContainer.end()), 457 | *std::max_element(tmpContainer.begin(),tmpContainer.end())); 458 | 459 | ui->qcp_motor_cur_1->xAxis->setRange(key, disp_num/20, Qt::AlignRight); 460 | ui->qcp_motor_spd_1->xAxis->setRange(key, disp_num/20, Qt::AlignRight); 461 | ui->qcp_motor_tmp_1->xAxis->setRange(key, disp_num/20, Qt::AlignRight); 462 | 463 | ui->qcp_motor_cur_1->replot(); 464 | ui->qcp_motor_tmp_1->replot(); 465 | ui->qcp_motor_spd_1->replot(); 466 | 467 | if (key > 43200){ 468 | //12h重置一次! 469 | time.restart(); 470 | lastPointKey = 0; 471 | keyContainer.clear(); 472 | tmpContainer.clear(); 473 | curContainer.clear(); 474 | spdContainer.clear(); 475 | setSpdContainer.clear(); 476 | } 477 | 478 | } 479 | // make key axis range scroll with the data (at a constant range size of 8): 480 | 481 | 482 | 483 | 484 | } 485 | //设置界面数据更新间隔 486 | void MainWindow::on_doubleSpinBox_moto_test_time_valueChanged(double arg1) 487 | { 488 | m_timer_update_.setInterval(arg1*1000); 489 | p_motor1_->setCurrentInterval(arg1*1000); 490 | } 491 | 492 | //非真空性能测试响应函数 493 | void MainWindow::on_pushButton_auto_test_with_air_power_1_clicked() 494 | { 495 | static bool this_mode_running = false; 496 | if (!m_sys_status_1_){ 497 | QMessageBox::warning(this,"电源未打开","电源未打开,请开启总电源!"); 498 | } 499 | else{ 500 | if(!p_motor1_->getIsRunning() && !this_mode_running && ui->checkBox_noair_1->isChecked()){ 501 | //如果选择了该模式,启动测试流程 502 | p_motor1_->setIsRunning(true); 503 | this_mode_running = true; 504 | m_timer_get_data_.start(); 505 | ui->pushButton_auto_test_with_air_power_1->setText("停止"); 506 | // ui->statusBar->showMessage("非真空性能测试运行中!"); 507 | connect(p_motor1_,SIGNAL(airTestEnd()),this,SLOT(on_pushButton_auto_test_with_air_power_1_clicked())); 508 | 509 | } 510 | else if (this_mode_running){ 511 | p_motor1_->setSetSpeed(0); 512 | // p_motor1_->setAirMode(false); 513 | p_motor1_->setIsRunning(false); 514 | this_mode_running = false; 515 | m_timer_get_data_.stop(); 516 | ui->pushButton_auto_test_with_air_power_1->setText("启动"); 517 | ui->statusBar->showMessage("飞轮1非真空性能测试结束!",5000); 518 | QMessageBox::warning(this,"完成","飞轮1非真空性能测试完成!"); 519 | disconnect(p_motor1_,SIGNAL(airTestEnd()),this,SLOT(on_pushButton_auto_test_with_air_power_1_clicked())); 520 | } 521 | else{ 522 | QMessageBox::warning(this,"警告","运行失败,请检查当前状态。"); 523 | } 524 | } 525 | } 526 | //数据库查询按钮 527 | void MainWindow::on_pushButton_sql_query_clicked() 528 | { 529 | tab_num_ = 0; 530 | p_sql_->getExpDataFromSqlDB(ui->lineEdit_sql_motor_id->text(),ui->lineEdit_sql_exp_id->text() 531 | ,ui->lineEdit_sql_motor_mode->text(),ui->dateTimeEdit_start_time->dateTime().toString("yyyy-MM-dd hh::mm::ss"),ui->dateTimeEdit_end_time->dateTime().toString("yyyy-MM-dd hh::mm::ss")); 532 | } 533 | 534 | void MainWindow::updataSqlTableView(const QVector > &res) 535 | { 536 | static QStandardItemModel *model = nullptr; 537 | if (model == nullptr){ 538 | model = new QStandardItemModel(); 539 | } 540 | if (tab_num_ == 0){ 541 | model->clear(); 542 | model->setColumnCount(20); 543 | model->setHeaderData(0,Qt::Horizontal,"实验ID"); 544 | model->setHeaderData(1,Qt::Horizontal,"实验名称"); 545 | model->setHeaderData(2,Qt::Horizontal,"人员名称"); 546 | model->setHeaderData(3,Qt::Horizontal,"实验编号"); 547 | model->setHeaderData(4,Qt::Horizontal,"飞轮编号"); 548 | model->setHeaderData(5,Qt::Horizontal,"飞轮电压"); 549 | model->setHeaderData(6,Qt::Horizontal,"飞轮电流"); 550 | model->setHeaderData(7,Qt::Horizontal,"飞轮设置速度"); 551 | model->setHeaderData(8,Qt::Horizontal,"飞轮实际速度"); 552 | model->setHeaderData(9,Qt::Horizontal,"飞轮设置力矩"); 553 | model->setHeaderData(10,Qt::Horizontal,"飞轮实际力矩"); 554 | model->setHeaderData(11,Qt::Horizontal,"飞轮功率"); 555 | model->setHeaderData(12,Qt::Horizontal,"飞轮角动量"); 556 | model->setHeaderData(13,Qt::Horizontal,"飞轮角动量常值偏差"); 557 | model->setHeaderData(14,Qt::Horizontal,"飞轮角动量动态偏差"); 558 | model->setHeaderData(15,Qt::Horizontal,"飞轮运行模式"); 559 | model->setHeaderData(16,Qt::Horizontal,"真空度"); 560 | model->setHeaderData(17,Qt::Horizontal,"实验地点"); 561 | model->setHeaderData(18,Qt::Horizontal,"采集电流"); 562 | model->setHeaderData(19,Qt::Horizontal,"运行时间"); 563 | ui->tableView_sql->setModel(model); 564 | } 565 | 566 | for (const QVector &query_dispResult_:res){ 567 | for (int j=0;j<20;++j){ 568 | model->setItem(tab_num_,j,new QStandardItem(query_dispResult_.at(j))); 569 | //设置字符位置 570 | model->item(tab_num_,j)->setTextAlignment(Qt::AlignCenter); 571 | } 572 | tab_num_++; 573 | if (tab_num_ > 100){ 574 | break; 575 | } 576 | } 577 | } 578 | //生成最后一次实验的实验报告 579 | void MainWindow::on_pushButton_make_report_clicked() 580 | { 581 | emit getLastExpData(ui->lineEdit_sql_motor_id->text(),ui->lineEdit_sql_motor_mode->text()); 582 | } 583 | //DAQ CARD 响应函数,从数据采集卡得到电压电流 584 | void MainWindow::setMotorDataFromDAQCard(const QVector &res) 585 | { 586 | if (res.size() != 7) return; 587 | p_motor1_->setVoltage(res[6]*10); 588 | p_motor1_->setActCur(2.5 - res[0]); 589 | p_motor1_->setWate(); 590 | } 591 | //浪涌电流测试 592 | void MainWindow::on_pushButton_ele_test_ly_mode_power_1_clicked() 593 | { 594 | if (m_sys_status_1_){ 595 | QMessageBox::warning(this,"警告","请关闭该飞轮电源后重试!"); 596 | return; 597 | } 598 | QVector current; 599 | p_daqcard_->getSurgeCurrent(0,current,1024); 600 | QVector key; 601 | for (int i =0;iqcp_motor_tmp_1->graph(0)->setData(key,current,true); 605 | ui->qcp_motor_tmp_1->graph(0)->rescaleValueAxis(true); 606 | ui->qcp_motor_tmp_1->yAxis->setRange(*std::min_element(current.begin(),current.end()), 607 | *std::max_element(current.begin(),current.end())); 608 | 609 | ui->qcp_motor_tmp_1->xAxis->setRange(0, key.size(), Qt::AlignLeft); 610 | ui->qcp_motor_tmp_1->replot(); 611 | } 612 | //绘图间隔改变 613 | void MainWindow::on_tab1_horizontalSlider_valueChanged(int value) 614 | { 615 | ui->label_tab1_disp_num->setText(QString::number(value)); 616 | if (!p_motor1_->getIsRunning()){ 617 | double key = ui->qcp_motor_cur_1->xAxis->range().upper; 618 | double disp_num = value; 619 | ui->qcp_motor_cur_1->xAxis->setRange(key, disp_num/20, Qt::AlignRight); 620 | ui->qcp_motor_spd_1->xAxis->setRange(key, disp_num/20, Qt::AlignRight); 621 | ui->qcp_motor_tmp_1->xAxis->setRange(key, disp_num/20, Qt::AlignRight); 622 | ui->qcp_motor_cur_1->replot(); 623 | ui->qcp_motor_tmp_1->replot(); 624 | ui->qcp_motor_spd_1->replot(); 625 | } 626 | } 627 | //一键测试模式启动按钮 628 | void MainWindow::on_pushButton_auto_test_noair_power_1_clicked() 629 | { 630 | static bool this_mode_running = false; 631 | if (!m_sys_status_1_){ 632 | QMessageBox::warning(this,"警告","飞轮电源未打开!"); 633 | } 634 | else{ 635 | if(!p_motor1_->getIsRunning() && !this_mode_running){ 636 | //如果选择了该模式,启动测试流程 637 | p_motor1_->setIsRunning(true); 638 | this_mode_running = true; 639 | m_timer_get_data_.start(); 640 | ui->pushButton_auto_test_noair_power_1->setText("停止"); 641 | 642 | //筛选选中的测试模式---在这里添加更多的 643 | QVector selected_test_mode; 644 | if (ui->checkBox_hs_mode_1->isChecked()) 645 | selected_test_mode.push_back(QString::number(FLYWHEEL_MODE_SPD)); 646 | if (ui->checkBox_hx_mode_1->isChecked()) 647 | selected_test_mode.push_back(QString::number(FLYWHEEL_MODE_HX)); 648 | 649 | emit startAutoTestModeNoAir(selected_test_mode); 650 | connect(p_motor1_,SIGNAL(autoTestEnd()),this,SLOT(on_pushButton_auto_test_noair_power_1_clicked())); 651 | } 652 | else if (this_mode_running){ 653 | p_motor1_->setSetSpeed(0); 654 | p_motor1_->setIsRunning(false); 655 | this_mode_running = false; 656 | m_timer_get_data_.stop(); 657 | ui->pushButton_auto_test_noair_power_1->setText("启动"); 658 | ui->statusBar->showMessage("飞轮1真空性能测试结束!",5000); 659 | QMessageBox::warning(this,"完成","飞轮1真空性能测试完成!"); 660 | disconnect(p_motor1_,SIGNAL(autoTestEnd()),this,SLOT(on_pushButton_auto_test_noair_power_1_clicked())); 661 | emit getLastExpData(tr("MOTOR1"),tr("")); 662 | } 663 | } 664 | } 665 | void MainWindow::on_doubleSpinBox_motor_test_acc_valueChanged(double arg1) 666 | { 667 | if (arg1>0 && arg1 < 200) 668 | p_motor1_->setAccelerate(arg1); 669 | } 670 | -------------------------------------------------------------------------------- /qmotorreport.cpp: -------------------------------------------------------------------------------- 1 | #include "qmotorreport.h" 2 | 3 | QMotorReport::QMotorReport(QObject *parent) : QObject(parent) 4 | { 5 | qRegisterMetaType >>("QVector >"); 6 | } 7 | 8 | void QMotorReport::setExpInfomation(const QVector &data) 9 | { 10 | //数据库改变的话,size = 20 也需要改变 11 | if (data.size() != 20) { 12 | emit logMsg(tr("数据库错误,是否改变了表的结构?")); 13 | return; 14 | } 15 | 16 | this->exp_id_ = data[0]; 17 | this->exp_name_ = data[1]; 18 | this->usr_name_ = data[2]; 19 | this->exp_no_ = data[3]; 20 | this->flywheel_no_ = data[4]; 21 | this->flywheel_vol_.push_back(data[5].toDouble()); 22 | this->flywheel_cur_.push_back(data[6].toDouble()); 23 | this->flywheel_setSpd_.push_back(data[7].toDouble()); 24 | this->flywheel_spd_.push_back(data[8].toDouble()); 25 | this->flywheel_setTor_.push_back(data[9].toDouble()); 26 | this->flywheel_tor_.push_back(data[10].toDouble()); 27 | this->flywheel_wate_.push_back( data[11].toDouble()); 28 | this->flywheel_JDL_.push_back( data[12].toDouble()); 29 | this->flywheel_JDL_dynamic_.push_back(data[13].toDouble()); 30 | this->flywheel_JDL_const_.push_back(data[14].toDouble()); 31 | this->flywheel_mode_.push_back(data[15].toInt()); 32 | this->exp_vacuum_ = data[16]; 33 | this->exp_address_ = data[17]; 34 | this->flywheel_act_cur_.push_back(data[18].toDouble()); 35 | this->exp_time_ = data[19]; 36 | 37 | } 38 | 39 | 40 | 41 | //创建word报告 42 | void QMotorReport::createWordReport() 43 | { 44 | QString save_path = "E:/result.doc";//E:/result.doc 45 | QWord word; 46 | if (!word.createNewWord(save_path)){ 47 | qDebug() << "qword:create word error!"; 48 | return; 49 | } 50 | word.setPageOrientation(0); //页面方向 51 | word.setWordPageView(3); //页面视图 52 | //sword.setFontName(QString::fromLocal8Bit("宋体")); 53 | word.setParagraphAlignment(0); //下面文字位置 54 | // word.setFontSize(20); //字体大小 55 | // word.setFontBold(true); //字体加粗 56 | // word.insertText(tr("Electrical Equipment Infrared Diagnosis Report ")); 57 | word.setFontBold(false); 58 | 59 | // word.insertMoveDown(); //控制插入位置 60 | 61 | // word.setFontSize(10); 62 | // word.setParagraphAlignment(1); 63 | // QString current_Time = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); 64 | // word.insertText(tr("Report Generation Date:")); 65 | // word.insertText(current_Time); 66 | 67 | word.intsertTable(52,10); //24 //创建表格 68 | word.setColumnHeight(1,1,10); 69 | 70 | //合并单元格 71 | word.MergeCells(1,1,1,1,10); //第一行4Nms-1A 飞轮电性能测试记录表 72 | 73 | word.MergeCells(1,2,2,2,4); //第二行 74 | word.MergeCells(1,2,4,2,5); 75 | word.MergeCells(1,2,6,2,7); 76 | 77 | word.MergeCells(1,3,2,3,4); //第三行 78 | word.MergeCells(1,3,4,3,5); 79 | word.MergeCells(1,3,6,3,7); 80 | 81 | word.MergeCells(1,4,4,4,7); //第四行 82 | word.MergeCells(1,4,5,5,8);//表示的是将c4l5的单元格与c5l8的单元格合并 83 | //第五行 84 | word.MergeCells(1,5,1,18,1);//(序号)1 85 | word.MergeCells(1,5,2,18,2);//转速控制特性n(-6000-6000rpm) 86 | word.MergeCells(1,5,3,18,3);//角动量控制偏差△H:≤0.002Nms常量偏差:≤0.005Nms 87 | word.MergeCells(1,5,9,18,9);//结论下的数据 88 | word.MergeCells(1,5,10,18,10);//转速可取多个数的平均值 89 | //第六行 90 | word.MergeCells(1,19,4,19,5); 91 | word.MergeCells(1,19,5,19,7); 92 | //word.MergeCells(1,6,6,6,); 93 | //第七行 94 | word.MergeCells(1,20,1,24,1); 95 | word.MergeCells(1,20,2,24,2); 96 | word.MergeCells(1,20,3,22,3); 97 | word.MergeCells(1,23,3,24,3); 98 | 99 | word.MergeCells(1,20,4,20,5); 100 | word.MergeCells(1,20,5,20,7); 101 | word.MergeCells(1,21,4,21,5); 102 | word.MergeCells(1,21,5,21,7); 103 | word.MergeCells(1,22,4,22,5); 104 | word.MergeCells(1,22,5,22,7); 105 | word.MergeCells(1,23,4,23,5); 106 | word.MergeCells(1,23,5,23,7); 107 | word.MergeCells(1,24,4,24,5); 108 | word.MergeCells(1,24,5,24,7); 109 | 110 | word.MergeCells(1,20,6,24,6); 111 | word.MergeCells(1,20,7,24,7); 112 | //第八行 113 | word.MergeCells(1,25,4,25,5); 114 | word.MergeCells(1,25,5,25,7); 115 | 116 | word.MergeCells(1,20,6,25,6); 117 | word.MergeCells(1,20,7,25,7); 118 | //第九行 119 | word.MergeCells(1,26,4,26,5); 120 | word.MergeCells(1,26,5,26,7); 121 | //第十行 122 | word.MergeCells(1,27,1,35,1); 123 | word.MergeCells(1,27,2,35,2); 124 | word.MergeCells(1,27,3,35,3); 125 | 126 | word.MergeCells(1,27,4,27,8); 127 | word.MergeCells(1,27,5,27,6); 128 | 129 | word.MergeCells(1,28,4,28,5); 130 | word.MergeCells(1,28,5,28,6); 131 | 132 | word.MergeCells(1,29,4,29,5); 133 | word.MergeCells(1,29,5,29,6); 134 | 135 | word.MergeCells(1,30,4,30,5); 136 | word.MergeCells(1,30,5,30,6); 137 | 138 | word.MergeCells(1,31,4,31,5); 139 | word.MergeCells(1,31,5,31,6); 140 | 141 | word.MergeCells(1,32,4,32,5); 142 | word.MergeCells(1,32,5,32,6); 143 | 144 | word.MergeCells(1,33,4,33,5); 145 | word.MergeCells(1,33,5,33,6); 146 | 147 | word.MergeCells(1,34,4,34,5); 148 | word.MergeCells(1,34,5,34,6); 149 | 150 | word.MergeCells(1,35,4,35,5); 151 | word.MergeCells(1,35,5,35,6); 152 | 153 | word.MergeCells(1,28,7,35,7); 154 | word.MergeCells(1,28,8,35,8); 155 | //第十一行 156 | word.MergeCells(1,36,1,46,1); 157 | word.MergeCells(1,36,2,46,2); 158 | word.MergeCells(1,36,3,46,3); 159 | 160 | word.MergeCells(1,36,4,36,5); 161 | word.MergeCells(1,36,5,36,6); 162 | 163 | word.MergeCells(1,37,4,37,5); 164 | word.MergeCells(1,37,5,37,6); 165 | 166 | word.MergeCells(1,38,4,38,5); 167 | word.MergeCells(1,38,5,38,6); 168 | 169 | word.MergeCells(1,39,4,39,5); 170 | word.MergeCells(1,39,5,39,6); 171 | 172 | word.MergeCells(1,40,4,40,5); 173 | word.MergeCells(1,40,5,40,6); 174 | 175 | word.MergeCells(1,41,4,41,5); 176 | word.MergeCells(1,41,5,41,6); 177 | 178 | word.MergeCells(1,42,4,42,5); 179 | word.MergeCells(1,42,5,42,6); 180 | 181 | word.MergeCells(1,43,4,43,5); 182 | word.MergeCells(1,43,5,43,6); 183 | 184 | word.MergeCells(1,44,4,44,5); 185 | word.MergeCells(1,44,5,44,6); 186 | 187 | word.MergeCells(1,45,4,45,5); 188 | word.MergeCells(1,45,5,45,6); 189 | 190 | word.MergeCells(1,46,4,46,5); 191 | word.MergeCells(1,46,5,46,6); 192 | 193 | word.MergeCells(1,36,7,46,7); 194 | word.MergeCells(1,36,8,46,8); 195 | //第十二行 196 | word.MergeCells(1,47,4,47,5); 197 | word.MergeCells(1,47,5,47,7); 198 | //第十三行 199 | word.MergeCells(1,48,4,48,5); 200 | word.MergeCells(1,48,5,48,7); 201 | //第十四行 202 | word.MergeCells(1,49,4,49,5); 203 | word.MergeCells(1,49,5,49,7); 204 | //第十五行 205 | word.MergeCells(1,50,4,50,5); 206 | word.MergeCells(1,50,5,50,7); 207 | //第十六行 208 | word.MergeCells(1,51,4,51,5); 209 | word.MergeCells(1,51,5,51,7); 210 | //第十七行 211 | word.MergeCells(1,52,1,52,10); 212 | //第一行数据设置 213 | word.setCellFontBold(1,1,1,true); //设置是否粗体 214 | // word.setTableAutoFitBehavior(0); //自动拉伸列 215 | word.setCellFontSize(1,1,1,14); 216 | word.setColumnWidth(1,1,120);//设置列的宽度 217 | word.setRowAlignment(1,1,0);//设置行的对其方式 218 | word.setCellString(1,1,1,tr("4Nms-1A 飞轮电性能测试记录表")); 219 | 220 | //第二行数据设置 221 | word.setCellFontBold(1,2,1,false); //设置是否粗体 222 | // word.setTableAutoFitBehavior(0); //自动拉伸列 223 | // word.setColumnWidth(1,2,30); 224 | word.setRowAlignment(1,2,0); 225 | word.setCellFontSize(1,2,1,10); 226 | word.setCellString(1,2,1,tr("代号")); 227 | 228 | word.setCellFontBold(1,2,2,false); //设置是否粗体 229 | word.setRowAlignment(1,2,0); 230 | word.setCellFontSize(1,2,2,10); 231 | word.setCellString(1,2,2,exp_no_); 232 | 233 | word.setCellFontBold(1,2,3,false); //设置是否粗体 234 | word.setRowAlignment(1,2,0); 235 | word.setCellFontSize(1,2,3,10); 236 | word.setCellString(1,2,3,tr("飞轮编号")); 237 | 238 | word.setCellFontBold(1,2,4,false); //设置是否粗体 239 | word.setRowAlignment(1,2,0); 240 | word.setCellFontSize(1,2,4,10); 241 | word.setCellString(1,2,4,flywheel_no_); 242 | 243 | word.setCellFontBold(1,2,5,false); //设置是否粗体 244 | // word.setTableAutoFitBehavior(0); //自动拉伸列 245 | // word.setColumnWidth(1,3,60); 246 | word.setRowAlignment(1,2,0); 247 | word.setCellFontSize(1,2,5,10); 248 | word.setCellString(1,2,5,tr("测试时真空度")); 249 | 250 | word.setCellFontBold(1,2,6,false); //设置是否粗体 251 | word.setRowAlignment(1,2,0); 252 | word.setCellFontSize(1,2,6,10); 253 | word.setCellString(1,2,6,exp_vacuum_); 254 | 255 | //第三行数据设置 256 | word.setCellFontBold(1,3,1,false); //设置是否粗体 257 | // word.setTableAutoFitBehavior(0); //自动拉伸列 258 | // word.setColumnWidth(1,2,30); 259 | word.setRowAlignment(1,3,0); 260 | word.setCellFontSize(1,3,1,10); 261 | word.setCellString(1,3,1,tr("测试时间")); 262 | 263 | word.setCellFontBold(1,3,2,false); //设置是否粗体 264 | word.setRowAlignment(1,3,0); 265 | word.setCellFontSize(1,3,2,10); 266 | word.setCellString(1,3,2,exp_time_); 267 | 268 | word.setCellFontBold(1,3,3,false); //设置是否粗体 269 | word.setRowAlignment(1,3,0); 270 | word.setCellFontSize(1,3,3,10); 271 | word.setCellString(1,3,3,tr("测试地点")); 272 | 273 | word.setCellFontBold(1,3,4,false); //设置是否粗体 274 | word.setRowAlignment(1,3,0); 275 | word.setCellFontSize(1,3,4,10); 276 | word.setCellString(1,3,4,exp_address_); 277 | 278 | word.setCellFontBold(1,3,5,false); //设置是否粗体 279 | // word.setTableAutoFitBehavior(0); //自动拉伸列 280 | // word.setColumnWidth(1,3,60); 281 | word.setRowAlignment(1,3,0); 282 | word.setCellFontSize(1,3,5,10); 283 | word.setCellString(1,3,5,tr("测试人员")); 284 | 285 | word.setCellFontBold(1,3,6,false); //设置是否粗体 286 | word.setRowAlignment(1,3,0); 287 | word.setCellFontSize(1,3,6,10); 288 | word.setCellString(1,3,6,this->usr_name_); 289 | 290 | //第四行数据设置 291 | word.setCellFontBold(1,4,1,false); //设置是否粗体 292 | word.setRowAlignment(1,4,0); 293 | word.setCellFontSize(1,4,1,8); 294 | word.setCellString(1,4,1,tr("序号")); 295 | 296 | word.setCellFontBold(1,4,2,false); //设置是否粗体 297 | word.setRowAlignment(1,4,0); 298 | word.setCellFontSize(1,4,2,8); 299 | word.setCellString(1,4,2,tr("测试项目")); 300 | 301 | word.setCellFontBold(1,4,3,false); //设置是否粗体 302 | word.setRowAlignment(1,4,0); 303 | word.setCellFontSize(1,4,3,8); 304 | word.setCellString(1,4,3,tr("指标值")); 305 | 306 | word.setCellFontBold(1,4,4,false); //设置是否粗体 307 | word.setRowAlignment(1,4,0); 308 | word.setCellFontSize(1,4,4,8); 309 | word.setCellString(1,4,4,tr("实测(计算)值")); 310 | 311 | word.setCellFontBold(1,4,5,false); //设置是否粗体 312 | word.setRowAlignment(1,4,0); 313 | word.setCellFontSize(1,4,5,8); 314 | word.setCellString(1,4,5,tr("指令转速")); 315 | 316 | word.setCellFontBold(1,4,6,false); //设置是否粗体 317 | word.setRowAlignment(1,4,0); 318 | word.setCellFontSize(1,4,6,8); 319 | word.setCellString(1,4,6,tr("结论")); 320 | 321 | word.setCellFontBold(1,4,7,false); //设置是否粗体 322 | word.setRowAlignment(1,4,0); 323 | word.setCellFontSize(1,4,7,8); 324 | word.setCellString(1,4,7,tr("备注")); 325 | //第五行数据 326 | word.setCellFontBold(1,5,1,false); //设置是否粗体 327 | word.setRowAlignment(1,5,0); 328 | word.setCellFontSize(1,5,1,8); 329 | word.setCellString(1,5,1,tr("1")); 330 | 331 | word.setCellFontBold(1,5,2,false); //设置是否粗体 332 | word.setRowAlignment(1,5,0); 333 | word.setCellFontSize(1,5,2,8); 334 | word.setCellString(1,5,2,tr("转速控制特性n(-6000~6000rpm)")); 335 | 336 | word.setCellFontBold(1,5,3,false); //设置是否粗体 337 | word.setRowAlignment(1,5,0); 338 | word.setCellFontSize(1,5,3,8); 339 | word.setCellString(1,5,3,tr("角动量控制偏差△H:≤0.002Nms常量偏差:≤0.005Nms")); 340 | 341 | word.setCellFontBold(1,5,10,false); //设置是否粗体 342 | word.setRowAlignment(1,5,0); 343 | word.setCellFontSize(1,5,10,8); 344 | word.setCellString(1,5,10,tr("转速可取多个数的平均值")); 345 | 346 | word.setCellFontBold(1,5,4,false); //设置是否粗体 347 | word.setRowAlignment(1,5,0); 348 | word.setCellFontSize(1,5,4,8); 349 | word.setCellString(1,5,4,tr("串口")); 350 | 351 | word.setCellFontBold(1,5,5,false); //设置是否粗体 352 | word.setRowAlignment(1,5,0); 353 | word.setCellFontSize(1,5,5,8); 354 | word.setCellString(1,5,5,tr("地测")); 355 | 356 | word.setCellFontBold(1,5,6,false); //设置是否粗体 357 | word.setRowAlignment(1,5,0); 358 | word.setCellFontSize(1,5,6,8); 359 | word.setCellString(1,5,6,tr("常值偏差")); 360 | 361 | word.setCellFontBold(1,5,7,false); //设置是否粗体 362 | word.setRowAlignment(1,5,0); 363 | word.setCellFontSize(1,5,7,8); 364 | word.setCellString(1,5,7,tr("△H偏差")); 365 | int cur_idx = 6; 366 | //第六行 367 | //速度测试:向表里填数据 m_test_unit_setspd_.size() 368 | for (int spd_idx =0;spd_idx < 13;++spd_idx,++cur_idx){ 369 | //写指令转速 370 | word.setCellFontBold(1,cur_idx,8,false); //设置是否粗体 371 | word.setRowAlignment(1,cur_idx,0); 372 | word.setCellFontSize(1,cur_idx,8,8); 373 | word.setCellString(1,cur_idx,8,QString::number(m_test_unit_setspd_.at(spd_idx))); 374 | //写串口 375 | word.setCellFontBold(1,cur_idx,4,false); //设置是否粗体 376 | word.setRowAlignment(1,cur_idx,0); 377 | word.setCellFontSize(1,cur_idx,4,8); 378 | word.setCellString(1,cur_idx,4,QString::number(m_result_spd_.at(spd_idx).at(0))); 379 | //写常值偏差 380 | word.setCellFontBold(1,cur_idx,6,false); //设置是否粗体 381 | word.setRowAlignment(1,cur_idx,0); 382 | word.setCellFontSize(1,cur_idx,6,8); 383 | word.setCellString(1,cur_idx,6,QString::number(m_result_spd_.at(spd_idx).at(1))); 384 | //写动态偏差 385 | word.setCellFontBold(1,cur_idx,7,false); //设置是否粗体 386 | word.setRowAlignment(1,cur_idx,0); 387 | word.setCellFontSize(1,cur_idx,7,8); 388 | word.setCellString(1,cur_idx,7,QString::number(m_result_spd_.at(spd_idx).at(2))); 389 | } 390 | cur_idx = 37; 391 | for (int spd_idx =0;spd_idx < 10;++spd_idx,cur_idx++){ 392 | //写指令转速 393 | word.setCellFontBold(1,cur_idx,6,false); //设置是否粗体 394 | word.setRowAlignment(1,cur_idx,0); 395 | word.setCellFontSize(1,cur_idx,6,8); 396 | word.setCellString(1,cur_idx,6,QString::number(m_test_unit_setspd_.at(spd_idx))); 397 | //写串口 398 | word.setCellFontBold(1,cur_idx,4,false); //设置是否粗体 399 | word.setRowAlignment(1,cur_idx,0); 400 | word.setCellFontSize(1,cur_idx,4,8); 401 | word.setCellString(1,cur_idx,4,QString::number(m_result_cur_.at(spd_idx).at(0))); 402 | //写常值偏差 403 | word.setCellFontBold(1,cur_idx,5,false); //设置是否粗体 404 | word.setRowAlignment(1,cur_idx,0); 405 | word.setCellFontSize(1,cur_idx,5,8); 406 | word.setCellString(1,cur_idx,5,QString::number(m_result_cur_.at(spd_idx).at(1))); 407 | } 408 | 409 | word.setCellFontBold(1,19,1,false); //设置是否粗体 410 | word.setRowAlignment(1,19,0); 411 | word.setCellFontSize(1,19,1,8); 412 | word.setCellString(1,19,1,tr("2")); 413 | 414 | word.setCellFontBold(1,19,2,false); //设置是否粗体 415 | word.setRowAlignment(1,19,0); 416 | word.setCellFontSize(1,19,2,8); 417 | word.setCellString(1,19,2,tr("最大反作用力矩T")); 418 | 419 | word.setCellFontBold(1,19,3,false); //设置是否粗体 420 | word.setRowAlignment(1,19,0); 421 | word.setCellFontSize(1,19,3,8); 422 | word.setCellString(1,19,3,tr("绝对值≥0.1Nm")); 423 | 424 | word.setCellFontBold(1,19,5,false); //设置是否粗体 425 | word.setRowAlignment(1,19,0); 426 | word.setCellFontSize(1,19,5,8); 427 | word.setCellString(1,19,5,tr("斜坡指令±60rpm 采样时间取0.4s")); 428 | 429 | word.setCellFontBold(1,19,7,false); //设置是否粗体 430 | word.setRowAlignment(1,19,0); 431 | word.setCellFontSize(1,19,7,8); 432 | word.setCellString(1,19,7,tr("可取多次平均")); 433 | 434 | word.setCellFontBold(1,20,1,false); //设置是否粗体 435 | word.setRowAlignment(1,20,0); 436 | word.setCellFontSize(1,20,1,8); 437 | word.setCellString(1,20,1,tr("3")); 438 | 439 | word.setCellFontBold(1,20,2,false); //设置是否粗体 440 | word.setRowAlignment(1,20,0); 441 | word.setCellFontSize(1,20,2,8); 442 | word.setCellString(1,20,2,tr("稳压功耗P(133Pa下)")); 443 | 444 | word.setCellFontBold(1,20,3,false); //设置是否粗体 445 | word.setRowAlignment(1,20,0); 446 | word.setCellFontSize(1,20,3,8); 447 | word.setCellString(1,20,3,tr("≤7.5W")); 448 | 449 | word.setCellFontBold(1,23,3,false); //设置是否粗体 450 | word.setRowAlignment(1,23,0); 451 | word.setCellFontSize(1,23,3,8); 452 | word.setCellString(1,23,3,tr("≤15W")); 453 | 454 | word.setCellFontBold(1,20,7,false); //设置是否粗体 455 | word.setRowAlignment(1,20,0); 456 | word.setCellFontSize(1,20,7,8); 457 | word.setCellString(1,20,7,tr("P=U*I, U、I可取多个数的平均值")); 458 | word.setCellFontBold(1,23,3,false); //设置是否粗体 459 | word.setRowAlignment(1,23,0); 460 | word.setCellFontSize(1,23,3,8); 461 | word.setCellString(1,23,3,tr("≤15W")); 462 | //第八行 463 | word.setCellFontBold(1,25,1,false); //设置是否粗体 464 | word.setRowAlignment(1,25,0); 465 | word.setCellFontSize(1,25,1,8); 466 | word.setCellString(1,25,1,tr("4")); 467 | 468 | word.setCellFontBold(1,25,2,false); //设置是否粗体 469 | word.setRowAlignment(1,25,0); 470 | word.setCellFontSize(1,25,2,8); 471 | word.setCellString(1,25,2,tr("最大功耗Pmax")); 472 | 473 | word.setCellFontBold(1,25,3,false); //设置是否粗体 474 | word.setRowAlignment(1,25,0); 475 | word.setCellFontSize(1,25,3,8); 476 | word.setCellString(1,25,3,tr("≤100W")); 477 | 478 | word.setCellFontBold(1,25,5,false); //设置是否粗体 479 | word.setRowAlignment(1,25,0); 480 | word.setCellFontSize(1,25,5,8); 481 | word.setCellString(1,25,5,tr("按±(0.1±0.01)Nm加减速")); 482 | 483 | //第九行 484 | word.setCellFontBold(1,26,1,false); //设置是否粗体 485 | word.setRowAlignment(1,26,0); 486 | word.setCellFontSize(1,26,1,8); 487 | word.setCellString(1,26,1,tr("5")); 488 | 489 | word.setCellFontBold(1,26,2,false); //设置是否粗体 490 | word.setRowAlignment(1,26,0); 491 | word.setCellFontSize(1,26,2,8); 492 | word.setCellString(1,26,2,tr("最大角动量Hmax")); 493 | 494 | word.setCellFontBold(1,26,3,false); //设置是否粗体 495 | word.setRowAlignment(1,26,0); 496 | word.setCellFontSize(1,26,3,8); 497 | word.setCellString(1,26,3,tr("≥4Nms")); 498 | 499 | word.setCellFontBold(1,26,5,false); //设置是否粗体 500 | word.setRowAlignment(1,26,0); 501 | word.setCellFontSize(1,26,5,8); 502 | word.setCellString(1,26,5,tr("转速绝对值≥6000rpm")); 503 | 504 | //第十行 505 | word.setCellFontBold(1,27,1,false); //设置是否粗体 506 | word.setRowAlignment(1,27,0); 507 | word.setCellFontSize(1,27,1,8); 508 | word.setCellString(1,27,1,tr("6")); 509 | 510 | word.setCellFontBold(1,27,2,false); //设置是否粗体 511 | word.setRowAlignment(1,27,0); 512 | word.setCellFontSize(1,27,2,8); 513 | word.setCellString(1,27,2,tr("力矩控制特性n(-5500~5500rpm)")); 514 | 515 | word.setCellFontBold(1,27,3,false); //设置是否粗体 516 | word.setRowAlignment(1,27,0); 517 | word.setCellFontSize(1,27,3,8); 518 | word.setCellString(1,27,3,tr("电流控制允许偏差绝对值≤0.24A,实测输出力矩绝对值≥|Tc|-10mNm")); 519 | 520 | word.setCellFontBold(1,27,4,false); //设置是否粗体 521 | word.setRowAlignment(1,27,0); 522 | word.setCellFontSize(1,27,4,8); 523 | word.setCellString(1,27,4,tr("实测(计算)值")); 524 | 525 | word.setCellFontBold(1,28,4,false); //设置是否粗体 526 | word.setRowAlignment(1,28,0); 527 | word.setCellFontSize(1,28,4,8); 528 | word.setCellString(1,28,4,tr("实测电机电流")); 529 | 530 | word.setCellFontBold(1,28,5,false); //设置是否粗体 531 | word.setRowAlignment(1,28,0); 532 | word.setCellFontSize(1,28,5,8); 533 | word.setCellString(1,28,5,tr("实测输出力矩")); 534 | 535 | word.setCellFontBold(1,28,6,false); //设置是否粗体 536 | word.setRowAlignment(1,28,0); 537 | word.setCellFontSize(1,28,6,8); 538 | word.setCellString(1,28,6,tr("力矩控制指令Tc")); 539 | 540 | word.setCellFontBold(1,28,8,false); //设置是否粗体 541 | word.setRowAlignment(1,28,0); 542 | word.setCellFontSize(1,28,8,8); 543 | word.setCellString(1,28,8,tr("可取多次平均")); 544 | 545 | //第十一行 546 | word.setCellFontBold(1,36,1,false); //设置是否粗体 547 | word.setRowAlignment(1,36,0); 548 | word.setCellFontSize(1,36,1,8); 549 | word.setCellString(1,36,1,tr("7")); 550 | 551 | word.setCellFontBold(1,36,2,false); //设置是否粗体 552 | word.setRowAlignment(1,36,0); 553 | word.setCellFontSize(1,36,2,8); 554 | word.setCellString(1,36,2,tr("转速模式电机电流")); 555 | 556 | word.setCellFontBold(1,36,3,false); //设置是否粗体 557 | word.setRowAlignment(1,36,0); 558 | word.setCellFontSize(1,36,3,8); 559 | word.setCellString(1,36,3,tr("≤3.2A")); 560 | 561 | word.setCellFontBold(1,36,4,false); //设置是否粗体 562 | word.setRowAlignment(1,36,0); 563 | word.setCellFontSize(1,36,4,8); 564 | word.setCellString(1,36,4,tr("测试口总电流")); 565 | 566 | word.setCellFontBold(1,36,5,false); //设置是否粗体 567 | word.setRowAlignment(1,36,0); 568 | word.setCellFontSize(1,36,5,8); 569 | word.setCellString(1,36,5,tr("实测电机电流")); 570 | 571 | word.setCellFontBold(1,36,6,false); //设置是否粗体 572 | word.setRowAlignment(1,36,0); 573 | word.setCellFontSize(1,36,6,8); 574 | word.setCellString(1,36,6,tr("转速指令")); 575 | 576 | // word.setCellFontBold(1,46,6,false); //设置是否粗体 577 | // word.setRowAlignment(1,46,0); 578 | // word.setCellFontSize(1,46,6,8); 579 | // word.setCellString(1,46,6,tr("按±(0.1±0.01)Nm加减速")); 580 | 581 | word.setCellFontBold(1,36,8,false); //设置是否粗体 582 | word.setRowAlignment(1,36,0); 583 | word.setCellFontSize(1,36,8,8); 584 | word.setCellString(1,36,8,tr("I可取多个数的平均值")); 585 | 586 | //第十二行 587 | word.setCellFontBold(1,47,1,false); //设置是否粗体 588 | word.setRowAlignment(1,47,0); 589 | word.setCellFontSize(1,47,1,8); 590 | word.setCellString(1,47,1,tr("8")); 591 | 592 | word.setCellFontBold(1,47,2,false); //设置是否粗体 593 | word.setRowAlignment(1,47,0); 594 | word.setCellFontSize(1,47,2,8); 595 | word.setCellString(1,47,2,tr("启动摩擦力矩")); 596 | 597 | word.setCellFontBold(1,47,3,false); //设置是否粗体 598 | word.setRowAlignment(1,47,0); 599 | word.setCellFontSize(1,47,3,8); 600 | word.setCellString(1,47,3,tr("≤10mNm")); 601 | 602 | word.setCellFontBold(1,47,5,false); //设置是否粗体 603 | word.setRowAlignment(1,47,0); 604 | word.setCellFontSize(1,47,5,8); 605 | word.setCellString(1,47,5,tr("0rpm条件下发送力矩指令")); 606 | 607 | word.setCellFontBold(1,47,7,false); //设置是否粗体 608 | word.setRowAlignment(1,47,0); 609 | word.setCellFontSize(1,47,7,8); 610 | word.setCellString(1,47,7,tr("可取多次平均")); 611 | 612 | //第十三行 613 | word.setCellFontBold(1,48,1,false); //设置是否粗体 614 | word.setRowAlignment(1,48,0); 615 | word.setCellFontSize(1,48,1,8); 616 | word.setCellString(1,48,1,tr("9")); 617 | 618 | word.setCellFontBold(1,48,2,false); //设置是否粗体 619 | word.setRowAlignment(1,48,0); 620 | word.setCellFontSize(1,48,2,8); 621 | word.setCellString(1,48,2,tr("最大损失力矩")); 622 | 623 | word.setCellFontBold(1,48,3,false); //设置是否粗体 624 | word.setRowAlignment(1,48,0); 625 | word.setCellFontSize(1,48,3,8); 626 | word.setCellString(1,48,3,tr("≤15mNm")); 627 | 628 | word.setCellFontBold(1,48,5,false); //设置是否粗体 629 | word.setRowAlignment(1,48,0); 630 | word.setCellFontSize(1,48,5,8); 631 | word.setCellString(1,48,5,tr("分段滑行时测试")); 632 | 633 | word.setCellFontBold(1,48,7,false); //设置是否粗体 634 | word.setRowAlignment(1,48,0); 635 | word.setCellFontSize(1,48,7,8); 636 | word.setCellString(1,48,7,tr("分段多次平均")); 637 | 638 | //第十四行 639 | word.setCellFontBold(1,49,1,false); //设置是否粗体 640 | word.setRowAlignment(1,49,0); 641 | word.setCellFontSize(1,49,1,8); 642 | word.setCellString(1,49,1,tr("10")); 643 | 644 | word.setCellFontBold(1,49,2,false); //设置是否粗体 645 | word.setRowAlignment(1,49,0); 646 | word.setCellFontSize(1,49,2,8); 647 | word.setCellString(1,49,2,tr("力矩响应时间")); 648 | 649 | word.setCellFontBold(1,49,3,false); //设置是否粗体 650 | word.setRowAlignment(1,49,0); 651 | word.setCellFontSize(1,49,3,8); 652 | word.setCellString(1,49,3,tr("≤20ms")); 653 | 654 | word.setCellFontBold(1,49,5,false); //设置是否粗体 655 | word.setRowAlignment(1,49,0); 656 | word.setCellFontSize(1,49,5,8); 657 | word.setCellString(1,49,5,tr("由力矩控制模式条件下测试")); 658 | word.setCellFontBold(1,50,1,false); //设置是否粗体 659 | word.setRowAlignment(1,50,0); 660 | word.setCellFontSize(1,50,1,8); 661 | word.setCellString(1,50,1,tr("11")); 662 | 663 | word.setCellFontBold(1,50,2,false); //设置是否粗体 664 | word.setRowAlignment(1,50,0); 665 | word.setCellFontSize(1,50,2,8); 666 | word.setCellString(1,50,2,tr("整机滑行时间")); 667 | 668 | word.setCellFontBold(1,50,3,false); //设置是否粗体 669 | word.setRowAlignment(1,50,0); 670 | word.setCellFontSize(1,50,3,8); 671 | word.setCellString(1,50,3,tr("不少于20min")); 672 | //第十五行 673 | word.setCellFontBold(1,51,1,false); //设置是否粗体 674 | word.setRowAlignment(1,51,0); 675 | word.setCellFontSize(1,51,1,8); 676 | word.setCellString(1,51,1,tr("12")); 677 | 678 | word.setCellFontBold(1,51,2,false); //设置是否粗体 679 | word.setRowAlignment(1,51,0); 680 | word.setCellFontSize(1,51,2,8); 681 | word.setCellString(1,51,2,tr("浪涌电流测试")); 682 | 683 | word.setCellFontBold(1,51,3,false); //设置是否粗体 684 | word.setRowAlignment(1,51,0); 685 | word.setCellFontSize(1,51,3,8); 686 | word.setCellString(1,51,3,tr("≤3A,15ms")); 687 | 688 | word.setCellFontSize(1,52,1,8); 689 | word.setRowAlignment(52,1,0);//设置行的对其方式 690 | word.setCellString(1,52,1,tr("注1:改性能测试采用软件自动测试。注2:测试时真空度要保持在133Pa以下。")); 691 | // save and close file 692 | word.setVisible(false); 693 | word.saveAs(); 694 | word.close(); 695 | 696 | emit logMsg(tr("生成报告:测试报表已生成!(100%),存储地址:%1").arg(save_path)); 697 | } 698 | 699 | 700 | void QMotorReport::getDataFromSql(const QVector > &res) 701 | { 702 | if (res.empty()) return; 703 | setExpInfomation(*res.begin()); 704 | for (int i =1;i < res.size();++i){ 705 | const QVector& data = res.at(i); 706 | this->flywheel_vol_.push_back(data[5].toDouble()); 707 | this->flywheel_cur_.push_back(data[6].toDouble()); 708 | this->flywheel_setSpd_.push_back(data[7].toDouble()); 709 | this->flywheel_spd_.push_back(data[8].toDouble()); 710 | this->flywheel_setTor_.push_back(data[9].toDouble()); 711 | this->flywheel_tor_.push_back(data[10].toDouble()); 712 | this->flywheel_wate_.push_back( data[11].toDouble()); 713 | this->flywheel_JDL_.push_back( data[12].toDouble()); 714 | this->flywheel_JDL_dynamic_.push_back(data[13].toDouble()); 715 | this->flywheel_JDL_const_.push_back(data[14].toDouble()); 716 | this->flywheel_act_cur_.push_back(data[18].toDouble()); 717 | this->flywheel_mode_.push_back(data[15].toInt()); 718 | } 719 | emit logMsg(tr("生成报告:数据查询完毕(20%)")); 720 | 721 | 722 | initExpData(); 723 | calExpDataSetSpd(); 724 | 725 | createWordReport(); 726 | 727 | emit reportCreated(); 728 | } 729 | 730 | //初始化实验数据 731 | void QMotorReport::initExpData() 732 | { 733 | //提取setspd 734 | int idx = 0; 735 | QSet t_setspd; 736 | for (double &setspd:flywheel_setSpd_){ 737 | //0 -> spd mode 738 | if (flywheel_mode_.at(idx++) == 0) 739 | t_setspd.insert(setspd); 740 | } 741 | 742 | m_test_unit_setspd_.clear(); 743 | for (auto &set_spd:t_setspd){ 744 | m_test_unit_setspd_.push_back(set_spd); 745 | } 746 | 747 | //输出结果排序 748 | std::sort(m_test_unit_setspd_.begin(),m_test_unit_setspd_.end(),[](const double &a,const double &b){ 749 | return qAbs(a) < qAbs(b) || (qAbs(a) == qAbs(b) && a >= 0) ; 750 | }); 751 | 752 | 753 | } 754 | 755 | //计算速度实验数据 756 | void QMotorReport::calExpDataSetSpd() 757 | { 758 | for (int idx = 0;idx need_test_spd; 763 | QVector jdl_const; 764 | QVector jdl_dynamic; 765 | QVector serial_cur; 766 | QVector daq_cur; 767 | for (int i =0;i < flywheel_setSpd_.size();++i){ 768 | if (flywheel_setSpd_.at(i) == current_set_spd && flywheel_mode_.at(i) == 0){ 769 | need_test_spd.push_back(flywheel_spd_.at(i)); 770 | jdl_const.push_back(flywheel_JDL_const_.at(i)); 771 | jdl_dynamic.push_back(flywheel_JDL_dynamic_.at(i)); 772 | serial_cur.push_back(flywheel_cur_.at(i)); 773 | daq_cur.push_back(flywheel_act_cur_.at(i)); 774 | } 775 | } 776 | 777 | //处理需要测试的数据 778 | //第一个处理速度 角动量常值偏差 动态偏差 779 | bool start_test = false; 780 | double avg_spd = 0; 781 | double avg_jdl_const = 0; 782 | double avg_jdl_dynamic = 0; 783 | double avg_cur = 0; 784 | double avg_act_cur = 0; 785 | uint data_num = 0; 786 | for (int i = 0;i < need_test_spd.size();++i){ 787 | double spd = need_test_spd.at(i); 788 | if (start_test == false && qAbs((spd) - (current_set_spd)) > 1){ 789 | continue; 790 | } 791 | else{ 792 | start_test = true; 793 | } 794 | 795 | avg_spd += spd; 796 | avg_jdl_const += jdl_const.at(i); 797 | avg_jdl_dynamic += jdl_dynamic.at(i); 798 | avg_cur += serial_cur.at(i); 799 | avg_act_cur += daq_cur.at(i); 800 | data_num++; 801 | } 802 | QVector tmp_res; 803 | tmp_res.push_back(avg_spd / data_num); 804 | tmp_res.push_back(avg_jdl_const / data_num); 805 | tmp_res.push_back(avg_jdl_dynamic / data_num); 806 | m_result_spd_.push_back(tmp_res); 807 | 808 | tmp_res.clear(); 809 | tmp_res.push_back(avg_cur / data_num); 810 | tmp_res.push_back(avg_act_cur / data_num); 811 | 812 | m_result_cur_.push_back(tmp_res); 813 | 814 | } 815 | emit logMsg(tr("生成报告:数据计算完毕(50%)")); 816 | } 817 | -------------------------------------------------------------------------------- /D2kDask.h: -------------------------------------------------------------------------------- 1 | #ifndef _D2K_DASK_H 2 | #define _D2K_DASK_H 3 | 4 | 5 | 6 | #ifdef __cplusplus 7 | namespace DAQCARD { 8 | 9 | 10 | extern "C" { 11 | #endif 12 | 13 | typedef void* HANDLE; 14 | typedef bool BOOLEAN; 15 | 16 | //DAQ2000 Device 17 | #define DAQ_2010 1 18 | #define DAQ_2205 2 19 | #define DAQ_2206 3 20 | #define DAQ_2005 4 21 | #define DAQ_2204 5 22 | #define DAQ_2006 6 23 | #define DAQ_2501 7 24 | #define DAQ_2502 8 25 | #define DAQ_2208 9 26 | #define DAQ_2213 10 27 | #define DAQ_2214 11 28 | #define DAQ_2016 12 29 | #define DAQ_2020 13 30 | #define DAQ_2022 14 31 | 32 | #ifndef __DaskConst 33 | #define __DaskConst 34 | //DASK Data Types 35 | typedef unsigned char U8; 36 | typedef short I16; 37 | typedef unsigned short U16; 38 | typedef long I32; 39 | typedef unsigned long U32; 40 | typedef float F32; 41 | typedef double F64; 42 | 43 | #define MAX_CARD 32 44 | 45 | //Error Number 46 | //#define NoError 0 47 | #define ErrorUnknownCardType -1 48 | #define ErrorInvalidCardNumber -2 49 | #define ErrorTooManyCardRegistered -3 50 | #define ErrorCardNotRegistered -4 51 | #define ErrorFuncNotSupport -5 52 | #define ErrorInvalidIoChannel -6 53 | #define ErrorInvalidAdRange -7 54 | #define ErrorContIoNotAllowed -8 55 | #define ErrorDiffRangeNotSupport -9 56 | #define ErrorLastChannelNotZero -10 57 | #define ErrorChannelNotDescending -11 58 | #define ErrorChannelNotAscending -12 59 | #define ErrorOpenDriverFailed -13 60 | #define ErrorOpenEventFailed -14 61 | #define ErrorTransferCountTooLarge -15 62 | #define ErrorNotDoubleBufferMode -16 63 | #define ErrorInvalidSampleRate -17 64 | #define ErrorInvalidCounterMode -18 65 | #define ErrorInvalidCounter -19 66 | #define ErrorInvalidCounterState -20 67 | #define ErrorInvalidBinBcdParam -21 68 | #define ErrorBadCardType -22 69 | #define ErrorInvalidDaRefVoltage -23 70 | #define ErrorAdTimeOut -24 71 | #define ErrorNoAsyncAI -25 72 | #define ErrorNoAsyncAO -26 73 | #define ErrorNoAsyncDI -27 74 | #define ErrorNoAsyncDO -28 75 | #define ErrorNotInputPort -29 76 | #define ErrorNotOutputPort -30 77 | #define ErrorInvalidDioPort -31 78 | #define ErrorInvalidDioLine -32 79 | #define ErrorContIoActive -33 80 | #define ErrorDblBufModeNotAllowed -34 81 | #define ErrorConfigFailed -35 82 | #define ErrorInvalidPortDirection -36 83 | #define ErrorBeginThreadError -37 84 | #define ErrorInvalidPortWidth -38 85 | #define ErrorInvalidCtrSource -39 86 | #define ErrorOpenFile -40 87 | #define ErrorAllocateMemory -41 88 | #define ErrorDaVoltageOutOfRange -42 89 | #define ErrorInvalidSyncMode -43 90 | #define ErrorInvalidBufferID -44 91 | #define ErrorInvalidCNTInterval -45 92 | #define ErrorReTrigModeNotAllowed -46 93 | #define ErrorResetBufferNotAllowed -47 94 | #define ErrorAnaTriggerLevel -48 95 | #define ErrorDAQEvent -49 96 | #define ErrorInvalidCounterValue -50 97 | #define ErrorOffsetCalibration -51 98 | #define ErrorGainCalibration -52 99 | #define ErrorCountOutofSDRAMSize -53 100 | #define ErrorNotStartTriggerModule -54 101 | #define ErrorInvalidRouteLine -55 102 | #define ErrorInvalidSignalCode -56 103 | #define ErrorInvalidSignalDirection -57 104 | #define ErrorTRGOSCalibration -58 105 | #define ErrorNoSDRAM -59 106 | #define ErrorIntegrationGain -60 107 | #define ErrorAcquisitionTiming -61 108 | #define ErrorIntegrationTiming -62 109 | #define ErrorInvalidTimeBase -70 110 | #define ErrorUndefinedParameter -71 111 | //Error number for calibration API 112 | #define ErrorCalAddress -110 113 | #define ErrorInvalidCalBank -111 114 | //Error number for driver API 115 | #define ErrorConfigIoctl -201 116 | #define ErrorAsyncSetIoctl -202 117 | #define ErrorDBSetIoctl -203 118 | #define ErrorDBHalfReadyIoctl -204 119 | #define ErrorContOPIoctl -205 120 | #define ErrorContStatusIoctl -206 121 | #define ErrorPIOIoctl -207 122 | #define ErrorDIntSetIoctl -208 123 | #define ErrorWaitEvtIoctl -209 124 | #define ErrorOpenEvtIoctl -210 125 | #define ErrorCOSIntSetIoctl -211 126 | #define ErrorMemMapIoctl -212 127 | #define ErrorMemUMapSetIoctl -213 128 | #define ErrorCTRIoctl -214 129 | #define ErrorGetResIoctl -215 130 | 131 | #define TRUE 1 132 | #define FALSE 0 133 | 134 | //Synchronous Mode 135 | #define SYNCH_OP 1 136 | #define ASYNCH_OP 2 137 | 138 | //AD Range 139 | #define AD_B_10_V 1 140 | #define AD_B_5_V 2 141 | #define AD_B_2_5_V 3 142 | #define AD_B_1_25_V 4 143 | #define AD_B_0_625_V 5 144 | #define AD_B_0_3125_V 6 145 | #define AD_B_0_5_V 7 146 | #define AD_B_0_05_V 8 147 | #define AD_B_0_005_V 9 148 | #define AD_B_1_V 10 149 | #define AD_B_0_1_V 11 150 | #define AD_B_0_01_V 12 151 | #define AD_B_0_001_V 13 152 | #define AD_U_20_V 14 153 | #define AD_U_10_V 15 154 | #define AD_U_5_V 16 155 | #define AD_U_2_5_V 17 156 | #define AD_U_1_25_V 18 157 | #define AD_U_1_V 19 158 | #define AD_U_0_1_V 20 159 | #define AD_U_0_01_V 21 160 | #define AD_U_0_001_V 22 161 | #define AD_B_2_V 23 162 | #define AD_B_0_25_V 24 163 | #define AD_B_0_2_V 25 164 | #define AD_U_4_V 26 165 | #define AD_U_2_V 27 166 | #define AD_U_0_5_V 28 167 | #define AD_U_0_4_V 29 168 | 169 | //DIO Port Direction 170 | #define INPUT_PORT 1 171 | #define OUTPUT_PORT 2 172 | //DIO Line Direction 173 | #define INPUT_LINE 1 174 | #define OUTPUT_LINE 2 175 | //Channel & Port 176 | #define Channel_P1A 0 177 | #define Channel_P1B 1 178 | #define Channel_P1C 2 179 | #define Channel_P1CL 3 180 | #define Channel_P1CH 4 181 | #define Channel_P1AE 10 182 | #define Channel_P1BE 11 183 | #define Channel_P1CE 12 184 | #define Channel_P2A 5 185 | #define Channel_P2B 6 186 | #define Channel_P2C 7 187 | #define Channel_P2CL 8 188 | #define Channel_P2CH 9 189 | #define Channel_P2AE 15 190 | #define Channel_P2BE 16 191 | #define Channel_P2CE 17 192 | #define Channel_P3A 10 193 | #define Channel_P3B 11 194 | #define Channel_P3C 12 195 | #define Channel_P3CL 13 196 | #define Channel_P3CH 14 197 | #define Channel_P4A 15 198 | #define Channel_P4B 16 199 | #define Channel_P4C 17 200 | #define Channel_P4CL 18 201 | #define Channel_P4CH 19 202 | #define Channel_P5A 20 203 | #define Channel_P5B 21 204 | #define Channel_P5C 22 205 | #define Channel_P5CL 23 206 | #define Channel_P5CH 24 207 | #define Channel_P6A 25 208 | #define Channel_P6B 26 209 | #define Channel_P6C 27 210 | #define Channel_P6CL 28 211 | #define Channel_P6CH 29 212 | 213 | #endif 214 | /*-------- Constants for DAQ2000 --------------------*/ 215 | 216 | #define All_Channels -1 217 | #define BufferNotUsed -1 218 | /* Constants for Analog trigger */ 219 | /* define analog trigger condition constants */ 220 | #define Below_Low_level 0x0000 221 | #define Above_High_Level 0x0100 222 | #define Inside_Region 0x0200 223 | #define High_Hysteresis 0x0300 224 | #define Low_Hysteresis 0x0400 225 | /* define analog trigger Dedicated Channel */ 226 | #define CH0ATRIG 0x00 227 | #define CH1ATRIG 0x02 228 | #define CH2ATRIG 0x04 229 | #define CH3ATRIG 0x06 230 | #define EXTATRIG 0x01 231 | #define ADCATRIG 0x00 //used for DAQ-2205/2206 232 | /* Time Base */ 233 | #define DAQ2K_IntTimeBase 0x00 234 | #define DAQ2K_ExtTimeBase 0x01 235 | #define DAQ2K_SSITimeBase 0x02 236 | #define DAQ2K_ExtTimeBase_AFI0 0x3 237 | #define DAQ2K_ExtTimeBase_AFI1 0x4 238 | #define DAQ2K_ExtTimeBase_AFI2 0x5 239 | #define DAQ2K_ExtTimeBase_AFI3 0x6 240 | #define DAQ2K_ExtTimeBase_AFI4 0x7 241 | #define DAQ2K_ExtTimeBase_AFI5 0x8 242 | #define DAQ2K_ExtTimeBase_AFI6 0x9 243 | #define DAQ2K_ExtTimeBase_AFI7 0xa 244 | #define DAQ2K_PXI_CLK 0xc 245 | #define DAQ2K_StarTimeBase 0xd 246 | #define DAQ2K_SMBTimeBase 0xe 247 | 248 | /* Constants for AD */ 249 | #define DAQ2K_AI_ADSTARTSRC_Int 0x00 250 | #define DAQ2K_AI_ADSTARTSRC_AFI0 0x10 251 | #define DAQ2K_AI_ADSTARTSRC_SSI 0x20 252 | 253 | #define DAQ2K_AI_ADCONVSRC_Int 0x00 254 | #define DAQ2K_AI_ADCONVSRC_AFI0 0x04 255 | #define DAQ2K_AI_ADCONVSRC_SSI 0x08 256 | #define DAQ2K_AI_ADCONVSRC_AFI1 0x0C 257 | 258 | #define DAQ2K_AI_ADCONVSRC_AFI2 0x100 259 | #define DAQ2K_AI_ADCONVSRC_AFI3 DAQ2K_AI_ADCONVSRC_AFI2+0x100 260 | #define DAQ2K_AI_ADCONVSRC_AFI4 DAQ2K_AI_ADCONVSRC_AFI2+0x200 261 | #define DAQ2K_AI_ADCONVSRC_AFI5 DAQ2K_AI_ADCONVSRC_AFI2+0x300 262 | #define DAQ2K_AI_ADCONVSRC_AFI6 DAQ2K_AI_ADCONVSRC_AFI2+0x400 263 | #define DAQ2K_AI_ADCONVSRC_AFI7 DAQ2K_AI_ADCONVSRC_AFI2+0x500 264 | 265 | #define DAQ2K_AI_ADCONVSRC_PFI0 DAQ2K_AI_ADCONVSRC_AFI0 266 | 267 | //AI Delay Counter SRC: only available for DAQ-250X 268 | #define DAQ2K_AI_DTSRC_Int 0x00 269 | #define DAQ2K_AI_DTSRC_AFI1 0x10 270 | #define DAQ2K_AI_DTSRC_GPTC0 0x20 271 | #define DAQ2K_AI_DTSRC_GPTC1 0x30 272 | 273 | #define DAQ2K_AI_TRGSRC_SOFT 0x00 274 | #define DAQ2K_AI_TRGSRC_ANA 0x01 275 | #define DAQ2K_AI_TRGSRC_ExtD 0x02 276 | #define DAQ2K_AI_TRSRC_SSI 0x03 277 | #define DAQ2K_AI_TRGMOD_POST 0x00 //Post Trigger Mode 278 | #define DAQ2K_AI_TRGMOD_DELAY 0x08 //Delay Trigger Mode 279 | #define DAQ2K_AI_TRGMOD_PRE 0x10 //Pre-Trigger Mode 280 | #define DAQ2K_AI_TRGMOD_MIDL 0x18 //Middle Trigger Mode 281 | #define DAQ2K_AI_ReTrigEn 0x80 282 | #define DAQ2K_AI_Dly1InSamples 0x100 283 | #define DAQ2K_AI_Dly1InTimebase 0x000 284 | #define DAQ2K_AI_MCounterEn 0x400 285 | #define DAQ2K_AI_TrgPositive 0x0000 286 | #define DAQ2K_AI_TrgNegative 0x1000 287 | 288 | #define DAQ2K_AI_TRGSRC_AFI0 0x10000 289 | #define DAQ2K_AI_TRGSRC_AFI1 DAQ2K_AI_TRGSRC_AFI0+0x10000 290 | #define DAQ2K_AI_TRGSRC_AFI2 DAQ2K_AI_TRGSRC_AFI0+0x20000 291 | #define DAQ2K_AI_TRGSRC_AFI3 DAQ2K_AI_TRGSRC_AFI0+0x30000 292 | #define DAQ2K_AI_TRGSRC_AFI4 DAQ2K_AI_TRGSRC_AFI0+0x40000 293 | #define DAQ2K_AI_TRGSRC_AFI5 DAQ2K_AI_TRGSRC_AFI0+0x50000 294 | #define DAQ2K_AI_TRGSRC_AFI6 DAQ2K_AI_TRGSRC_AFI0+0x60000 295 | #define DAQ2K_AI_TRGSRC_AFI7 DAQ2K_AI_TRGSRC_AFI0+0x70000 296 | #define DAQ2K_AI_TRGSRC_PXIStar DAQ2K_AI_TRGSRC_AFI0+0x90000 297 | #define DAQ2K_AI_TRGSRC_SMB DAQ2K_AI_TRGSRC_AFI0+0xa0000 298 | 299 | //AI Reference ground 300 | #define AI_RSE 0x0000 301 | #define AI_DIFF 0x0100 302 | #define AI_NRSE 0x0200 303 | /* Constants for DA */ 304 | //DA CH config constant 305 | #define DAQ2K_DA_BiPolar 0x1 306 | #define DAQ2K_DA_UniPolar 0x0 307 | #define DAQ2K_DA_Int_REF 0x0 308 | #define DAQ2K_DA_Ext_REF 0x1 309 | //DA control constant 310 | #define DAQ2K_DA_WRSRC_Int 0x00 311 | #define DAQ2K_DA_WRSRC_AFI1 0x01 312 | #define DAQ2K_DA_WRSRC_SSI 0x02 313 | 314 | #define DAQ2K_DA_WRSRC_PFI0 DAQ2K_DA_WRSRC_AFI0 315 | #define DAQ2K_DA_WRSRC_AFI0 DAQ2K_DA_WRSRC_AFI1 316 | //DA group 317 | #define DA_Group_A 0x00 318 | #define DA_Group_B 0x04 319 | #define DA_Group_AB 0x08 320 | //DA TD Counter SRC: only available for DAQ-250X 321 | #define DAQ2K_DA_TDSRC_Int 0x00 322 | #define DAQ2K_DA_TDSRC_AFI0 0x10 323 | #define DAQ2K_DA_TDSRC_GPTC0 0x20 324 | #define DAQ2K_DA_TDSRC_GPTC1 0x30 325 | //DA BD Counter SRC: only available for DAQ-250X 326 | #define DAQ2K_DA_BDSRC_Int 0x00 327 | #define DAQ2K_DA_BDSRC_AFI0 0x40 328 | #define DAQ2K_DA_BDSRC_GPTC0 0x80 329 | #define DAQ2K_DA_BDSRC_GPTC1 0xC0 330 | 331 | //DA trigger constant 332 | #define DAQ2K_DA_TRGSRC_SOFT 0x00 333 | #define DAQ2K_DA_TRGSRC_ANA 0x01 334 | #define DAQ2K_DA_TRGSRC_ExtD 0x02 335 | #define DAQ2K_DA_TRSRC_SSI 0x03 336 | #define DAQ2K_DA_TRGMOD_POST 0x00 337 | #define DAQ2K_DA_TRGMOD_DELAY 0x04 338 | #define DAQ2K_DA_ReTrigEn 0x20 339 | #define DAQ2K_DA_Dly1InUI 0x40 340 | #define DAQ2K_DA_Dly1InTimebase 0x00 341 | #define DAQ2K_DA_Dly2InUI 0x80 342 | #define DAQ2K_DA_Dly2InTimebase 0x00 343 | #define DAQ2K_DA_DLY2En 0x100 344 | #define DAQ2K_DA_TrgPositive 0x000 345 | #define DAQ2K_DA_TrgNegative 0x200 346 | 347 | //DA stop mode 348 | #define DAQ2K_DA_TerminateImmediate 0 349 | #define DAQ2K_DA_TerminateUC 1 350 | #define DAQ2K_DA_TerminateIC 2 351 | 352 | #define DAQ2K_DA_TerminateFIFORC DAQ2K_DA_TerminateIC 353 | //DA stop source : only available for DAQ-250X 354 | #define DAQ2K_DA_STOPSRC_SOFT 0 355 | #define DAQ2K_DA_STOPSRC_AFI0 1 356 | #define DAQ2K_DA_STOPSRC_ATrig 2 357 | #define DAQ2K_DA_STOPSRC_AFI1 3 358 | 359 | #ifndef __CTR8254Const 360 | #define __CTR8254Const 361 | /*-------- Timer/Counter -----------------------------*/ 362 | //Counter Mode (8254) 363 | #define TOGGLE_OUTPUT 0 //Toggle output from low to high on terminal count 364 | #define PROG_ONE_SHOT 1 //Programmable one-shot 365 | #define RATE_GENERATOR 2 //Rate generator 366 | #define SQ_WAVE_RATE_GENERATOR 3 //Square wave rate generator 367 | #define SOFT_TRIG 4 //Software-triggered strobe 368 | #define HARD_TRIG 5 //Hardware-triggered strobe 369 | //16-bit binary or 4-decade BCD counter 370 | #define BIN 0 371 | #define BCD 1 372 | #endif 373 | //General Purpose Timer/Counter 374 | //Counter Mode 375 | #define SimpleGatedEventCNT 0x01 376 | #define SinglePeriodMSR 0x02 377 | #define SinglePulseWidthMSR 0x03 378 | #define SingleGatedPulseGen 0x04 379 | #define SingleTrigPulseGen 0x05 380 | #define RetrigSinglePulseGen 0x06 381 | #define SingleTrigContPulseGen 0x07 382 | #define ContGatedPulseGen 0x08 383 | //GPTC clock source 384 | #define GPTC_GATESRC_EXT 0x04 385 | #define GPTC_GATESRC_INT 0x00 386 | #define GPTC_CLKSRC_EXT 0x08 387 | #define GPTC_CLKSRC_INT 0x00 388 | #define GPTC_UPDOWN_SEL_EXT 0x10 389 | #define GPTC_UPDOWN_SEL_INT 0x00 390 | //GPTC clock polarity 391 | #define GPTC_CLKEN_LACTIVE 0x01 392 | #define GPTC_CLKEN_HACTIVE 0x00 393 | #define GPTC_GATE_LACTIVE 0x02 394 | #define GPTC_GATE_HACTIVE 0x00 395 | #define GPTC_UPDOWN_LACTIVE 0x04 396 | #define GPTC_UPDOWN_HACTIVE 0x00 397 | #define GPTC_OUTPUT_LACTIVE 0x08 398 | #define GPTC_OUTPUT_HACTIVE 0x00 399 | #define GPTC_INT_LACTIVE 0x10 400 | #define GPTC_INT_HACTIVE 0x00 401 | //GPTC paramID 402 | #define GPTC_IntGATE 0x00 403 | #define GPTC_IntUpDnCTR 0x01 404 | #define GPTC_IntENABLE 0x02 405 | 406 | //SSI signal code 407 | #define SSI_TIME 1 408 | #define SSI_CONV 2 409 | #define SSI_WR 4 410 | #define SSI_ADSTART 8 411 | #define SSI_ADTRIG 0x20 412 | #define SSI_DATRIG 0x40 413 | //signal code for GPTC 414 | #define GPTC_CLK_0 0x100 415 | #define GPTC_GATE_0 0x200 416 | #define GPTC_OUT_0 0x300 417 | #define GPTC_CLK_1 0x400 418 | #define GPTC_GATE_1 0x500 419 | #define GPTC_OUT_1 0x600 420 | //signal code for clockoutToSMB source 421 | #define PXI_CLK_10_M 0x1000 422 | #define CLK_20_M 0x2000 423 | //signal code for external SMB clk 424 | #define SMB_CLK_IN 0x3000 425 | 426 | //signal route lines 427 | #define PXI_TRIG_0 0 428 | #define PXI_TRIG_1 1 429 | #define PXI_TRIG_2 2 430 | #define PXI_TRIG_3 3 431 | #define PXI_TRIG_4 4 432 | #define PXI_TRIG_5 5 433 | #define PXI_TRIG_6 6 434 | #define PXI_TRIG_7 7 435 | #define PXI_STAR_TRIG 8 436 | #define TRG_IO 9 437 | #define SMB_CLK_OUT 10 438 | #define AFI0 0x10 439 | #define AFI1 0x11 440 | #define AFI2 0x12 441 | #define AFI3 0x13 442 | #define AFI4 0x14 443 | #define AFI5 0x15 444 | #define AFI6 0x16 445 | #define AFI7 0x17 446 | #define PXI_CLK 0x18 447 | 448 | //export signal plarity 449 | #define Signal_ActiveHigh 0x0 450 | #define Signal_ActiveLow 0x1 451 | 452 | //DAQ Event type for the event message 453 | #define DAQEnd 0 454 | #define DBEvent 1 455 | #define TrigEvent 2 456 | #define DAQEnd_A 0 457 | #define DAQEnd_B 2 458 | #define DAQEnd_AB 3 459 | #define DATrigEvent 4 460 | #define DATrigEvent_A 4 461 | #define DATrigEvent_B 5 462 | #define DATrigEvent_AB 6 463 | //Not_Reset_Code 464 | #define DIONotRest 0x01 465 | /*------------------------------------------------------------------ 466 | ** PCIS-DASK Function prototype 467 | ------------------------------------------------------------------*/ 468 | I16 __stdcall D2K_Register_Card (U16 CardType, U16 card_num); 469 | I16 __stdcall D2K_Release_Card (U16 CardNumber); 470 | I16 __stdcall D2K_AIO_Config (U16 wCardNumber, U16 TimerBase, U16 AnaTrigCtrl, U16 H_TrgLevel, U16 L_TrgLevel); 471 | I16 __stdcall D2K_Register_Card_By_PXISlot_GA (U16 CardType, U16 ga); 472 | I16 __stdcall D2K_GetPXISlotGeographAddr (U16 wCardNumber, U8* geo_addr); 473 | I16 __stdcall D2K_SoftTrigGen(U16 wCardNumber, U8 op); 474 | /*---------------------------------------------------------------------------*/ 475 | I16 __stdcall D2K_AI_Config (U16 wCardNumber, U16 ConfigCtrl, U32 TrigCtrl, U32 MidOrDlyScans, U16 MCnt, U16 TrgCnt, BOOLEAN AutoResetBuf); 476 | I16 __stdcall D2K_AI_ConfigEx (U16 wCardNumber, U16 ConfigCtrl, U32 TrigCtrl, U32 MidOrDlyScans, U32 MCnt, U32 TrgCnt, BOOLEAN AutoResetBuf); 477 | 478 | I16 __stdcall D2K_AI_PostTrig_Config (U16 wCardNumber, U16 ClkSrc, U32 TrigSrcCtrl, U16 ReTrgEn, U16 TrgCnt, BOOLEAN AutoResetBuf); 479 | I16 __stdcall D2K_AI_PostTrig_ConfigEx (U16 wCardNumber, U16 ClkSrc, U32 TrigSrcCtrl, U16 ReTrgEn, U32 TrgCnt, BOOLEAN AutoResetBuf); 480 | 481 | I16 __stdcall D2K_AI_DelayTrig_Config (U16 wCardNumber, U16 ClkSrc, U32 TrigSrcCtrl, U32 DlyScans, U16 TrgEn, U16 ReTrgCnt, BOOLEAN AutoResetBuf); 482 | I16 __stdcall D2K_AI_DelayTrig_ConfigEx (U16 wCardNumber, U16 ClkSrc, U32 TrigSrcCtrl, U32 DlyScans, U16 TrgEn, U32 ReTrgCnt, BOOLEAN AutoResetBuf); 483 | 484 | I16 __stdcall D2K_AI_PreTrig_Config (U16 wCardNumber, U16 ClkSrc, U32 TrigSrcCtrl, U16 MCtrEn, U16 MCnt, BOOLEAN AutoResetBuf); 485 | I16 __stdcall D2K_AI_PreTrig_ConfigEx (U16 wCardNumber, U16 ClkSrc, U32 TrigSrcCtrl, U16 MCtrEn, U32 MCnt, BOOLEAN AutoResetBuf); 486 | 487 | I16 __stdcall D2K_AI_MiddleTrig_Config (U16 wCardNumber, U16 ClkSrc, U32 TrigSrcCtrl, U32 MiddleScans, U16 MCtrEn, U16 MCnt, BOOLEAN AutoResetBuf); 488 | I16 __stdcall D2K_AI_MiddleTrig_ConfigEx (U16 wCardNumber, U16 ClkSrc, U32 TrigSrcCtrl, U32 MiddleScans, U16 MCtrEn, U32 MCnt, BOOLEAN AutoResetBuf); 489 | 490 | I16 __stdcall D2K_AI_CH_Config (U16 wCardNumber, U16 wChannel, U16 wAdRange_RefGnd); 491 | I16 __stdcall D2K_AI_InitialMemoryAllocated (U16 CardNumber, U32 *MemSize); 492 | I16 __stdcall D2K_AI_ReadChannel (U16 CardNumber, U16 Channel, U16 *Value); 493 | I16 __stdcall D2K_AI_VReadChannel (U16 CardNumber, U16 Channel, F64 *voltage); 494 | I16 __stdcall D2K_AI_SimuReadChannel (U16 wCardNumber, U16 wNumChans, U16 *pwChans, U16 *pwBuffer); 495 | I16 __stdcall D2K_AI_ScanReadChannels (U16 wCardNumber, U16 wNumChans, U16 *pwChans, U16 *pwBuffer); 496 | I16 __stdcall D2K_AI_VoltScale (U16 CardNumber, U16 AdRange, I16 reading, F64 *voltage); 497 | I16 __stdcall D2K_AI_ContReadChannel (U16 CardNumber, U16 Channel, 498 | U16 BufId, U32 ReadScans, U32 ScanIntrv, U32 SampIntrv, U16 SyncMode); 499 | I16 __stdcall D2K_AI_ContReadMultiChannels (U16 CardNumber, U16 NumChans, U16 *Chans, 500 | U16 BufId, U32 ReadScans, U32 ScanIntrv, U32 SampIntrv, U16 SyncMode); 501 | I16 __stdcall D2K_AI_ContScanChannels (U16 CardNumber, U16 Channel, 502 | U16 BufId, U32 ReadScans, U32 ScanIntrv, U32 SampIntrv, U16 SyncMode); 503 | I16 __stdcall D2K_AI_ContReadChannelToFile (U16 CardNumber, U16 Channel, U16 BufId, 504 | U8 *FileName, U32 ReadScans, U32 ScanIntrv, U32 SampIntrv, U16 SyncMode); 505 | I16 __stdcall D2K_AI_ContReadMultiChannelsToFile (U16 CardNumber, U16 NumChans, U16 *Chans, 506 | U16 BufId, U8 *FileName, U32 ReadScans, U32 ScanIntrv, U32 SampIntrv, U16 SyncMode); 507 | I16 __stdcall D2K_AI_ContScanChannelsToFile (U16 CardNumber, U16 Channel, U16 BufId, 508 | U8 *FileName, U32 ReadScans, U32 ScanIntrv, U32 SampIntrv, U16 SyncMode); 509 | I16 __stdcall D2K_AI_ContStatus (U16 CardNumber, U16 *Status); 510 | I16 __stdcall D2K_AI_ContVScale (U16 wCardNumber, U16 adRange, void *readingArray, F64 *voltageArray, I32 count); 511 | I16 __stdcall D2K_AI_AsyncCheck (U16 CardNumber, BOOLEAN *Stopped, U32 *AccessCnt); 512 | I16 __stdcall D2K_AI_AsyncClear (U16 CardNumber, U32 *StartPos, U32 *AccessCnt); 513 | I16 __stdcall D2K_AI_AsyncClearEx (U16 CardNumber, U32 *StartPos, U32 *AccessCnt, U32 NoWait); 514 | I16 __stdcall D2K_AI_AsyncDblBufferHalfReady (U16 CardNumber, BOOLEAN *HalfReady, BOOLEAN *StopFlag); 515 | I16 __stdcall D2K_AI_AsyncDblBufferMode (U16 CardNumber, BOOLEAN Enable); 516 | I16 __stdcall D2K_AI_AsyncDblBufferToFile (U16 CardNumber); 517 | I16 __stdcall D2K_AI_ContBufferSetup (U16 wCardNumber, void *pwBuffer, U32 dwReadCount, U16 *BufferId); 518 | I16 __stdcall D2K_AI_ContBufferReset (U16 wCardNumber); 519 | I16 __stdcall D2K_AI_MuxScanSetup (U16 wCardNumber, U16 wNumChans, U16* pwChans, U16* pwAdRange_RefGnds); 520 | I16 __stdcall D2K_AI_ReadMuxScan (U16 wCardNumber, U16 *pwBuffer); 521 | I16 __stdcall D2K_AI_ContMuxScan (U16 wCardNumber, U16 BufId, U32 ReadScans, U32 ScanIntrv, U32 SampIntrv, U16 wSyncMode); 522 | I16 __stdcall D2K_AI_ContMuxScanToFile (U16 wCardNumber, U16 BufId, U8 *fileName, U32 ReadScans, U32 ScanIntrv, U32 SampIntrv, U16 wSyncMode); 523 | I16 __stdcall D2K_AI_EventCallBack (U16 wCardNumber, I16 mode, I16 EventType, U32 callbackAddr); 524 | I16 __stdcall D2K_AI_AsyncReTrigNextReady (U16 wCardNumber, BOOLEAN *trgReady, BOOLEAN *StopFlag, U16 *RdyTrigCnt); 525 | I16 __stdcall D2K_AI_AsyncReTrigNextReadyEx (U16 wCardNumber, BOOLEAN *bReady, BOOLEAN *StopFlag, U32 *dwRdyTrigCnt); 526 | I16 __stdcall D2K_AI_AsyncDblBufferHandled (U16 wCardNumber); 527 | I16 __stdcall D2K_AI_AsyncDblBufferOverrun (U16 wCardNumber, U16 op, U16 *overrunFlag); 528 | I16 __stdcall D2K_AI_SetTimeout (U16 wCardNumber, U32 msec); 529 | /*---------------------------------------------------------------------------*/ 530 | I16 __stdcall D2K_AO_CH_Config (U16 wCardNumber, U16 wChannel, U16 wOutputPolarity, U16 wIntOrExtRef, F64 refVoltage); 531 | I16 __stdcall D2K_AO_Config (U16 wCardNumber, U16 ConfigCtrl, U16 TrigCtrl, U16 ReTrgCnt, U16 DLY1Cnt, U16 DLY2Cnt, BOOLEAN AutoResetBuf); 532 | I16 __stdcall D2K_AO_PostTrig_Config (U16 wCardNumber, U16 ClkSrc, U16 TrigSrcCtrl, U16 DLY2Ctrl, U16 DLY2Cnt, U16 ReTrgEn, U16 ReTrgCnt, BOOLEAN AutoResetBuf); 533 | I16 __stdcall D2K_AO_DelayTrig_Config (U16 wCardNumber, U16 ClkSrc, U16 TrigSrcCtrl, U16 DLY1Cnt, U16 DLY2Ctrl, U16 DLY2Cnt, U16 ReTrgEn, U16 ReTrgCnt, BOOLEAN AutoResetBuf); 534 | I16 __stdcall D2K_AO_InitialMemoryAllocated (U16 CardNumber, U32 *MemSize); 535 | I16 __stdcall D2K_AO_WriteChannel (U16 CardNumber, U16 Channel, I16 Value); 536 | I16 __stdcall D2K_AO_VWriteChannel (U16 CardNumber, U16 Channel, F64 Voltage); 537 | I16 __stdcall D2K_AO_VoltScale (U16 CardNumber, U16 Channel, F64 Voltage, I16 *binValue); 538 | I16 __stdcall D2K_AO_ContWriteChannel (U16 wCardNumber, U16 wChannel, 539 | U16 BufId, U32 dwUpdateCount, U32 wIterations, U32 dwCHUI, U16 definite, U16 wSyncMode); 540 | I16 __stdcall D2K_AO_ContWriteMultiChannels (U16 wCardNumber, U16 wNumChans, U16 *pwChans, 541 | U16 BufId, U32 dwUpdateCount, U32 wIterations, U32 dwCHUI, U16 definite, U16 wSyncMode); 542 | I16 __stdcall D2K_AO_AsyncCheck (U16 CardNumber, BOOLEAN *Stopped, U32 *WriteCnt); 543 | I16 __stdcall D2K_AO_AsyncClear (U16 CardNumber, U32 *WriteCnt, U16 stop_mode); 544 | I16 __stdcall D2K_AO_AsyncClearEx (U16 CardNumber, U32 *WriteCnt, U16 stop_mode, U32 NoWait); 545 | I16 __stdcall D2K_AO_AsyncDblBufferHalfReady (U16 CardNumber, BOOLEAN *HalfReady); 546 | I16 __stdcall D2K_AO_AsyncDblBufferMode (U16 CardNumber, BOOLEAN Enable); 547 | I16 __stdcall D2K_AO_SimuWriteChannel (U16 wCardNumber, U16 wNumChans, U16 *pwBuffer); 548 | I16 __stdcall D2K_AO_ContBufferSetup (U16 wCardNumber, void *pwBuffer, U32 dwWriteCount, U16 *BufferId); 549 | I16 __stdcall D2K_AO_ContBufferReset (U16 wCardNumber); 550 | I16 __stdcall D2K_AO_ContStatus (U16 CardNumber, U16 *Status); 551 | I16 __stdcall D2K_AO_ContBufferComposeAll (U16 wCardNumber, U16 group, U32 dwUpdateCount, void *ConBuffer, void * pwBuffer, BOOLEAN fifoload); 552 | I16 __stdcall D2K_AO_ContBufferCompose (U16 wCardNumber, U16 group, U16 wChannel, U32 dwUpdateCount, void *ConBuffer, void *pwBuffer, BOOLEAN fifoload); 553 | I16 __stdcall D2K_AO_EventCallBack (U16 wCardNumber, I16 mode, I16 EventType, U32 callbackAddr); 554 | I16 __stdcall D2K_AO_SetTimeout (U16 wCardNumber, U32 msec); 555 | /*---------------------------------------------------------------------------*/ 556 | I16 __stdcall D2K_AO_Group_Setup (U16 wCardNumber, U16 group, U16 wNumChans, U16 *pwChans); 557 | I16 __stdcall D2K_AO_Group_Update (U16 CardNumber, U16 group, I16 *pwBuffer); 558 | I16 __stdcall D2K_AO_Group_VUpdate (U16 CardNumber, U16 group, F64 *pVoltage); 559 | I16 __stdcall D2K_AO_Group_FIFOLoad (U16 wCardNumber, U16 group, U16 BufId, U32 dwWriteCount); 560 | I16 __stdcall D2K_AO_Group_FIFOLoad_2 (U16 wCardNumber, U16 group, U16 BufId, U32 dwWriteCount); 561 | I16 __stdcall D2K_AO_Group_WFM_StopConfig (U16 wCardNumber, U16 group, U16 stopSrc, U16 stopMode); 562 | I16 __stdcall D2K_AO_Group_WFM_Start (U16 wardNumber, U16 group, U16 fstBufIdOrNotUsed, U16 sndBufId, 563 | U32 dwUpdateCount, U32 wIterations, U32 dwCHUI, U16 definite); 564 | I16 __stdcall D2K_AO_Group_WFM_AsyncCheck (U16 CardNumber, U16 group, U8 *Stopped, U32 *WriteCnt); 565 | I16 __stdcall D2K_AO_Group_WFM_AsyncClear (U16 CardNumber, U16 group, U32 *WriteCnt, U16 stop_mode); 566 | /*---------------------------------------------------------------------------*/ 567 | I16 __stdcall D2K_DI_ReadLine (U16 CardNumber, U16 Port, U16 Line, U16 *State); 568 | I16 __stdcall D2K_DI_ReadPort (U16 CardNumber, U16 Port, U32 *Value); 569 | /*---------------------------------------------------------------------------*/ 570 | I16 __stdcall D2K_DO_WriteLine (U16 CardNumber, U16 Port, U16 Line, U16 Value); 571 | I16 __stdcall D2K_DO_WritePort (U16 CardNumber, U16 Port, U32 Value); 572 | I16 __stdcall D2K_DO_ReadLine (U16 CardNumber, U16 Port, U16 Line, U16 *Value); 573 | I16 __stdcall D2K_DO_ReadPort (U16 CardNumber, U16 Port, U32 *Value); 574 | /*---------------------------------------------------------------------------*/ 575 | I16 __stdcall D2K_DIO_PortConfig (U16 CardNumber, U16 Port, U16 Direction); 576 | I16 __stdcall D2K_DIO_LineConfig (U16 wCardNumber, U16 wPort, U32 wLine, U16 wDirection); 577 | I16 __stdcall D2K_DIO_LinesConfig (U16 wCardNumber, U16 wPort, U32 wLinesdirmap); 578 | /*---------------------------------------------------------------------------*/ 579 | I16 __stdcall D2K_GCTR_Setup (U16 wCardNumber, U16 wGCtr, U16 wMode, U8 SrcCtrl, U8 PolCtrl, U16 LReg1_Val, U16 LReg2_Val); 580 | I16 __stdcall D2K_GCTR_Control (U16 wCardNumber, U16 wGCtr, U16 ParamID, U16 Value); 581 | I16 __stdcall D2K_GCTR_Reset (U16 wCardNumber, U16 wGCtr); 582 | I16 __stdcall D2K_GCTR_Read (U16 wCardNumber, U16 wGCtr, U32 *pValue); 583 | I16 __stdcall D2K_GCTR_Status (U16 wCardNumber, U16 wGCtr, U16 *pValue); 584 | I16 __stdcall D2K_GCTR_SetupEx (U16 wCardNumber, U16 wGCtr, U16 wMode, U8 SrcCtrl, U8 PolCtrl, U32 LReg1_Val, U32 LReg2_Val); 585 | 586 | I16 __stdcall D2K_SSI_SourceConn (U16 wCardNumber, U16 sigCode); 587 | I16 __stdcall D2K_SSI_SourceDisConn (U16 wCardNumber, U16 sigCode); 588 | I16 __stdcall D2K_SSI_SourceClear (U16 wCardNumber); 589 | I16 __stdcall D2K_Route_Signal (U16 wCardNumber, U16 signal, U16 polarity, U16 Line, U16 dir); 590 | I16 __stdcall D2K_Signal_DisConn (U16 wCardNumber, U16 signal, U16 polarity, U16 Line); 591 | 592 | I16 __stdcall DAQ2205_Acquire_DA_Error(U16 wCardNumber, U16 channel, U16 polarity, F32 *da0v_err, F32 *da5v_err); 593 | I16 __stdcall DAQ2205_Acquire_AD_Error(U16 wCardNumber, F32 *gain_err, F32 *bioffset_err, F32 *unioffset_err, F32 *hg_bios_err); 594 | I16 __stdcall DAQ2206_Acquire_DA_Error(U16 wCardNumber, U16 channel, U16 polarity, F32 *da0v_err, F32 *da5v_err); 595 | I16 __stdcall DAQ2206_Acquire_AD_Error(U16 wCardNumber, F32 *gain_err, F32 *bioffset_err, F32 *unioffset_err, F32 *hg_bios_err); 596 | I16 __stdcall DAQ2213_Acquire_AD_Error(U16 wCardNumber, F32 *gain_err, F32 *bioffset_err, F32 *unioffset_err, F32 *hg_bios_err); 597 | I16 __stdcall DAQ2214_Acquire_DA_Error(U16 wCardNumber, U16 channel, U16 polarity, F32 *da0v_err, F32 *da5v_err); 598 | I16 __stdcall DAQ2214_Acquire_AD_Error(U16 wCardNumber, F32 *gain_err, F32 *bioffset_err, F32 *unioffset_err, F32 *hg_bios_err); 599 | I16 __stdcall DAQ2010_Acquire_AD_Error(U16 wCardNumber, U16 channel, U16 polarity, F32 *gain_err, F32 *offset_err); 600 | I16 __stdcall DAQ2010_Acquire_DA_Error(U16 wCardNumber, U16 channel, U16 polarity, F32 *gain_err, F32 *offset_err); 601 | I16 __stdcall DAQ2005_Acquire_AD_Error(U16 wCardNumber, U16 channel, U16 polarity, F32 *gain_err, F32 *offset_err); 602 | I16 __stdcall DAQ2005_Acquire_DA_Error(U16 wCardNumber, U16 channel, U16 polarity, F32 *gain_err, F32 *offset_err); 603 | I16 __stdcall DAQ2006_Acquire_AD_Error(U16 wCardNumber, U16 channel, U16 polarity, F32 *gain_err, F32 *offset_err); 604 | I16 __stdcall DAQ2006_Acquire_DA_Error(U16 wCardNumber, U16 channel, U16 polarity, F32 *gain_err, F32 *offset_err); 605 | I16 __stdcall DAQ2016_Acquire_AD_Error(U16 wCardNumber, U16 channel, U16 polarity, F32 *gain_err, F32 *offset_err); 606 | I16 __stdcall DAQ2016_Acquire_DA_Error(U16 wCardNumber, U16 channel, U16 polarity, F32 *gain_err, F32 *offset_err); 607 | I16 __stdcall DAQ2204_Acquire_DA_Error(U16 wCardNumber, U16 channel, U16 polarity, F32 *da0v_err, F32 *da5v_err); 608 | I16 __stdcall DAQ2204_Acquire_AD_Error(U16 wCardNumber, F32 *gain_err, F32 *bioffset_err, F32 *unioffset_err, F32 *hg_bios_err); 609 | I16 __stdcall DAQ2208_Acquire_AD_Error(U16 wCardNumber, F32 *gain_err, F32 *bioffset_err, F32 *unioffset_err, F32 *hg_bios_err); 610 | I16 __stdcall DAQ250X_Acquire_DA_Error(I16 wCardNumber, U16 channel, U16 polarity, float *gain_err, float *offset_err); 611 | I16 __stdcall DAQ250X_Acquire_AD_Error(I16 wCardNumber, U16 polarity, float *gain_err, float *offset_err); 612 | I16 __stdcall D2K_DB_Auto_Calibration_ALL(U16 wCardNumber); 613 | I16 __stdcall D2K_EEPROM_CAL_Constant_Update(U16 wCardNumber, U16 bank); 614 | I16 __stdcall D2K_Load_CAL_Data(U16 wCardNumber, U16 bank); 615 | I16 __stdcall D2K_Set_Default_Load_Area(U16 wCardNumber, U16 bank); 616 | I16 __stdcall D2K_Get_Default_Load_Area (U16 wCardNumber); 617 | 618 | I16 __stdcall D2K_AI_GetEvent(U16 wCardNumber, HANDLE *hEvent); 619 | I16 __stdcall D2K_AO_GetEvent(U16 wCardNumber, HANDLE *hEvent); 620 | I16 __stdcall D2K_DI_GetEvent(U16 wCardNumber, HANDLE *hEvent); 621 | I16 __stdcall D2K_DO_GetEvent(U16 wCardNumber, HANDLE *hEvent); 622 | } 623 | #ifdef __cplusplus 624 | } 625 | #endif 626 | 627 | #endif //D2K_DASK_H 628 | --------------------------------------------------------------------------------