#!/usr/bin/env python """ # Copyright (C) 2008 Michael Buesch # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 # 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, see . """ import getopt import sys from serial.serialposix import * # Serial communication port configuration CONFIG_BAUDRATE = 9600 CONFIG_BYTESIZE = 8 CONFIG_PARITY = PARITY_EVEN CONFIG_STOPBITS = 2 def usage(): print "Pressure control - remote configuration" print "" print "Copyright (C) 2008 Michael Buesch " print "Licensed under the GNU/GPL version 3" print "" print "Usage: pctl-remote [OPTIONS] /dev/ttyS0" print "" print "-h|--help Print this help text" def parseArgs(): global opt_ttyfile if len(sys.argv) < 2: usage() sys.exit(1) opt_ttyfile = sys.argv[-1] try: (opts, args) = getopt.getopt(sys.argv[1:-1], "h", [ "help" ]) except getopt.GetoptError: usage() sys.exit(1) for (o, v) in opts: if o in ("-h", "--help"): usage() sys.exit(0) def main(): parseArgs() fd = Serial(opt_ttyfile, CONFIG_BAUDRATE, CONFIG_BYTESIZE, CONFIG_PARITY, CONFIG_STOPBITS) while True: x = fd.readline() sys.stdout.write(x) if __name__ == "__main__": try: main() except SerialException, e: print "[Serial error] %s" % e.message