merge from KWH
This commit is contained in:
parent
89d1827e71
commit
de82f08c78
178
mainwindow.cpp
178
mainwindow.cpp
@ -1,5 +1,6 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
@ -9,6 +10,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
drvSPI = new DRV_Spi(this);
|
drvSPI = new DRV_Spi(this);
|
||||||
drvUart = new DRV_Uart(this);
|
drvUart = new DRV_Uart(this);
|
||||||
fHandler = new FrameHandler(this);
|
fHandler = new FrameHandler(this);
|
||||||
|
fHandler = new FrameHandler(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
@ -107,6 +109,7 @@ void MainWindow::on_pushButton_5_clicked()
|
|||||||
ui->lineEdit->setEnabled(false);
|
ui->lineEdit->setEnabled(false);
|
||||||
ui->pushButton_5->setEnabled(false);
|
ui->pushButton_5->setEnabled(false);
|
||||||
ui->pushButton_7->setEnabled(true);
|
ui->pushButton_7->setEnabled(true);
|
||||||
|
ui->btnSpiSaveSetting->setEnabled(false);
|
||||||
onLogPrint("Close device success");
|
onLogPrint("Close device success");
|
||||||
}else{
|
}else{
|
||||||
onLogPrint("Close device failed");
|
onLogPrint("Close device failed");
|
||||||
@ -135,15 +138,17 @@ void MainWindow::on_pushButton_2_clicked()
|
|||||||
|
|
||||||
// 判断打开串口设备是否成功
|
// 判断打开串口设备是否成功
|
||||||
if(status == TRUE){
|
if(status == TRUE){
|
||||||
ui->comboBox_3->setEnabled(true);
|
ui->comboSpiMode->setEnabled(true);
|
||||||
ui->comboBox_4->setEnabled(true);
|
ui->comboSpiClock->setEnabled(true);
|
||||||
ui->comboBox_5->setEnabled(true);
|
ui->comboSpiByteOrder->setEnabled(true);
|
||||||
ui->comboBox_6->setEnabled(true);
|
ui->comboSpiDataBits->setEnabled(true);
|
||||||
ui->comboBox_16->setEnabled(true);
|
ui->comboSpiCS1Pol->setEnabled(true);
|
||||||
ui->comboBox_17->setEnabled(true);
|
ui->comboSpiCS2Pol->setEnabled(true);
|
||||||
ui->pushButton_3->setEnabled(true);
|
ui->pushButton_3->setEnabled(true);
|
||||||
ui->pushButton_2->setEnabled(false);
|
ui->pushButton_2->setEnabled(false);
|
||||||
|
ui->btnSpiSaveSetting->setEnabled(true);
|
||||||
onLogPrint("Open device success");
|
onLogPrint("Open device success");
|
||||||
|
on_btnSpiSaveSetting_clicked(); // 初始化SPI参数
|
||||||
}else{
|
}else{
|
||||||
onLogPrint("Open device failed");
|
onLogPrint("Open device failed");
|
||||||
}
|
}
|
||||||
@ -158,12 +163,12 @@ void MainWindow::on_pushButton_3_clicked()
|
|||||||
|
|
||||||
// 判断打开串口设备是否成功
|
// 判断打开串口设备是否成功
|
||||||
if(status == TRUE){
|
if(status == TRUE){
|
||||||
ui->comboBox_3->setEnabled(false);
|
ui->comboSpiMode->setEnabled(false);
|
||||||
ui->comboBox_4->setEnabled(false);
|
ui->comboSpiClock->setEnabled(false);
|
||||||
ui->comboBox_5->setEnabled(false);
|
ui->comboSpiByteOrder->setEnabled(false);
|
||||||
ui->comboBox_6->setEnabled(false);
|
ui->comboSpiDataBits->setEnabled(false);
|
||||||
ui->comboBox_16->setEnabled(false);
|
ui->comboSpiCS1Pol->setEnabled(false);
|
||||||
ui->comboBox_17->setEnabled(false);
|
ui->comboSpiCS2Pol->setEnabled(false);
|
||||||
ui->pushButton_3->setEnabled(false);
|
ui->pushButton_3->setEnabled(false);
|
||||||
ui->pushButton_2->setEnabled(true);
|
ui->pushButton_2->setEnabled(true);
|
||||||
|
|
||||||
@ -174,16 +179,151 @@ void MainWindow::on_pushButton_3_clicked()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::on_pushButton_9_clicked()
|
void MainWindow::on_pushButton_9_clicked() {
|
||||||
{
|
unsigned char REG[4] = { 0 };
|
||||||
QByteArray tmp = fHandler->genREGWrite(0x01,0x01,0x09,0x81);
|
unsigned char ucDAC = ui->comboBox_15->currentText().toUInt(NULL, 10);
|
||||||
qDebug()<<tmp.toHex();
|
unsigned char ucChannel = 0;
|
||||||
|
QString tmp = ui->lineEdit_2->text();
|
||||||
|
if (tmp.toInt() < 0 || tmp.toInt() > 256) {
|
||||||
|
onLogPrint("Wrong channel #");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (tmp.toUInt()) {
|
||||||
|
case 256:
|
||||||
|
ucChannel = 0;
|
||||||
|
ucDAC = ucDAC | 0x80;
|
||||||
|
REG[1] = REG[1] | 0x02;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ucChannel = tmp.toUInt();
|
||||||
|
REG[3] = ucChannel;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char ucFun1 = 0;
|
||||||
|
//EN_TADC
|
||||||
|
if (ui->checkBox->isChecked()) {
|
||||||
|
ucFun1 = ucFun1 | 0x01;
|
||||||
|
REG[1] = REG[1] | 0x80;
|
||||||
|
}
|
||||||
|
//FBK_EN
|
||||||
|
if (ui->checkBox_2->isChecked()) {
|
||||||
|
ucFun1 = ucFun1 | 0x02;
|
||||||
|
REG[1] = REG[1] | 0x01;
|
||||||
|
|
||||||
|
}
|
||||||
|
//TEMPTEST_EN
|
||||||
|
if (ui->checkBox_4->isChecked()) {
|
||||||
|
ucFun1 = ucFun1 | 0x04;
|
||||||
|
REG[2] = REG[2] | 0x80;
|
||||||
|
qDebug() << REG[2];
|
||||||
|
}
|
||||||
|
//TEST_EN
|
||||||
|
if (ui->checkBox_3->isChecked()) {
|
||||||
|
ucFun1 = ucFun1 | 0x08;
|
||||||
|
REG[2] = REG[2] | 0x20;
|
||||||
|
}
|
||||||
|
//TRIG_TADC
|
||||||
|
if (ui->checkBox_5->isChecked()) {
|
||||||
|
ucFun1 = ucFun1 | 0x10;
|
||||||
|
REG[2] = REG[2] | 0x40;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char ucFun2 = 0;
|
||||||
|
ucFun2 = ucFun2 | ui->comboBox_12->currentText().toUInt(NULL, 10); //N_CLKDIV18
|
||||||
|
ucFun2 = ucFun2 | (ui->comboBox_14->currentText().toUInt(NULL, 2) << 4); //ICON8
|
||||||
|
REG[1] = REG[1] | (ui->comboBox_12->currentText().toUInt(NULL, 10) << 5);
|
||||||
|
REG[2] = REG[2] | (ui->comboBox_14->currentText().toUInt(NULL, 2));
|
||||||
|
|
||||||
|
QString sendRegData;
|
||||||
|
for (auto i : REG) {
|
||||||
|
sendRegData += "0x" + QString::number(i, 16) + " ";
|
||||||
|
}
|
||||||
|
onLogPrint("Ready to write REG[1] - REG[4] : " + sendRegData);
|
||||||
|
|
||||||
|
QByteArray tmp1 = fHandler->genREGWrite(ucDAC, ucChannel, ucFun1, ucFun2);
|
||||||
|
switch (ui->comboBox->currentIndex()) {
|
||||||
|
case 0:
|
||||||
|
if (drvUart->Uart_Write(tmp1)) {
|
||||||
|
onLogPrint("Send data success");
|
||||||
|
} else {
|
||||||
|
onLogPrint("Send data fail");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
onLogPrint("write data is " + tmp1.toHex());
|
||||||
|
if (drvSPI->spi_Write(tmp1)) {
|
||||||
|
onLogPrint("Send data success");
|
||||||
|
} else {
|
||||||
|
onLogPrint("Send data failed");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_pushButton_10_clicked() {
|
||||||
|
unsigned char ucDAC = ui->comboBox_15->currentText().toUInt(NULL, 10);
|
||||||
|
QByteArray tmp = fHandler->genREGRead(ucDAC);
|
||||||
|
switch (ui->comboBox->currentIndex()) {
|
||||||
|
case 0:
|
||||||
|
if (drvUart->Uart_Write(tmp)) {
|
||||||
|
onLogPrint("Send data success");
|
||||||
|
} else {
|
||||||
|
onLogPrint("Send data fail");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
onLogPrint("write data is " + tmp.toHex());
|
||||||
|
if (drvSPI->spi_Write(tmp)) {
|
||||||
|
onLogPrint("Send data success");
|
||||||
|
QTimer::singleShot(1000, [this]() {
|
||||||
|
QByteArray ba;
|
||||||
|
drvSPI->spi_Read(ba);
|
||||||
|
ui->textBrowser->append("SPI read: " + ba.toHex());
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
onLogPrint("Send data fail");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::on_pushButton_10_clicked()
|
void MainWindow::on_btnSpiSaveSetting_clicked() {
|
||||||
{
|
drvSPI->spi_Init(
|
||||||
|
ui->comboSpiMode->currentIndex(),
|
||||||
|
ui->comboSpiClock->currentIndex(),
|
||||||
|
ui->comboSpiByteOrder->currentIndex(),
|
||||||
|
ui->comboSpiDataBits->currentIndex(),
|
||||||
|
ui->comboSpiCS1Pol->currentIndex(),
|
||||||
|
ui->comboSpiCS2Pol->currentIndex()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onWriteRegButtonClicked() {
|
||||||
|
QByteArray tmp = fHandler->genREGWrite(0x01, 0x01, 0x09, 0x81);
|
||||||
|
ui->textBrowser->append("SPI write: " + tmp.toHex());
|
||||||
|
drvSPI->spi_Write(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onReadRegButtonClicked() {
|
||||||
QByteArray tmp = fHandler->genREGRead(0x01);
|
QByteArray tmp = fHandler->genREGRead(0x01);
|
||||||
qDebug()<<tmp.toHex();
|
ui->textBrowser->append("SPI write: " + tmp.toHex());
|
||||||
|
QTimer::singleShot(2000, [this]() {
|
||||||
|
QByteArray ba;
|
||||||
|
drvSPI->spi_Read(ba);
|
||||||
|
ui->textBrowser->append("SPI read: " + ba.toHex());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_comboBox_currentTextChanged(const QString& text) {
|
||||||
|
// if (text.toLower() == "spi") {
|
||||||
|
// connect(ui->pushButton_4, &QPushButton::clicked, this, &MainWindow::onWriteRegButtonClicked);
|
||||||
|
// connect(ui->pushButton_10, &QPushButton::clicked, this, &MainWindow::onReadRegButtonClicked);
|
||||||
|
// } else {
|
||||||
|
// disconnect(ui->pushButton_4, &QPushButton::clicked, this, &MainWindow::onWriteRegButtonClicked);
|
||||||
|
// disconnect(ui->pushButton_10, &QPushButton::clicked, this, &MainWindow::onReadRegButtonClicked);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
10
mainwindow.h
10
mainwindow.h
@ -6,7 +6,7 @@
|
|||||||
#include "src/headers/drv_uart.h"
|
#include "src/headers/drv_uart.h"
|
||||||
#include "src/headers/drv_spi.h"
|
#include "src/headers/drv_spi.h"
|
||||||
#include "QDateTime"
|
#include "QDateTime"
|
||||||
#include "src/headers/framehandler.h"
|
#include "src/headers/framehandler.h"#include "src/headers/framehandler.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -53,6 +53,12 @@ private slots:
|
|||||||
|
|
||||||
void on_pushButton_10_clicked();
|
void on_pushButton_10_clicked();
|
||||||
|
|
||||||
|
void on_btnSpiSaveSetting_clicked();
|
||||||
|
void onWriteRegButtonClicked();
|
||||||
|
void onReadRegButtonClicked();
|
||||||
|
|
||||||
|
void on_comboBox_currentTextChanged(const QString& text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
DialogCalibrate *dc;
|
DialogCalibrate *dc;
|
||||||
@ -60,6 +66,8 @@ private:
|
|||||||
DRV_Spi *drvSPI;
|
DRV_Spi *drvSPI;
|
||||||
FrameHandler *fHandler;
|
FrameHandler *fHandler;
|
||||||
|
|
||||||
|
FrameHandler *fHandler;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|||||||
@ -90,7 +90,7 @@
|
|||||||
<string>Timeout(ms):</string>
|
<string>Timeout(ms):</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignCenter</set>
|
<set>Qt::AlignmentFlag::AlignCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -149,7 +149,7 @@
|
|||||||
<string>Data Bits:</string>
|
<string>Data Bits:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignCenter</set>
|
<set>Qt::AlignmentFlag::AlignCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -159,7 +159,7 @@
|
|||||||
<string>Stop Bits:</string>
|
<string>Stop Bits:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignCenter</set>
|
<set>Qt::AlignmentFlag::AlignCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -258,7 +258,7 @@
|
|||||||
<string>Baud Rate:</string>
|
<string>Baud Rate:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -268,7 +268,7 @@
|
|||||||
<string>Parity Bits:</string>
|
<string>Parity Bits:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -288,7 +288,7 @@
|
|||||||
<string>UART Device List:</string>
|
<string>UART Device List:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -311,15 +311,18 @@
|
|||||||
<string>SPI Device List:</string>
|
<string>SPI Device List:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignCenter</set>
|
<set>Qt::AlignmentFlag::AlignCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="2" column="1">
|
||||||
<widget class="QComboBox" name="comboBox_4">
|
<widget class="QComboBox" name="comboSpiByteOrder">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="currentIndex">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>LSB</string>
|
<string>LSB</string>
|
||||||
@ -333,7 +336,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="3">
|
<item row="2" column="3">
|
||||||
<widget class="QComboBox" name="comboBox_6">
|
<widget class="QComboBox" name="comboSpiDataBits">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
@ -355,12 +358,15 @@
|
|||||||
<string>SPI Mode:</string>
|
<string>SPI Mode:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignCenter</set>
|
<set>Qt::AlignmentFlag::AlignCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="5" rowspan="2">
|
<item row="1" column="5" rowspan="2">
|
||||||
<widget class="QPushButton" name="pushButton_4">
|
<widget class="QPushButton" name="btnSpiSaveSetting">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
|
<sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
@ -383,10 +389,13 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="3">
|
<item row="1" column="3">
|
||||||
<widget class="QComboBox" name="comboBox_5">
|
<widget class="QComboBox" name="comboSpiClock">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="currentIndex">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>60MHz</string>
|
<string>60MHz</string>
|
||||||
@ -435,7 +444,7 @@
|
|||||||
<string>Clock:</string>
|
<string>Clock:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignCenter</set>
|
<set>Qt::AlignmentFlag::AlignCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -445,12 +454,12 @@
|
|||||||
<string>LSB/MSB</string>
|
<string>LSB/MSB</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignCenter</set>
|
<set>Qt::AlignmentFlag::AlignCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QComboBox" name="comboBox_3">
|
<widget class="QComboBox" name="comboSpiMode">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
@ -482,12 +491,12 @@
|
|||||||
<string>DataBits:</string>
|
<string>DataBits:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignCenter</set>
|
<set>Qt::AlignmentFlag::AlignCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="4">
|
<item row="1" column="4">
|
||||||
<widget class="QComboBox" name="comboBox_16">
|
<widget class="QComboBox" name="comboSpiCS1Pol">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
@ -504,7 +513,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="4">
|
<item row="2" column="4">
|
||||||
<widget class="QComboBox" name="comboBox_17">
|
<widget class="QComboBox" name="comboSpiCS2Pol">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
@ -632,10 +641,10 @@
|
|||||||
<item row="0" column="6">
|
<item row="0" column="6">
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Orientation::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeType">
|
<property name="sizeType">
|
||||||
<enum>QSizePolicy::MinimumExpanding</enum>
|
<enum>QSizePolicy::Policy::MinimumExpanding</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
@ -1091,7 +1100,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>839</width>
|
<width>839</width>
|
||||||
<height>21</height>
|
<height>33</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
|||||||
@ -57,7 +57,8 @@ public:
|
|||||||
bool spi_openDevice(ULONG SpiI2cGpioDevIndex); // 打开设备
|
bool spi_openDevice(ULONG SpiI2cGpioDevIndex); // 打开设备
|
||||||
bool spi_closeDevice(); // 关闭设备
|
bool spi_closeDevice(); // 关闭设备
|
||||||
bool spi_Write(QByteArray &sendData); // SPI写数据
|
bool spi_Write(QByteArray &sendData); // SPI写数据
|
||||||
BOOL spi_Read(QByteArray &revData); // SPI读数据
|
bool spi_Read(QByteArray &revData); // SPI读数据
|
||||||
|
bool spi_Init(int mode, int clock, int byteOrder, int CS1Pol, int CS2Pol, int dataBits);
|
||||||
|
|
||||||
/*************变量定义*************/
|
/*************变量定义*************/
|
||||||
mDRV_Spi_Infors m_DRV_Spi_Infors; //Spi驱动相关信息
|
mDRV_Spi_Infors m_DRV_Spi_Infors; //Spi驱动相关信息
|
||||||
|
|||||||
@ -79,7 +79,6 @@ bool DRV_Spi::spi_openDevice(ULONG SpiI2cGpioDevIndex)
|
|||||||
// 设置当前打开设备的索引号
|
// 设置当前打开设备的索引号
|
||||||
this->m_DRV_Spi_Infors.opendDevIndex = SpiI2cGpioDevIndex;
|
this->m_DRV_Spi_Infors.opendDevIndex = SpiI2cGpioDevIndex;
|
||||||
return true;
|
return true;
|
||||||
// CH347InitSpi();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//关闭设备
|
//关闭设备
|
||||||
@ -107,35 +106,67 @@ bool DRV_Spi::spi_Write(QByteArray &sendData)
|
|||||||
// 获取数据包的长度
|
// 获取数据包的长度
|
||||||
ULONG OutLen = sendData.length();
|
ULONG OutLen = sendData.length();
|
||||||
// 将QByteArray转化为UCHAR
|
// 将QByteArray转化为UCHAR
|
||||||
const UCHAR *OutBuf = reinterpret_cast<const unsigned char*>(sendData.constData());
|
UCHAR *OutBuf = reinterpret_cast<unsigned char*>(sendData.data());
|
||||||
|
|
||||||
BOOL RetVal = FALSE;
|
BOOL RetVal = FALSE;
|
||||||
// 调用底层串口发送函数发送数据
|
// 调用底层串口发送函数发送数据
|
||||||
RetVal = CH347SPI_Write(this->m_DRV_Spi_Infors.opendDevIndex, SPI_WRITE_CS, OutLen, SPI_WRITE_BLOCK_SIZE, (UCHAR *)OutBuf);
|
//RetVal = CH347SPI_Write(this->m_DRV_Spi_Infors.opendDevIndex, SPI_WRITE_CS, OutLen, SPI_WRITE_BLOCK_SIZE, (UCHAR *)OutBuf);
|
||||||
|
RetVal = CH347SPI_WriteRead(this->m_DRV_Spi_Infors.opendDevIndex, 0x80, sendData.count(), OutBuf);
|
||||||
// 日志窗口输出调试信息
|
// 日志窗口输出调试信息
|
||||||
DbgPrint("frame:%d,Spi_Write %dBytes %s.",sendData.at(14), OutLen,RetVal?"succ":"failure");
|
DbgPrint("Spi_Write %dBytes %s.", OutLen,RetVal?"succ":"failure");
|
||||||
|
|
||||||
return RetVal;
|
return RetVal ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL DRV_Spi::spi_Read(QByteArray &revData)
|
bool DRV_Spi::spi_Read(QByteArray &revData)
|
||||||
{
|
{
|
||||||
ULONG InLen = 512; // 设置读取的长度,读取完后会将该值赋值为真实的长度
|
ULONG InLen = 7;
|
||||||
ULONG OutLen = 0; // 设置读取的长度,读取完后会将该值赋值为真实的长度
|
// ULONG OutLen = 0;
|
||||||
UCHAR InBuf[512] = {0x00};
|
// UCHAR InBuf[512] = {0x00};
|
||||||
|
revData.clear();
|
||||||
|
revData.append(InLen, 0x00);
|
||||||
|
|
||||||
BOOL RetVal = FALSE;
|
BOOL RetVal = FALSE;
|
||||||
|
|
||||||
// 读取串口数据
|
// 读取串口数据
|
||||||
RetVal = CH347SPI_Read(this->m_DRV_Spi_Infors.opendDevIndex, SPI_READ_CS, OutLen, &InLen, InBuf);
|
//RetVal = CH347SPI_Read(this->m_DRV_Spi_Infors.opendDevIndex, SPI_READ_CS, OutLen, &InLen, InBuf);
|
||||||
|
RetVal = CH347SPI_WriteRead(this->m_DRV_Spi_Infors.opendDevIndex, 0x80, InLen, revData.data());
|
||||||
|
|
||||||
DbgPrint("CH347Spi_Read %dB %s.",InLen,RetVal?"succ":"failure");
|
DbgPrint("CH347Spi_Read %dB %s.", InLen, RetVal ? "succ" : "failure");
|
||||||
|
|
||||||
if(RetVal)
|
// if(RetVal)
|
||||||
{
|
// {
|
||||||
//将数据存入revData变量中,返回给调用的函数
|
// //将数据存入revData变量中,返回给调用的函数
|
||||||
revData = QByteArray::fromRawData(reinterpret_cast<const char*>(InBuf), InLen);
|
// revData = QByteArray::fromRawData(static_cast<char*>(InBuf), InLen);
|
||||||
}
|
// }
|
||||||
return RetVal;
|
return RetVal ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DRV_Spi::spi_Init(int mode, int clock, int byteOrder, int CS1Pol, int CS2Pol, int dataBits) {
|
||||||
|
mSpiCfgS spiCon;
|
||||||
|
BOOL rv = FALSE;
|
||||||
|
rv = CH347SPI_GetCfg(m_DRV_Spi_Infors.opendDevIndex, &spiCon);
|
||||||
|
DbgPrint("CH347SPI_GetCfg %s.", rv ? "succ" : "failure");
|
||||||
|
if (rv == FALSE)
|
||||||
|
return false;
|
||||||
|
spiCon.iMode = mode;
|
||||||
|
spiCon.iClock = clock;
|
||||||
|
spiCon.iByteOrder = byteOrder;
|
||||||
|
spiCon.iSpiOutDefaultData = 0xFF;
|
||||||
|
spiCon.iChipSelect = 0x80;
|
||||||
|
spiCon.CS1Polarity = CS1Pol;
|
||||||
|
spiCon.CS2Polarity = CS2Pol;
|
||||||
|
spiCon.iIsAutoDeativeCS = 0;
|
||||||
|
spiCon.iActiveDelay = 0;
|
||||||
|
spiCon.iDelayDeactive = 0;
|
||||||
|
rv = CH347SPI_Init(m_DRV_Spi_Infors.opendDevIndex, &spiCon);
|
||||||
|
DbgPrint("CH347SPI_Init %s.", rv ? "succ" : "failure");
|
||||||
|
if (rv == FALSE)
|
||||||
|
return false;
|
||||||
|
rv = CH347SPI_SetDataBits(m_DRV_Spi_Infors.opendDevIndex, dataBits);
|
||||||
|
DbgPrint("CH347SPI_SetDataBits %s.", rv ? "succ" : "failure");
|
||||||
|
if (rv == FALSE)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
16
voltageTmp/voltagetmp_0.csv
Normal file
16
voltageTmp/voltagetmp_0.csv
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||||
|
16
voltageTmp/voltagetmp_random.csv
Normal file
16
voltageTmp/voltagetmp_random.csv
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
291,147,51,117,295,144,54,7,270,81,106,163,18,79,45,244
|
||||||
|
170,20,292,109,222,298,184,276,249,163,35,141,99,301,148,80
|
||||||
|
106,215,5,77,264,239,111,242,145,50,316,118,2,134,204,228
|
||||||
|
133,33,240,317,85,32,90,318,275,247,0,234,155,153,216,145
|
||||||
|
235,257,73,162,249,42,249,41,23,49,199,104,259,55,103,240
|
||||||
|
163,58,212,255,306,186,192,168,317,199,196,213,192,131,178,310
|
||||||
|
231,3,262,95,146,14,154,212,251,76,38,147,19,186,142,170
|
||||||
|
56,67,296,21,313,93,48,272,302,28,176,27,145,46,296,272
|
||||||
|
77,94,311,50,74,275,78,267,151,226,264,191,1,27,141,233
|
||||||
|
253,114,2,170,149,46,109,154,212,150,307,65,194,281,134,0
|
||||||
|
237,240,185,65,160,287,275,204,91,107,164,300,187,287,107,213
|
||||||
|
160,136,114,175,93,77,255,69,217,9,310,59,85,106,275,173
|
||||||
|
66,19,126,263,284,72,61,234,225,273,286,34,300,268,177,205
|
||||||
|
24,52,165,242,95,79,72,288,224,198,149,313,12,266,149,126
|
||||||
|
273,34,55,189,292,139,136,98,288,160,29,232,225,164,197,107
|
||||||
|
146,310,19,24,11,118,92,181,283,107,52,122,253,8,87,286
|
||||||
|
Loading…
Reference in New Issue
Block a user