Re: Probleme With Threads.



You'll have to use a Dispatcher to pass a signal from your data
capturing thread to the gtkmm main loop. I did something similar a long
while ago and it works quite well.

Depending on your sampling frequency the overhead of signalling for each
new data point will be far too big, in which case you'll have to
implement some buffering and transfer the data in blocks.

-Bartek

Florent Blanchon wrote:
> Hello to all.
>  
> I've a big problem.
> I'm using plotmm to display a curve (normal).
>  
> the datas I want to display come frome a ComPort (or a blocking Socket).
>  
> I've tried with a pthread mechanism, by passing main class in argument,
> but, when I arrive at
>  
> 
>     PlotTest->m_plot.scale(PlotMM::AXIS_LEFT)->set_range( Ymin, Ymax);
>      
> 
> I've this message :
>  
> 
>     fatal io error 11 resource temporarily unavailable on x server 0.0
> 
>  
>  
> below, is the code I want to be implemented in a thread because I wait
> before receiving data :
> Thanks for your help.
> Flo
>  
> 
>     bool PlotTest::LoopReceive()
>     {
>     //PlotTest *MainLoop = (PlotTest*)pt;
>     double data[2000];
>     char cbuffer[6033];
>     int recu;
>     int taille;
>     int frequence;
>     int intcurve;
>     double ymax;
>     double ymin;
> 
>      recu = 0;
>      memset(cbuffer, 0, 6033);
> 
>      std::cout << "Top Receive" <<std::endl;
>      while(recu != 33)
>      {
>       recu += Rs->recv((char*)cbuffer + recu, 33 - recu);
>      }
>      taille = *(short*)&cbuffer[14];
>      
>      frequence = *(short*)&cbuffer[2];
>      
>      while(recu != taille)
>      {
>       recu += Rs->recv((char*)cbuffer + recu, taille - recu);
>      }
>      // 20Hz
>      if(taille == 93)  intcurve = 20;
>      if(taille == 633) intcurve = 200;
>      
>      // 50Hz
>      if(taille == 183) intcurve = 50;
>      if(taille == 1533) intcurve = 500;
>      
>      //100Hz
>      if(taille == 333) intcurve = 100;
>      if(taille == 3033) intcurve = 1000;
>         Glib::Timer timer;
>         timer.start();
>      //200Hz
>      if(taille == 633)  intcurve = 200;
>      if(taille == 6033) intcurve = 2000;
>      
>          ymax = -G_MAXFLOAT;
>          ymin = G_MAXFLOAT;
>      
>      
>      for(int i = 0; i < intcurve; i++)
>      {
>       int t =0;
>       unsigned  char *A;
>       A =(unsigned char*) &t;
>       int u = 0;
>       unsigned char *B;
>       B = (unsigned char*)&u;
>       *(A+3) = cbuffer[30 + 3*i]&0x80?0xff:0x00;
>       *(A+2) = cbuffer[30 + 3*i];
>       *(A+1) = cbuffer[29 + 3*i];
>       *(A)   = cbuffer[28 + 3*i];
>       
>       data[i] = t;
>       if(t > ymax) ymax = t;
>       if(t < ymin) ymin = t;
>      
>      }
>     myCurve1->set_data(x,data,intcurve);
>     m_plot.scale(PlotMM::AXIS_LEFT)->set_range(ymin+ymin/10,ymax + ymax/10);
>     m_plot.replot();
>      
>      
>     }  
> 
>  
>  
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]