Hello!

I'm trying to use the static QTimer::singleShot() function to create delay between write and read cycles via serial interface.

I have done the following code:

Hedaer:
Qt Code:
  1. #ifndef CAN_TRANSFER_H
  2. #define CAN_TRANSFER_H
  3.  
  4. #include <QMainWindow>
  5. #include "qextserialport.h"
  6. #include <Qtimer.h>
  7.  
  8.  
  9. namespace Ui {
  10. class CAN_transfer;
  11.  
  12. }
  13.  
  14. class CAN_transfer : public QMainWindow {
  15. Q_OBJECT
  16.  
  17. public:
  18. CAN_transfer(QWidget *parent = 0);
  19. ~CAN_transfer();
  20.  
  21.  
  22. protected:
  23. void changeEvent(QEvent *e);
  24.  
  25. private:
  26. Ui::CAN_transfer *ui;
  27. QextSerialPort* _comPort;
  28. unsigned char mas[64];
  29. unsigned char* DATA_pointer;
  30.  
  31. private slots:
  32.  
  33. void readBR(unsigned char t);
  34. void on_store_all_button_clicked();
  35. void on_store_sel_button_clicked();
  36. void on_connectbutton_clicked();
  37. void timer_event();
  38. };
  39.  
  40. #endif // CAN_TRANSFER_H
To copy to clipboard, switch view to plain text mode 
Source:

Qt Code:
  1. #include "can_transfer.h"
  2. #include "ui_can_transfer.h"
  3. #include "qextserialport.h"
  4. #include "win_qextserialport.h"
  5. //#include <Qtimer.h>
  6. #include <QTimer>
  7. unsigned char clkdt,te;
  8. CAN_transfer::CAN_transfer(QWidget *parent) :
  9. QMainWindow(parent),
  10. ui(new Ui::CAN_transfer)
  11. {
  12. ui->setupUi(this);
  13. ui->logw->setReadOnly(true);
  14. ui->logw->setFontWeight(QFont::Bold);
  15. ui->logw->append(tr("CAN transfer configurator is ready to use!"));
  16. ui->logw->setFontWeight(QFont::QFont::Normal);
  17. ui->logw->setTextColor(Qt::black);
  18. QString s="COM1";
  19. _comPort = new QextSerialPort(s);
  20. _comPort->setBaudRate(BAUD9600);
  21. _comPort->setFlowControl(FLOW_OFF);
  22. _comPort->setParity(PAR_NONE);
  23. _comPort->setDataBits(DATA_8);
  24. _comPort->setStopBits(STOP_1);
  25. DATA_pointer = &mas[0];
  26. clkdt = 0;
  27. }
  28.  
  29. CAN_transfer::~CAN_transfer()
  30. {
  31. _comPort->close();
  32. delete(_comPort);
  33. delete ui;
  34. }
  35.  
  36. void CAN_transfer::changeEvent(QEvent *e)
  37. {
  38. QMainWindow::changeEvent(e);
  39. switch (e->type()) {
  40. case QEvent::LanguageChange:
  41. ui->retranslateUi(this);
  42. break;
  43. default:
  44. break;
  45. }
  46. }
  47.  
  48.  
  49. void CAN_transfer :: timer_event()
  50. {
  51. te = 0;
  52. timer->stop();
  53. }
  54. void CAN_transfer::on_connectbutton_clicked()
  55. {unsigned char rb=0;
  56. ui->logw->append(tr("COM1 configurating...."));
  57. _comPort->open(QIODevice::ReadWrite | QIODevice::Unbuffered);
  58. ui->logw->append(tr("conneting...."));
  59. *DATA_pointer = 0x55;
  60. if(_comPort->write((const char*)DATA_pointer, 1))
  61. {
  62.  
  63. te = 1;
  64. QTimer :: singleShot(100, this, SLOT(timer_event()));
  65. while(te);
  66. rb = _comPort->bytesAvailable();
  67. if(rb)
  68. {
  69. _comPort->read((char*)DATA_pointer,rb);
  70. if(*DATA_pointer==0xAA)
  71. ui->logw->append(tr("connection established!"));
  72. }
  73. else
  74. {
  75. ui->logw->append(tr("no connection"));
  76. }
  77.  
  78. }
  79.  
  80. statusBar()->showMessage(tr("Connected"));
  81. //_comPort->close();
  82. }
To copy to clipboard, switch view to plain text mode 

The problem is in that what application do not affect the SLOT(event_timer) code, at least it seems to be.

Compiler don not issue any warning or errors and I casue of that I don't understand in what the problem is.

I need some help to solve this problem, I would glad of any information about it.


Thanks in advance