You can ask Tk to run a specified routine periodically: $widget->repeat(milliseconds, callback);, like perhaps: $widget->repeat(500, \&update_serial_info); This will cause Tk to call update_serial_info() every 1/2 second - the Tk code continues executing immediately after this "request".
In the update_serial_info routine, you should use non-blocking calls to the serial port S/W. If the Tk display is not ready to be updated, then don't do anything. If the data is "ready" perhaps you just put the data into some $text_variable that the GUI knows about. If the info received so far warrants a display update like a text window pane, then do that being aware that updating the GUI is very "expensive" compute wise. You probably don't want to do that for every single individual character received! This Serial Port code may run just fine without being in a separate thread if you call it every 200ms or so (maybe less, maybe more).
A key is to call the non-blocking serial port methods. If there is nothing to be read, then just don't do anything. That will happen most of the time, so make that path fast.
In reply to Re: RS232 and Tk with threads
by Marshall
in thread RS232 and Tk with threads
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |