|
|
|
|
![]() ![]() |
Nov 17 2006, 04:28 PM
Post
#1
|
|
|
Member [ Level 1 ] 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? |
|
|
|
![]() ![]() |
Similar Topics
| Topics | Topics | |
|---|---|---|
|
|
|
|
Lo-Fi Version | Time is now: 5th September 2008 - 12:50 PM |