Skip to content

Commit

Permalink
修复手动发送一直发送第一行的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
changfeng1050 committed Jan 23, 2021
1 parent fe8f8d3 commit da81a79
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ set(SOURCE_FILES
data/TcpClientReadWriter.h
data/SerialBridgeReadWriter.cpp data/SerialBridgeReadWriter.h)

add_executable(SerialWizard ${SOURCE_FILES})
#add_executable(SerialWizard WIN32 ${SOURCE_FILES})
#add_executable(SerialWizard ${SOURCE_FILES})
add_executable(SerialWizard WIN32 ${SOURCE_FILES})
qt5_use_modules(SerialWizard Widgets Core SerialPort Network)
21 changes: 16 additions & 5 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,6 @@ void MainWindow::createConnect() {

connect(readWriterButtonGroup, QOverload<QAbstractButton *, bool>::of(&QButtonGroup::buttonToggled),
[=](QAbstractButton *button, bool checked) {

if (checked && isReadWriterOpen()) {
SerialType serialType;
if (button == tcpServerRadioButton) {
Expand Down Expand Up @@ -673,6 +672,7 @@ void MainWindow::createConnect() {
});

connect(refreshSerialButton, &QPushButton::clicked, [=] {
_dirty = true;
updateSerialPortNames();
});

Expand Down Expand Up @@ -715,9 +715,12 @@ void MainWindow::createConnect() {
if (autoSendState == AutoSendState::Sending) {
stopAutoSend();
} else {
_sendType = SendType::Line;
updateSendData(hexCheckBox->isChecked(), sendTextEdit->toPlainText());
updateSendType();
if (_dirty) {
_dirty = false;
_sendType = SendType::Line;
updateSendData(hexCheckBox->isChecked(), sendTextEdit->toPlainText());
updateSendType();
}
sendNextData();
startAutoSendTimerIfNeed();
}
Expand Down Expand Up @@ -746,6 +749,13 @@ void MainWindow::createConnect() {
[this] {
sendNextData();
});
connect(hexCheckBox, &QCheckBox::stateChanged, [this] {
this->_dirty = true;
});

connect(sendTextEdit, &QTextEdit::textChanged, [this] {
this->_dirty = true;
});
}

void MainWindow::setOpenButtonText(bool isOpen) {
Expand Down Expand Up @@ -917,7 +927,7 @@ void MainWindow::updateSendData(bool isHex, const QString &text) {
lines << in.readLine();
}
QList<QByteArray> dataList;
if (hexCheckBox->isChecked()) {
if (isHex) {
for (auto &line :lines) {
dataList << dataFromHex(line);
}
Expand Down Expand Up @@ -1334,6 +1344,7 @@ void MainWindow::updateSendType() {
if (_sendType == SendType::Line) {
newController = new LineSerialController(serialController);
}
serialController = newController;
}


Expand Down
2 changes: 2 additions & 0 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ public slots:
int skipSendCount{0};

QByteArray lineReturn;

bool _dirty{true};
};

#endif //SERIALWIZARD_MAINWINDOW_H

0 comments on commit da81a79

Please sign in to comment.