libftdi Archives

Subject: Re: libftdi - Python SWIG & unsigned char *

From: Chris Zeh <chris.w.zeh@xxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Tue, 26 Apr 2011 21:34:27 -0600
Hi Thomas,

Sorry it took me awhile getting around to posting this, but here is
the patch to get the ftdi_read_pins function working in Python:

chris@ubuntu:~/Desktop/libftdi$ git diff
diff --git a/bindings/ftdi.i b/bindings/ftdi.i
index 1fc2a59..ab33d4c 100644
--- a/bindings/ftdi.i
+++ b/bindings/ftdi.i
@@ -3,8 +3,11 @@
 %include "typemaps.i"
 %include "cpointer.i"
 %pointer_functions(unsigned int, uintp);
+%pointer_functions(unsigned char *, ucharp);
+%pointer_functions(char *, charp);

 %typemap(in) unsigned char* = char*;
+
 %ignore ftdi_write_data_async;
 %ignore ftdi_async_complete;


I'm far from an expert in SWIG, but this appears to be working nicely.

Here is a some sample code that I'm using to read the pin state:
def ReadPins():
   pins = ftdi.new_charp()
   ret = ftdi.ftdi_read_pins(ftdic,pins)
   return ftdi.charp_value(pins)

Hope that is helpful for the community.

Thanks for all the great work on this library!

Best regards,
Chris

On Wed, Apr 13, 2011 at 3:54 AM, Thomas Jarosch
<thomas.jarosch@xxxxxxxxxxxxx> wrote:
> On Monday, 7. March 2011 19:36:57 Chris Zeh wrote:
>> I tried adding the following and recompiling:
>> pointer_functions(unsigned char *, ucharp);
>>
>> However, Python still gave me a Type error. I was only able to get the
>> ftdi_read_pin function working when I added and used the following:
>> pointer_functions(char *, charp);
>>
>> Perhaps the following line in the ftdi.i file "%typemap(in) unsigned
>> char* = char*;" is what requires the use of char* instead of uchar* of
>> this?
>
> Does anyone here has some knowledge about SWIG / python and can comment?
>
> @Chris: Please post your modification as a patch.
>
> Thanks,
> Thomas
>
> --
> libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
> To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
>
>

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

Current Thread