SPI读寄存器正常,读电压正常;UART不对
This commit is contained in:
parent
de82f08c78
commit
3b2d14508b
@ -10,24 +10,27 @@ CONFIG += c++17
|
||||
|
||||
SOURCES += \
|
||||
dialogcalibrate.cpp \
|
||||
dialogtest.cpp \
|
||||
src/sources/dachandler.cpp \
|
||||
src/sources/framehandler.cpp \
|
||||
main.cpp \
|
||||
mainwindow.cpp \
|
||||
src/sources/crc.cpp \
|
||||
src/sources/drv_spi.cpp \
|
||||
src/sources/drv_uart.cpp
|
||||
|
||||
HEADERS += \
|
||||
dialogcalibrate.h \
|
||||
dialogtest.h \
|
||||
src/headers/dachandler.h \
|
||||
src/headers/framehandler.h \
|
||||
mainwindow.h \
|
||||
src/headers/CH347DLL.H \
|
||||
src/headers/crc.h \
|
||||
src/headers/drv_spi.h \
|
||||
src/headers/drv_uart.h
|
||||
|
||||
FORMS += \
|
||||
dialogcalibrate.ui \
|
||||
dialogtest.ui \
|
||||
mainwindow.ui
|
||||
|
||||
LIBS += -L$$PWD/lib -lCH347DLLA64
|
||||
|
||||
@ -15,6 +15,7 @@ public:
|
||||
explicit DialogCalibrate(QWidget *parent = nullptr);
|
||||
~DialogCalibrate();
|
||||
|
||||
|
||||
private slots:
|
||||
void on_pushButton_clicked();
|
||||
|
||||
|
||||
45
dialogtest.cpp
Normal file
45
dialogtest.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#include "dialogtest.h"
|
||||
#include "ui_dialogtest.h"
|
||||
|
||||
DialogTest::DialogTest(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
, ui(new Ui::DialogTest)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
DialogTest::~DialogTest()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void DialogTest::on_pushButton_clicked()
|
||||
{
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
|
||||
void DialogTest::on_pushButton_2_clicked()
|
||||
{
|
||||
QByteArray data(4,0);
|
||||
data[0]=ui->lineEdit->text().toUInt();
|
||||
data[1]=ui->lineEdit_2->text().toUInt();
|
||||
data[2]=ui->lineEdit_3->text().toUInt();
|
||||
data[3]=ui->lineEdit_4->text().toUInt();
|
||||
emit testSendRegSPI(data);
|
||||
}
|
||||
|
||||
|
||||
void DialogTest::on_pushButton_3_clicked()
|
||||
{
|
||||
emit testSendSPI0();
|
||||
}
|
||||
|
||||
|
||||
void DialogTest::on_pushButton_4_clicked()
|
||||
{
|
||||
QByteArray data;
|
||||
data.append(ui->lineEdit->text().toUInt());
|
||||
emit testReadRegSPI(data);
|
||||
}
|
||||
|
||||
36
dialogtest.h
Normal file
36
dialogtest.h
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef DIALOGTEST_H
|
||||
#define DIALOGTEST_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui {
|
||||
class DialogTest;
|
||||
}
|
||||
|
||||
class DialogTest : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DialogTest(QWidget *parent = nullptr);
|
||||
~DialogTest();
|
||||
|
||||
private slots:
|
||||
void on_pushButton_clicked();
|
||||
|
||||
void on_pushButton_2_clicked();
|
||||
|
||||
|
||||
void on_pushButton_3_clicked();
|
||||
|
||||
void on_pushButton_4_clicked();
|
||||
|
||||
signals:
|
||||
void testSendRegSPI(QByteArray data);
|
||||
void testReadRegSPI(QByteArray data);
|
||||
void testSendSPI0();
|
||||
private:
|
||||
Ui::DialogTest *ui;
|
||||
};
|
||||
|
||||
#endif // DIALOGTEST_H
|
||||
98
dialogtest.ui
Normal file
98
dialogtest.ui
Normal file
@ -0,0 +1,98 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>DialogTest</class>
|
||||
<widget class="QDialog" name="DialogTest">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>493</width>
|
||||
<height>443</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>SPI</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Fun2:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1" colspan="3">
|
||||
<widget class="QLineEdit" name="lineEdit_4"/>
|
||||
</item>
|
||||
<item row="2" column="1" colspan="3">
|
||||
<widget class="QLineEdit" name="lineEdit_3"/>
|
||||
</item>
|
||||
<item row="1" column="1" colspan="3">
|
||||
<widget class="QLineEdit" name="lineEdit_2"/>
|
||||
</item>
|
||||
<item row="0" column="1" colspan="3">
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
</item>
|
||||
<item row="4" column="3">
|
||||
<widget class="QPushButton" name="pushButton_3">
|
||||
<property name="text">
|
||||
<string>Send 0</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QPushButton" name="pushButton_2">
|
||||
<property name="text">
|
||||
<string>Set Reg</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>DAC Channel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>DAC #</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Fun1:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<widget class="QPushButton" name="pushButton_4">
|
||||
<property name="text">
|
||||
<string>Read Reg</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Back</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
488
mainwindow.cpp
488
mainwindow.cpp
@ -7,10 +7,25 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
drvSPI = new DRV_Spi(this);
|
||||
dacHandler= new DACHandler(this);
|
||||
drvUart = new DRV_Uart(this);
|
||||
drvSPI = new DRV_Spi(this);
|
||||
fHandler = new FrameHandler(this);
|
||||
fHandler = new FrameHandler(this);
|
||||
|
||||
|
||||
connect(dacHandler,&DACHandler::logMsg,this,&MainWindow::onLogPrint);
|
||||
|
||||
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
for (int j = 0; j < 16; ++j) {
|
||||
// 将 int 转换为 QString
|
||||
QString data = QString::number(0);
|
||||
// 创建 QTableWidgetItem 并设置数据
|
||||
QTableWidgetItem *item = new QTableWidgetItem(data);
|
||||
// 将 item 放入指定的单元格
|
||||
ui->tableWidget->setItem(i, j, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@ -27,6 +42,33 @@ void MainWindow::onLogPrint(QString msg){
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::handleTestSendRegSPI(QByteArray data)
|
||||
{
|
||||
QByteArray tmp = fHandler->genREGWrite(data[0],data[1],data[2],data[3]);
|
||||
QByteArray tmp1=tmp;
|
||||
drvSPI->spi_Write(tmp1);
|
||||
onLogPrint(" [SPI] --> Send data success, data is (hex) :" + tmp.toHex(' '));
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::handleTestSendSPI0()
|
||||
{
|
||||
QByteArray tmp(7,0);
|
||||
QByteArray tmp1=tmp;
|
||||
drvSPI->spi_Write(tmp1);
|
||||
onLogPrint(" [SPI] --> Send data success, data is (hex) :" + tmp.toHex(' '));
|
||||
onLogPrint(" [SPI] <-- Read Reg data data is (hex) :" + tmp1.toHex(' '));
|
||||
}
|
||||
|
||||
void MainWindow::handleTestReadRegSPI(QByteArray data)
|
||||
{
|
||||
QByteArray tmp = fHandler->genREGRead(data[0]);
|
||||
QByteArray tmp1=tmp;
|
||||
drvSPI->spi_Write(tmp1);
|
||||
onLogPrint(" [SPI] --> Send data success, data is (hex) :" + tmp.toHex(' '));
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::on_pushButton_14_clicked()
|
||||
{
|
||||
dc= new DialogCalibrate(this);
|
||||
@ -50,7 +92,7 @@ void MainWindow::on_pushButton_6_clicked()
|
||||
for(int i = 0; i < drvUart->m_DRV_Uart_Infors.ulDevCnt; i++)
|
||||
ui->comboBox_7->addItem(drvUart->m_DRV_Uart_Infors.bDeviceName[i]);
|
||||
}else{
|
||||
onLogPrint("No devices");
|
||||
onLogPrint("No UART devices");
|
||||
}
|
||||
|
||||
}
|
||||
@ -72,9 +114,9 @@ void MainWindow::on_pushButton_7_clicked()
|
||||
ui->lineEdit->setEnabled(true);
|
||||
ui->pushButton_5->setEnabled(true);
|
||||
ui->pushButton_7->setEnabled(false);
|
||||
onLogPrint("Open device success");
|
||||
onLogPrint("Open UART device success");
|
||||
}else{
|
||||
onLogPrint("Open device failed");
|
||||
onLogPrint("Fail to open UART device");
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,9 +131,9 @@ void MainWindow::on_pushButton_8_clicked()
|
||||
UCHAR Timeout = this->ui->lineEdit->text().toUInt();
|
||||
// 调用配置参数函数进行配置
|
||||
if(drvUart->Uart_setPara(Baudrate, StopBits, Parity, DataBits, Timeout)){
|
||||
onLogPrint("Set parameters success");
|
||||
onLogPrint("Set UART parameters success");
|
||||
}else{
|
||||
onLogPrint("Fail to set parameters");
|
||||
onLogPrint("Fail to set UART parameters");
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,9 +152,9 @@ void MainWindow::on_pushButton_5_clicked()
|
||||
ui->pushButton_5->setEnabled(false);
|
||||
ui->pushButton_7->setEnabled(true);
|
||||
ui->btnSpiSaveSetting->setEnabled(false);
|
||||
onLogPrint("Close device success");
|
||||
onLogPrint("Close UART device success");
|
||||
}else{
|
||||
onLogPrint("Close device failed");
|
||||
onLogPrint("Fail to close UART device ");
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,7 +167,7 @@ void MainWindow::on_pushButton_clicked()
|
||||
// 将串口设备的名称添加至列表中
|
||||
ui->comboBox_2->addItem(drvSPI->m_DRV_Spi_Infors.bDeviceName);
|
||||
}else{
|
||||
onLogPrint("No devices");
|
||||
onLogPrint("No SPI devices");
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,10 +175,10 @@ void MainWindow::on_pushButton_clicked()
|
||||
void MainWindow::on_pushButton_2_clicked()
|
||||
{
|
||||
ULONG index = ui->comboBox_2->currentIndex();
|
||||
// 调用串口打开函数
|
||||
// 调用打开函数
|
||||
BOOL status = drvSPI->spi_openDevice(index);
|
||||
|
||||
// 判断打开串口设备是否成功
|
||||
// 判断打开设备是否成功
|
||||
if(status == TRUE){
|
||||
ui->comboSpiMode->setEnabled(true);
|
||||
ui->comboSpiClock->setEnabled(true);
|
||||
@ -147,15 +189,13 @@ void MainWindow::on_pushButton_2_clicked()
|
||||
ui->pushButton_3->setEnabled(true);
|
||||
ui->pushButton_2->setEnabled(false);
|
||||
ui->btnSpiSaveSetting->setEnabled(true);
|
||||
onLogPrint("Open device success");
|
||||
on_btnSpiSaveSetting_clicked(); // 初始化SPI参数
|
||||
onLogPrint("Open SPI device success");
|
||||
}else{
|
||||
onLogPrint("Open device failed");
|
||||
onLogPrint("Fail to open SPI device.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MainWindow::on_pushButton_3_clicked()
|
||||
{
|
||||
|
||||
@ -172,9 +212,9 @@ void MainWindow::on_pushButton_3_clicked()
|
||||
ui->pushButton_3->setEnabled(false);
|
||||
ui->pushButton_2->setEnabled(true);
|
||||
|
||||
onLogPrint("Close device success");
|
||||
onLogPrint("Close SPI device success");
|
||||
}else{
|
||||
onLogPrint("Close device failed");
|
||||
onLogPrint("Fail to close device.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -239,23 +279,22 @@ void MainWindow::on_pushButton_9_clicked() {
|
||||
for (auto i : REG) {
|
||||
sendRegData += "0x" + QString::number(i, 16) + " ";
|
||||
}
|
||||
onLogPrint("Ready to write REG[1] - REG[4] : " + sendRegData);
|
||||
onLogPrint("Ready to set DAC REG[1] - REG[4] is :"+sendRegData);
|
||||
qDebug()<<"parameter is "<<Qt::hex <<ucDAC<<ucChannel<<ucFun1<<ucFun2;
|
||||
QByteArray tmp1 = fHandler->genREGWrite(ucDAC, ucChannel, ucFun1, ucFun2);
|
||||
|
||||
|
||||
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");
|
||||
if (!dacHandler->setDACReg(drvUart,tmp1))
|
||||
{
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
onLogPrint("write data is " + tmp1.toHex());
|
||||
if (drvSPI->spi_Write(tmp1)) {
|
||||
onLogPrint("Send data success");
|
||||
} else {
|
||||
onLogPrint("Send data failed");
|
||||
if (!dacHandler->setDACReg(drvSPI,tmp1))
|
||||
{
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -264,34 +303,78 @@ void MainWindow::on_pushButton_9_clicked() {
|
||||
}
|
||||
|
||||
void MainWindow::on_pushButton_10_clicked() {
|
||||
unsigned char ucDAC = ui->comboBox_15->currentText().toUInt(NULL, 10);
|
||||
QByteArray tmp = fHandler->genREGRead(ucDAC);
|
||||
unsigned char ucDAC = ui->comboBox_15->currentText().toUInt(NULL, 10);
|
||||
QByteArray tmp = fHandler->genREGRead(ucDAC);
|
||||
QByteArray revDatatmp;
|
||||
switch (ui->comboBox->currentIndex()) {
|
||||
case 0:
|
||||
if (drvUart->Uart_Write(tmp)) {
|
||||
onLogPrint("Send data success");
|
||||
} else {
|
||||
onLogPrint("Send data fail");
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
{
|
||||
revDatatmp = dacHandler->getDACReg(drvUart,tmp);
|
||||
onLogPrint(" [UART] <-- Read Reg data is :"+revDatatmp.toHex(' '));
|
||||
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;
|
||||
{
|
||||
revDatatmp= dacHandler->getDACReg(drvSPI,tmp);
|
||||
onLogPrint(" [SPI] <-- Read Reg data is :"+revDatatmp.toHex(' '));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// revDatatmp.append(static_cast<char>(0x00));
|
||||
// revDatatmp.append(static_cast<char>(0x81));
|
||||
// revDatatmp.append(static_cast<char>(0x11));
|
||||
// revDatatmp.append(static_cast<char>(0x01));
|
||||
// revDatatmp.append(static_cast<char>(0x21));
|
||||
// revDatatmp.append(static_cast<char>(0xa0));
|
||||
// revDatatmp.append(static_cast<char>(0x00));
|
||||
|
||||
// onLogPrint(" [UART] <-- Read Reg data is :"+revDatatmp.toHex(' '));
|
||||
|
||||
|
||||
// for(int i=0;i<revDatatmp.length();i++){
|
||||
// QString hexString = QString::asprintf("0x%x", static_cast<unsigned char>(revDatatmp[i])); // 正确
|
||||
// onLogPrint("DEBUG: revDatatmp is "+hexString);
|
||||
// }
|
||||
|
||||
if(revDatatmp.length()>=7){
|
||||
QByteArray tempHexArray;
|
||||
|
||||
// 设置第一个 lineEdit_3
|
||||
tempHexArray = revDatatmp.mid(0, 1);
|
||||
ui->lineEdit_3->setText("0x" + tempHexArray.toHex());
|
||||
|
||||
// 设置 lineEdit_8
|
||||
tempHexArray = revDatatmp.mid(1, 1);
|
||||
ui->lineEdit_8->setText("0x" + tempHexArray.toHex());
|
||||
|
||||
// 设置 lineEdit_13
|
||||
tempHexArray = revDatatmp.mid(2, 1);
|
||||
ui->lineEdit_13->setText("0x" + tempHexArray.toHex());
|
||||
|
||||
// 设置 lineEdit_10
|
||||
tempHexArray = revDatatmp.mid(3, 1);
|
||||
ui->lineEdit_10->setText("0x" + tempHexArray.toHex());
|
||||
|
||||
// 设置 lineEdit_12
|
||||
tempHexArray = revDatatmp.mid(4, 1);
|
||||
ui->lineEdit_12->setText("0x" + tempHexArray.toHex());
|
||||
|
||||
// 设置 lineEdit_9
|
||||
tempHexArray = revDatatmp.mid(5, 1);
|
||||
ui->lineEdit_9->setText("0x" + tempHexArray.toHex());
|
||||
|
||||
// 设置 lineEdit_11
|
||||
tempHexArray = revDatatmp.mid(6, 1);
|
||||
ui->lineEdit_11->setText("0x" + tempHexArray.toHex());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::on_btnSpiSaveSetting_clicked() {
|
||||
drvSPI->spi_Init(
|
||||
BOOL ret = false;
|
||||
ret= drvSPI->spi_Init(
|
||||
ui->comboSpiMode->currentIndex(),
|
||||
ui->comboSpiClock->currentIndex(),
|
||||
ui->comboSpiByteOrder->currentIndex(),
|
||||
@ -299,31 +382,294 @@ void MainWindow::on_btnSpiSaveSetting_clicked() {
|
||||
ui->comboSpiCS1Pol->currentIndex(),
|
||||
ui->comboSpiCS2Pol->currentIndex()
|
||||
);
|
||||
if(ret){
|
||||
onLogPrint("Save SPI parameters success");
|
||||
}else{
|
||||
onLogPrint("Fail to set SPI parameters.");
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onWriteRegButtonClicked() {
|
||||
QByteArray tmp = fHandler->genREGWrite(0x01, 0x01, 0x09, 0x81);
|
||||
ui->textBrowser->append("SPI write: " + tmp.toHex());
|
||||
drvSPI->spi_Write(tmp);
|
||||
|
||||
|
||||
void MainWindow::on_pushButton_11_clicked()
|
||||
{
|
||||
// 弹出“打开文件”对话框
|
||||
QString filePath = QFileDialog::getOpenFileName(
|
||||
this,
|
||||
tr("Choose csv file"),
|
||||
QDir::homePath(),
|
||||
tr("csv文件 (*.csv);")
|
||||
);
|
||||
|
||||
if(filePath.isEmpty()){
|
||||
onLogPrint("Empty file.");
|
||||
return;
|
||||
}
|
||||
|
||||
int voltageValue[16][16]={0};
|
||||
const int rows = 16;
|
||||
const int cols = 16;
|
||||
|
||||
QFile file(filePath);
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
qWarning() << "Can't open file" << file.errorString();
|
||||
return ;
|
||||
}
|
||||
|
||||
QTextStream in(&file);
|
||||
int rowCount = 0;
|
||||
|
||||
// 逐行读取文件,直到文件末尾或达到最大行数
|
||||
while (!in.atEnd() && rowCount < rows) {
|
||||
QString line = in.readLine();
|
||||
QStringList fields = line.split(',');
|
||||
|
||||
|
||||
// 遍历当前行的所有字段,并将其转换为整数
|
||||
for (int colCount = 0; colCount < cols; ++colCount) {
|
||||
bool ok;
|
||||
int value = fields.at(colCount).toInt(&ok);
|
||||
|
||||
if (ok) {
|
||||
voltageValue[rowCount][colCount] = value;
|
||||
} else {
|
||||
onLogPrint("Row is "+QString::number(rowCount + 1)+" Column is "+QString::number(colCount + 1)+" has invalid data");
|
||||
voltageValue[rowCount][colCount] = 0; // 或者设置为其他默认值
|
||||
}
|
||||
}
|
||||
|
||||
rowCount++;
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
ui->tableWidget->clearContents();
|
||||
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
for (int j = 0; j < 16; ++j) {
|
||||
// 将 int 转换为 QString
|
||||
QString data = QString::number(voltageValue[i][j]);
|
||||
// 创建 QTableWidgetItem 并设置数据
|
||||
QTableWidgetItem *item = new QTableWidgetItem(data);
|
||||
// 将 item 放入指定的单元格
|
||||
ui->tableWidget->setItem(i, j, item);
|
||||
}
|
||||
}
|
||||
ui->label_13->setText("Ready to write : ");
|
||||
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::onReadRegButtonClicked() {
|
||||
QByteArray tmp = fHandler->genREGRead(0x01);
|
||||
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_pushButton_12_clicked()
|
||||
{
|
||||
// // 从1至256通道依次读取电压值
|
||||
// for(ch_index = 1; ch_index <= 256; ch_index++)
|
||||
// {
|
||||
// // 设置配置项
|
||||
// this->ui->comboBox_icdDacCh->setCurrentIndex(0); // 设置通道值为全0
|
||||
// this->ui->checkBox_icdTRIG_TADC->setCheckState(Qt::Unchecked); // 关闭TADC
|
||||
// this->ui->pushButton_icdRegConfig->click(); // 触发配置寄存器按钮
|
||||
// QThread::msleep(10); // 延时10毫秒
|
||||
// this->ui->checkBox_icdTRIG_TADC->setCheckState(Qt::Checked); // 开启TADC
|
||||
// this->ui->comboBox_icdDacCh->setCurrentIndex(ch_index); //设置当前通道
|
||||
// this->ui->pushButton_icdRegConfig->click(); // 触发配置寄存器按钮
|
||||
// QThread::msleep(10); // 延时10毫秒
|
||||
// this->ui->pushButton_icdRegConfig->click(); // 再次触发配置寄存器按钮
|
||||
// QThread::msleep(10); // 延时10毫秒
|
||||
// this->ui->pushButton_icdRegRead->click(); // 读取寄存器值
|
||||
// QThread::msleep(10); // 延时10毫秒
|
||||
// }
|
||||
|
||||
int voltage[256]={0};
|
||||
|
||||
#if 1
|
||||
QByteArray regData[256];
|
||||
unsigned char ucDAC = ui->comboBox_15->currentText().toUInt(NULL, 10);
|
||||
QByteArray cmd1 = fHandler->genREGWrite(ucDAC,0x00,0x09,0x11); //关闭TADC
|
||||
|
||||
QByteArray cmd3 = fHandler->genREGRead(ucDAC); // 读取寄存器值
|
||||
int mode = ui->comboBox->currentIndex();
|
||||
for(int i=1;i<=256;i++){
|
||||
// ui->lineEdit_2->setText(QString::number(0));
|
||||
// ui->checkBox_5->setCheckState(Qt::Unchecked);
|
||||
// on_pushButton_9_clicked();
|
||||
// QThread::msleep(10); // 延时10毫秒
|
||||
// ui->checkBox_5->setCheckState(Qt::Checked);
|
||||
// ui->lineEdit_2->setText(QString::number(i));
|
||||
// on_pushButton_9_clicked();
|
||||
// QThread::msleep(10); // 延时10毫秒
|
||||
// on_pushButton_9_clicked();
|
||||
// QThread::msleep(10); // 延时10毫秒
|
||||
// on_pushButton_10_clicked(); //读取寄存器的值
|
||||
|
||||
QByteArray cmd2;
|
||||
if(i!=256){
|
||||
cmd2= fHandler->genREGWrite(ucDAC,(unsigned char)i,0x19,0x11); //开启TADC
|
||||
}else{
|
||||
cmd2 =fHandler->genREGWrite(ucDAC|0x80,0x00,0x19,0x11);
|
||||
}
|
||||
|
||||
switch(mode){
|
||||
case 0:{
|
||||
dacHandler->setDACReg(drvUart,cmd1);
|
||||
QThread::msleep(10); // 延时10毫秒
|
||||
dacHandler->setDACReg(drvUart,cmd2);
|
||||
QThread::msleep(10); // 延时10毫秒
|
||||
dacHandler->setDACReg(drvUart,cmd2);
|
||||
QThread::msleep(10); // 延时10毫秒
|
||||
QByteArray revData = dacHandler->getDACReg(drvUart,cmd3);
|
||||
onLogPrint(" [UART] <-- Read Reg data is :"+revData.toHex(' '));
|
||||
if(revData.length()>=7){
|
||||
regData[i-1]=revData;
|
||||
}else{
|
||||
QByteArray tmp(7,0);
|
||||
regData[i-1]=tmp;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
dacHandler->setDACReg(drvSPI,cmd1);
|
||||
QThread::msleep(10); // 延时10毫秒
|
||||
dacHandler->setDACReg(drvSPI,cmd2);
|
||||
QThread::msleep(10); // 延时10毫秒
|
||||
dacHandler->setDACReg(drvSPI,cmd2);
|
||||
QThread::msleep(10); // 延时10毫秒
|
||||
regData[i-1]=dacHandler->getDACReg(drvSPI,cmd3);
|
||||
onLogPrint(" [SPI] <-- Read Reg data is :"+regData[i-1].toHex(' '));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// qDebug()<<"index is "+QString::number(i);
|
||||
}
|
||||
|
||||
//再次关闭TADC
|
||||
switch(mode){
|
||||
case 0 :{
|
||||
dacHandler->setDACReg(drvUart,cmd1);
|
||||
break;
|
||||
}
|
||||
case 1:{
|
||||
dacHandler->setDACReg(drvSPI,cmd1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
for(int j=0;j<256;j++){
|
||||
// voltage[j]=((regData[j].at(1)&0x3)<<8)|regData[j].at(2);
|
||||
voltage[j]=((static_cast<unsigned int>((regData[j].at(1))&0x03))<<8)|(static_cast<unsigned char>((regData[j].at(2))&0xff));;
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
for (int j = 0; j < 16; ++j) {
|
||||
// 将 int 转换为 QString
|
||||
QString data = QString::number(voltage[i*16+j]);
|
||||
// qDebug()<<voltage[i*16+j];
|
||||
// 创建 QTableWidgetItem 并设置数据
|
||||
QTableWidgetItem *item = new QTableWidgetItem(data);
|
||||
// 将 item 放入指定的单元格
|
||||
ui->tableWidget->setItem(i, j, item);
|
||||
}
|
||||
}
|
||||
ui->label_13->setText("Read voltage from chip : ");
|
||||
}
|
||||
|
||||
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);
|
||||
// }
|
||||
|
||||
void MainWindow::on_pushButton_4_clicked()
|
||||
{
|
||||
unsigned int voltageValue[16][16]={0};
|
||||
// 遍历表格的每一行和每一列
|
||||
for (int row = 0; row < 16; ++row) {
|
||||
for (int col = 0; col < 16; ++col) {
|
||||
// 检查单元格是否存在
|
||||
if (QTableWidgetItem *item = ui->tableWidget->item(row, col)) {
|
||||
// 获取单元格文本并转换为整数
|
||||
bool ok;
|
||||
unsigned int value = item->text().toUInt(&ok);
|
||||
if (ok) {
|
||||
// 转换成功,将值存入数组
|
||||
voltageValue[row][col] = value;
|
||||
} else {
|
||||
// 转换失败(例如单元格为空或包含非数字字符),
|
||||
// 在这里可以处理错误,比如设置一个默认值
|
||||
voltageValue[row][col] = 0; // 默认值
|
||||
}
|
||||
} else {
|
||||
// 单元格不存在,也设置一个默认值
|
||||
voltageValue[row][col] = 0; // 默认值
|
||||
}
|
||||
}
|
||||
}
|
||||
unsigned char ucDAC = ui->comboBox_15->currentText().toUInt(NULL, 10);
|
||||
|
||||
QByteArray tmp = fHandler->genVoltage(ucDAC,voltageValue);
|
||||
|
||||
|
||||
switch (ui->comboBox->currentIndex()) {
|
||||
case 0:{
|
||||
if(!dacHandler->setDACVoltage(drvUart,tmp))
|
||||
{
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 1:
|
||||
{
|
||||
|
||||
if(!dacHandler->setDACVoltage(drvSPI,tmp))
|
||||
{
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_pushButton_13_clicked()
|
||||
{
|
||||
ui->textBrowser->clear();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_pushButton_16_clicked()
|
||||
{
|
||||
// 1. 获取当前时间并格式化
|
||||
QString currentDateTime = QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss");
|
||||
|
||||
// 2. 构建完整的文件名
|
||||
QString fileName = currentDateTime + ".txt";
|
||||
|
||||
// 3. 创建 QFileDialog 并打开文件
|
||||
QFile file(fileName);
|
||||
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
// 4. 使用 QTextStream 写入文本内容
|
||||
QTextStream out(&file);
|
||||
|
||||
// 获取 QTextBrowser 的纯文本内容
|
||||
out << ui->textBrowser->toPlainText();
|
||||
file.close();
|
||||
onLogPrint("Save log success, filename is "+fileName);
|
||||
}else{
|
||||
onLogPrint("Fail to save log.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_pushButton_15_clicked()
|
||||
{
|
||||
dt = new DialogTest(this);
|
||||
connect(dt,&DialogTest::testReadRegSPI,this,&MainWindow::handleTestReadRegSPI);
|
||||
connect(dt,&DialogTest::testSendRegSPI,this,&MainWindow::handleTestSendRegSPI);
|
||||
connect(dt,&DialogTest::testSendSPI0,this,&MainWindow::handleTestSendSPI0);
|
||||
dt->show();
|
||||
|
||||
}
|
||||
|
||||
|
||||
37
mainwindow.h
37
mainwindow.h
@ -3,12 +3,12 @@
|
||||
|
||||
#include <QMainWindow>
|
||||
#include "dialogcalibrate.h"
|
||||
#include "src/headers/drv_uart.h"
|
||||
#include "src/headers/drv_spi.h"
|
||||
#include "QDateTime"
|
||||
#include "src/headers/framehandler.h"#include "src/headers/framehandler.h"
|
||||
|
||||
|
||||
#include "QFile"
|
||||
#include "QFileDialog"
|
||||
#include "QTextStream"
|
||||
#include "dachandler.h"
|
||||
#include "dialogtest.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
@ -28,6 +28,9 @@ public:
|
||||
|
||||
public slots:
|
||||
void onLogPrint(QString msg);
|
||||
void handleTestSendRegSPI(QByteArray data);
|
||||
void handleTestReadRegSPI(QByteArray data);
|
||||
void handleTestSendSPI0();
|
||||
|
||||
private slots:
|
||||
void on_pushButton_14_clicked();
|
||||
@ -54,20 +57,30 @@ private slots:
|
||||
void on_pushButton_10_clicked();
|
||||
|
||||
void on_btnSpiSaveSetting_clicked();
|
||||
void onWriteRegButtonClicked();
|
||||
void onReadRegButtonClicked();
|
||||
|
||||
void on_comboBox_currentTextChanged(const QString& text);
|
||||
void on_pushButton_11_clicked();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
DialogCalibrate *dc;
|
||||
void on_pushButton_12_clicked();
|
||||
|
||||
void on_pushButton_4_clicked();
|
||||
|
||||
void on_pushButton_13_clicked();
|
||||
|
||||
void on_pushButton_16_clicked();
|
||||
|
||||
void on_pushButton_15_clicked();
|
||||
|
||||
public :
|
||||
DRV_Uart *drvUart;
|
||||
DRV_Spi *drvSPI;
|
||||
FrameHandler *fHandler;
|
||||
|
||||
FrameHandler *fHandler;
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
DialogCalibrate *dc;
|
||||
DACHandler *dacHandler;
|
||||
|
||||
DialogTest *dt;
|
||||
|
||||
};
|
||||
#endif // MAINWINDOW_H
|
||||
|
||||
146
mainwindow.ui
146
mainwindow.ui
@ -90,7 +90,7 @@
|
||||
<string>Timeout(ms):</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignmentFlag::AlignCenter</set>
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -149,7 +149,7 @@
|
||||
<string>Data Bits:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignmentFlag::AlignCenter</set>
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -159,7 +159,7 @@
|
||||
<string>Stop Bits:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignmentFlag::AlignCenter</set>
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -258,7 +258,7 @@
|
||||
<string>Baud Rate:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter</set>
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -268,7 +268,7 @@
|
||||
<string>Parity Bits:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter</set>
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -288,7 +288,7 @@
|
||||
<string>UART Device List:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter</set>
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -311,7 +311,7 @@
|
||||
<string>SPI Device List:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignmentFlag::AlignCenter</set>
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -358,7 +358,7 @@
|
||||
<string>SPI Mode:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignmentFlag::AlignCenter</set>
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -444,7 +444,7 @@
|
||||
<string>Clock:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignmentFlag::AlignCenter</set>
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -454,7 +454,7 @@
|
||||
<string>LSB/MSB</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignmentFlag::AlignCenter</set>
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -491,7 +491,7 @@
|
||||
<string>DataBits:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignmentFlag::AlignCenter</set>
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -572,21 +572,35 @@
|
||||
<string>Voltage Check</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="pushButton_11">
|
||||
<property name="text">
|
||||
<string>Import Voltage From File</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QPushButton" name="pushButton_12">
|
||||
<property name="text">
|
||||
<string>Read Voltage From Chip</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="3" column="1">
|
||||
<widget class="QPushButton" name="pushButton_4">
|
||||
<property name="text">
|
||||
<string>Send Voltage</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<widget class="QPushButton" name="pushButton_14">
|
||||
<property name="text">
|
||||
<string>Start Calibrate</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_13">
|
||||
<property name="text">
|
||||
<string>Ready to write:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="2">
|
||||
<widget class="QTableWidget" name="tableWidget">
|
||||
<property name="rowCount">
|
||||
<number>16</number>
|
||||
@ -628,10 +642,10 @@
|
||||
<column/>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QPushButton" name="pushButton_14">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QPushButton" name="pushButton_11">
|
||||
<property name="text">
|
||||
<string>Start Calibrate</string>
|
||||
<string>Import Voltage From File</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -641,10 +655,10 @@
|
||||
<item row="0" column="6">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Policy::MinimumExpanding</enum>
|
||||
<enum>QSizePolicy::MinimumExpanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@ -666,6 +680,13 @@
|
||||
<string>Log</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_7">
|
||||
<item row="2" column="0">
|
||||
<widget class="QPushButton" name="pushButton_13">
|
||||
<property name="text">
|
||||
<string>Clear</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QTextBrowser" name="textBrowser">
|
||||
<property name="enabled">
|
||||
@ -680,9 +701,9 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="pushButton_13">
|
||||
<widget class="QPushButton" name="pushButton_16">
|
||||
<property name="text">
|
||||
<string>Clear</string>
|
||||
<string>Save</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -728,16 +749,16 @@
|
||||
<string>Reg Value</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_11">
|
||||
<item row="3" column="2">
|
||||
<widget class="QLineEdit" name="lineEdit_10"/>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLabel" name="label_26">
|
||||
<item row="3" column="1">
|
||||
<widget class="QLabel" name="label_25">
|
||||
<property name="text">
|
||||
<string>Reg 3:</string>
|
||||
<string>Reg 4:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLineEdit" name="lineEdit_11"/>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QLabel" name="label_23">
|
||||
<property name="text">
|
||||
@ -745,11 +766,14 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QLineEdit" name="lineEdit_12"/>
|
||||
<item row="4" column="2">
|
||||
<widget class="QLineEdit" name="lineEdit_13"/>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLineEdit" name="lineEdit_9"/>
|
||||
<item row="5" column="2">
|
||||
<widget class="QLineEdit" name="lineEdit_8"/>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QLineEdit" name="lineEdit_10"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="label_27">
|
||||
@ -758,11 +782,25 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="2">
|
||||
<widget class="QLineEdit" name="lineEdit_8"/>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLineEdit" name="lineEdit_9"/>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<widget class="QLineEdit" name="lineEdit_13"/>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label_24">
|
||||
<property name="text">
|
||||
<string>Reg 1:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QLineEdit" name="lineEdit_12"/>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLabel" name="label_26">
|
||||
<property name="text">
|
||||
<string>Reg 3:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLabel" name="label_22">
|
||||
@ -771,22 +809,15 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLineEdit" name="lineEdit_11"/>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLabel" name="label_25">
|
||||
<item row="6" column="1">
|
||||
<widget class="QLabel" name="label_16">
|
||||
<property name="text">
|
||||
<string>Reg 4:</string>
|
||||
<string>Reg 7:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label_24">
|
||||
<property name="text">
|
||||
<string>Reg 1:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<item row="6" column="2">
|
||||
<widget class="QLineEdit" name="lineEdit_3"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
@ -1092,6 +1123,13 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="7">
|
||||
<widget class="QPushButton" name="pushButton_15">
|
||||
<property name="text">
|
||||
<string>Test Mode</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
@ -1100,7 +1138,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>839</width>
|
||||
<height>33</height>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
|
||||
@ -1,10 +0,0 @@
|
||||
#ifndef CRC_H
|
||||
#define CRC_H
|
||||
|
||||
#include <QByteArray>
|
||||
|
||||
// 直接计算反射型CRC16-CCITT,输出低字节在前的QByteArray
|
||||
QByteArray crc16Reverse(const QByteArray& data);
|
||||
// void generate_crc16_reverse_table(quint16 table[256]);
|
||||
|
||||
#endif // CRC_H
|
||||
41
src/headers/dachandler.h
Normal file
41
src/headers/dachandler.h
Normal file
@ -0,0 +1,41 @@
|
||||
#ifndef DACHANDLER_H
|
||||
#define DACHANDLER_H
|
||||
|
||||
#include <QObject>
|
||||
#include "src/headers/framehandler.h"
|
||||
#include "src/headers/drv_uart.h"
|
||||
#include "src/headers/drv_spi.h"
|
||||
#include "QThread"
|
||||
|
||||
class DACHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DACHandler(QObject *parent = nullptr);
|
||||
|
||||
//UART
|
||||
bool setDACVoltage(DRV_Uart *drvUart, QByteArray &data); //发送一个DAC的电压,done
|
||||
bool setVoltage(DRV_Uart *drvUart, QByteArray &data); //发送所有DAC的电压
|
||||
bool setDACReg(DRV_Uart *drvUart, QByteArray &data); //设置DAC寄存器,done
|
||||
|
||||
QByteArray getDACReg(DRV_Uart *drvUart, QByteArray &data); // 回读DAC寄存器,done
|
||||
bool getChannelVoltage(DRV_Uart *drvUart,QByteArray &data); //回读指定通道的电压值
|
||||
bool getDACVoltage(DRV_Uart *drvUart, QByteArray &data); //回读指定DAC的所有电压值
|
||||
|
||||
//SPI
|
||||
bool setDACVoltage(DRV_Spi *drvSPI, QByteArray &data); //发送一个DAC的电压,done
|
||||
bool setVoltage(DRV_Spi *drvSPI,QByteArray &data); //发送所有DAC的电压
|
||||
bool setDACReg(DRV_Spi *drvSPI, QByteArray &data); //设置DAC寄存器,done
|
||||
|
||||
QByteArray getDACReg(DRV_Spi *drvSPI, QByteArray &data); // 回读DAC寄存器,done
|
||||
bool getChannelVoltage(DRV_Spi *drvSPI,QByteArray &data); //回读指定通道的电压值
|
||||
bool getDACVoltage(DRV_Spi *drvSPI, QByteArray &data); //回读指定DAC的所有电压值
|
||||
|
||||
|
||||
|
||||
|
||||
signals:
|
||||
void logMsg(QString msg);
|
||||
};
|
||||
|
||||
#endif // DACHANDLER_H
|
||||
@ -12,6 +12,7 @@ public:
|
||||
explicit FrameHandler(QObject *parent = nullptr);
|
||||
QByteArray genREGWrite(unsigned char ucDAC,unsigned char ucChannel,unsigned char ucFun1,unsigned char ucFun2);
|
||||
QByteArray genREGRead(unsigned char ucDAC);
|
||||
QByteArray genVoltage(unsigned char ucDAC, unsigned int (*voltage)[16]); //fixed lenth is 16*16;
|
||||
QByteArray genCrc16(const QByteArray& data);
|
||||
QByteArray genSum(const QByteArray& data);
|
||||
static void genCrc16table(quint16 table[256], quint16 poly);
|
||||
|
||||
@ -1,7 +0,0 @@
|
||||
#include "crc.h"
|
||||
|
||||
// 函数声明
|
||||
// void generate_crc16_reverse_table(quint16 *table);
|
||||
// QByteArray crc16Reverse(const QByteArray& data);
|
||||
|
||||
|
||||
91
src/sources/dachandler.cpp
Normal file
91
src/sources/dachandler.cpp
Normal file
@ -0,0 +1,91 @@
|
||||
#include "dachandler.h"
|
||||
#include "dachandler.h"
|
||||
|
||||
DACHandler::DACHandler(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool DACHandler::setDACVoltage(DRV_Uart *drvUart, QByteArray &data)
|
||||
{
|
||||
|
||||
if (drvUart->Uart_Write(data)) {
|
||||
emit logMsg(" [UART] --> Send data success, data is (hex) :" + data.toHex(' '));
|
||||
return true;
|
||||
} else {
|
||||
emit logMsg(" [UART] Send data fail");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool DACHandler::setDACReg(DRV_Uart *drvUart, QByteArray &data)
|
||||
{
|
||||
if(drvUart->Uart_Write(data)){
|
||||
emit logMsg(" [UART] --> Send data success, data is (hex) :" + data.toHex(' '));
|
||||
return true;
|
||||
}else{
|
||||
emit logMsg(" [UART] Send data failed");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray DACHandler::getDACReg(DRV_Uart *drvUart, QByteArray &data)
|
||||
{
|
||||
if (drvUart->Uart_Write(data)) {
|
||||
emit logMsg(" [UART] --> Send data success, data is (hex) :" + data.toHex(' '));
|
||||
} else {
|
||||
emit logMsg(" [UART] Send data failed");
|
||||
}
|
||||
QThread::msleep(2);
|
||||
QByteArray revDatatmp;
|
||||
drvUart->Uart_Read(revDatatmp);
|
||||
return revDatatmp;
|
||||
}
|
||||
|
||||
bool DACHandler::setDACVoltage(DRV_Spi *drvSPI, QByteArray &data)
|
||||
{
|
||||
QByteArray data1= data;
|
||||
if (drvSPI->spi_Write(data1)) {
|
||||
emit logMsg(" [SPI] --> Send data success, data is (hex) :" + data.toHex(' '));
|
||||
return true;
|
||||
} else {
|
||||
emit logMsg(" [SPI] Send data fail");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool DACHandler::setDACReg(DRV_Spi *drvSPI, QByteArray &data)
|
||||
{
|
||||
QByteArray data1= data;
|
||||
if(drvSPI->spi_Write(data1)){
|
||||
emit logMsg(" [SPI] --> Send data success, data is (hex) :" + data.toHex(' '));
|
||||
return true;
|
||||
}else{
|
||||
emit logMsg(" [SPI] Send data failed");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray DACHandler::getDACReg(DRV_Spi *drvSPI, QByteArray &data)
|
||||
{
|
||||
QByteArray revData(7,0);
|
||||
QByteArray data1= data;
|
||||
if(drvSPI->spi_Write(data1)){
|
||||
emit logMsg(" [SPI] --> Send data success, data is (hex) :" + data.toHex(' '));
|
||||
QThread::msleep(2);
|
||||
if(drvSPI->spi_Write(revData)){
|
||||
emit logMsg(" [SPI] --> Send data success, data is (hex) :" + revData.toHex(' '));
|
||||
}else{
|
||||
emit logMsg(" [SPI] Send data failed");
|
||||
}
|
||||
}else{
|
||||
emit logMsg(" [SPI] Send data failed");
|
||||
}
|
||||
return revData;
|
||||
}
|
||||
|
||||
|
||||
@ -91,3 +91,56 @@ QByteArray FrameHandler::genREGRead(unsigned char ucDAC)
|
||||
nFrameCount++;
|
||||
return cmd1;
|
||||
}
|
||||
|
||||
QByteArray FrameHandler::genVoltage(unsigned char ucDAC, unsigned int (*voltage)[16])
|
||||
{
|
||||
QByteArray cmd1(17,0);
|
||||
cmd1[0]=0x9F;
|
||||
cmd1[1]=0xE4;
|
||||
cmd1[2]=0x03;
|
||||
cmd1[3]=0x03;
|
||||
cmd1[4]=ucDAC;
|
||||
cmd1[14]=nFrameCount;
|
||||
QByteArray sumResult = genSum(cmd1);
|
||||
cmd1[15]=static_cast<char>(sumResult.at(0));
|
||||
cmd1[16]=0x02;
|
||||
|
||||
uint16_t data_in[256]; // 16x16=256个元素
|
||||
for(int i = 0; i < 16; i++) {
|
||||
for(int j = 0; j < 16; j++) {
|
||||
// 确保10bit数据在0-1023范围内
|
||||
data_in[i*16 + j] = static_cast<uint16_t>(voltage[i][j] & 0x3FF);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 准备输出缓冲区
|
||||
QByteArray data_out;
|
||||
data_out.resize(320); // 64*5=320字节
|
||||
|
||||
// 3. 执行原始的数据转换,已经顺序交换
|
||||
// for(uint16_t i = 0; i < 64; i++) {
|
||||
// data_out[i*5] = static_cast<char>(data_in[i*4+3] >> 2);
|
||||
// data_out[i*5+1] = static_cast<char>((data_in[i*4+3] << 6) | (data_in[i*4+2] >> 4));
|
||||
// data_out[i*5+2] = static_cast<char>((data_in[i*4+2] << 4) | (data_in[i*4+1] >> 6));
|
||||
// data_out[i*5+3] = static_cast<char>((data_in[i*4+1] << 2) | (data_in[i*4] >> 8));
|
||||
// data_out[i*5+4] = static_cast<char>(data_in[i*4] & 0xFF);
|
||||
// }
|
||||
|
||||
for(uint16_t i = 0; i < 64; i++) {
|
||||
data_out[i*5] = static_cast<char>(data_in[i*4] & 0xFF);
|
||||
data_out[i*5+1] = static_cast<char>((data_in[i*4+1] << 2) | (data_in[i*4] >> 8));
|
||||
data_out[i*5+2] = static_cast<char>((data_in[i*4+2] << 4) | (data_in[i*4+1] >> 6));
|
||||
data_out[i*5+3] = static_cast<char>((data_in[i*4+3] << 6) | (data_in[i*4+2] >> 4));
|
||||
data_out[i*5+4] = static_cast<char>(data_in[i*4+3] >> 2);
|
||||
}
|
||||
|
||||
QByteArray crcRes= genCrc16(data_out);
|
||||
|
||||
|
||||
QByteArray cmd = cmd1+data_out+crcRes;
|
||||
cmd.append(genSum(cmd));
|
||||
|
||||
nFrameCount++;
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
||||
16
voltageTmp/voltagetmp_1.csv
Normal file
16
voltageTmp/voltagetmp_1.csv
Normal file
@ -0,0 +1,16 @@
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
|
||||
|
Loading…
Reference in New Issue
Block a user