#!/usr/bin/python import sys import os import termios import struct import fcntl import time import glob TIOCM_DTR_str = struct.pack('I', termios.TIOCM_DTR) def set_DTR(fd, level=1): """Set terminal status line: Data Terminal Ready""" if level: fcntl.ioctl(fd, termios.TIOCMBIS, TIOCM_DTR_str) else: fcntl.ioctl(fd, termios.TIOCMBIC, TIOCM_DTR_str) def pulse_DTR(dev_file): print "opening '%s'" % dev_file fd = os.open(dev_file, os.O_RDWR | os.O_NOCTTY) ### this shouldn't be needed, as the thing resets on the above open() print 'pulsing...' set_DTR(fd, 1) time.sleep(0.1) set_DTR(fd, 0) os.close(fd) print 'done.' def usage(): print 'USAGE: %s /dev/SERIAL-DEVICE' % os.path.basename(__file__) sys.exit(1) if __name__ == '__main__': if len(sys.argv) == 1: files = glob.glob('/dev/cu.usb*') if len(files) != 1: usage() dev = files[0] elif len(sys.argv) == 2: dev = sys.argv[1] else: usage() pulse_DTR(dev)