@@ -11,6 +11,7 @@ MainWindow::MainWindow(QWidget *parent) :
1111 connect (ui->pushButton_serialConnect , SIGNAL (clicked ()), this , SLOT (handle_serialConnectBtn ()));
1212 connect (ui->pushButton_fileSelect , SIGNAL (clicked ()), this , SLOT (handle_selectFileBtn ()));
1313 connect (ui->pushButton_fileLoad , SIGNAL (clicked ()), this , SLOT (do_loadFile ()));
14+ connect (ui->pushButton_doPlot , SIGNAL (clicked ()), this , SLOT (do_plot ()));
1415
1516 // Initialize interface
1617 ui->comboBox_baud ->insertItems (0 , QStringList () << " 2400" << " 4800" << " 9600" << " 19200" << " 38400" << " 57600" << " 115200" );
@@ -242,13 +243,16 @@ void MainWindow::do_loadFile()
242243 {
243244 QString buffer = " " ;
244245 char tmp = 0 ;
245- while (tmp != ' ;' )
246+ while (tmp != ' ;' && !inputFile. atEnd () )
246247 {
247248 inputFile.read (&tmp, 1 );
248249 buffer += tmp;
249250 }
250- cmdList.append (buffer);
251- ui->textBrowser_read ->append (buffer);
251+ if (buffer.endsWith (" ;" ))
252+ {
253+ cmdList.append (buffer);
254+ ui->textBrowser_read ->append (buffer);
255+ }
252256 }
253257
254258 plotScene.clear ();
@@ -259,13 +263,15 @@ void MainWindow::do_loadFile()
259263 if (cmdList.at (i)[0 ] == ' P' && cmdList.at (i)[1 ] == ' D' )
260264 {
261265 ui->textBrowser_console ->append (" Found PD: " + cmdList.at (i));
262- int charIndex = 2 ;
266+ int charIndex = 1 ;
263267 int nextX, nextY;
264268 while (cmdList.at (i)[charIndex] != ' ;' )
265269 {
270+ charIndex++;
266271 nextX = get_nextInt (cmdList.at (i), &charIndex);
267272 charIndex++;
268273 nextY = get_nextInt (cmdList.at (i), &charIndex);
274+
269275 plotScene.addLine (curX, -curY, nextX, -nextY);
270276 ui->textBrowser_console ->append (timeStamp () + " Adding line [" +
271277 QString::number (curX) + " ," + QString::number (curY) +
@@ -278,9 +284,10 @@ void MainWindow::do_loadFile()
278284 else if (cmdList.at (i)[0 ] == ' P' && cmdList.at (i)[1 ] == ' U' )
279285 {
280286 ui->textBrowser_console ->append (" Found PU: " + cmdList.at (i));
281- int charIndex = 2 ;
287+ int charIndex = 1 ;
282288 while (cmdList.at (i)[charIndex] != ' ;' )
283289 {
290+ charIndex++;
284291 curX = get_nextInt (cmdList.at (i), &charIndex);
285292 charIndex++;
286293 curY = get_nextInt (cmdList.at (i), &charIndex);
@@ -294,7 +301,16 @@ void MainWindow::do_loadFile()
294301
295302void MainWindow::do_plot ()
296303{
297- // serialBuffer->write();
304+ if (!serialBuffer->isOpen () || cmdList.isEmpty ())
305+ {
306+ ui->textBrowser_console ->append (timeStamp () + " Can't plot!" );
307+ return ;
308+ }
309+ for (int i = 0 ; i < cmdList.count (); i++)
310+ {
311+ int size = cmdList.at (i).length ();
312+ serialBuffer->write (cmdList.at (i).toStdString ().c_str (), size);
313+ }
298314}
299315
300316
0 commit comments