The branch, master has been updated
via 953a958ce0d7c74864c0fafe3a8644c400734ebf (commit)
from e15345abbb5bfc4492a93551bc030e530f43f179 (commit)
- Log -----------------------------------------------------------------
commit 953a958ce0d7c74864c0fafe3a8644c400734ebf
Author: Michel Zou <xantares09@xxxxxxxxxxx>
Date: Sat Feb 9 17:49:03 2013 +0100
Fixed read_pins argout typemap being sensitive to encoding.
-----------------------------------------------------------------------
Summary of changes:
bindings/ftdi1.i | 8 +++++---
examples/python/complete.py | 32 +++++++++++++++++---------------
2 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/bindings/ftdi1.i b/bindings/ftdi1.i
index ba9aca2..1e820dd 100644
--- a/bindings/ftdi1.i
+++ b/bindings/ftdi1.i
@@ -79,11 +79,13 @@ PyObject* convertString( const char *v, Py_ssize_t len )
"read_pins(context) -> (return_code, pins)"
%enddef
%feature("autodoc", ftdi_read_pins_docstring) ftdi_read_pins;
-%apply char *OUTPUT { unsigned char *pins };
+%typemap(in,numinputs=0) unsigned char *pins ($*ltype temp) %{ $1 = &temp; %}
+%typemap(argout) (unsigned char *pins) %{ $result =
SWIG_Python_AppendOutput($result, convertString((char*)$1, 1)); %}
int ftdi_read_pins(struct ftdi_context *ftdi, unsigned char *pins);
%clear unsigned char *pins;
-%apply char *OUTPUT { unsigned char *latency };
+%typemap(in,numinputs=0) unsigned char *latency ($*ltype temp) %{ $1 = &temp;
%}
+%typemap(argout) (unsigned char *latency) %{ $result =
SWIG_Python_AppendOutput($result, convertString((char*)$1, 1)); %}
int ftdi_get_latency_timer(struct ftdi_context *ftdi, unsigned char
*latency);
%clear unsigned char *latency;
@@ -114,7 +116,7 @@ PyObject* convertString( const char *v, Py_ssize_t len )
%feature("autodoc", ftdi_read_eeprom_docstring) ftdi_read_eeprom;
%define ftdi_read_chipid_docstring
-"read_pins(context) -> (return_code, chipid)"
+"ftdi_read_chipid(context) -> (return_code, chipid)"
%enddef
%feature("autodoc", ftdi_read_chipid_docstring) ftdi_read_chipid;
%apply int *OUTPUT { unsigned int *chipid };
diff --git a/examples/python/complete.py b/examples/python/complete.py
index 239188c..afa59fa 100644
--- a/examples/python/complete.py
+++ b/examples/python/complete.py
@@ -13,10 +13,13 @@ import sys
import ftdi1 as ftdi
import time
+# version
+print ( 'version: %s\n' % ftdi.__version__ )
+
# initialize
ftdic = ftdi.new()
if ftdic == 0:
- print( 'new failed: %d', ret )
+ print( 'new failed: %d' % ret )
os._exit( 1 )
# try to list ftdi devices 0x6010 or 0x6001
@@ -27,7 +30,7 @@ if ret <= 0:
if ret < 0:
print( 'ftdi_usb_find_all failed: %d (%s)' % ( ret, ftdi.get_error_string(
ftdic ) ) )
os._exit( 1 )
-print( 'Number of FTDI devices found: %d\n' % ret )
+print( 'devices: %d' % ret )
curnode = devlist
i = 0
while( curnode != None ):
@@ -35,7 +38,7 @@ while( curnode != None ):
if ret < 0:
print( 'ftdi_usb_get_strings failed: %d (%s)' % ( ret,
ftdi.get_error_string( ftdic ) ) )
os._exit( 1 )
- print( 'Device #%d: manufacturer="%s" description="%s" serial="%s"\n' % (
i, manufacturer, description, serial ) )
+ print( '#%d: manufacturer="%s" description="%s" serial="%s"\n' % ( i,
manufacturer, description, serial ) )
curnode = curnode.next
i += 1
@@ -67,18 +70,19 @@ print( '' )
# read pins
-# FIXME: read_pins fails with python3, so I disabled it for now
-# tested on ubuntu 12.04 ( python3.2.3 / swig 2.0.4 )
-if (sys.version_info[0]<3):
- ret, pins = ftdi.read_pins( ftdic )
- if ( ret == 0 ):
- print( 'pins: %02x' % ord( pins[0] ) )
+ret, pins = ftdi.read_pins( ftdic )
+if ( ret == 0 ):
+ if sys.version_info[0] < 3: # python 2
+ pins = ord( pins )
+ else:
+ pins = pins[0]
+ print( 'pins: 0x%x' % pins )
# read chip id
ret, chipid = ftdi.read_chipid( ftdic )
if (ret==0):
- print( 'chip id: %X\n' % chipid )
+ print( 'chip id: %x\n' % chipid )
# read eeprom
@@ -93,15 +97,13 @@ size = 128
ret, eeprom = ftdi.get_eeprom_buf ( ftdic, size )
if ( ret == 0 ):
for i in range( size ):
- if isinstance(eeprom[i], str):
- octet = ord( eeprom[i] ) # python2
- else:
- octet = eeprom[i] # python3
+ octet = eeprom[i]
+ if sys.version_info[0] < 3: # python 2
+ octet = ord( octet )
sys.stdout.write( '%02x ' % octet )
if ( i % 8 == 7 ):
print( '' )
print( '' )
-
# close usb
ret = ftdi.usb_close( ftdic )
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
|