def search_and_instantiate_plotters():
    """Dynamically searches and instantiates all found plotters.
    The function sniffs all serial ports in search for pen plotters and
    instantiates all plotters found. If a plotter is not recognized,
    the function interactively queries user for plotter type."""

    print("Scanning serial ports...")
    ports = list(scan_serial_ports().values())
    print("Found ports:")
    print("  " + "\n  ".join(ports))

    ## get serial ports that have a plotter connected...
    print("\nSniffing for plotters in all serial ports...")
    plotters_found = sniff_ports_for_plotters(ports)
    if len(plotters_found) == 0:
        print("Found no plotter connected to any of the serial ports.")
        print("Is your plotter on?\n")
        ## return a list so we don't get a python error when trying
        ## to index the result.
        return [None]
    else:
        for serial_address, pln in list(plotters_found.items()):
            print("   Found plotter %s in port %s" % (pln, serial_address))
    ## instantiate a plotter for every port with a plotter...
    result = []
    for serial_address, pln in list(plotters_found.items()):
        plotter = _instantiate_plotter(serial_address, pln)
        result.append(plotter)
    return result
Example #2
0
def interactive_open_serial(baudrate, bytesize, parity, stopbits, timeout,
                            xonxoff, rtscts):
    '''The function scans for all serial ports, lists them and prompts
    the user to select a port.  The function returns a Serial instance.
    '''
    ports = scan_serial_ports()
    print "Available ports:\n"
    for k, port in ports.items():
        print "(%d) %s" % (k, port.portstr)
    ## get user's input...
    while True:
        sp = raw_input("\nChoose serial port number: ")
        ## check response...
        try:
            sp = int(sp)
            if not sp in ports.keys():
                raise ValueError
            else:
                break
        except ValueError:
            print 'Whoops! wrong port number. Try again...'
    ## configure port...
    selected_serial = ports[sp]
    selected_serial.baudrate = baudrate
    selected_serial.bytesize = bytesize
    selected_serial.parity = parity
    selected_serial.stopbits = stopbits
    selected_serial.timeout = timeout
    selected_serial.xonxoff = xonxoff
    selected_serial.rtscts = rtscts
    selected_serial.open()
    print "Okay, opening %s." % selected_serial.portstr
    return selected_serial
def search_and_instantiate_plotters( ):
    '''Dynamically searches and instantiates all found plotters.
    The function sniffs all serial ports in search for pen plotters and
    instantiates all plotters found. If a plotter is not recognized,
    the function interactively queries user for plotter type.'''

    from chiplotle.tools.plottertools import instantiate_plotter_from_id
    from chiplotle.tools.plottertools import interactive_choose_plotter

    print 'Scanning serial ports...'
    ports = scan_serial_ports( ).values( )
    print 'Found ports:'
    print '  ' + '\n  '.join(ports)

    ## get serial ports that have a plotter connected...
    print '\nSniffing for plotters in all serial ports...'
    plotters_found = sniff_ports_for_plotters(ports)
    if len(plotters_found) == 0:
        print 'Found no plotter connected to any of the serial ports.'
        print 'Is your plotter on?\n'
        ## return a list so we don't get a python error when trying
        ## to index the result.
        return [None]
    else:
        for serial_address, pln in plotters_found.items( ):
            print '   Found plotter %s in port %s' % (pln, serial_address)
    ## instantiate a plotter for every port with a plotter...
    result = [ ]
    for serial_address, pln in plotters_found.items( ):
        plotter = _instantiate_plotter(serial_address, pln)
        result.append(plotter)
    return result
def interactive_open_serial(baudrate, bytesize, parity, stopbits, timeout,
    xonxoff, rtscts):
    '''The function scans for all serial ports, lists them and prompts
    the user to select a port.  The function returns a Serial instance.
    '''
    ports = scan_serial_ports( )
    print "Available ports:\n"
    for k, port in ports.items( ):
        print "(%d) %s" % (k, port.portstr)
    ## get user's input...
    while True:
        sp = raw_input("\nChoose serial port number: ")
        ## check response...
        try:
            sp = int(sp)
            if not sp in ports.keys( ):
                raise ValueError
            else:
                break
        except ValueError:
            print 'Whoops! wrong port number. Try again...'
    ## configure port...
    selected_serial = ports[sp]
    selected_serial.baudrate = baudrate
    selected_serial.bytesize = bytesize
    selected_serial.parity = parity
    selected_serial.stopbits = stopbits
    selected_serial.timeout = timeout
    selected_serial.xonxoff = xonxoff
    selected_serial.rtscts = rtscts
    selected_serial.open( )
    print "Okay, opening %s." % selected_serial.portstr
    return selected_serial
def search_and_instantiate_plotters():
    '''Dynamically searches and instantiates all found plotters.
    The function sniffs all serial ports in search for pen plotters and
    instantiates all plotters found. If a plotter is not recognized,
    the function interactively queries user for plotter type.'''

    from chiplotle.tools.plottertools import instantiate_plotter_from_id
    from chiplotle.tools.plottertools import interactive_choose_plotter

    print 'Scanning serial ports...'
    ports = scan_serial_ports().values()
    print 'Found ports:'
    print '  ' + '\n  '.join(ports)

    ## get serial ports that have a plotter connected...
    print '\nSniffing for plotters in all serial ports...'
    plotters_found = sniff_ports_for_plotters(ports)
    if len(plotters_found) == 0:
        print 'Found no plotter connected to any of the serial ports.'
        print 'Is your plotter on?\n'
        ## return a list so we don't get a python error when trying
        ## to index the result.
        return [None]
    else:
        for serial_address, pln in plotters_found.items():
            print '   Found plotter %s in port %s' % (pln, serial_address)
    ## instantiate a plotter for every port with a plotter...
    result = []
    for serial_address, pln in plotters_found.items():
        plotter = _instantiate_plotter(serial_address, pln)
        result.append(plotter)
    return result