Home > Archive > Tcl > June 2006 > Re: Using TK to read/write to serial port, allowing stdout display and TK GUI control
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: Using TK to read/write to serial port, allowing stdout display and TK GUI control
|
|
| norbert 2006-06-25, 10:05 pm |
| Hi,
Thank you for the quick response and helpful advice. I am going to
re-write the code using fileevent properly (if at all?). In the
meantime, I was able to use the 'after' command to recursively call a
read procedure (to read from the serial port), similar to the following
code I found for another entry on this group (for creating a counter):
***
set Seconds 0
label .sec -textvariable Seconds
pack .sec
proc tick {} {
global Seconds
incr Seconds
after 1000 tick
}
tick
***
Using this approach, I am able to acheive what I want at the moment,
however I do want to change the code to read/write from/to the serial
port in a more conventional manner.
It looks like other postings may have closed their issues. Should I
flag this as a closed issue?
Again, thanks for all the help, I really appreciate it.
Norbert
| |
| Adrian Ho 2006-06-26, 4:21 am |
| On 2006-06-26, norbert <norbert@student.unsw.edu.au> wrote:
> [...] In the
> meantime, I was able to use the 'after' command to recursively call a
> read procedure (to read from the serial port), similar to the following
> code I found for another entry on this group (for creating a counter):
> [...]
> proc tick {} {
> global Seconds
> incr Seconds
> after 1000 tick
> }
>
> tick
To be pedantic, this isn't recursion, since each call to [tick] actually
terminates long before the next call is started by the event loop.
Think of it more as a user-level interrupt service routine that's tied to
timer ticks. I think the distinction is important because if it really
*were* recursion (say, due to a logic bug), you'd probably have a stack
overflow and much badness before long.
In any case, the above is a classic Tcl idiom viz. programming with
events, and is certainly worth keeping in mind.
- Adrian
|
|
|
|
|