Compare commits
No commits in common. "a2ed7045c809526a88bcf0587ad67be8b4bb6233" and "89d1827e71ed0f4263b63555d94bb6c1ef9a3624" have entirely different histories.
a2ed7045c8
...
89d1827e71
@ -10,27 +10,24 @@ CONFIG += c++17
|
|||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
dialogcalibrate.cpp \
|
dialogcalibrate.cpp \
|
||||||
dialogtest.cpp \
|
|
||||||
src/sources/dachandler.cpp \
|
|
||||||
src/sources/framehandler.cpp \
|
src/sources/framehandler.cpp \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
mainwindow.cpp \
|
mainwindow.cpp \
|
||||||
|
src/sources/crc.cpp \
|
||||||
src/sources/drv_spi.cpp \
|
src/sources/drv_spi.cpp \
|
||||||
src/sources/drv_uart.cpp
|
src/sources/drv_uart.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
dialogcalibrate.h \
|
dialogcalibrate.h \
|
||||||
dialogtest.h \
|
|
||||||
src/headers/dachandler.h \
|
|
||||||
src/headers/framehandler.h \
|
src/headers/framehandler.h \
|
||||||
mainwindow.h \
|
mainwindow.h \
|
||||||
src/headers/CH347DLL.H \
|
src/headers/CH347DLL.H \
|
||||||
|
src/headers/crc.h \
|
||||||
src/headers/drv_spi.h \
|
src/headers/drv_spi.h \
|
||||||
src/headers/drv_uart.h
|
src/headers/drv_uart.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
dialogcalibrate.ui \
|
dialogcalibrate.ui \
|
||||||
dialogtest.ui \
|
|
||||||
mainwindow.ui
|
mainwindow.ui
|
||||||
|
|
||||||
LIBS += -L$$PWD/lib -lCH347DLLA64
|
LIBS += -L$$PWD/lib -lCH347DLLA64
|
||||||
|
|||||||
@ -15,7 +15,6 @@ public:
|
|||||||
explicit DialogCalibrate(QWidget *parent = nullptr);
|
explicit DialogCalibrate(QWidget *parent = nullptr);
|
||||||
~DialogCalibrate();
|
~DialogCalibrate();
|
||||||
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_pushButton_clicked();
|
void on_pushButton_clicked();
|
||||||
|
|
||||||
|
|||||||
@ -1,45 +0,0 @@
|
|||||||
#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
36
dialogtest.h
@ -1,36 +0,0 @@
|
|||||||
#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
|
|
||||||
@ -1,98 +0,0 @@
|
|||||||
<?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>
|
|
||||||
558
mainwindow.cpp
558
mainwindow.cpp
@ -1,31 +1,14 @@
|
|||||||
#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)
|
||||||
, ui(new Ui::MainWindow)
|
, ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
dacHandler= new DACHandler(this);
|
|
||||||
drvUart = new DRV_Uart(this);
|
|
||||||
drvSPI = new DRV_Spi(this);
|
drvSPI = new DRV_Spi(this);
|
||||||
|
drvUart = new DRV_Uart(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()
|
MainWindow::~MainWindow()
|
||||||
@ -42,33 +25,6 @@ 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()
|
void MainWindow::on_pushButton_14_clicked()
|
||||||
{
|
{
|
||||||
dc= new DialogCalibrate(this);
|
dc= new DialogCalibrate(this);
|
||||||
@ -92,7 +48,7 @@ void MainWindow::on_pushButton_6_clicked()
|
|||||||
for(int i = 0; i < drvUart->m_DRV_Uart_Infors.ulDevCnt; i++)
|
for(int i = 0; i < drvUart->m_DRV_Uart_Infors.ulDevCnt; i++)
|
||||||
ui->comboBox_7->addItem(drvUart->m_DRV_Uart_Infors.bDeviceName[i]);
|
ui->comboBox_7->addItem(drvUart->m_DRV_Uart_Infors.bDeviceName[i]);
|
||||||
}else{
|
}else{
|
||||||
onLogPrint("No UART devices");
|
onLogPrint("No devices");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -114,9 +70,9 @@ void MainWindow::on_pushButton_7_clicked()
|
|||||||
ui->lineEdit->setEnabled(true);
|
ui->lineEdit->setEnabled(true);
|
||||||
ui->pushButton_5->setEnabled(true);
|
ui->pushButton_5->setEnabled(true);
|
||||||
ui->pushButton_7->setEnabled(false);
|
ui->pushButton_7->setEnabled(false);
|
||||||
onLogPrint("Open UART device success");
|
onLogPrint("Open device success");
|
||||||
}else{
|
}else{
|
||||||
onLogPrint("Fail to open UART device");
|
onLogPrint("Open device failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,9 +87,9 @@ void MainWindow::on_pushButton_8_clicked()
|
|||||||
UCHAR Timeout = this->ui->lineEdit->text().toUInt();
|
UCHAR Timeout = this->ui->lineEdit->text().toUInt();
|
||||||
// 调用配置参数函数进行配置
|
// 调用配置参数函数进行配置
|
||||||
if(drvUart->Uart_setPara(Baudrate, StopBits, Parity, DataBits, Timeout)){
|
if(drvUart->Uart_setPara(Baudrate, StopBits, Parity, DataBits, Timeout)){
|
||||||
onLogPrint("Set UART parameters success");
|
onLogPrint("Set parameters success");
|
||||||
}else{
|
}else{
|
||||||
onLogPrint("Fail to set UART parameters");
|
onLogPrint("Fail to set parameters");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,10 +107,9 @@ 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 UART device success");
|
|
||||||
}else{
|
}else{
|
||||||
onLogPrint("Fail to close UART device ");
|
onLogPrint("Close device failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +122,7 @@ void MainWindow::on_pushButton_clicked()
|
|||||||
// 将串口设备的名称添加至列表中
|
// 将串口设备的名称添加至列表中
|
||||||
ui->comboBox_2->addItem(drvSPI->m_DRV_Spi_Infors.bDeviceName);
|
ui->comboBox_2->addItem(drvSPI->m_DRV_Spi_Infors.bDeviceName);
|
||||||
}else{
|
}else{
|
||||||
onLogPrint("No SPI devices");
|
onLogPrint("No devices");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,27 +130,27 @@ void MainWindow::on_pushButton_clicked()
|
|||||||
void MainWindow::on_pushButton_2_clicked()
|
void MainWindow::on_pushButton_2_clicked()
|
||||||
{
|
{
|
||||||
ULONG index = ui->comboBox_2->currentIndex();
|
ULONG index = ui->comboBox_2->currentIndex();
|
||||||
// 调用打开函数
|
// 调用串口打开函数
|
||||||
BOOL status = drvSPI->spi_openDevice(index);
|
BOOL status = drvSPI->spi_openDevice(index);
|
||||||
|
|
||||||
// 判断打开设备是否成功
|
// 判断打开串口设备是否成功
|
||||||
if(status == TRUE){
|
if(status == TRUE){
|
||||||
ui->comboSpiMode->setEnabled(true);
|
ui->comboBox_3->setEnabled(true);
|
||||||
ui->comboSpiClock->setEnabled(true);
|
ui->comboBox_4->setEnabled(true);
|
||||||
ui->comboSpiByteOrder->setEnabled(true);
|
ui->comboBox_5->setEnabled(true);
|
||||||
ui->comboSpiDataBits->setEnabled(true);
|
ui->comboBox_6->setEnabled(true);
|
||||||
ui->comboSpiCS1Pol->setEnabled(true);
|
ui->comboBox_16->setEnabled(true);
|
||||||
ui->comboSpiCS2Pol->setEnabled(true);
|
ui->comboBox_17->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 SPI device success");
|
|
||||||
}else{
|
}else{
|
||||||
onLogPrint("Fail to open SPI device.");
|
onLogPrint("Open device failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::on_pushButton_3_clicked()
|
void MainWindow::on_pushButton_3_clicked()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -203,477 +158,32 @@ void MainWindow::on_pushButton_3_clicked()
|
|||||||
|
|
||||||
// 判断打开串口设备是否成功
|
// 判断打开串口设备是否成功
|
||||||
if(status == TRUE){
|
if(status == TRUE){
|
||||||
ui->comboSpiMode->setEnabled(false);
|
ui->comboBox_3->setEnabled(false);
|
||||||
ui->comboSpiClock->setEnabled(false);
|
ui->comboBox_4->setEnabled(false);
|
||||||
ui->comboSpiByteOrder->setEnabled(false);
|
ui->comboBox_5->setEnabled(false);
|
||||||
ui->comboSpiDataBits->setEnabled(false);
|
ui->comboBox_6->setEnabled(false);
|
||||||
ui->comboSpiCS1Pol->setEnabled(false);
|
ui->comboBox_16->setEnabled(false);
|
||||||
ui->comboSpiCS2Pol->setEnabled(false);
|
ui->comboBox_17->setEnabled(false);
|
||||||
ui->pushButton_3->setEnabled(false);
|
ui->pushButton_3->setEnabled(false);
|
||||||
ui->pushButton_2->setEnabled(true);
|
ui->pushButton_2->setEnabled(true);
|
||||||
|
|
||||||
onLogPrint("Close SPI device success");
|
onLogPrint("Close device success");
|
||||||
}else{
|
}else{
|
||||||
onLogPrint("Fail to close device.");
|
onLogPrint("Close device failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::on_pushButton_9_clicked() {
|
void MainWindow::on_pushButton_9_clicked()
|
||||||
unsigned char REG[4] = { 0 };
|
|
||||||
unsigned char ucDAC = ui->comboBox_15->currentText().toUInt(NULL, 10);
|
|
||||||
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 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);
|
|
||||||
|
|
||||||
|
|
||||||
switch (ui->comboBox->currentIndex()) {
|
|
||||||
case 0:
|
|
||||||
if (!dacHandler->setDACReg(drvUart,tmp1))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
if (!dacHandler->setDACReg(drvSPI,tmp1))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::on_pushButton_10_clicked() {
|
|
||||||
unsigned char ucDAC = ui->comboBox_15->currentText().toUInt(NULL, 10);
|
|
||||||
QByteArray tmp = fHandler->genREGRead(ucDAC);
|
|
||||||
QByteArray revDatatmp;
|
|
||||||
switch (ui->comboBox->currentIndex()) {
|
|
||||||
case 0:
|
|
||||||
{
|
|
||||||
QByteArray ba = dacHandler->getDACReg(drvUart,tmp);
|
|
||||||
revDatatmp = ba;
|
|
||||||
revDatatmp.detach();
|
|
||||||
onLogPrint(" [UART] <-- Read Reg data is :"+ ba.toHex(' '));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
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() {
|
|
||||||
BOOL ret = false;
|
|
||||||
ret= drvSPI->spi_Init(
|
|
||||||
ui->comboSpiMode->currentIndex(),
|
|
||||||
ui->comboSpiClock->currentIndex(),
|
|
||||||
ui->comboSpiByteOrder->currentIndex(),
|
|
||||||
ui->comboSpiDataBits->currentIndex(),
|
|
||||||
ui->comboSpiCS1Pol->currentIndex(),
|
|
||||||
ui->comboSpiCS2Pol->currentIndex()
|
|
||||||
);
|
|
||||||
if(ret){
|
|
||||||
onLogPrint("Save SPI parameters success");
|
|
||||||
}else{
|
|
||||||
onLogPrint("Fail to set SPI parameters.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::on_pushButton_11_clicked()
|
|
||||||
{
|
{
|
||||||
// 弹出“打开文件”对话框
|
QByteArray tmp = fHandler->genREGWrite(0x01,0x01,0x09,0x81);
|
||||||
QString filePath = QFileDialog::getOpenFileName(
|
qDebug()<<tmp.toHex();
|
||||||
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::on_pushButton_12_clicked()
|
void MainWindow::on_pushButton_10_clicked()
|
||||||
{
|
{
|
||||||
// // 从1至256通道依次读取电压值
|
QByteArray tmp = fHandler->genREGRead(0x01);
|
||||||
// for(ch_index = 1; ch_index <= 256; ch_index++)
|
qDebug()<<tmp.toHex();
|
||||||
// {
|
|
||||||
// // 设置配置项
|
|
||||||
// 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 tmp = dacHandler->getDACReg(drvUart,cmd3);
|
|
||||||
QByteArray revData = tmp;
|
|
||||||
revData.detach();
|
|
||||||
onLogPrint(" [UART] <-- Read Reg data is :"+tmp.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_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 <QMainWindow>
|
||||||
#include "dialogcalibrate.h"
|
#include "dialogcalibrate.h"
|
||||||
|
#include "src/headers/drv_uart.h"
|
||||||
|
#include "src/headers/drv_spi.h"
|
||||||
#include "QDateTime"
|
#include "QDateTime"
|
||||||
#include "QFile"
|
#include "src/headers/framehandler.h"
|
||||||
#include "QFileDialog"
|
|
||||||
#include "QTextStream"
|
|
||||||
#include "dachandler.h"
|
|
||||||
#include "dialogtest.h"
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
@ -28,9 +28,6 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onLogPrint(QString msg);
|
void onLogPrint(QString msg);
|
||||||
void handleTestSendRegSPI(QByteArray data);
|
|
||||||
void handleTestReadRegSPI(QByteArray data);
|
|
||||||
void handleTestSendSPI0();
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_pushButton_14_clicked();
|
void on_pushButton_14_clicked();
|
||||||
@ -56,31 +53,13 @@ private slots:
|
|||||||
|
|
||||||
void on_pushButton_10_clicked();
|
void on_pushButton_10_clicked();
|
||||||
|
|
||||||
void on_btnSpiSaveSetting_clicked();
|
private:
|
||||||
|
Ui::MainWindow *ui;
|
||||||
void on_pushButton_11_clicked();
|
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_Uart *drvUart;
|
||||||
DRV_Spi *drvSPI;
|
DRV_Spi *drvSPI;
|
||||||
FrameHandler *fHandler;
|
FrameHandler *fHandler;
|
||||||
|
|
||||||
private:
|
|
||||||
Ui::MainWindow *ui;
|
|
||||||
DialogCalibrate *dc;
|
|
||||||
DACHandler *dacHandler;
|
|
||||||
|
|
||||||
DialogTest *dt;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|||||||
165
mainwindow.ui
165
mainwindow.ui
@ -316,13 +316,10 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="2" column="1">
|
||||||
<widget class="QComboBox" name="comboSpiByteOrder">
|
<widget class="QComboBox" name="comboBox_4">
|
||||||
<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>
|
||||||
@ -336,7 +333,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="3">
|
<item row="2" column="3">
|
||||||
<widget class="QComboBox" name="comboSpiDataBits">
|
<widget class="QComboBox" name="comboBox_6">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
@ -363,10 +360,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="5" rowspan="2">
|
<item row="1" column="5" rowspan="2">
|
||||||
<widget class="QPushButton" name="btnSpiSaveSetting">
|
<widget class="QPushButton" name="pushButton_4">
|
||||||
<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>
|
||||||
@ -389,13 +383,10 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="3">
|
<item row="1" column="3">
|
||||||
<widget class="QComboBox" name="comboSpiClock">
|
<widget class="QComboBox" name="comboBox_5">
|
||||||
<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>
|
||||||
@ -459,7 +450,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QComboBox" name="comboSpiMode">
|
<widget class="QComboBox" name="comboBox_3">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
@ -496,7 +487,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="4">
|
<item row="1" column="4">
|
||||||
<widget class="QComboBox" name="comboSpiCS1Pol">
|
<widget class="QComboBox" name="comboBox_16">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
@ -513,7 +504,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="4">
|
<item row="2" column="4">
|
||||||
<widget class="QComboBox" name="comboSpiCS2Pol">
|
<widget class="QComboBox" name="comboBox_17">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
@ -572,35 +563,21 @@
|
|||||||
<string>Voltage Check</string>
|
<string>Voltage Check</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_4">
|
<layout class="QGridLayout" name="gridLayout_4">
|
||||||
<item row="2" column="0" colspan="2">
|
<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">
|
||||||
<widget class="QPushButton" name="pushButton_12">
|
<widget class="QPushButton" name="pushButton_12">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Read Voltage From Chip</string>
|
<string>Read Voltage From Chip</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="1">
|
<item row="2" column="0">
|
||||||
<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">
|
<widget class="QTableWidget" name="tableWidget">
|
||||||
<property name="rowCount">
|
<property name="rowCount">
|
||||||
<number>16</number>
|
<number>16</number>
|
||||||
@ -642,10 +619,10 @@
|
|||||||
<column/>
|
<column/>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0" colspan="2">
|
<item row="3" column="0">
|
||||||
<widget class="QPushButton" name="pushButton_11">
|
<widget class="QPushButton" name="pushButton_14">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Import Voltage From File</string>
|
<string>Start Calibrate</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -680,13 +657,6 @@
|
|||||||
<string>Log</string>
|
<string>Log</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_7">
|
<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">
|
<item row="0" column="0">
|
||||||
<widget class="QTextBrowser" name="textBrowser">
|
<widget class="QTextBrowser" name="textBrowser">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
@ -701,9 +671,9 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QPushButton" name="pushButton_16">
|
<widget class="QPushButton" name="pushButton_13">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Save</string>
|
<string>Clear</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -749,52 +719,9 @@
|
|||||||
<string>Reg Value</string>
|
<string>Reg Value</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_11">
|
<layout class="QGridLayout" name="gridLayout_11">
|
||||||
<item row="3" column="1">
|
|
||||||
<widget class="QLabel" name="label_25">
|
|
||||||
<property name="text">
|
|
||||||
<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">
|
|
||||||
<string>Reg 6:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="2">
|
|
||||||
<widget class="QLineEdit" name="lineEdit_13"/>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="2">
|
|
||||||
<widget class="QLineEdit" name="lineEdit_8"/>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="2">
|
<item row="3" column="2">
|
||||||
<widget class="QLineEdit" name="lineEdit_10"/>
|
<widget class="QLineEdit" name="lineEdit_10"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="QLabel" name="label_27">
|
|
||||||
<property name="text">
|
|
||||||
<string>Reg 2:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="2">
|
|
||||||
<widget class="QLineEdit" name="lineEdit_9"/>
|
|
||||||
</item>
|
|
||||||
<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">
|
<item row="2" column="1">
|
||||||
<widget class="QLabel" name="label_26">
|
<widget class="QLabel" name="label_26">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -802,6 +729,32 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="5" column="1">
|
||||||
|
<widget class="QLabel" name="label_23">
|
||||||
|
<property name="text">
|
||||||
|
<string>Reg 6:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="2">
|
||||||
|
<widget class="QLineEdit" name="lineEdit_12"/>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="2">
|
||||||
|
<widget class="QLineEdit" name="lineEdit_9"/>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QLabel" name="label_27">
|
||||||
|
<property name="text">
|
||||||
|
<string>Reg 2:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="2">
|
||||||
|
<widget class="QLineEdit" name="lineEdit_8"/>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="2">
|
||||||
|
<widget class="QLineEdit" name="lineEdit_13"/>
|
||||||
|
</item>
|
||||||
<item row="4" column="1">
|
<item row="4" column="1">
|
||||||
<widget class="QLabel" name="label_22">
|
<widget class="QLabel" name="label_22">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -809,15 +762,22 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="6" column="1">
|
<item row="0" column="2">
|
||||||
<widget class="QLabel" name="label_16">
|
<widget class="QLineEdit" name="lineEdit_11"/>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="1">
|
||||||
|
<widget class="QLabel" name="label_25">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Reg 7:</string>
|
<string>Reg 4:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="6" column="2">
|
<item row="0" column="1">
|
||||||
<widget class="QLineEdit" name="lineEdit_3"/>
|
<widget class="QLabel" name="label_24">
|
||||||
|
<property name="text">
|
||||||
|
<string>Reg 1:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
@ -1123,13 +1083,6 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="7">
|
|
||||||
<widget class="QPushButton" name="pushButton_15">
|
|
||||||
<property name="text">
|
|
||||||
<string>Test Mode</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenuBar" name="menubar">
|
<widget class="QMenuBar" name="menubar">
|
||||||
|
|||||||
10
src/headers/crc.h
Normal file
10
src/headers/crc.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#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
|
||||||
@ -1,41 +0,0 @@
|
|||||||
#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
|
|
||||||
@ -57,8 +57,7 @@ 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驱动相关信息
|
||||||
|
|||||||
@ -12,7 +12,6 @@ public:
|
|||||||
explicit FrameHandler(QObject *parent = nullptr);
|
explicit FrameHandler(QObject *parent = nullptr);
|
||||||
QByteArray genREGWrite(unsigned char ucDAC,unsigned char ucChannel,unsigned char ucFun1,unsigned char ucFun2);
|
QByteArray genREGWrite(unsigned char ucDAC,unsigned char ucChannel,unsigned char ucFun1,unsigned char ucFun2);
|
||||||
QByteArray genREGRead(unsigned char ucDAC);
|
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 genCrc16(const QByteArray& data);
|
||||||
QByteArray genSum(const QByteArray& data);
|
QByteArray genSum(const QByteArray& data);
|
||||||
static void genCrc16table(quint16 table[256], quint16 poly);
|
static void genCrc16table(quint16 table[256], quint16 poly);
|
||||||
|
|||||||
7
src/sources/crc.cpp
Normal file
7
src/sources/crc.cpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "crc.h"
|
||||||
|
|
||||||
|
// 函数声明
|
||||||
|
// void generate_crc16_reverse_table(quint16 *table);
|
||||||
|
// QByteArray crc16Reverse(const QByteArray& data);
|
||||||
|
|
||||||
|
|
||||||
@ -1,91 +0,0 @@
|
|||||||
#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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@ -79,6 +79,7 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
//关闭设备
|
//关闭设备
|
||||||
@ -106,67 +107,35 @@ bool DRV_Spi::spi_Write(QByteArray &sendData)
|
|||||||
// 获取数据包的长度
|
// 获取数据包的长度
|
||||||
ULONG OutLen = sendData.length();
|
ULONG OutLen = sendData.length();
|
||||||
// 将QByteArray转化为UCHAR
|
// 将QByteArray转化为UCHAR
|
||||||
UCHAR *OutBuf = reinterpret_cast<unsigned char*>(sendData.data());
|
const UCHAR *OutBuf = reinterpret_cast<const unsigned char*>(sendData.constData());
|
||||||
|
|
||||||
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("Spi_Write %dBytes %s.", OutLen,RetVal?"succ":"failure");
|
DbgPrint("frame:%d,Spi_Write %dBytes %s.",sendData.at(14), OutLen,RetVal?"succ":"failure");
|
||||||
|
|
||||||
return RetVal ? true : false;
|
return RetVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DRV_Spi::spi_Read(QByteArray &revData)
|
BOOL DRV_Spi::spi_Read(QByteArray &revData)
|
||||||
{
|
{
|
||||||
ULONG InLen = 7;
|
ULONG InLen = 512; // 设置读取的长度,读取完后会将该值赋值为真实的长度
|
||||||
// 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(static_cast<char*>(InBuf), InLen);
|
revData = QByteArray::fromRawData(reinterpret_cast<const char*>(InBuf), InLen);
|
||||||
// }
|
}
|
||||||
return RetVal ? true : false;
|
return RetVal;
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -91,56 +91,3 @@ QByteArray FrameHandler::genREGRead(unsigned char ucDAC)
|
|||||||
nFrameCount++;
|
nFrameCount++;
|
||||||
return cmd1;
|
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;
|
|
||||||
}
|
|
||||||
|
|||||||
@ -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,0,0
|
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
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
|
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
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