3
# Copyright (c) 2009 Twisted Matrix Laboratories.
4
# See LICENSE for details.
7
Example using MouseMan protocol with the SerialPort transport.
10
# TODO set tty modes, etc.
13
# speed 1200 baud; rows 0; columns 0; line = 0;
14
# intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D;
15
# eol = <undef>; eol2 = <undef>; start = ^Q; stop = ^S; susp = ^Z;
16
# rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
17
# -parenb -parodd cs7 hupcl -cstopb cread clocal -crtscts ignbrk
18
# -brkint ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon
19
# -ixoff -iuclc -ixany -imaxbel -opost -olcuc -ocrnl -onlcr -onocr
20
# -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 -isig -icanon -iexten
21
# -echo -echoe -echok -echonl -noflsh -xcase -tostop -echoprt -echoctl
25
from twisted.python import usage, log
26
from twisted.protocols.mice import mouseman
28
if sys.platform == 'win32':
29
# win32 serial does not work yet!
30
raise NotImplementedError, "The SerialPort transport does not currently support Win32"
31
from twisted.internet import win32eventreactor
32
win32eventreactor.install()
34
class Options(usage.Options):
36
['port', 'p', '/dev/mouse', 'Device for serial mouse'],
37
['baudrate', 'b', '1200', 'Baudrate for serial mouse'],
38
['outfile', 'o', None, 'Logfile [default: sys.stdout]'],
41
class McFooMouse(mouseman.MouseMan):
48
def down_middle(self):
61
log.msg("(%d,%d)" % (x, y))
63
if __name__ == '__main__':
64
from twisted.internet import reactor
65
from twisted.internet.serialport import SerialPort
69
except usage.UsageError, errortext:
70
print "%s: %s" % (sys.argv[0], errortext)
71
print "%s: Try --help for usage details." % (sys.argv[0])
76
logFile = o.opts['outfile']
77
log.startLogging(logFile)
79
SerialPort(McFooMouse(), o.opts['port'], reactor, baudrate=int(o.opts['baudrate']))