By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,933 Members | 1,716 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,933 IT Pros & Developers. It's quick & easy.

Refresh widget

P: 62
I try port reading and displaying in widgets.Well, I try to demostrate the problem during the next simplified example:



Expand|Select|Wrap|Line Numbers
  1.  1. use Win32::SerialPort 0.09;
  2.    2. use Tk;
  3.    3.  
  4.    4. $mw=MainWindow->new();
  5.    5.  
  6.    6. $mw->maxsize(600,470);
  7.    7. $mw->minsize(600,470);
  8.    8.  
  9.    9. ########################### widgets #######################x
  10.   10. $d1=0.000;
  11.   11. $e1=$mw->Entry(-width => 10,
  12.   12. -textvariable => \$d1); #here iwant display the data from port
  13.   13. $e1->place(-x =>100, -y =>100);
  14.   14.  
  15.   15.  
  16.   16. $g2 = $mw->Button(-text => "Start read",
  17.   17. -command => sub{ &read} #here i start the first read
  18.   18. );
  19.   19. $g2->place(-x => 240, -y => 100);
  20.   20. ######################### Port Object#########################
  21.   21. unless ($soros_port = Win32::SerialPort->new ('com1')) {
  22.   22. printf "Nem tudtam megnyitni a soros portot!\n";
  23.   23. exit 1;
  24.   24.  
  25.   25. $soros_port->baudrate(9600) || die "rossz BAUD";
  26.   26. $soros_port->parity('even') || die "rossz Parias";
  27.   27. $soros_port->databits(8) || die "rossz Adatbit";
  28.   28. $soros_port->stopbits(1) || die "rossz Stopbit";
  29.   29. $soros_port->buffers(4096,4096) || die "rossz Buffer";
  30.   30. $soros_port->handshake("none") || die "rossz Handshake";
  31.   31. ################################################## ########
  32.   32. MainLoop();
  33.   33.  
  34.   34. sub read #the function go back whit the data freshing the $e1 widgets
  35.   35. {
  36.   36. while(1)
  37.   37. {
  38.   38. ($count_in, $d1) = $soros_port->read(1) or die "itten";
  39.   39. if($count_in!=0) {last;}
  40.   40. }
  41.   41. }
  42.   42. ################################################## #########
  43.  
How can after the return of " sub read" (so refreshing the widget)
fast and automatically call the "sub read" again and again?->so can I continous displaying the data from port (the repeat are to slow->1ms)
Sep 22 '08 #1
Share this Question
Share on Google+
1 Reply


Icecrack
Expert 100+
P: 174
i will have to try your code when i get home from work, as i do not have the equipment here to do it.
Sep 23 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.