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"""
17 print ( 'version: %s\n' % ftdi.__version__ )
22 print( 'new failed: %d' % ret )
25 # try to list ftdi devices 0x6010 or 0x6001
26 ret, devlist = ftdi.usb_find_all( ftdic, 0x0403, 0x6010 )
28 ret, devlist = ftdi.usb_find_all( ftdic, 0x0403, 0x6001)
31 print( 'ftdi_usb_find_all failed: %d (%s)' % ( ret, ftdi.get_error_string( ftdic ) ) )
33 print( 'devices: %d' % ret )
36 while( curnode != None ):
37 ret, manufacturer, description, serial = ftdi.usb_get_strings( ftdic, curnode.dev )
39 print( 'ftdi_usb_get_strings failed: %d (%s)' % ( ret, ftdi.get_error_string( ftdic ) ) )
41 print( '#%d: manufacturer="%s" description="%s" serial="%s"\n' % ( i, manufacturer, description, serial ) )
42 curnode = curnode.next
46 ret = ftdi.usb_open( ftdic, 0x0403, 0x6001 )
48 print( 'unable to open ftdi device: %d (%s)' % ( ret, ftdi.get_error_string( ftdic ) ) )
53 ret = ftdi.set_bitmode( ftdic, 0xff, ftdi.BITMODE_BITBANG )
55 print( 'Cannot enable bitbang' )
57 print( 'turning everything on' )
58 ftdi.write_data( ftdic, chr(0xff), 1 )
60 print( 'turning everything off\n' )
61 ftdi.write_data( ftdic, chr(0x00), 1 )
65 print( 'enabling bit #%d (0x%02x)' % (i, val) )
66 ftdi.write_data( ftdic, chr(val), 1 )
68 ftdi.disable_bitbang( ftdic )
73 ret, pins = ftdi.read_pins( ftdic )
75 if sys.version_info[0] < 3: # python 2
79 print( 'pins: 0x%x' % pins )
83 ret, chipid = ftdi.read_chipid( ftdic )
85 print( 'chip id: %x\n' % chipid )
90 ret, eeprom_val = ftdi.read_eeprom_location( ftdic, eeprom_addr )
92 print( 'eeprom @ %d: 0x%04x\n' % ( eeprom_addr, eeprom_val ) )
95 ret = ftdi.read_eeprom( ftdic )
97 ret, eeprom = ftdi.get_eeprom_buf ( ftdic, size )
99 for i in range( size ):
101 if sys.version_info[0] < 3: # python 2
103 sys.stdout.write( '%02x ' % octet )
109 ret = ftdi.usb_close( ftdic )
111 print( 'unable to close ftdi device: %d (%s)' % ( ret, ftdi.get_error_string( ftdic ) ) )
114 print ('device closed')