2 # -*- coding: utf-8 -*-
4 """Python example program.
6 Complete program to demonstrate the usage
7 of the swig generated python wrapper
9 You need to build and install the wrapper first"""
18 print( 'new failed: %d', ret )
22 ret, devlist = ftdi.usb_find_all( ftdic, 0x0403, 0x6001 )
24 print( 'ftdi_usb_find_all failed: %d (%s)' % ( ret, ftdi.get_error_string( ftdic ) ) )
26 print( 'Number of FTDI devices found: %d\n' % ret )
29 while( curnode != None ):
30 ret, manufacturer, description, serial = ftdi.usb_get_strings( ftdic, curnode.dev )
32 print( 'ftdi_usb_get_strings failed: %d (%s)' % ( ret, ftdi.get_error_string( ftdic ) ) )
34 print( 'Device #%d: manufacturer="%s" description="%s" serial="%s"\n' % ( i, manufacturer, description, serial ) )
35 curnode = curnode.next
39 ret = ftdi.usb_open( ftdic, 0x0403, 0x6001 )
41 print( 'unable to open ftdi device: %d (%s)' % ( ret, ftdi.get_error_string( ftdic ) ) )
46 ret = ftdi.set_bitmode( ftdic, 0xff, ftdi.BITMODE_BITBANG )
48 print( 'Cannot enable bitbang' )
50 print( 'turning everything on' )
51 ftdi.write_data( ftdic, chr(0xff), 1 )
53 print( 'turning everything off\n' )
54 ftdi.write_data( ftdic, chr(0x00), 1 )
58 print( 'enabling bit #%d (0x%02x)' % (i, val) )
59 ftdi.write_data( ftdic, chr(val), 1 )
61 ftdi.disable_bitbang( ftdic )
66 ret, pins = ftdi.read_pins( ftdic )
69 print( '%02x' % ord( pins[0] ) )
74 ret, chipid = ftdi.read_chipid( ftdic )
75 print( 'FDTI chip id: %X\n' % chipid )
80 ret, eeprom_val = ftdi.read_eeprom_location( ftdic, eeprom_addr )
82 print( 'eeprom @ %d: 0x%04x\n' % ( eeprom_addr, eeprom_val ) )
84 print( 'complete eeprom:' )
85 ret = ftdi.read_eeprom( ftdic )
87 ret, eeprom = ftdi.get_eeprom_buf ( ftdic, size )
89 for i in range( size ):
90 print( '%02x' % ord( eeprom[i] ) )
95 ret = ftdi.usb_close( ftdic )
97 print( 'unable to close ftdi device: %d (%s)' % ( ret, ftdi.get_error_string( ftdic ) ) )