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)
def __init__(self, vid=FT232H_VID, pid=FT232H_PID, serial=None): """Create a FT232H object. Will search for the first available FT232H device with the specified USB vendor ID and product ID (defaults to FT232H default VID & PID). Can also specify an optional serial number string to open an explicit FT232H device given its serial number. See the FT232H.enumerate_device_serials() function to see how to list all connected device serial numbers. """ # Initialize FTDI device connection. self._ctx = ftdi.new() if self._ctx == 0: raise RuntimeError('ftdi_new failed! Is libftdi1 installed?') # Register handler to close and cleanup FTDI context on program exit. atexit.register(self.close) if serial is None: # Open USB connection for specified VID and PID if no serial is specified. self._check(ftdi.usb_open, vid, pid) else: # Open USB connection for VID, PID, serial. ##self._check(ftdi.usb_open_string, 's:{0}:{1}:{2}'.format(vid, pid, serial)) finaldev = None device_list = None count, device_list = ftdi.usb_find_all(self._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, serialtest = ftdi.usb_get_strings(self._ctx, device_list.dev, 256, 256, 256) if serialtest == serial: finaldev = device_list.dev device_list = device_list.next if finaldev is None: raise RuntimeError('Could not find correct device') self._check(ftdi.usb_open_dev, finaldev) # # Reset device. self._check(ftdi.usb_reset) # Disable flow control. Commented out because it is unclear if this is necessary. #self._check(ftdi.setflowctrl, ftdi.SIO_DISABLE_FLOW_CTRL) # Change read & write buffers to maximum size, 65535 bytes. self._check(ftdi.read_data_set_chunksize, 65535) self._check(ftdi.write_data_set_chunksize, 65535) # Clear pending read data & write buffers. self._check(ftdi.usb_purge_buffers) # Enable MPSSE and syncronize communication with device. self._mpsse_enable() self._mpsse_sync() # Initialize all GPIO as inputs. self._write('\x80\x00\x00\x82\x00\x00') self._direction = 0x0000 self._level = 0x0000
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
os._exit(1) # try to list ftdi devices 0x6010 or 0x6001 ret, devlist = ftdi.usb_find_all(ftdic, UM232H_B_VID, UM232H_B_PID) if ret <= 0: ret, devlist = ftdi.usb_find_all(ftdic, 0x0403, 0x6001) if ret < 0: print('ftdi_usb_find_all failed: %d (%s)' % (ret, ftdi.get_error_string(ftdic))) os._exit(1) print('Number of FTDI devices found: %d\n' % ret) curnode = devlist i = 0 while (curnode != None): ret, manufacturer, description, serial = ftdi.usb_get_strings( ftdic, curnode.dev) if ret < 0: print('ftdi_usb_get_strings failed: %d (%s)' % (ret, ftdi.get_error_string(ftdic))) os._exit(1) print('Device #%d: manufacturer="%s" description="%s" serial="%s"\n' % (i, manufacturer, description, serial)) curnode = curnode.next i += 1 # open usb ret = ftdi.usb_open(ftdic, UM232H_B_VID, UM232H_B_PID) if ret < 0: print('unable to open ftdi device: %d (%s)' % (ret, ftdi.get_error_string(ftdic))) os._exit(1)
# Allocate and inialize an ftdi context. ftdic = ftdi.new() if ftdic == 0: raise ErrorMsg('ftdi.new() failed') # List all the FT230X devices. nDevices, devlist = ftdi.usb_find_all(ftdic, 0x0403, 0x6015) if nDevices < 0: raise ErrorMsg('ftdi.usb_find_all error = %s' % ftdi.get_error_string(ftdic)) elif nDevices == 0: raise ErrorMsg('No FT230X devices found') elif nDevices != 1: raise ErrorMsg('More than one FT230X device found') # Display the identified single FT230X device. ret, manufacturer, description, serial = ftdi.usb_get_strings(ftdic, devlist.dev) if ret < 0: raise ErrorMsg('ftdi.usb_get_strings error = %s' % ftdi.get_error_string(ftdic)) print 'manufacturer="%s" description="%s" serial="%s"' % (manufacturer, description, serial) # Open the identified single FT230X device. ret = ftdi.usb_open_desc(ftdic, 0x0403, 0x6015, description, serial) if ret < 0: raise ErrorMsg('ftdi.usb_open_desc error = %s' % ftdi.get_error_string(ftdic)) # Read the chip id. ret, chipid = ftdi.read_chipid(ftdic) if ret < 0: raise ErrorMsg('ftdi.read_chipid error = %s' % ftdi.get_error_string(ftdic)) print 'chip id=0x%08X' % (chipid % 2**32)
os._exit(1) # try to list ftdi devices 0x6010 or 0x6001 ret, devlist = ftdi.usb_find_all(ftdic, 0x0403, 0x6010) if ret <= 0: ret, devlist = ftdi.usb_find_all(ftdic, 0x0403, 0x6001) if ret < 0: print('ftdi_usb_find_all failed: %d (%s)' % (ret, ftdi.get_error_string(ftdic))) os._exit(1) print('devices: %d' % ret) curnode = devlist i = 0 while(curnode != None): ret, manufacturer, description, serial = ftdi.usb_get_strings( ftdic, curnode.dev) if ret < 0: print('ftdi_usb_get_strings failed: %d (%s)' % (ret, ftdi.get_error_string(ftdic))) os._exit(1) print('#%d: manufacturer="%s" description="%s" serial="%s"\n' % (i, manufacturer, description, serial)) curnode = curnode.next i += 1 # open usb ret = ftdi.usb_open(ftdic, 0x0403, 0x6001) if ret < 0: print('unable to open ftdi device: %d (%s)' % (ret, ftdi.get_error_string(ftdic))) os._exit(1)
# Allocate and inialize an ftdi context. ftdic = ftdi.new() if ftdic == 0: raise ErrorMsg('ftdi.new() failed') # List all the FT230X devices. nDevices, devlist = ftdi.usb_find_all(ftdic, 0x0403, 0x6015) if nDevices < 0: raise ErrorMsg('ftdi.usb_find_all error = %s' % ftdi.get_error_string(ftdic)); elif nDevices == 0: raise ErrorMsg('No FT230X devices found'); elif nDevices != 1: raise ErrorMsg('More than one FT230X device found'); # Display the identified single FT230X device. ret, manufacturer, description, serial = ftdi.usb_get_strings(ftdic, devlist.dev) if ret < 0: raise ErrorMsg('ftdi.usb_get_strings error = %s' % ftdi.get_error_string(ftdic)) print 'manufacturer="%s" description="%s" serial="%s"' % (manufacturer, description, serial) # Open the identified single FT230X device. ret = ftdi.usb_open_desc(ftdic, 0x0403, 0x6015, description, serial); if ret < 0: raise ErrorMsg('ftdi.usb_open_desc error = %s' % ftdi.get_error_string(ftdic)) # Read the chip id. ret, chipid = ftdi.read_chipid(ftdic) if ret < 0: raise ErrorMsg('ftdi.read_chipid error = %s' % ftdi.get_error_string(ftdic)) print 'chip id=0x%08X' % (chipid % 2**32)