libftdi-git Archives

Subject: A library to talk to FTDI chips branch, master, updated. v0.17-305-g50d77f8

From: libftdi-git@xxxxxxxxxxxxxxxxxxxxxxx
To: libftdi-git@xxxxxxxxxxxxxxxxxxxxxxx
Date: Fri, 3 Feb 2012 16:37:50 +0100 (CET)
The branch, master has been updated
       via  50d77f8f2e8f484106bf254a201b57b4c1572be7 (commit)
      from  9330b1205d8889de6586606228bfb5774491315b (commit)


- Log -----------------------------------------------------------------
commit 50d77f8f2e8f484106bf254a201b57b4c1572be7
Author: Michel Zou <xantares09@xxxxxxxxxxx>
Date:   Fri Feb 3 16:36:04 2012 +0100

    Python wrapper update
    
    - Properly wrap ftdi_read_pins / ftdi_read_data
    - Add example invocation of the read function to complete.py

-----------------------------------------------------------------------

Summary of changes:
 bindings/ftdi.i             |   15 ++++++---------
 examples/python/complete.py |   13 +++++++++++--
 2 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/bindings/ftdi.i b/bindings/ftdi.i
index 54a45e6..42c2646 100644
--- a/bindings/ftdi.i
+++ b/bindings/ftdi.i
@@ -38,9 +38,10 @@
 %clear char * manufacturer, char * description, char * serial;
 %clear int mnf_len, int desc_len, int serial_len;
 
-%apply char *OUTPUT { unsigned char *buf };
+%typemap(in,numinputs=1) (unsigned char *buf, int size) %{ $2 = 
PyInt_AsLong($input);$1 = (unsigned char*)malloc($2*sizeof(char)); %}
+%typemap(argout) (unsigned char *buf, int size) %{ if(result<0) $2=0; $result 
= SWIG_Python_AppendOutput($result, PyString_FromStringAndSize((char*)$1, $2)); 
free($1); %}
     int ftdi_read_data(struct ftdi_context *ftdi, unsigned char *buf, int 
size);
-%clear unsigned char *buf;
+%clear (unsigned char *buf, int size);
 
 %apply int *OUTPUT { unsigned int *chunksize };
     int ftdi_read_data_get_chunksize(struct ftdi_context *ftdi, unsigned int 
*chunksize);
@@ -63,14 +64,10 @@
     int ftdi_get_eeprom_value(struct ftdi_context *ftdi, enum 
ftdi_eeprom_value value_name, int* value);
 %clear int* value;
 
-%apply char *OUTPUT { unsigned char *buf };
-%typemap(in,numinputs=0) unsigned char *buf(char temp[FTDI_MAX_EEPROM_SIZE]) 
%{ $1 = ($1_ltype) temp; %}
-%typemap(freearg,match="in") unsigned char *buf "";
-%typemap(argout,fragment="SWIG_FromCharPtrAndSize") unsigned char *buf %{ 
$result = SWIG_Python_AppendOutput($result, 
SWIG_FromCharPtrAndSize((char*)$1,FTDI_MAX_EEPROM_SIZE)); %}
-%typemap(default,noblock=1) int size { $1 = 128; }
+%typemap(in,numinputs=1) (unsigned char *buf, int size) %{ $2 = 
PyInt_AsLong($input);$1 = (unsigned char*)malloc($2*sizeof(char)); %}
+%typemap(argout) (unsigned char *buf, int size) %{ if(result<0) $2=0; $result 
= SWIG_Python_AppendOutput($result, PyString_FromStringAndSize((char*)$1, $2)); 
free($1); %}
     int ftdi_get_eeprom_buf(struct ftdi_context *ftdi, unsigned char * buf, 
int size);
-%clear unsigned char *buf;
-%clear int size;
+%clear (unsigned char *buf, int size);
 
 %apply short *OUTPUT { unsigned short *eeprom_val };
     int ftdi_read_eeprom_location (struct ftdi_context *ftdi, int eeprom_addr, 
unsigned short *eeprom_val);
diff --git a/examples/python/complete.py b/examples/python/complete.py
index cf60d4d..cee917d 100644
--- a/examples/python/complete.py
+++ b/examples/python/complete.py
@@ -63,6 +63,14 @@ ftdi.disable_bitbang( ftdic )
 print ''
 
 
+# read pins
+ret, pins = ftdi.read_pins( ftdic )
+print 'pins:',
+if ( ret == 0 ):
+    print '%02x' % ord( pins[0] )
+print ''    
+
+
 # read chip id
 ret, chipid = ftdi.read_chipid( ftdic )
 print 'FDTI chip id: %X\n' % chipid
@@ -76,9 +84,10 @@ if (ret==0):
 
 print 'complete eeprom:'
 ret = ftdi.read_eeprom( ftdic )
-ret, eeprom = ftdi.get_eeprom_buf ( ftdic )
+size = 128
+ret, eeprom = ftdi.get_eeprom_buf ( ftdic, size )
 if ( ret == 0 ):
-    for i in range( 128 ):
+    for i in range( size ):
         print '%02x' % ord( eeprom[i] ),
         if ( i % 8 == 7 ):
             print ''


hooks/post-receive
-- 
A library to talk to FTDI chips

--
libftdi-git - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi-git+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx   

Current Thread
  • A library to talk to FTDI chips branch, master, updated. v0.17-305-g50d77f8, libftdi-git <=