[Pythonmac-SIG] Passing tuples to C
Greg Hoover
ghoover19 at cox.net
Fri Mar 5 04:24:32 EST 2004
I'm trying to pass multiple values to a C function. As far as I know,
this is done using tuples. Is there anything special required on the
python side to pass this tuple?
This is the C function being called. It is in a module called serial.
So I've tried calling serial.serial_write((1, "q"))
serial.serial_write(1, "q") serial.serial_write([1, "q"]) ---
all of which fail. Several report that they require integer arguments,
other errors specify that only 1 argument is accepted.
static PyObject *
serial_write(PyObject *self, PyObject *args)
{
int numCharsToSend;
char *writeBuffer;
if(serialPortFileDescriptor < 0)
return Py_BuildValue("i", -1);
// Python provides storage for string
if(!PyArg_ParseTuple(args, "is", &numCharsToSend, &writeBuffer))
return NULL;
write(serialPortFileDescriptor, writeBuffer, numCharsToSend);
return Py_BuildValue("i", numCharsToSend);
}
Thanks in advance.
--Greg Hoover
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 1643 bytes
Desc: not available
Url : http://mail.python.org/pipermail/pythonmac-sig/attachments/20040305/be76c29f/attachment.bin
More information about the Pythonmac-SIG
mailing list