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 id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-statements """Return a unique id for the detected chip, if any.""" # There are some times we want to trick the platform detection # say if a raspberry pi doesn't have the right ID, or for testing try: return os.environ['BLINKA_FORCECHIP'] except KeyError: # no forced chip, continue with testing! pass # Special case, if we have an environment var set, we could use FT232H try: if os.environ['BLINKA_FT232H']: # we can't have ftdi1 as a dependency cause its wierd # to install, sigh. import ftdi1 as ftdi # pylint: disable=import-error try: ctx = None ctx = ftdi.new() # Create a libftdi context. # Enumerate FTDI devices. count, _ = ftdi.usb_find_all(ctx, 0, 0) if count < 0: raise RuntimeError( 'ftdi_usb_find_all returned error %d : %s' % count, ftdi.get_error_string(self._ctx)) if count == 0: raise RuntimeError('BLINKA_FT232H environment variable' + \ 'set, but no FT232H device found') finally: # Make sure to clean up list and context when done. if ctx is not None: ftdi.free(ctx) return FT232H except KeyError: # no FT232H environment var pass platform = sys.platform if platform == "linux" or platform == "linux2": return self._linux_id() if platform == "esp8266": return ESP8266 if platform == "samd21": return SAMD21 if platform == "pyboard": return STM32 # nothing found! return None
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
import os import sys import ftdi1 as ftdi import time UM232H_B_VID = 0x0403 UM232H_B_PID = 0x6014 # initialize ftdic = ftdi.new() if ftdic == 0: print('new failed: %d', ret) 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)' %
#!/usr/bin/env python import os import sys import ftdi1 as ftdi import time ftdic = ftdi.new() if ftdic == 0: print('new failed: %d', ret) 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('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)
if value == ftdi.CBUSX_TXRXLED: return 'TXRXLED' if value == ftdi.CBUSX_VBUS_SENSE: return 'VBUS_SENSE' return 'UNKNOWN' # Surround the program with a try ... except clause. try: # 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)
import os import sys import ftdi1 as ftdi import time # version print ('version: %s\n' % ftdi.__version__) # initialize ftdic = ftdi.new() if ftdic == 0: print('new failed: %d' % ret) 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)' %
import os import sys import ftdi1 as ftdi import time UM232H_B_VID = 0x0403 UM232H_B_PID = 0x6014 # initialize ftdic = ftdi.new() if ftdic == 0: print( 'new failed: %d', ret ) 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 ) )
if value == ftdi.CBUSH_TXRXLED: return 'TXRXLED' if value == ftdi.CBUSH_VBUS_SENSE: return 'VBUS_SENSE' return 'UNKNOWN' # Surround the program with a try ... except clause. try: # 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);
#BAUD, = sys.argv # command line inputs BAUD = 400000 # 400kHz, 2xNyquist for 100kHz I2C FT232H_VID = 0x0403 # Default FTDI FT232H vendor ID FT232H_PID = 0x6014 # Default FTDI FT232H product ID # Initialize new context ftdictx = ftdi.new() if ftdictx == 0: print( 'failed to create new context: %d', ret ) os._exit( 1 ) # Try to list FT232H devices ret, devlist = ftdi.usb_find_all( ftdictx, FT232H_VID, FT232H_PID ) if ret < 0: print( 'ftdi_usb_find_all failed: %d (%s)' % ( ret, ftdi.get_error_string( ftdictx ) ) ) 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( ftdictx, curnode.dev ) # if ret < 0: # print( 'ftdi_usb_get_strings failed: %d (%s)' % ( ret, ftdi.get_error_string( ftdictx ) ) ) # os._exit( 1 ) # print( 'Device #%d: manufacturer="%s" description="%s" serial="%s"\n' % ( i, manufacturer, description, serial ) ) # curnode = curnode.next # i += 1