text
stringlengths
1
93.6k
userinput = RawInput()
while not self.ctlc:
c = userinput()
if c in self.UPKEYS:
self.NextBaudrate(1)
elif c in self.DOWNKEYS:
self.NextBaudrate(-1)
elif c == '\x03':
self.ctlc = True
def MinicomConfig(self, name=None):
success = True
if name is None:
name = self.name
config = "########################################################################\n"
config += "# Minicom configuration file - use \"minicom -s\" to change parameters.\n"
config += "pu port %s\n" % self.port
config += "pu baudrate %s\n" % self.BAUDRATES[self.index]
config += "pu bits 8\n"
config += "pu parity N\n"
config += "pu stopbits 1\n"
config += "pu rtscts No\n"
config += "########################################################################\n"
if name is not None and name:
try:
open("/etc/minicom/minirc.%s" % name, "w").write(config)
except Exception, e:
print "Error saving minicom config file:", str(e)
success = False
return (success, config)
def Close(self):
self.ctlc = True
self.serial.close()
if __name__ == '__main__':
import subprocess
from getopt import getopt as GetOpt, GetoptError
def usage():
baud = Baudrate()
print ""
print "Baudrate v%s" % baud.VERSION
print "Craig Heffner, http://www.devttys0.com"
print ""
print "Usage: %s [OPTIONS]" % sys.argv[0]
print ""
print "\t-p <serial port> Specify the serial port to use [/dev/ttyUSB0]"
print "\t-t <seconds> Set the timeout period used when switching baudrates in auto detect mode [%d]" % baud.READ_TIMEOUT
print "\t-c <num> Set the minimum ASCII character threshold used during auto detect mode [%d]" % baud.MIN_CHAR_COUNT
print "\t-n <name> Save the resulting serial configuration as <name> and automatically invoke minicom (implies -a)"
print "\t-a Enable auto detect mode"
print "\t-b Display supported baud rates and exit"
print "\t-q Do not display data read from the serial port"
print "\t-h Display help"
print ""
sys.exit(1)
def main():
display = False
verbose = True
auto = False
run = False
threshold = 25
timeout = 5
name = None
port = '/dev/ttyUSB0'
try:
(opts, args) = GetOpt(sys.argv[1:], 'p:t:c:n:abqh')
except GetoptError, e:
print e
usage()
for opt, arg in opts:
if opt == '-t':
timeout = int(arg)
elif opt == '-c':
threshold = int(arg)
elif opt == '-p':
port = arg
elif opt == '-n':
name = arg
auto = True
run = True
elif opt == '-a':
auto = True
elif opt == '-b':
display = True
elif opt == '-q':
verbose = False