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 devlist = ftdi.new_device_listpp()
23 ret = ftdi.usb_find_all( ftdic, devlist, 0x0403, 0x6001 )
25 print 'ftdi_usb_find_all failed: %d (%s)' % ( ret, ftdi.get_error_string( ftdic ) )
27 print 'Number of FTDI devices found: %d\n' % ret
30 for i in range( count ):
31 print 'Checking device: %d' % i
33 curnode = ftdi.device_listpp_value( curdev )
34 ret, manufacturer, description, serial = ftdi.usb_get_strings( ftdic, curnode.dev, 128, 128, 128 )
36 print 'ftdi_usb_get_strings failed: %d (%s)' % ( ret, ftdi.get_error_string( ftdic ) )
38 print 'Manufacturer: %s, Description: %s, Serial: %s\n' % ( manufacturer, description, serial )
39 ftdi.device_listpp_assign( curdev, curnode.next )
42 ret = ftdi.usb_open( ftdic, 0x0403, 0x6001 )
44 print 'unable to open ftdi device: %d (%s)' % ( ret, ftdi.get_error_string( ftdic ) )
49 ret = ftdi.set_bitmode( ftdic, 0xff, ftdi.BITMODE_BITBANG )
51 print 'Cannot enable bitbang'
53 print 'turning everything on'
54 ftdi.write_data( ftdic, chr(0xff), 1 )
56 print 'turning everything off\n'
57 ftdi.write_data( ftdic, chr(0x00), 1 )
60 print 'enabling bit', i
62 ftdi.write_data( ftdic, chr(val), 1 )
64 ftdi.disable_bitbang( ftdic )
69 ret, chipid = ftdi.read_chipid( ftdic )
70 print 'FDTI chip id: %X\n' % chipid
75 ret, eeprom_val = ftdi.read_eeprom_location( ftdic, eeprom_addr )
76 print 'eeprom @ %d: 0x%04x\n' % ( eeprom_addr, eeprom_val )
79 ret=ftdi.read_eeprom( ftdic )
80 ret=ftdi.eeprom_decode( ftdic ,1)
84 ret = ftdi.usb_close( ftdic )
86 print 'unable to close ftdi device: %d (%s)' % ( ret, ftdi.get_error_string( ftdic ) )