Page 1 of 1

onidle question

Posted: Fri Aug 26, 2011 9:10 pm
by spectrum
Dear all,

i am using OnIdle event/callback on a wxFrame to read bytes from the serial port, to avoid further threads. My actual approach is:

Code: Select all

 void MyFrame::OnIdle (wxIdleEvent &e)
      int i;
      if ((i=serial->Read())>0)
         --- process data and eventually update some status messages in the frame ---
This works, but i am not sure it is the correct/portable way to do it.
Also, i am looking for faster data detection, with a read interval even < 20msec.

Any help is appreciated,

Re: onidle question

Posted: Sat Aug 27, 2011 12:13 pm
by JimFairway

Have you considered using a wxTimer instead?
This example has a timer in it: ... ng_a_timer

Hope that helps,


Re: onidle question

Posted: Sat Aug 27, 2011 3:09 pm
by dlchnr
As Jim wrote, wxTimer is the solution - here the code lines, I solved the same problem:

Code: Select all

class cMainFrame : public wxFrame {
  // :
  wxTimer tim;
  bool timlock;
  // :
  // privat member functions
  // privat copy ctor and assignment operator, if these aren't defined
  cMainFrame (const cMainFrame& obj);
  cMainFrame& operator=(const cMainFrame& obj);
  // any class providing RTTI must use this macro
  // any class wishing to process wxWidgets events must use this macro
  // ctor
  cMainFrame(cPrgData& PrgDat);
  // dtor
  virtual ~cMainFrame();
  // basic member functions
  // :          
  // member functions
  // :
  bool PollFunction();
  // :
  void FollowAuxColouring();
  // event handlers (these functions should _not_ be virtual)
  // :
  void OnTimer(wxTimerEvent& event);
  // :

cMainFrame::cMainFrame(cPrgData& PrgDat) :  
            wxFrame (NULL, wxID_ANY, _T(""), wxDefaultPosition, wxSize(888,748)),
            prgdata(PrgDat), startUp(PrgDat.AutoExec(), *PrgDat.pC()), 
            pBook(), pPageTRC(), pPageOUT(), pPagePRG(), 
            tim(this, wxID_ANY), timlock(false), movOnRdy(false), 
            autoMode(false), exec_1st(false), busycnt(0), traceALL(0) {
  // set the frame icon

  // create the file menu
  // :

  // :

  // :
  Connect(tim.GetId(), wxEVT_TIMER, wxTimerEventHandler(cMainFrame::OnTimer), NULL, this); 

void cMainFrame::OnTimer(wxTimerEvent& event) {

  if (!timlock) {
    timlock = true;
    timlock = false;