I am trying to create a script in python that sends data through a parallel port. I create my own module in C language.
The problem is that when trying to execute my module python crashes. No errors, no data, nothing. It just closes.
This is my module:
#include <Python.h> #include <sys/io.h> #define BaseAddr 0x378 /*---------------------------------------------------------------------------------- Este es un mรณdulo destinado a controlar el puerto paralelo. Probablemente tenga que ser ejecutado como administrador. Created by markmb ------------------------------------------------------------------------------------*/ static PyObject * paralelo(PyObject *self, PyObject *args){ int pin; ioperm(BaseAddr,3,1); if (!PyArg_ParseTuple(args, "i", &pin)) return NULL; outb(pin,BaseAddr); ioperm(BaseAddr,3,0); return 1 } PyMethodDef methods[] = { {"paralelo", paralelo, METH_VARARGS, "Sends data through a parallel port"}, {NULL, NULL, 0, NULL} }; PyMODINIT_FUNC initparalelo(void){ (void) Py_InitModule("paralelo", methods); }
(It works without any python mess) I will compile it through distutils, and then, in the terminal (using xubuntu), I will put:
import paralelo while True: paralelo.paralelo(255)
And here it exits python, it puts "markmb @ ..."
Thanks in advance!
source share