> Date: Fri, 20 Jan 2012 16:59:03 +0100
> From: [email protected]
> Subject: Re: python ftdi.read_data
> To: [email protected]; [email protected]
>
> Hi,
>
> Sorry, stupid typo - I meant there is NO new_charp() in the git code.
> How is it meant to be used on the git code?
>
> best regards,
> Lazarus
>
> -------- Original-Nachricht --------
> > Datum: Fri, 20 Jan 2012 16:53:53 +0100
> > Von: "Lazarus Longitudis" <[email protected]>
> > An: [email protected]
> > Betreff: Re: python ftdi.read_data
>
> > Hi,
> >
> > On the git code there is now new_charp() python method - at least in the
> > wrapper which got generated on my system.
> >
> > Inside the complete.py example there is no read at all neither a read_pins
> > nor a read_data.
> >
> > On 0.19 there is a new_charp which is OK, but on 0.19 I get an
> > usb_bulk_write error -2 on ftdi.ftdi_write_data
> >
> > So either code base I try I am a little bit stuck....
> >
> >
> > -------- Original-Nachricht --------
> > > Datum: Thu, 19 Jan 2012 14:07:33 -0700
> > > Von: Chris Zeh <[email protected]>
> > > An: [email protected]
> > > Betreff: Re: python ftdi.read_data
> >
> > > Hi Lazarus,
> > >
> > > It's been awhile since I've worked with the libftdi library using
> > > Python, and I think there might have been some SWIG changes since last
> > > I used it, but have a look at this message from the mailinglist:
> > >
> > http://developer.intra2net.com/mailarchive/html/libftdi/2011/msg00154.html
> > >
> > > At that time, you were required to create a pointer wrapper in order
> > > to do reads from the device, like so:
> > > #Read the Pins (Bitbang mode)
> > > pins = ftdi.new_charp()
> > > ret = ftdi.ftdi_read_pins(ftdic,pins)
> > > print ftdi.charp_value(pins)
> > >
> > > I vaguely remember seeing a message from someone who really knew SWIG
> > > well and may have revamped the Python stuff. So, hope that helps, but
> > > it may be completely irrelevant at this time :-)
> > >
> > >
> > > Best regards,
> > > Chris
> > >
> > >
> > >
> > >
> > > On Thu, Jan 19, 2012 at 1:54 PM, Lazarus Longitudis
> > <[email protected]>
> > > wrote:
> > > > Hi,
> > > >
> > > > Maybee I call the function wrong.
> > > > Anyone with an example - the python examples do not include a
> > read...
> > > > If I do:
> > > > new_data =3D ftdi.read_data(ftdic, wrote)
> > > > I get a seg fault....
> > > >
> > > >
> > > > best regards,
> > > > Lazarus
> > > > -------- Original-Nachricht --------
> > > >> Datum: Wed, 18 Jan 2012 14:05:36 +0100
> > > >> Von: "Lazarus Longitudis" <[email protected]>
> > > >> An: [email protected]
> > > >> Betreff: python ftdi.read_data
> > > >
> > > >>
> > > >> Hi,
> > > >>
> > > >> I am working with the current git code.
> > > >> Was trying to use the python wrapper, it works mostly but the
> > > >> ftdi.read_data call seems to be messed up.
> > > >>
> > > >> Python says the function requires only two arguments, the context
> > and
> > > an
> > > >> integer, obviously the target buffer pointer is missing.
> > > >>
> > > >> I have compared the swig generated ftdi_wrap.c against 0.19 and it
> > is
> > > >> clear to see that the parameter parsing is broken here.
> > > >>
> > > >> any ideas?
> > > >>
> > > >> 0.19:
> > > >> if (!PyArg_ParseTuple(args,(char
> > > >> *)"OOO:ftdi_read_data",&obj0,&obj1,&obj2)) SWIG_fail;
> > > >> res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ftdi_context, 0 |
> > > 0 );
> > > >> if (!SWIG_IsOK(res1)) {
> > > >> SWIG_exception_fail(SWIG_ArgError(res1), "in method '"
> > > >> "ftdi_read_data" "', argument " "1"" of type '" "struct ftdi_context
> > > *""'");
> > > >> }
> > > >> arg1 = (struct ftdi_context *)(argp1);
> > > >> res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2);
> > > >> if (!SWIG_IsOK(res2)) {
> > > >> SWIG_exception_fail(SWIG_ArgError(res2), "in method '"
> > > >> "ftdi_read_data" "', argument " "2"" of type '" "unsigned char
> > *""'");
> > > >> }
> > > >> arg2 = (unsigned char *)(buf2);
> > > >> ecode3 = SWIG_AsVal_int(obj2, &val3);
> > > >> if (!SWIG_IsOK(ecode3)) {
> > > >> SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '"
> > > >> "ftdi_read_data" "', argument " "3"" of type '" "int""'");
> > > >> }
> > > >> arg3 = (int)(val3);
> > > >> result = (int)ftdi_read_data(arg1,arg2,arg3);
> > > >> resultobj = SWIG_From_int((int)(result));
> > > >> return resultobj;
> > > >>
> > > >> git:
> > > >> arg2 = &temp2;
> > > >> if (!PyArg_ParseTuple(args,(char *)"OO:read_data",&obj0,&obj1))
> > > >> SWIG_fail;
> > > >> res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ftdi_context, 0 |
> > > 0 );
> > > >> if (!SWIG_IsOK(res1)) {
> > > >> SWIG_exception_fail(SWIG_ArgError(res1), "in method '"
> > > "read_data"
> > > >> "', argument " "1"" of type '" "struct ftdi_context *""'");
> > > >> }
> > > >> arg1 = (struct ftdi_context *)(argp1);
> > > >> ecode3 = SWIG_AsVal_int(obj1, &val3);
> > > >> if (!SWIG_IsOK(ecode3)) {
> > > >> SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '"
> > > "read_data"
> > > >> "', argument " "3"" of type '" "int""'");
> > > >> }
> > > >> arg3 = (int)(val3);
> > > >> result = (int)ftdi_read_data(arg1,arg2,arg3);
> > > >> resultobj = SWIG_From_int((int)(result));
> > > >> if (SWIG_IsTmpObj(res2)) {
> > > >> resultobj = SWIG_Python_AppendOutput(resultobj,
> > > >> SWIG_From_char((*arg2)));
> > > >> } else {
> > > >> int new_flags = SWIG_IsNewObj(res2) ? (SWIG_POINTER_OWN | 0
> > )
> > > : 0 ;
> > > >> resultobj = SWIG_Python_AppendOutput(resultobj,
> > > >> SWIG_NewPointerObj((void*)(arg2), SWIGTYPE_p_unsigned_char,
> > > new_flags));
> > > >> }
> > > >> return resultobj;
> > > >> fail:
> > > >>
> > > >> --
> > > >> Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
> > > >> belohnen Sie mit bis zu 50,- Euro!
> > https://freundschaftswerbung.gmx.de
> > > >>
> > > >> --
> > > >> libftdi - see http://www.intra2net.com/en/developer/libftdi for
> > > details.
> > > >> To unsubscribe send a mail to
> > > [email protected]
> > > >>
> > > >>
> > > >
> > > > --
> > > > Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
> > > > belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de
> > > >
> > > > --
> > > > libftdi - see http://www.intra2net.com/en/developer/libftdi for
> > details.
> > > > To unsubscribe send a mail to
> > > [email protected]
> > > >
> > >
> > > --
> > > libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
> > > To unsubscribe send a mail to
> > [email protected]
> > >
> > >
> >
> > --
> > Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
> > belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de
> >
> > --
> > libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
> > To unsubscribe send a mail to [email protected]
> >
> >
>
> --
> Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
> belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de
>
> --
> libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
> To unsubscribe send a mail to [email protected]
>
Hi,
Here is the patch to wrap correctly read_data from python.
Keep me posted.
M.
--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [email protected]
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 ''