2 # Simple test program for ctb module: emulate a terminal.
3 # To simplify matters use the python console window for output.
12 print 'Done, err=', err
15 if not ctb
.available():
16 print 'Communications Toolbox not available'
18 # Disable Python's event processing (we do that)
19 MacOS
.SchedParams(1, 0)
20 print 'Minimal terminal emulator V1.0'
21 print '(type command-Q to exit)'
24 l
= ctb
.CMNew('Serial Tool', None)
26 l
.SetConfig(l
.GetConfig() + ' baud 4800')
29 l
.Idle() # Give time to ctb
31 ok
, evt
= Evt
.WaitNextEvent(0xffff, 0)
33 what
, message
, when
, where
, modifiers
= evt
35 if what
== Events
.keyDown
:
36 # It is ours. Check for command-. to terminate
37 ch
= chr(message
& Events
.charCodeMask
)
38 if ch
== 'q' and (modifiers
& Events
.cmdKey
):
40 l
.Write(ch
, ctb
.cmData
, -1, 0)
41 d
, dummy
= l
.Read(1000, ctb
.cmData
, 1)