Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Lpt Port And Python, Using SWIG to build python wrappers
ignite
post Nov 17 2006, 04:28 PM
Post #1


Member [ Level 1 ]
Group Icon

Group: Members
Posts: 34
Joined: 17-November 06
Member No.: 17,334



Some time ago i was asked to program device, connected to PC parallel port. Main program was written in python.
First of all i found nice C library which perform the task: parapin. Building and installation is straightforward, so i don't stop on this.
Then i start to build python wrapper. With SWIG its easy.
First create file parapin.i, here is head of it:
QUOTE
%module parapin
%{
#include <parapin.h>
%}

int pin_init_user(int lp_base);
#define LPT1 0x378
#define LPT2 0x278

void set_pin(int pins);
void clear_pin(int pins);
void change_pin(int pins, int state);
#define LP_CLEAR 0 /* for change_pin */
#define LP_SET 1 /* for change_pin */


Actually i wrote only first 3 line, rest is copypasted from library header paragui.h. I take only those functions and definitions, which i need for my task.

Then i wrote make config file Makefile:
QUOTE
all: _parapin.so

_parapin.so: parapin_wrap.o
gcc -o _parapin.so -shared parapin_wrap.o -lparapin

parapin_wrap.o: parapin_wrap.c
gcc -fpic -c parapin_wrap.c -I/usr/include/python2.4/ -I/usr/local/include

parapin_wrap.c: parapin.i
swig -python parapin.i



After running make utility i had ready for use python module parapin.py with functions set_pin, clear_pin and so on.

Not so hard, isnt't it?
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Python(5)
  2. Python (win32)(1)
  3. [python]got A Problem In My Little Program(1)
  4. Python Versus Java ?(4)
  5. Prove Yourself As A Python Coder - Challenge Site(4)
  6. Pagerank Checksum Algo For Python(0)
  7. Localizing Python(1)
  8. Python Mysqldb Threading(0)


 



- Lo-Fi Version Time is now: 5th September 2008 - 12:50 PM