175 lines
4.6 KiB
C++
175 lines
4.6 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::MainWindow)
|
|
{
|
|
ui->setupUi(this);
|
|
drvSPI = new DRV_Spi(this);
|
|
drvUart = new DRV_Uart(this);
|
|
}
|
|
|
|
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::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 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 device success");
|
|
}else{
|
|
onLogPrint("Open device failed");
|
|
}
|
|
}
|
|
|
|
|
|
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 parameters success");
|
|
}else{
|
|
onLogPrint("Fail to set 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);
|
|
onLogPrint("Close device success");
|
|
}else{
|
|
onLogPrint("Close device failed");
|
|
}
|
|
}
|
|
|
|
|
|
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 devices");
|
|
}
|
|
}
|
|
|
|
|
|
void MainWindow::on_pushButton_2_clicked()
|
|
{
|
|
ULONG index = ui->comboBox_2->currentIndex();
|
|
// 调用串口打开函数
|
|
BOOL status = drvSPI->spi_openDevice(index);
|
|
|
|
// 判断打开串口设备是否成功
|
|
if(status == TRUE){
|
|
ui->comboBox_3->setEnabled(true);
|
|
ui->comboBox_4->setEnabled(true);
|
|
ui->comboBox_5->setEnabled(true);
|
|
ui->comboBox_6->setEnabled(true);
|
|
ui->comboBox_16->setEnabled(true);
|
|
ui->comboBox_17->setEnabled(true);
|
|
ui->pushButton_3->setEnabled(true);
|
|
ui->pushButton_2->setEnabled(false);
|
|
onLogPrint("Open device success");
|
|
}else{
|
|
onLogPrint("Open device failed");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_pushButton_3_clicked()
|
|
{
|
|
|
|
BOOL status = drvSPI->spi_closeDevice();
|
|
|
|
// 判断打开串口设备是否成功
|
|
if(status == TRUE){
|
|
ui->comboBox_3->setEnabled(false);
|
|
ui->comboBox_4->setEnabled(false);
|
|
ui->comboBox_5->setEnabled(false);
|
|
ui->comboBox_6->setEnabled(false);
|
|
ui->comboBox_16->setEnabled(false);
|
|
ui->comboBox_17->setEnabled(false);
|
|
ui->pushButton_3->setEnabled(false);
|
|
ui->pushButton_2->setEnabled(true);
|
|
|
|
onLogPrint("Close device success");
|
|
}else{
|
|
onLogPrint("Close device failed");
|
|
}
|
|
}
|
|
|