Results 1 to 4 of 4

Thread: Maintaining the delay between sending and reading the data

  1. #1
    Join Date
    Sep 2007
    Posts
    83
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Maintaining the delay between sending and reading the data

    Hai,
    In the bellow application am facing the delay problem.

    I will explain clearly what my functionality requires--
    Using the bellow function i will get the some data from the micro controller using the serial port and i will display that particular data on my GUI.

    Initially i will send " : 7 0" code data to the Micro controller,using that code data micro controller will send some data,which i want to read and show on my GUI.

    I gave some delay(using dummy for loops) between sending code data(": 7 0") and receiving controller data.
    The for loops causes the problem to me,because the delay reduces with the CPU configuration.without delay my application unable to read entire data which i required.

    plz assist me to overcome this problem.

    one more thing i required is how to take the data on to QBytearray instead of taking on to the buffer,while reading the data.

    i desperately need your suggestions.

    Thanx alot.
    Qt Code:
    1. void Synth1::get() // recieving synth lock detects from RC
    2. {
    3. port->open(QIODevice::ReadWrite);
    4. port->write(QString::QString(":").toAscii());
    5. for(long int i=0;i<=10000000;i++);
    6. port->write(QString::QString(" ").toAscii());
    7. port->write(QString::number(7).toAscii());
    8. port->write(QString::QString(" ").toAscii());
    9. for(long int i=0;i<=10000000;i++);
    10. for(long int i=0;i<=10000000;i++);
    11. port->write(QString::number(0).toAscii());
    12. port->write(QString::QString(" ").toAscii());
    13.  
    14. for(long int i=0;i<=100000000;i++);
    15. for(long int i=0;i<=100000000;i++);
    16. for(long int i=0;i<=100000000;i++);
    17. for(long int i=0;i<=100000000;i++);
    18. for(long int i=0;i<=100000000;i++);
    19. for(long int i=0;i<=100000000;i++);
    20. for(long int i=0;i<=100000000;i++);
    21. for(long int i=0;i<=100000000;i++);
    22. char buff[2048];
    23. int numBytes;
    24. numBytes = port->bytesAvailable();
    25. if(numBytes > 0)
    26. {
    27. if(numBytes > 2048)
    28. numBytes = 2048;
    29. int i = port->read(buff, numBytes);
    30. buff[i] = '\0';
    31. QString msg = buff;
    32. QString y = ": 7 ";
    33. int j=msg.indexOf(y,0);
    34. msg.remove(0,j);
    35. ui.lineEdit_13->clear();
    36. ui.lineEdit_13->insert(msg);
    37. QStringList fields =msg.split(" ");
    38. if(fields.size()==16)
    39. {
    40. QString str,id2,sum2,sy1,sy2,sy3,sy4,sy5,sy6,sy7,sy8,sy9,sy10,sy11,sy12;
    41. str=fields[0];
    42. id2=fields[1];
    43. sum2=fields[2];
    44. sy1=fields[3];
    45. sy2=fields[4];
    46. sy3=fields[5];
    47. sy4=fields[6];
    48. sy5=fields[7];
    49. sy6=fields[8];
    50. sy7=fields[9];
    51. sy8=fields[10];
    52. sy9=fields[11];
    53. sy10=fields[12];
    54. sy11=fields[13];
    55. sy12=fields[14];
    56. if(id2=="7")
    57. {
    58. ui.lineEdit->clear();
    59. ui.lineEdit_2->clear();
    60. ui.lineEdit_3->clear();
    61. ui.lineEdit_4->clear();
    62. ui.lineEdit_5->clear();
    63. ui.lineEdit_6->clear();
    64. ui.lineEdit_7->clear();
    65. ui.lineEdit_8->clear();
    66. ui.lineEdit_9->clear();
    67. ui.lineEdit_10->clear();
    68. ui.lineEdit_11->clear();
    69. ui.lineEdit_12->clear();
    70. ui.lineEdit->insert(sy1);
    71. ui.lineEdit_2->insert(sy2);
    72. ui.lineEdit_3->insert(sy3);
    73. ui.lineEdit_4->insert(sy4);
    74. ui.lineEdit_5->insert(sy5);
    75. ui.lineEdit_6->insert(sy6);
    76. ui.lineEdit_7->insert(sy7);
    77. ui.lineEdit_8->insert(sy8);
    78. ui.lineEdit_9->insert(sy9);
    79. ui.lineEdit_10->insert(sy10);
    80. ui.lineEdit_11->insert(sy11);
    81. ui.lineEdit_12->insert(sy12);
    82. }
    83. else
    84. {
    85. QMessageBox:: about(this,tr("PORT"),
    86. tr("<b>NOT VALID PACKET</b> recieved..."));
    87. }
    88. }
    89. else
    90. {
    91. QMessageBox:: about(this,tr("PORT"),
    92. tr("<b>DATA</b> NOT recieved properly."));
    93. }
    94. }
    95.  
    96. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 7th December 2007 at 06:56. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Maintaining the delay between sending and reading the data

    The for loops causes the problem to me,because the delay reduces with the CPU configuration.without delay my application unable to read entire data which i required.
    What do you mean delay reduces the CPU configuration. I do not understand what do you want to say.
    Qt 5.3 Opensource & Creator 3.1.2

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Maintaining the delay between sending and reading the data

    Quote Originally Posted by jjbabu View Post
    Qt Code:
    1. for(long int i=0;i<=100000000;i++);
    2. for(long int i=0;i<=100000000;i++);
    3. for(long int i=0;i<=100000000;i++);
    4. for(long int i=0;i<=100000000;i++);
    5. for(long int i=0;i<=100000000;i++);
    6. for(long int i=0;i<=100000000;i++);
    7. for(long int i=0;i<=100000000;i++);
    8. for(long int i=0;i<=100000000;i++);
    To copy to clipboard, switch view to plain text mode 
    You shouldn't block GUI applications' event loop with busy loops like these. You should use for example QTimer to schedule a slot to be called at certain delay. This makes it possible for the application to process its events meanwhile.
    J-P Nurmi

  4. #4
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Maintaining the delay between sending and reading the data

    Or better, you can read data on its own thread.
    Qt 5.3 Opensource & Creator 3.1.2

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.