1995-03-07 12:40:18 -04:00
|
|
|
#
|
|
|
|
# Simple test program for ctb module: emulate a terminal.
|
1997-04-03 10:45:28 -04:00
|
|
|
# To simplify matters use the python console window for output.
|
1995-03-07 12:40:18 -04:00
|
|
|
#
|
|
|
|
import ctb
|
1997-04-03 10:45:28 -04:00
|
|
|
import Evt
|
|
|
|
import Events
|
|
|
|
import MacOS
|
1995-03-07 12:40:18 -04:00
|
|
|
import sys
|
|
|
|
|
|
|
|
def cb(err):
|
|
|
|
print 'Done, err=', err
|
|
|
|
|
|
|
|
def main():
|
|
|
|
if not ctb.available():
|
|
|
|
print 'Communications Toolbox not available'
|
|
|
|
sys.exit(1)
|
1997-04-03 10:45:28 -04:00
|
|
|
# Disable Python's event processing (we do that)
|
|
|
|
MacOS.EnableAppswitch(0)
|
1995-03-07 12:40:18 -04:00
|
|
|
print 'Minimal terminal emulator V1.0'
|
1997-04-03 10:45:28 -04:00
|
|
|
print '(type command-Q to exit)'
|
1995-03-07 12:40:18 -04:00
|
|
|
print
|
|
|
|
|
|
|
|
l = ctb.CMNew('Serial Tool', None)
|
1997-04-03 10:45:28 -04:00
|
|
|
l.Open(10)
|
|
|
|
l.SetConfig(l.GetConfig() + ' baud 4800')
|
1995-03-07 12:40:18 -04:00
|
|
|
|
|
|
|
while 1:
|
1997-04-03 10:45:28 -04:00
|
|
|
l.Idle() # Give time to ctb
|
|
|
|
|
|
|
|
ok, evt = Evt.WaitNextEvent(0xffff, 0)
|
|
|
|
if ok:
|
|
|
|
what, message, when, where, modifiers = evt
|
|
|
|
|
|
|
|
if what == Events.keyDown:
|
|
|
|
# It is ours. Check for command-. to terminate
|
|
|
|
ch = chr(message & Events.charCodeMask)
|
|
|
|
if ch == 'q' and (modifiers & Events.cmdKey):
|
|
|
|
break
|
|
|
|
l.Write(ch, ctb.cmData, -1, 0)
|
|
|
|
d, dummy = l.Read(1000, ctb.cmData, 1)
|
1995-03-07 12:40:18 -04:00
|
|
|
if d:
|
1997-04-03 10:45:28 -04:00
|
|
|
for ch in d:
|
|
|
|
if ch != '\r':
|
|
|
|
sys.stdout.write(ch)
|
|
|
|
sys.stdout.flush()
|
1995-03-07 12:40:18 -04:00
|
|
|
l.Close(-1, 1)
|
|
|
|
del l
|
|
|
|
|
1995-12-21 11:38:14 -04:00
|
|
|
main()
|