File tree Expand file tree Collapse file tree 2 files changed +9
-3
lines changed
Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -450,9 +450,14 @@ void MainWindow::updateConnectState(const bool connected) const {
450450}
451451
452452void MainWindow::onReceivedData () {
453- const QByteArray bytes = serialPort.readAll ();
454- if (bytes != nullptr ) {
455- updateComMessageLog (bytes, " 收" );
453+ bufferReceived += serialPort.readAll ();
454+ while (true ) {
455+ int endIndex = bufferReceived.indexOf (' \n ' );
456+ if (endIndex == -1 )
457+ break ;
458+
459+ updateComMessageLog (bufferReceived, " 收" );
460+ bufferReceived.remove (0 , endIndex + 1 );
456461 }
457462}
458463
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ class MainWindow : public QMainWindow {
3434 QSqlQuery *sqlQuery;
3535 QTableWidgetItem *commandItem = nullptr ;
3636 QTableWidgetItem *remarkItem = nullptr ;
37+ QByteArray bufferReceived;
3738 QList<ComMessage> history;
3839 QTimer *timer = nullptr ;
3940
You can’t perform that action at this time.
0 commit comments