Results 1 to 17 of 17

Thread: Plotting of QProcess output taking about 5 minutes to plot single value.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2017
    Posts
    13
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Android

    Default Plotting of QProcess output taking about 5 minutes to plot single value.

    Hello all ,
    I am new to Qt , i am designing a system which will receive values from sensors and Plot in GUI. I have complete C code for serial port setting and data Processing . By using Q Process i am running this C program and Plotting the Processed values .
    My GUI contain a text Edit for displaying Proceeded output readings and widget for plotting processed values with respect to time . Output values and Plot are as expected . Device sending with 4800 Baud rate and with odd parity , which is set in C program .But its taking more than 5 Minutes to read and plot one value and taking more than 30 minutes to read and plot about 6 values . why it taking this much time to read ?

    My Code is attached ...

    Qt Code:
    1. ui->setupUi(this);
    2. QVector<double> data_x(101), data_y(101);
    3. timer.start();
    4. init_port();
    5. init_line_plot();
    6. x_position = 0;
    7. }
    8.  
    9. graphwidget::~graphwidget()
    10. {
    11. delete ui;
    12. }
    13. void graphwidget::init_port()
    14. {
    15. process = new QProcess(this);
    16. connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(receive()));
    17. process->start("./test2");
    18.  
    19. process->waitForStarted();
    20. qDebug()<<"process error code:" <<process->error();
    21.  
    22.  
    23. }
    24. void graphwidget::init_line_plot()
    25. {
    26.  
    27. ui->customPlot->addGraph();
    28. // ui->customPlot->setMinimumSize(500,500);
    29. ui->customPlot->xAxis->setLabel("t");
    30. ui->customPlot->yAxis->setLabel("V");
    31. ui->customPlot->axisRect()->setAutoMargins(QCP::msNone);
    32. ui->customPlot->axisRect()->setMargins(QMargins(0,0,0,0));
    33. }
    34.  
    35.  
    36. void graphwidget::receive()
    37. {
    38. // recieves data as ASCII string
    39. int datalength = 1000;
    40. char data [1000];
    41. int bytesRead =process->readLine(data, datalength);
    42. data[bytesRead]='\0';
    43.  
    44. ui->textEdit->append(QString(data));
    45.  
    46. QTextStream out(stdout);
    47. out << data << endl;
    48. addDataPoint(atof(data));
    49. }
    50.  
    51. void graphwidget::addDataPoint(double datapoint)
    52. {
    53. if (x_position>60)data_x.pop_front();
    54. double ms = timer.elapsed();
    55. data_x.push_back((double)ms/1000);
    56. x_position++;
    57. if (x_position>60) data_y.pop_front();
    58. data_y.push_back(datapoint);
    59.  
    60. ui->customPlot->graph(0)->setData(data_x,data_y);
    61. ui->customPlot->xAxis->grid()->setSubGridVisible(false);
    62. ui->customPlot->yAxis->grid()->setSubGridVisible(false);
    63. ui->customPlot->xAxis->grid()->setVisible(false);
    64. ui->customPlot->yAxis->grid()->setVisible(false);
    65. ui->customPlot->graph(0)->setPen(QPen(QColor(0,200,0)));
    66. ui->customPlot->setBackground(Qt::black);
    67.  
    68. ui->customPlot->graph(0)->rescaleAxes();
    69. ui->customPlot->replot();
    70. }
    To copy to clipboard, switch view to plain text mode 



    please suggest necessary changes ........
    Last edited by anda_skoa; 20th February 2017 at 12:46. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Plotting of QProcess output taking about 5 minutes to plot single value.

    data_x and data_y in line 2 are local stack variables (I assume this is your class constructor) and have no relationship to the variables of the same name you use later.

    In line 56, you increment x_position. I don't see anywhere where you reset its value, so once it reaches 60, it will continue to increase.

    Otherwise, there doesn't appear to be anything in the code you have posted which would cause such delays. I would write a test program that strips out everything except the communication between your sensors and your monitoring program and see if that is where the trouble starts. No GUI, no writing to files, no plotting, just qDebug() statements to write what you receive to the console. And run it in the debugger, of course.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    suhairkp (21st February 2017)

  4. #3
    Join Date
    Jan 2017
    Posts
    13
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Android

    Default Re: Plotting of QProcess output taking about 5 minutes to plot single value.

    k. But i tested same qt program with simple C program . it will just print 1,2,3,4,5,4,3,2,1... and no serial port setting in C program , it worked fine and giving continues output without delay .

  5. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Plotting of QProcess output taking about 5 minutes to plot single value.

    Quote Originally Posted by suhairkp View Post
    k. But i tested same qt program with simple C program . it will just print 1,2,3,4,5,4,3,2,1... and no serial port setting in C program , it worked fine and giving continues output without delay .
    So the problem is with the serial port. Why You don't use QSerialPort ?

  6. #5
    Join Date
    Jan 2017
    Posts
    13
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Android

    Default Re: Plotting of QProcess output taking about 5 minutes to plot single value.

    Serial port is set in C program , so calling QProcess will set serial port . thats y not using Qserialport in Qt .Also , C program process the received signal from serial port and print output . this output is storing in byte array and using for plot .
    I compiled C program from terminal and getting correct output in terminal . but Qt taking more time call QProcess and plot , don't getting idea where this delay occurring ...

  7. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Plotting of QProcess output taking about 5 minutes to plot single value.

    I still think you need to break the problem down into the smallest piece possible, than add more features. I would start by writing a Qt program that simply starts the listener process, reads the output from your sensor and prints it using qDebug(). No printing it to a text edit, no logging to files, no plotting. At this point, you have no idea which step in this chain is going wrong, so eliminate everything except the first one: getting data successfully from the QProcess into your program. Once that seems to be working in the same way as your C program, then you know the communication works, so add the graphics and other features.

    You might also try using QProcess:readAllStandardOutput() to get all of the available data at once instead of using readLine(). Use QByteArray::data() or QByteArray::constData() to get the NULL-terminated C string it contains. This way you do not have to worry about the buffer size or whether you have read it all.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  8. The following user says thank you to d_stranz for this useful post:

    suhairkp (23rd February 2017)

  9. #7
    Join Date
    Jan 2017
    Posts
    13
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Android

    Default Re: Plotting of QProcess output taking about 5 minutes to plot single value.

    k . sir. I am testing it without plot . in my above code , it displaying "process error code : 2 " in Application output area of Qt Creator , when output gui display open and saying " Qprocess : Destroyed while process is still running ". when i changed process->waitForStarted from process->waitForFinished , it show that "process error code : 5 "
    Last edited by suhairkp; 23rd February 2017 at 12:10.

  10. #8
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Plotting of QProcess output taking about 5 minutes to plot single value.

    Once again : why You use external program to read data from serial port ? Why You don't do it in Qt program ?

Similar Threads

  1. How to Plot from QProcess output
    By suhairkp in forum Newbie
    Replies: 0
    Last Post: 31st January 2017, 15:12
  2. Can I read output of a single with the help of Mingw Compiler?
    By parulkalra14 in forum Qt Programming
    Replies: 1
    Last Post: 4th February 2014, 11:03
  3. Replies: 2
    Last Post: 28th January 2014, 10:02
  4. Problem in plotting 3D plot using QWT
    By johnMick in forum Newbie
    Replies: 1
    Last Post: 15th July 2011, 12:19
  5. Replies: 1
    Last Post: 9th September 2010, 11:22

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.