Esempio n. 1
0
def enumerate_device_serials(vid=FT232H_VID, pid=FT232H_PID):
    """Return a list of all FT232H device serial numbers connected to the
    machine.  You can use these serial numbers to open a specific FT232H device
    by passing it to the FT232H initializer's serial parameter.
    """
    try:
        # Create a libftdi context.
        ctx = None
        ctx = ftdi.new()
        # Enumerate FTDI devices.
        device_list = None
        count, device_list = ftdi.usb_find_all(ctx, vid, pid)
        if count < 0:
            raise RuntimeError('ftdi_usb_find_all returned error {0}: {1}'.format(count, ftdi.get_error_string(self._ctx)))
        # Walk through list of devices and assemble list of serial numbers.
        devices = []
        while device_list is not None:
            # Get USB device strings and add serial to list of devices.
            ret, manufacturer, description, serial = ftdi.usb_get_strings(ctx, device_list.dev, 256, 256, 256)
            if serial is not None:
                devices.append(serial)
            device_list = device_list.next
        return devices
    finally:
        # Make sure to clean up list and context when done.
        if device_list is not None:
            ftdi.list_free(device_list)
        if ctx is not None:
            ftdi.free(ctx)
Esempio n. 2
0
def enumerate_device_serials(vid=FT232H_VID, pid=FT232H_PID):
    """Return a list of all FT232H device serial numbers connected to the
    machine.  You can use these serial numbers to open a specific FT232H device
    by passing it to the FT232H initializer's serial parameter.
    """
    try:
        # Create a libftdi context.
        ctx = None
        ctx = ftdi.new()
        # Enumerate FTDI devices.
        device_list = None
        count, device_list = ftdi.usb_find_all(ctx, vid, pid)
        if count < 0:
            raise RuntimeError('ftdi_usb_find_all returned error {0}: {1}'.format(count, ftdi.get_error_string(self._ctx)))
        # Walk through list of devices and assemble list of serial numbers.
        devices = []
        while device_list is not None:
            # Get USB device strings and add serial to list of devices.
            ret, manufacturer, description, serial = ftdi.usb_get_strings(ctx, device_list.dev, 256, 256, 256)
            if serial is not None:
                devices.append(serial)
            device_list = device_list.next
        return devices
    finally:
        # Make sure to clean up list and context when done.
        if device_list is not None:
            ftdi.list_free(device_list)
        if ctx is not None:
            ftdi.free(ctx)
Esempio n. 3
0
	def __init__(self, num_pixels, num_rows):
		# Create a libftdi context.
		ctx = None
		ctx = ftdi.new()
		# Define USB vendor and product ID
		vid = 0x0403
		pid = 0x6014
		# Enumerate FTDI devices.
		self.serial = None
		device_list = None
		count, device_list = ftdi.usb_find_all(ctx, vid, pid)
		while device_list is not None:
			# Get USB device strings and add serial to list of devices.
			ret, manufacturer, description, serial = ftdi.usb_get_strings(ctx, device_list.dev, 256, 256, 256)
			print 'return: {0}, manufacturer: {1}, description: {2}, serial: |{3}|'.format(ret,manufacturer,description,serial)
			if 'FTDI' in manufacturer and 'Serial' in description and 'FT' in serial:
				self.serial = serial
			device_list = device_list.next
		# Make sure to clean up list and context when done.
		if device_list is not None:
			ftdi.list_free(device_list)
		if ctx is not None:
			ftdi.free(ctx)	
		
		# Create an FT232H object.
		self.ft232h = FT232H.FT232H(serial=self.serial)
		# Create an FT232H object.
		self.ft232h = FT232H.FT232H()
		# Create a SPI interface for the FT232H object.  Set the SPI bus to 6mhz.
		self.spi    = FT232H.SPI(self.ft232h, max_speed_hz=SPI_BAUD)
		# Create a pixel data buffer and lookup table.
		self.buffer = bytearray(num_pixels*BYTES_PER_PIXEL*3)
		self.lookup = self.build_byte_lookup()
		#print self.lookup
		self.set_brightness(MAX_INTENSITY/2) #set brightness to 25% by default
		self.num_pixels	= num_pixels
		self.rows 		= num_rows
		self.cols 		= num_pixels/num_rows
Esempio n. 4
0
## Loop grabbing data and storing in array
print 'Gathering data. Press Ctrl-C to quit.'
output = []
try:
    while True:
	    # Sleep based on baudrate
        time.sleep(1.0/BAUD)
	    # Read the input and store to array
        ret, pins = ftdi.read_pins(ftdictx)			# reads pins directly, needs sleep time to be exact
        output.append(pins)
        #ret, databuf = ftdi.read_data(ftdictx)		# reads the data buffer, no need for exact timing (just fast enough to keep buffer from overflowing)
        #output.extend(databuf)
except KeyboardInterrupt:
    pass

## Write captured data to file
with open("output.bin", "wb") as outfile:
    writedata = bytearray(output)
    outfile.write(writedata)

## Cleanup: free devlist, reset bitmode, close usb, etc
ftdi.list_free(devlist)
ftdi.disable_bitbang(ftdictx)
ftdi.set_bitmode(ftdictx, 0x00, ftdi.BITMODE_RESET)
ret = ftdi.usb_close( ftdictx )
if ret < 0:
    print( 'unable to close ftdi device: %d (%s)' % ( ret, ftdi.get_error_string( ftdictx ) ) )
    os._exit( 1 )
    
print ('device closed')    
ftdi.free( ftdictx )