Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Terminal Emulator App

50 views
Skip to first unread message

Ian Bell

unread,
Dec 21, 2004, 1:10:12 PM12/21/04
to
I am writing a terminal emulator in tcl/tk which communicates via a serial
link with a microcontroller development board. it is unusual because of
the microcontroller monitor programme comtrolling the other end of the
serial link. When the terminal sends a character, the monitor expects the
terminal to *wait* until the monitor has echoed the character before
sending another. The monitor may also send streams of data to the terminal.
The logic of this is not hard to deal with but it would be simplest if I
had an event triggered whenever a character is received. A simple flag set
by sending a char would allow the event handler to differentiate between
and echoed character and one in a stream. The problem is I don't know how
to set up the event. Read does not do what I want AFAICS.

Any help appreciated.

Ian
--
Ian Bell

Christopher Nelson

unread,
Dec 21, 2004, 3:15:27 PM12/21/04
to
Ian Bell wrote:
> ...

> The logic of this is not hard to deal with but it would be simplest
if I
> had an event triggered whenever a character is received. ...

Can you use a combination of [fileevent]
(http://aspn.activestate.com/ASPN/docs/ActiveTcl/tcl/TclCmd/fileevent.htm)
and [event generate]
(http://aspn.activestate.com/ASPN/docs/ActiveTcl/tcl/TkCmd/event.htm#M7)
with some virtual event to do what you need?
.
. Chris

Quokka

unread,
Dec 21, 2004, 7:27:27 PM12/21/04
to
Christopher Nelson wrote:
> Ian Bell wrote:
>
>>...
>>The logic of this is not hard to deal with but it would be simplest
>
> if I
>
>>had an event triggered whenever a character is received. ...

Maybe the following wiki pages may help

http://wiki.tcl.tk/3213
http://wiki.tcl.tk/3642

Paul

Melissa Schrumpf

unread,
Dec 21, 2004, 8:10:53 PM12/21/04
to
Ian Bell wrote:

> Any help appreciated.

This is not very unusual at all. Basically, you've defined the
microcontroller as the master in the network protocol, most likely
because it's resources are limited, and you use the echo feature to
prevent overloading it with interrupts, but the computer is presumed to
be able to handle receipt and buffering of streaming data, right?

Here's a loose description of how it could be done, sprinkled with
example code from one of my serial device comms programs, and some more
mocked up:

set wait_echo 0
set echo_char ""

proc opencomm {} {
global cid
set cid [open COM1: RDWR]
fconfigure $cid -blocking 0 -mode 38400,n,8,1 -translation binary
fileevent $cid readable rxchar
}

proc closecomm {} {
global cid
fileevent $cid readable {}
close $cid
}

proc rxchar {} {

global cid wait_echo echo_char
set c [read $cid 1]
#binary scan $c H* hval

if {$wait_echo} {
if {$echo_char!=$c} {
# handle echo error
}
} else {
# do something, like appending the streaming data
# into another global, and evaluate the contents of
# that buffer, e.g. for message completeness, checksum,
# etc.
}

if {[eof $cid]} {
# handle a suddenly-closed com port
}
}

proc txchar {c} {
global cid wait_echo echo_char
if {[catch {puts -nonewline $cid $c} res]} {
# couldn't write to serial
# handle the error here, perhaps by:
# catch {closecomm}; opencomm
}
set echo_char $c
set wait_echo 1
}


Is that about what you're looking for?

--
MKS

Ian Bell

unread,
Dec 22, 2004, 2:01:14 PM12/22/04
to
Quokka wrote:

> Christopher Nelson wrote:
>> Ian Bell wrote:
>>
>>>...
>>>The logic of this is not hard to deal with but it would be simplest
>>
>> if I
>>
>>>had an event triggered whenever a character is received. ...
>
> Maybe the following wiki pages may help

Many thanks, they did indeed help
>
> http://wiki.tcl.tk/3213

Wow, that is elegant code

> http://wiki.tcl.tk/3642


Excellent stuff. Most of what I need.

Cheers

Ian
--
Ian Bell

Ian Bell

unread,
Dec 22, 2004, 2:09:17 PM12/22/04
to
Melissa Schrumpf wrote:

> Ian Bell wrote:
>
>> I am writing a terminal emulator in tcl/tk which communicates via a
>> serial
>> link with a microcontroller development board. it is unusual because of
>> the microcontroller monitor programme comtrolling the other end of the
>> serial link. When the terminal sends a character, the monitor expects the
>> terminal to *wait* until the monitor has echoed the character before
>> sending another. The monitor may also send streams of data to the
>> terminal. The logic of this is not hard to deal with but it would be
>> simplest if I
>> had an event triggered whenever a character is received. A simple flag
>> set by sending a char would allow the event handler to differentiate
>> between
>> and echoed character and one in a stream. The problem is I don't know
>> how
>> to set up the event. Read does not do what I want AFAICS.
>
>> Any help appreciated.
>
> This is not very unusual at all. Basically, you've defined the
> microcontroller as the master in the network protocol, most likely
> because it's resources are limited, and you use the echo feature to
> prevent overloading it with interrupts, but the computer is presumed to
> be able to handle receipt and buffering of streaming data, right?

Pretty much spot on. The monitor prog is given by the manufacturer of the
microcontroller development board so in that sense We are forced to
consider it as master.


>
> Here's a loose description of how it could be done, sprinkled with
> example code from one of my serial device comms programs, and some more
> mocked up:

Thanks for the code. Just the thing.


--
Ian Bell

Ian Bell

unread,
Dec 29, 2004, 11:08:39 AM12/29/04
to
Just a quick note of thanks to all who helped me with my rather specialised
terminal application for use with an 8051 single board computer. It is up
an running now thanks to help from the members of this group. If anyone is
interested you can find a link to the code on this page:

http://www.8052.com/users/redtommo

0 new messages