#!/usr/bin/python # fnordlicht serial client script # # for additional information please # see http://koeln.ccc.de/prozesse/running/fnordlicht # # (c) by Alexander Neumann # and Lars Noschinski # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # For more information on the GPL, please go to: # http://www.gnu.org/copyleft/gpl.html from select import select from os import fdopen from sys import stdin from tty import setcbreak if __name__ == "__main__": # current keyboard command inputcmd = "" # open connection to the converter bus = open("/dev/ttyUSB0", "r+", 0) # disable line-buffering setcbreak(bus.fileno()) setcbreak(stdin.fileno()) # multiplex io with stdin inl = [bus, stdin] while 1: # select over all fds inf, ouf, erf = select(inl, [], []) # check every fd for a change if bus in inf: c = bus.read(1) if ord(c) < 32: print "received 0x%x" % ord(c) else: print "received '%0s'(0x%x)" % (c, ord(c)) elif stdin in inf: inputcmd += stdin.read(1) if inputcmd == "-": print "-" * 76 else: bus.write(inputcmd) inputcmd = ""