Bump version to 0.9.1.
[python/dscho.git] / Mac / Lib / test / ctbtest.py
blobcb1b5068e0820ac4be43365ca5b62719bf889ea9
2 # Simple test program for ctb module: emulate a terminal.
3 # To simplify matters use the python console window for output.
5 import ctb
6 import Evt
7 import Events
8 import MacOS
9 import sys
11 def cb(err):
12 print 'Done, err=', err
14 def main():
15 if not ctb.available():
16 print 'Communications Toolbox not available'
17 sys.exit(1)
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)'
22 print
24 l = ctb.CMNew('Serial Tool', None)
25 l.Open(10)
26 l.SetConfig(l.GetConfig() + ' baud 4800')
28 while 1:
29 l.Idle() # Give time to ctb
31 ok, evt = Evt.WaitNextEvent(0xffff, 0)
32 if ok:
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):
39 break
40 l.Write(ch, ctb.cmData, -1, 0)
41 d, dummy = l.Read(1000, ctb.cmData, 1)
42 if d:
43 for ch in d:
44 if ch != '\r':
45 sys.stdout.write(ch)
46 sys.stdout.flush()
47 l.Close(-1, 1)
48 del l
50 main()