libftdi Archives

Subject: Re: Python Bindings

From: James Snyder <jbsnyder@xxxxxxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Mon, 4 May 2009 15:05:16 -0500


On May 4, 2009, at 2:31 PM, Thomas Jarosch wrote:

Hi James,

James Snyder wrote:
I'm wondering if anyone is using the python bindings yet?

The python bindings are pretty new, so I guess you were the first
one to try them besides the original author.

OK.  That's what I figured.


I've attempted to play around with them and found that at least with the
SWIG I've got I had to rearrange a few things to get them to compile
properly.  There are also some macros provided by cstring.i that make
using at least the read function a lot more python-like.

Which version of SWIG are you using?

Version: 1.3.39

That particular issue seemed to stem from the order in which the other header files were included in the ftdi.i file.


Feel free to send a patch for the cstring.i stuff, though I can't really review it myself as I hardly speak python. Maybe I can bug Tarek to join
the list as our current email policy discards posts from non-members.

There are a few things that would make these a lot more "pythonic" and they shouldn't be too hard since the underlying API lends itself well to a class instance w/ methods usage style.

I've not made a huge number of changes, but I have adjusted things a bit so that, for example, you needn't create a buffer object in python to contain what what you get back from a read call. I can submit patches for these things. To nail down the rest of it (class/methods usage style) might take a little more effort though. I don't use all aspects of libftdi so I may not know the best way to expose functionality in python.


Also, It seems like many of these functions are ripe to become methods
for a class that deals with the context struct.  I'm not sure of the
best way to do this since I'm not a SWIG expert.

I didn't even know about SWIG before the patch was sent :-)

I've used it a little bit, but I'm not hugely familiar with best practices for bindings in situations like the one with libftdi.

What I would like is to get it working as a drop-in replacement for pyserial with the added functionality that libftdi provides. This would save me a fair amount of time and effort because I hate having to use some code that uses the serial port kernel driver and then sometimes unload that and use things that talk to it from userspace since sometimes the module won't unload or things get weird after a few load/unload cycles.

--
James Snyder
Biomedical Engineering
Northwestern University
jbsnyder@xxxxxxxxxxxxxx
http://fanplastic.org/key.txt
ph: (847) 448-0386

Attachment: PGP.sig
Description: This is a digitally signed message part

Current Thread