#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QDebug>
#include<QSerialPort>
#include<QSerialPortInfo>
#include<QMessageBox>
#include<QInputDialog>
#include"stringtohex.h"
MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow)
{
ui->setupUi(this);
qDebug()<<"MainWindow has been setup";
foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts())
{
ui->comboBox->addItem(info.portName());
}
info=new QLabel("null");
ui->statusBar->addWidget(info);
ui->comboBoxBaud->addItem("9600");
ui->comboBoxBaud->addItem("19200");
ui->comboBoxBaud->addItem("38400");
ui->comboBoxBaud->addItem("57600");
ui->comboBoxBaud->addItem("115200");
ui->comboBoxDatebits->addItem("8");
ui->comboBoxDatebits->addItem("7");
ui->comboBoxDatebits->addItem("6");
ui->comboBoxDatebits->addItem("5");
ui->comboBoxParity->addItem("None");
ui->comboBoxParity->addItem("Even");
ui->comboBoxParity->addItem("Odd");
ui->comboBoxParity->addItem("Mark");
ui->comboBoxParity->addItem("Space");
ui->comboBoxStopBits->addItem("1");
ui->comboBoxStopBits->addItem("1.5");
ui->comboBoxStopBits->addItem("2");
ui->checkBoxrAscii->setChecked(true);
ui->checkBoxrhex->setChecked(false);
ui->checkBoxsAscii->setChecked(true);
ui->checkBoxshex->setChecked(false);
GroupRev = new QButtonGroup(this);
GroupSend=new QButtonGroup(this);
GroupRev->addButton(ui->checkBoxrAscii);
GroupRev->addButton(ui->checkBoxrhex);
GroupSend->addButton(ui->checkBoxsAscii);
GroupSend->addButton(ui->checkBoxshex);
serialPortHelper=new SerialPortHelper;
//connect(serialPortHelper,SIGNAL(SerialDataIn(QByteArray)),this,SLOT(on_SerialBytesIn(QByteArray)));
connect(serialPortHelper,SIGNAL(SerialDataIn(QString)),this,SLOT(on_SerailStringIn(QString)));
}
MainWindow::~MainWindow()
{
delete info;
delete GroupRev;
delete GroupSend;
delete serialPortHelper;
delete ui;
}
void MainWindow::on_pushButtonOpen_clicked()
{
auto text=ui->pushButtonOpen->text();
if(text=="Open")
{
ui->pushButtonOpen->setText("Close");
serialPortHelper->Load(ui->comboBox->currentText(),ui->comboBoxBaud->currentText(),
ui->comboBoxDatebits->currentText(),
ui->comboBoxStopBits->currentText(),
ui->comboBoxParity->currentText());
}
else
{
ui->pushButtonOpen->setText("Open");
serialPortHelper->UnLoad();
}
}
void MainWindow::on_pushButtonSend_clicked()
{
QString cmdstr=ui->textEditSender->toPlainText();
if(ui->checkBoxsAscii->checkState()==Qt::Checked)
{
serialPortHelper->Write(cmdstr);
}
else
{
QByteArray arr;
StringToHex(cmdstr,arr);
serialPortHelper->Write(arr);
}
}
void MainWindow::on_SerailStringIn(QString data)
{
if(ui->checkBoxrAscii->checkState()==Qt::Checked)
ui->textEditReceiver->append(data);
}
void MainWindow::on_SerialBytesIn(QByteArray data)
{
if(ui->checkBoxrhex->checkState()==Qt::Unchecked) return;
QString ret(data.toHex().toUpper());
int len = ret.length()/2;
qDebug()<<len;
for(int i=1;i<len;i++)
{
qDebug()<<i;
ret.insert(2*i+i-1," ");
}
ui->textEditReceiver->append(ret);
}
LemoStudio
- 粉丝: 0
- 资源: 14
最新资源
- 全国企业风险投资及融资事件数据集(1921-2024.2).txt
- Android Adb文件浏览器
- STM32单片机人流量检测器设计程序源码+文档说明(高分项目)
- 基于django的学生选课系统的设计与实现(含报告) .zip
- 在YOLOv7的基础上使用KLD损失修改为旋转目标检测yolov7-obb.zip
- 基于LSTM针对长时序的气温、降水、气压、相对湿度、风速等气象站点数据,对尼洋河径流进行模拟预测+python源码+文档说明+数据集
- 国内最优秀的基于JAVA的AI开源量化交易平台,秒替文华、MC、金字塔 具备历史回放、策略研发、模拟交易、实盘交易等功能 兼顾全自动与半自动的使用场景
- 在pytorch中复现YOLO系列论文,包括YOLOv4,PP-YOLO,YOLOv5,YOLOv3等 .zip
- 在oxford hand数据集上对YOLOv3做模型剪枝(network slimming).zip
- 预期功能安全,SOTIF,ISO 21448中文版,GBT 3267
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈