680 lines
20 KiB
C++
680 lines
20 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
#include <QTimer>
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::MainWindow)
|
|
{
|
|
ui->setupUi(this);
|
|
dacHandler= new DACHandler(this);
|
|
drvUart = new DRV_Uart(this);
|
|
drvSPI = new DRV_Spi(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()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
|
|
void MainWindow::onLogPrint(QString msg){
|
|
|
|
auto now = QDateTime::currentDateTime();
|
|
QString tmp = now.toString("yyyy-MM-dd HH:mm:ss")+" "+msg;
|
|
ui->textBrowser->append(tmp);
|
|
|
|
}
|
|
|
|
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);
|
|
dc->show();
|
|
}
|
|
|
|
|
|
void MainWindow::on_comboBox_activated(int index)
|
|
{
|
|
ui->stackedWidget->setCurrentIndex(ui->comboBox->currentIndex());
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_pushButton_6_clicked()
|
|
{
|
|
ui->comboBox_7->clear();
|
|
// 刷新UART设备
|
|
if(drvUart->Uart_enumDevice()){
|
|
// 将串口设备的名称添加至列表中
|
|
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 UART devices");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
void MainWindow::on_pushButton_7_clicked()
|
|
{
|
|
ULONG index = ui->comboBox_7->currentIndex();
|
|
// 调用串口打开函数
|
|
BOOL status = drvUart->Uart_openDevice(index);
|
|
|
|
// 判断打开串口设备是否成功
|
|
if(status == TRUE){
|
|
ui->comboBox_8->setEnabled(true);
|
|
ui->comboBox_9->setEnabled(true);
|
|
ui->comboBox_10->setEnabled(true);
|
|
ui->comboBox_11->setEnabled(true);
|
|
ui->pushButton_8->setEnabled(true);
|
|
ui->lineEdit->setEnabled(true);
|
|
ui->pushButton_5->setEnabled(true);
|
|
ui->pushButton_7->setEnabled(false);
|
|
onLogPrint("Open UART device success");
|
|
}else{
|
|
onLogPrint("Fail to open UART device");
|
|
}
|
|
}
|
|
|
|
|
|
void MainWindow::on_pushButton_8_clicked()
|
|
{
|
|
// 读取组件中配置参数的值
|
|
ULONG Baudrate = this->ui->comboBox_8->currentText().toLong();
|
|
UCHAR StopBits = this->ui->comboBox_10->currentIndex();
|
|
UCHAR Parity = this->ui->comboBox_9->currentIndex();
|
|
UCHAR DataBits = this->ui->comboBox_11->currentText().toUInt();
|
|
UCHAR Timeout = this->ui->lineEdit->text().toUInt();
|
|
// 调用配置参数函数进行配置
|
|
if(drvUart->Uart_setPara(Baudrate, StopBits, Parity, DataBits, Timeout)){
|
|
onLogPrint("Set UART parameters success");
|
|
}else{
|
|
onLogPrint("Fail to set UART parameters");
|
|
}
|
|
}
|
|
|
|
|
|
void MainWindow::on_pushButton_5_clicked()
|
|
{
|
|
|
|
BOOL status = drvUart->Uart_closeDevice();
|
|
if(status == TRUE){
|
|
ui->comboBox_8->setEnabled(false);
|
|
ui->comboBox_9->setEnabled(false);
|
|
ui->comboBox_10->setEnabled(false);
|
|
ui->comboBox_11->setEnabled(false);
|
|
ui->pushButton_8->setEnabled(false);
|
|
ui->lineEdit->setEnabled(false);
|
|
ui->pushButton_5->setEnabled(false);
|
|
ui->pushButton_7->setEnabled(true);
|
|
ui->btnSpiSaveSetting->setEnabled(false);
|
|
onLogPrint("Close UART device success");
|
|
}else{
|
|
onLogPrint("Fail to close UART device ");
|
|
}
|
|
}
|
|
|
|
|
|
void MainWindow::on_pushButton_clicked()
|
|
{
|
|
ui->comboBox_2->clear();
|
|
// 刷新UART设备
|
|
if(drvSPI->spi_enumDevice()){
|
|
// 将串口设备的名称添加至列表中
|
|
ui->comboBox_2->addItem(drvSPI->m_DRV_Spi_Infors.bDeviceName);
|
|
}else{
|
|
onLogPrint("No SPI devices");
|
|
}
|
|
}
|
|
|
|
|
|
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);
|
|
ui->comboSpiByteOrder->setEnabled(true);
|
|
ui->comboSpiDataBits->setEnabled(true);
|
|
ui->comboSpiCS1Pol->setEnabled(true);
|
|
ui->comboSpiCS2Pol->setEnabled(true);
|
|
ui->pushButton_3->setEnabled(true);
|
|
ui->pushButton_2->setEnabled(false);
|
|
ui->btnSpiSaveSetting->setEnabled(true);
|
|
onLogPrint("Open SPI device success");
|
|
}else{
|
|
onLogPrint("Fail to open SPI device.");
|
|
}
|
|
}
|
|
|
|
|
|
void MainWindow::on_pushButton_3_clicked()
|
|
{
|
|
|
|
BOOL status = drvSPI->spi_closeDevice();
|
|
|
|
// 判断打开串口设备是否成功
|
|
if(status == TRUE){
|
|
ui->comboSpiMode->setEnabled(false);
|
|
ui->comboSpiClock->setEnabled(false);
|
|
ui->comboSpiByteOrder->setEnabled(false);
|
|
ui->comboSpiDataBits->setEnabled(false);
|
|
ui->comboSpiCS1Pol->setEnabled(false);
|
|
ui->comboSpiCS2Pol->setEnabled(false);
|
|
ui->pushButton_3->setEnabled(false);
|
|
ui->pushButton_2->setEnabled(true);
|
|
|
|
onLogPrint("Close SPI device success");
|
|
}else{
|
|
onLogPrint("Fail to close device.");
|
|
}
|
|
}
|
|
|
|
|
|
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()
|
|
{
|
|
// 弹出“打开文件”对话框
|
|
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::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 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();
|
|
|
|
}
|
|
|