ftdi_read_chipid cannot be used from python due to TypeError

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

ftdi_read_chipid cannot be used from python due to TypeError

Flynn Marquardt
Hello,

I tried to read the chipid in python:

import ftdi
ftdic = ftdi.ftdi_context()
ret = ftdi.ftdi_usb_open(ftdic, 0x0403, 0x6001)
chipid = 0
ftdi.ftdi_read_chipid(ftdic, chipid)

results in a TypeError:

TypeError: in method 'ftdi_read_chipid', argument 2 of type 'unsigned
int *'

Without help from Swig it is not possible to create the correct object.

Inserting in bindings/ftdi.i the line

%pointer_functions(unsigned int, uintp);

after %include "cpointer.i" helps (pointer_class could also be used).

With a little modification in python:

import ftdi
ftdic = ftdi.ftdi_context()
ret = ftdi.ftdi_usb_open(ftdic, 0x0403, 0x6001)
chipid = ftdi.new_uintp()
ftdi.ftdi_read_chipid(ftdic, chipid)
hex(ftdi.uintp_value(chipid))

the correct chipid is printed.

It seems (I'm not an expert in swig), that the *OUTPUT directives are
not correct for
ftdi_read_chipid, otherwise this patch woud not be needed.

Flynn


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]  

Reply | Threaded
Open this post in threaded view
|

Re: ftdi_read_chipid cannot be used from python due to TypeError

Thomas Jarosch
Hello Flynn,

On Saturday, 10. July 2010 17:06:35 Flynn Marquardt wrote:

> I tried to read the chipid in python:
>
> import ftdi
> ftdic = ftdi.ftdi_context()
> ret = ftdi.ftdi_usb_open(ftdic, 0x0403, 0x6001)
> chipid = 0
> ftdi.ftdi_read_chipid(ftdic, chipid)
>
> results in a TypeError:
>
> TypeError: in method 'ftdi_read_chipid', argument 2 of type 'unsigned
> int *'
>
> Without help from Swig it is not possible to create the correct object.
>
> Inserting in bindings/ftdi.i the line
>
> %pointer_functions(unsigned int, uintp);
>
> after %include "cpointer.i" helps (pointer_class could also be used).
>
> With a little modification in python:
>
> import ftdi
> ftdic = ftdi.ftdi_context()
> ret = ftdi.ftdi_usb_open(ftdic, 0x0403, 0x6001)
> chipid = ftdi.new_uintp()
> ftdi.ftdi_read_chipid(ftdic, chipid)
> hex(ftdi.uintp_value(chipid))
>
> the correct chipid is printed.
>
> It seems (I'm not an expert in swig), that the *OUTPUT directives are
> not correct for
> ftdi_read_chipid, otherwise this patch woud not be needed.

Thanks for the info. Care to send a proper patch
as I'm not too familiar with swig?

Cheers,
Thomas

--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]  

Reply | Threaded
Open this post in threaded view
|

Re: ftdi_read_chipid cannot be used from python due to TypeError

Flynn Marquardt
Am 13.07.2010 17:27, schrieb Thomas Jarosch:

> Hello Flynn,
>
> On Saturday, 10. July 2010 17:06:35 Flynn Marquardt wrote:
>  
>> I tried to read the chipid in python:
>>
>> import ftdi
>> ftdic = ftdi.ftdi_context()
>> ret = ftdi.ftdi_usb_open(ftdic, 0x0403, 0x6001)
>> chipid = 0
>> ftdi.ftdi_read_chipid(ftdic, chipid)
>>
>> results in a TypeError:
>>
>> TypeError: in method 'ftdi_read_chipid', argument 2 of type 'unsigned
>> int *'
>>
>> Without help from Swig it is not possible to create the correct object.
>>
>> Inserting in bindings/ftdi.i the line
>>
>> %pointer_functions(unsigned int, uintp);
>>
>> after %include "cpointer.i" helps (pointer_class could also be used).
>>
>> With a little modification in python:
>>
>> import ftdi
>> ftdic = ftdi.ftdi_context()
>> ret = ftdi.ftdi_usb_open(ftdic, 0x0403, 0x6001)
>> chipid = ftdi.new_uintp()
>> ftdi.ftdi_read_chipid(ftdic, chipid)
>> hex(ftdi.uintp_value(chipid))
>>
>> the correct chipid is printed.
>>
>> It seems (I'm not an expert in swig), that the *OUTPUT directives are
>> not correct for
>> ftdi_read_chipid, otherwise this patch woud not be needed.
>>    
> Thanks for the info. Care to send a proper patch
> as I'm not too familiar with swig?
>
> Cheers,
> Thomas
>  
Here it is, it's only a oneliner:

--- libftdi-0.17-orig/bindings/ftdi.i    2009-04-07 18:58:14.000000000 +0200
+++ libftdi-0.17/bindings/ftdi.i    2010-07-10 16:49:35.981446841 +0200
@@ -2,6 +2,8 @@
 %module ftdi
 %include "typemaps.i"
 %include "cpointer.i"
+%pointer_functions(unsigned int, uintp);
+
 %typemap(in) unsigned char* = char*;
 %ignore ftdi_write_data_async;
 %ignore ftdi_async_complete;

and should apply clean also to version 0.18.

Maybe the example code

import ftdi
ftdic = ftdi.ftdi_context()
ret = ftdi.ftdi_usb_open(ftdic, 0x0403, 0x6001)
chipid = ftdi.new_uintp()
ftdi.ftdi_read_chipid(ftdic, chipid)
hex(ftdi.uintp_value(chipid))

should be put in a README, because the method initializing an unsigned int
pointer (chipid = ftdi.new_uintp()) is not very common to python
programmers.

Flynn


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]