Drop 64bit lib suffix on debian systems
[libftdi] / examples / python / complete.py
CommitLineData
4c5afeb9
MZ
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""Python example program.
5
6Complete program to demonstrate the usage
7of the swig generated python wrapper
8
9You need to build and install the wrapper first"""
10
11import os
12import ftdi
13import time
14
15# initialize
16ftdic = ftdi.new()
17if ftdic == 0:
18 print 'new failed: %d', ret
19 os._exit( 1 )
20
21# list all devices
22devlist = ftdi.new_device_listpp()
23ret = ftdi.usb_find_all( ftdic, devlist, 0x0403, 0x6001 )
24if ret < 0:
25 print 'ftdi_usb_find_all failed: %d (%s)' % ( ret, ftdi.get_error_string( ftdic ) )
26 os._exit( 1 )
27print 'Number of FTDI devices found: %d\n' % ret
28count = ret
29curdev = devlist
30for i in range( count ):
31 print 'Checking device: %d' % i
32
33 curnode = ftdi.device_listpp_value( curdev )
34 ret, manufacturer, description, serial = ftdi.usb_get_strings( ftdic, curnode.dev, 128, 128, 128 )
35 if ret < 0:
36 print 'ftdi_usb_get_strings failed: %d (%s)' % ( ret, ftdi.get_error_string( ftdic ) )
37 os._exit( 1 )
38 print 'Manufacturer: %s, Description: %s, Serial: %s\n' % ( manufacturer, description, serial )
39 ftdi.device_listpp_assign( curdev, curnode.next )
40
41# open usb
42ret = ftdi.usb_open( ftdic, 0x0403, 0x6001 )
43if ret < 0:
44 print 'unable to open ftdi device: %d (%s)' % ( ret, ftdi.get_error_string( ftdic ) )
45 os._exit( 1 )
46
47
48# bitbang
49ret = ftdi.set_bitmode( ftdic, 0xff, ftdi.BITMODE_BITBANG )
50if ret < 0:
51 print 'Cannot enable bitbang'
52 os._exit( 1 )
53print 'turning everything on'
54ftdi.write_data( ftdic, chr(0xff), 1 )
55time.sleep( 1 )
56print 'turning everything off\n'
57ftdi.write_data( ftdic, chr(0x00), 1 )
58time.sleep( 1 )
59for i in range( 8 ):
60 print 'enabling bit', i
61 val = 2**i
62 ftdi.write_data( ftdic, chr(val), 1 )
63 time.sleep ( 1 )
64ftdi.disable_bitbang( ftdic )
65print ''
66
67
68# read chip id
69ret, chipid = ftdi.read_chipid( ftdic )
70print 'FDTI chip id: %X\n' % chipid
71
72
73# read eeprom
74eeprom_addr = 1
75ret, eeprom_val = ftdi.read_eeprom_location( ftdic, eeprom_addr )
76print 'eeprom @ %d: 0x%04x\n' % ( eeprom_addr, eeprom_val )
77
78print 'eeprom:'
79ret=ftdi.read_eeprom( ftdic )
80ret=ftdi.eeprom_decode( ftdic ,1)
81
82
83# close usb
84ret = ftdi.usb_close( ftdic )
85if ret < 0:
86 print 'unable to close ftdi device: %d (%s)' % ( ret, ftdi.get_error_string( ftdic ) )
87 os._exit( 1 )
88ftdi.free( ftdic )