1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/client.py Sun Jan 10 00:30:41 2016 +0100
1.3 @@ -0,0 +1,69 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +A client for updating the display of the ElecFreaks alphanumeric display brick.
1.8 +
1.9 +Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
1.10 +
1.11 +This program is free software; you can redistribute it and/or modify it under
1.12 +the terms of the GNU General Public License as published by the Free Software
1.13 +Foundation; either version 3 of the License, or (at your option) any later
1.14 +version.
1.15 +
1.16 +This program is distributed in the hope that it will be useful, but WITHOUT ANY
1.17 +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
1.18 +PARTICULAR PURPOSE. See the GNU General Public License for more details.
1.19 +
1.20 +You should have received a copy of the GNU General Public License along
1.21 +with this program. If not, see <http://www.gnu.org/licenses/>.
1.22 +"""
1.23 +
1.24 +from serial import Serial
1.25 +from time import sleep
1.26 +import sys
1.27 +
1.28 +port = "/dev/ttyUSB0"
1.29 +rate = 115200
1.30 +
1.31 +def openPort():
1.32 + global s
1.33 + s = Serial(port, rate)
1.34 + s.setTimeout(5)
1.35 + s.readline()
1.36 +
1.37 +def closePort():
1.38 + global s
1.39 + s.close()
1.40 + s = None
1.41 +
1.42 +def writeToPort(data):
1.43 + s.write(data)
1.44 + s.flush()
1.45 + print >>sys.stderr, data.rstrip()
1.46 +
1.47 +def readFromPort():
1.48 + resp = s.readline().rstrip("\r\n")
1.49 + if resp == "?":
1.50 + resp = s.readline().rstrip("\r\n")
1.51 + return resp
1.52 +
1.53 +def console():
1.54 + try:
1.55 + while 1:
1.56 + cmd = raw_input("> ")
1.57 + if cmd:
1.58 + s.write(cmd + "\n")
1.59 + s.flush()
1.60 + print s.readline().rstrip("\r\n")
1.61 + except EOFError:
1.62 + print "Session closed."
1.63 +
1.64 +if __name__ == "__main__":
1.65 + openPort()
1.66 +
1.67 + try:
1.68 + console()
1.69 + finally:
1.70 + closePort()
1.71 +
1.72 +# vim: tabstop=4 expandtab shiftwidth=4